Implement suspend, resume and cancel the download.
The DownloadAction can now be suspended and resumed, using the existing
libcurl hooks to pause the download. For canceling an ongoing update,
this patch leverages the existing StopProcessing method previously used
in unittest only with a slight change: Stopping the ActionProcessor
also removes all the pending actions.
The LibcurlHttpFetcher Pause/Unpause methods where improved to support
(not crash) if paused in circumstances where there isn't a current
connection, like when waiting for the proxy resolver and when trying to
reconnect.
Finally, the value of ongoing_update_ is now properly set in the
UpdateAttempter.
Bug: 27047026
TEST=Tested suspending, resuming and canceling the update on a device.
TEST=Added unittest for the Pause/Unpause logic.
Change-Id: I0df1e1a8cf70a3b736bc9cd4899d37813f381b94
diff --git a/payload_consumer/download_action.h b/payload_consumer/download_action.h
index d000c67..fc32068 100644
--- a/payload_consumer/download_action.h
+++ b/payload_consumer/download_action.h
@@ -68,6 +68,9 @@
class DownloadAction : public InstallPlanAction,
public HttpFetcherDelegate {
public:
+ // Debugging/logging
+ static std::string StaticType() { return "DownloadAction"; }
+
// Takes ownership of the passed in HttpFetcher. Useful for testing.
// A good calling pattern is:
// DownloadAction(prefs, boot_contol, hardware, system_state,
@@ -78,8 +81,13 @@
SystemState* system_state,
HttpFetcher* http_fetcher);
~DownloadAction() override;
+
+ // InstallPlanAction overrides.
void PerformAction() override;
+ void SuspendAction() override;
+ void ResumeAction() override;
void TerminateProcessing() override;
+ std::string Type() const override { return StaticType(); }
// Testing
void SetTestFileWriter(FileWriter* writer) {
@@ -88,10 +96,6 @@
int GetHTTPResponseCode() { return http_fetcher_->http_response_code(); }
- // Debugging/logging
- static std::string StaticType() { return "DownloadAction"; }
- std::string Type() const override { return StaticType(); }
-
// HttpFetcherDelegate methods (see http_fetcher.h)
void ReceivedBytes(HttpFetcher* fetcher,
const void* bytes, size_t length) override;