diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2020-12-14 14:50:40 -0500 |
---|---|---|
committer | Kelvin Zhang <zhangkelvin@google.com> | 2021-01-05 10:07:54 -0500 |
commit | 22b62e4133bd7ea028f04409e9cb0ec09d45e8db (patch) | |
tree | a826e1ed07d5a7036985cce6d36a3ebdb86db121 | |
parent | bb8e999e212f339a61a55dc91d7572c6b993e852 (diff) |
Remove two pointers of delta performer
Test: treehugger
Bug: 176087961
Change-Id: I00fa7b5ba508a31162a986f50034ceeb34becbfd
-rw-r--r-- | common/download_action.h | 9 | ||||
-rw-r--r-- | download_action.cc | 29 | ||||
-rw-r--r-- | download_action_android_unittest.cc | 18 |
3 files changed, 23 insertions, 33 deletions
diff --git a/common/download_action.h b/common/download_action.h index caa5a7b7..7b496b17 100644 --- a/common/download_action.h +++ b/common/download_action.h @@ -23,6 +23,7 @@ #include <memory> #include <string> +#include <utility> #include "update_engine/common/action.h" #include "update_engine/common/boot_control_interface.h" @@ -87,7 +88,9 @@ class DownloadAction : public InstallPlanAction, public HttpFetcherDelegate { std::string Type() const override { return StaticType(); } // Testing - void SetTestFileWriter(DeltaPerformer* writer) { writer_ = writer; } + void SetTestFileWriter(std::unique_ptr<DeltaPerformer> writer) { + delta_performer_ = std::move(writer); + } int GetHTTPResponseCode() { return http_fetcher_->http_response_code(); } @@ -130,10 +133,6 @@ class DownloadAction : public InstallPlanAction, public HttpFetcherDelegate { // update. bool interactive_; - // The FileWriter that downloaded data should be written to. It will - // either point to a writer for unittest or *delta_performer_. - DeltaPerformer* writer_; - std::unique_ptr<DeltaPerformer> delta_performer_; // Used by TransferTerminated to figure if this action terminated itself or diff --git a/download_action.cc b/download_action.cc index 04562984..62a84230 100644 --- a/download_action.cc +++ b/download_action.cc @@ -47,7 +47,6 @@ DownloadAction::DownloadAction(PrefsInterface* prefs, hardware_(hardware), http_fetcher_(new MultiRangeHttpFetcher(http_fetcher)), interactive_(interactive), - writer_(nullptr), code_(ErrorCode::kSuccess), delegate_(nullptr) {} @@ -105,14 +104,11 @@ bool DownloadAction::LoadCachedManifest(int64_t manifest_size) { return false; } - if (writer_ && writer_ != delta_performer_.get()) { - LOG(INFO) << "Using writer for test."; - } ErrorCode error; const bool success = - writer_->Write( + delta_performer_->Write( cached_manifest_bytes.data(), cached_manifest_bytes.size(), &error) && - writer_->IsManifestValid(); + delta_performer_->IsManifestValid(); if (success) { LOG(INFO) << "Successfully parsed cached manifest"; } else { @@ -127,7 +123,7 @@ void DownloadAction::StartDownloading() { download_active_ = true; http_fetcher_->ClearRanges(); - if (writer_ && writer_ != delta_performer_.get()) { + if (delta_performer_ != nullptr) { LOG(INFO) << "Using writer for test."; } else { delta_performer_.reset(new DeltaPerformer(prefs_, @@ -137,7 +133,6 @@ void DownloadAction::StartDownloading() { &install_plan_, payload_, interactive_)); - writer_ = delta_performer_.get(); } if (install_plan_.is_resume && @@ -159,7 +154,6 @@ void DownloadAction::StartDownloading() { &install_plan_, payload_, interactive_); - writer_ = delta_performer_.get(); } http_fetcher_->AddRange(base_offset_, manifest_metadata_size + manifest_signature_size); @@ -200,9 +194,9 @@ void DownloadAction::ResumeAction() { } void DownloadAction::TerminateProcessing() { - if (writer_) { - writer_->Close(); - writer_ = nullptr; + if (delta_performer_) { + delta_performer_->Close(); + delta_performer_.reset(); } download_active_ = false; // Terminates the transfer. The action is terminated, if necessary, when the @@ -223,7 +217,7 @@ bool DownloadAction::ReceivedBytes(HttpFetcher* fetcher, if (delegate_ && download_active_) { delegate_->BytesReceived(length, bytes_downloaded_total, bytes_total_); } - if (writer_ && !writer_->Write(bytes, length, &code_)) { + if (delta_performer_ && !delta_performer_->Write(bytes, length, &code_)) { if (code_ != ErrorCode::kSuccess) { LOG(ERROR) << "Error " << utils::ErrorCodeToString(code_) << " (" << code_ << ") in DeltaPerformer's Write method when " @@ -240,12 +234,9 @@ bool DownloadAction::ReceivedBytes(HttpFetcher* fetcher, } void DownloadAction::TransferComplete(HttpFetcher* fetcher, bool successful) { - if (writer_) { - LOG_IF(WARNING, writer_->Close() != 0) << "Error closing the writer."; - if (delta_performer_.get() == writer_) { - // no delta_performer_ in tests, so leave the test writer in place - writer_ = nullptr; - } + if (delta_performer_) { + LOG_IF(WARNING, delta_performer_->Close() != 0) + << "Error closing the writer."; } download_active_ = false; ErrorCode code = diff --git a/download_action_android_unittest.cc b/download_action_android_unittest.cc index c1ad9c23..b17550bf 100644 --- a/download_action_android_unittest.cc +++ b/download_action_android_unittest.cc @@ -156,15 +156,15 @@ TEST_F(DownloadActionTest, CacheManifestValid) { &prefs, &boot_control, nullptr, http_fetcher, false /* interactive */); FakeHardware hardware; - DeltaPerformer delta_performer(&prefs, - &boot_control, - &hardware, - nullptr, - &install_plan, - &payload, - false); - delta_performer.set_public_key_path(kUnittestPublicKeyPath); - download_action->SetTestFileWriter(&delta_performer); + auto delta_performer = std::make_unique<DeltaPerformer>(&prefs, + &boot_control, + &hardware, + nullptr, + &install_plan, + &payload, + false); + delta_performer->set_public_key_path(kUnittestPublicKeyPath); + download_action->SetTestFileWriter(std::move(delta_performer)); download_action->set_in_pipe(action_pipe); MockActionProcessor mock_processor; download_action->SetProcessor(&mock_processor); |