| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2011 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 16 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/common/download_action.h" | 
| Alex Deymo | aab50e3 | 2014-11-10 19:55:35 -0800 | [diff] [blame] | 18 |  | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 19 | #include <errno.h> | 
| Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 20 |  | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 21 | #include <algorithm> | 
| Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 22 | #include <string> | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 23 |  | 
| Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 24 | #include <base/files/file_path.h> | 
| Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 25 | #include <base/metrics/statistics_recorder.h> | 
| Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 26 | #include <base/strings/stringprintf.h> | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 27 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 28 | #include "update_engine/common/boot_control_interface.h" | 
| Alex Deymo | ed9cc18 | 2016-06-15 16:19:29 -0700 | [diff] [blame] | 29 | #include "update_engine/common/error_code_utils.h" | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 30 | #include "update_engine/common/multi_range_http_fetcher.h" | 
| Kelvin Zhang | 5c1451f | 2020-12-02 17:01:54 -0500 | [diff] [blame] | 31 | #include "update_engine/common/prefs_interface.h" | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 32 | #include "update_engine/common/utils.h" | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 33 |  | 
| Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 34 | using base::FilePath; | 
| Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 35 | using std::string; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 36 |  | 
|  | 37 | namespace chromeos_update_engine { | 
|  | 38 |  | 
| Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 39 | DownloadAction::DownloadAction(PrefsInterface* prefs, | 
| Alex Deymo | 1b3556c | 2016-02-03 09:54:02 -0800 | [diff] [blame] | 40 | BootControlInterface* boot_control, | 
|  | 41 | HardwareInterface* hardware, | 
| Amin Hassani | 7ecda26 | 2017-07-11 17:10:50 -0700 | [diff] [blame] | 42 | HttpFetcher* http_fetcher, | 
| Kelvin Zhang | 1304fe7 | 2021-10-06 19:12:12 -0700 | [diff] [blame] | 43 | bool interactive, | 
|  | 44 | std::string update_certificates_path) | 
| Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 45 | : prefs_(prefs), | 
| Alex Deymo | 1b3556c | 2016-02-03 09:54:02 -0800 | [diff] [blame] | 46 | boot_control_(boot_control), | 
|  | 47 | hardware_(hardware), | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 48 | http_fetcher_(new MultiRangeHttpFetcher(http_fetcher)), | 
| Amin Hassani | ed37d68 | 2018-04-06 13:22:00 -0700 | [diff] [blame] | 49 | interactive_(interactive), | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 50 | code_(ErrorCode::kSuccess), | 
| Kelvin Zhang | 1304fe7 | 2021-10-06 19:12:12 -0700 | [diff] [blame] | 51 | delegate_(nullptr), | 
|  | 52 | update_certificates_path_(std::move(update_certificates_path)) {} | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 53 |  | 
|  | 54 | DownloadAction::~DownloadAction() {} | 
|  | 55 |  | 
|  | 56 | void DownloadAction::PerformAction() { | 
|  | 57 | http_fetcher_->set_delegate(this); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 58 |  | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 59 | // Get the InstallPlan and read it | 
|  | 60 | CHECK(HasInputObject()); | 
| Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 61 | install_plan_ = GetInputObject(); | 
| Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 62 | install_plan_.Dump(); | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 63 |  | 
|  | 64 | bytes_received_ = 0; | 
| Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 65 | bytes_received_previous_payloads_ = 0; | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 66 | bytes_total_ = 0; | 
|  | 67 | for (const auto& payload : install_plan_.payloads) | 
|  | 68 | bytes_total_ += payload.size; | 
|  | 69 |  | 
|  | 70 | if (install_plan_.is_resume) { | 
|  | 71 | int64_t payload_index = 0; | 
|  | 72 | if (prefs_->GetInt64(kPrefsUpdateStatePayloadIndex, &payload_index) && | 
|  | 73 | static_cast<size_t>(payload_index) < install_plan_.payloads.size()) { | 
|  | 74 | // Save the index for the resume payload before downloading any previous | 
|  | 75 | // payload, otherwise it will be overwritten. | 
|  | 76 | resume_payload_index_ = payload_index; | 
|  | 77 | for (int i = 0; i < payload_index; i++) | 
|  | 78 | install_plan_.payloads[i].already_applied = true; | 
|  | 79 | } | 
|  | 80 | } | 
| Kelvin Zhang | 5c1451f | 2020-12-02 17:01:54 -0500 | [diff] [blame] | 81 | CHECK_GE(install_plan_.payloads.size(), 1UL); | 
| Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 82 | if (!payload_) | 
|  | 83 | payload_ = &install_plan_.payloads[0]; | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 84 |  | 
| Alex Deymo | 5ed695e | 2015-10-05 16:59:23 -0700 | [diff] [blame] | 85 | LOG(INFO) << "Marking new slot as unbootable"; | 
| Alex Deymo | 1b3556c | 2016-02-03 09:54:02 -0800 | [diff] [blame] | 86 | if (!boot_control_->MarkSlotUnbootable(install_plan_.target_slot)) { | 
| Alex Deymo | 5ed695e | 2015-10-05 16:59:23 -0700 | [diff] [blame] | 87 | LOG(WARNING) << "Unable to mark new slot " | 
|  | 88 | << BootControlInterface::SlotName(install_plan_.target_slot) | 
|  | 89 | << ". Proceeding with the update anyway."; | 
|  | 90 | } | 
|  | 91 |  | 
| Sen Jiang | 6c73668 | 2017-03-10 15:01:36 -0800 | [diff] [blame] | 92 | StartDownloading(); | 
|  | 93 | } | 
|  | 94 |  | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 95 | bool DownloadAction::LoadCachedManifest(int64_t manifest_size) { | 
|  | 96 | std::string cached_manifest_bytes; | 
|  | 97 | if (!prefs_->GetString(kPrefsManifestBytes, &cached_manifest_bytes) || | 
|  | 98 | cached_manifest_bytes.size() <= 0) { | 
|  | 99 | LOG(INFO) << "Cached Manifest data not found"; | 
|  | 100 | return false; | 
|  | 101 | } | 
|  | 102 | if (static_cast<int64_t>(cached_manifest_bytes.size()) != manifest_size) { | 
|  | 103 | LOG(WARNING) << "Cached metadata has unexpected size: " | 
|  | 104 | << cached_manifest_bytes.size() << " vs. " << manifest_size; | 
|  | 105 | return false; | 
|  | 106 | } | 
|  | 107 |  | 
| Daniel Zheng | da4f729 | 2022-09-02 22:59:32 +0000 | [diff] [blame] | 108 | ErrorCode error{}; | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 109 | const bool success = | 
| Kelvin Zhang | 22b62e4 | 2020-12-14 14:50:40 -0500 | [diff] [blame] | 110 | delta_performer_->Write( | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 111 | cached_manifest_bytes.data(), cached_manifest_bytes.size(), &error) && | 
| Kelvin Zhang | 22b62e4 | 2020-12-14 14:50:40 -0500 | [diff] [blame] | 112 | delta_performer_->IsManifestValid(); | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 113 | if (success) { | 
|  | 114 | LOG(INFO) << "Successfully parsed cached manifest"; | 
|  | 115 | } else { | 
|  | 116 | // If parsing of cached data failed, fall back to fetch them using HTTP | 
|  | 117 | LOG(WARNING) << "Cached manifest data fails to load, error code:" | 
|  | 118 | << static_cast<int>(error) << "," << error; | 
|  | 119 | } | 
|  | 120 | return success; | 
|  | 121 | } | 
|  | 122 |  | 
| Sen Jiang | 6c73668 | 2017-03-10 15:01:36 -0800 | [diff] [blame] | 123 | void DownloadAction::StartDownloading() { | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 124 | download_active_ = true; | 
|  | 125 | http_fetcher_->ClearRanges(); | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 126 |  | 
| Kelvin Zhang | 22b62e4 | 2020-12-14 14:50:40 -0500 | [diff] [blame] | 127 | if (delta_performer_ != nullptr) { | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 128 | LOG(INFO) << "Using writer for test."; | 
|  | 129 | } else { | 
|  | 130 | delta_performer_.reset(new DeltaPerformer(prefs_, | 
|  | 131 | boot_control_, | 
|  | 132 | hardware_, | 
|  | 133 | delegate_, | 
|  | 134 | &install_plan_, | 
|  | 135 | payload_, | 
| Kelvin Zhang | 1304fe7 | 2021-10-06 19:12:12 -0700 | [diff] [blame] | 136 | interactive_, | 
|  | 137 | update_certificates_path_)); | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 140 | if (install_plan_.is_resume && | 
|  | 141 | payload_ == &install_plan_.payloads[resume_payload_index_]) { | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 142 | // Resuming an update so parse the cached manifest first | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 143 | int64_t manifest_metadata_size = 0; | 
|  | 144 | int64_t manifest_signature_size = 0; | 
|  | 145 | prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size); | 
|  | 146 | prefs_->GetInt64(kPrefsManifestSignatureSize, &manifest_signature_size); | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 147 |  | 
|  | 148 | // TODO(zhangkelvin) Add unittest for success and fallback route | 
|  | 149 | if (!LoadCachedManifest(manifest_metadata_size + manifest_signature_size)) { | 
|  | 150 | if (delta_performer_) { | 
|  | 151 | // Create a new DeltaPerformer to reset all its state | 
| Kelvin Zhang | 1304fe7 | 2021-10-06 19:12:12 -0700 | [diff] [blame] | 152 | delta_performer_ = | 
|  | 153 | std::make_unique<DeltaPerformer>(prefs_, | 
|  | 154 | boot_control_, | 
|  | 155 | hardware_, | 
|  | 156 | delegate_, | 
|  | 157 | &install_plan_, | 
|  | 158 | payload_, | 
|  | 159 | interactive_, | 
|  | 160 | update_certificates_path_); | 
| Kelvin Zhang | cc011d3 | 2020-07-10 18:20:08 -0400 | [diff] [blame] | 161 | } | 
|  | 162 | http_fetcher_->AddRange(base_offset_, | 
|  | 163 | manifest_metadata_size + manifest_signature_size); | 
|  | 164 | } | 
|  | 165 |  | 
| Kelvin Zhang | ead9fd7 | 2020-12-03 12:57:35 -0500 | [diff] [blame] | 166 | // If there're remaining unprocessed data blobs, fetch them. Be careful | 
|  | 167 | // not to request data beyond the end of the payload to avoid 416 HTTP | 
|  | 168 | // response error codes. | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 169 | int64_t next_data_offset = 0; | 
|  | 170 | prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset); | 
|  | 171 | uint64_t resume_offset = | 
|  | 172 | manifest_metadata_size + manifest_signature_size + next_data_offset; | 
|  | 173 | if (!payload_->size) { | 
|  | 174 | http_fetcher_->AddRange(base_offset_ + resume_offset); | 
|  | 175 | } else if (resume_offset < payload_->size) { | 
|  | 176 | http_fetcher_->AddRange(base_offset_ + resume_offset, | 
|  | 177 | payload_->size - resume_offset); | 
|  | 178 | } | 
|  | 179 | } else { | 
|  | 180 | if (payload_->size) { | 
|  | 181 | http_fetcher_->AddRange(base_offset_, payload_->size); | 
|  | 182 | } else { | 
|  | 183 | // If no payload size is passed we assume we read until the end of the | 
|  | 184 | // stream. | 
|  | 185 | http_fetcher_->AddRange(base_offset_); | 
|  | 186 | } | 
|  | 187 | } | 
|  | 188 |  | 
| Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 189 | http_fetcher_->BeginTransfer(install_plan_.download_url); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
| Alex Deymo | f285857 | 2016-02-25 11:20:13 -0800 | [diff] [blame] | 192 | void DownloadAction::SuspendAction() { | 
|  | 193 | http_fetcher_->Pause(); | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | void DownloadAction::ResumeAction() { | 
|  | 197 | http_fetcher_->Unpause(); | 
|  | 198 | } | 
|  | 199 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 200 | void DownloadAction::TerminateProcessing() { | 
| Kelvin Zhang | 22b62e4 | 2020-12-14 14:50:40 -0500 | [diff] [blame] | 201 | if (delta_performer_) { | 
|  | 202 | delta_performer_->Close(); | 
|  | 203 | delta_performer_.reset(); | 
| Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 204 | } | 
| Alex Deymo | 1b3556c | 2016-02-03 09:54:02 -0800 | [diff] [blame] | 205 | download_active_ = false; | 
| Darin Petkov | 9ce452b | 2010-11-17 14:33:28 -0800 | [diff] [blame] | 206 | // Terminates the transfer. The action is terminated, if necessary, when the | 
|  | 207 | // TransferTerminated callback is received. | 
|  | 208 | http_fetcher_->TerminateTransfer(); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 209 | } | 
|  | 210 |  | 
| Andrew de los Reyes | 34e41a1 | 2010-10-26 20:07:58 -0700 | [diff] [blame] | 211 | void DownloadAction::SeekToOffset(off_t offset) { | 
|  | 212 | bytes_received_ = offset; | 
|  | 213 | } | 
|  | 214 |  | 
| Amin Hassani | 0cd9d77 | 2018-07-31 23:55:43 -0700 | [diff] [blame] | 215 | bool DownloadAction::ReceivedBytes(HttpFetcher* fetcher, | 
| Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 216 | const void* bytes, | 
|  | 217 | size_t length) { | 
| Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 218 | bytes_received_ += length; | 
| Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 219 | uint64_t bytes_downloaded_total = | 
|  | 220 | bytes_received_previous_payloads_ + bytes_received_; | 
| Alex Deymo | 542c19b | 2015-12-03 07:43:31 -0300 | [diff] [blame] | 221 | if (delegate_ && download_active_) { | 
| Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 222 | delegate_->BytesReceived(length, bytes_downloaded_total, bytes_total_); | 
| Alex Deymo | 542c19b | 2015-12-03 07:43:31 -0300 | [diff] [blame] | 223 | } | 
| Kelvin Zhang | 22b62e4 | 2020-12-14 14:50:40 -0500 | [diff] [blame] | 224 | if (delta_performer_ && !delta_performer_->Write(bytes, length, &code_)) { | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 225 | if (code_ != ErrorCode::kSuccess) { | 
|  | 226 | LOG(ERROR) << "Error " << utils::ErrorCodeToString(code_) << " (" << code_ | 
|  | 227 | << ") in DeltaPerformer's Write method when " | 
|  | 228 | << "processing the received payload -- Terminating processing"; | 
| Kelvin Zhang | 430852d | 2023-05-25 17:00:24 -0700 | [diff] [blame] | 229 | } else { | 
|  | 230 | LOG(ERROR) << "Unknown error in DeltaPerformer's Write method when " | 
|  | 231 | << "processing the received payload -- Terminating processing"; | 
|  | 232 | code_ = ErrorCode::kDownloadWriteError; | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 233 | } | 
| Darin Petkov | 9ce452b | 2010-11-17 14:33:28 -0800 | [diff] [blame] | 234 | // Don't tell the action processor that the action is complete until we get | 
|  | 235 | // the TransferTerminated callback. Otherwise, this and the HTTP fetcher | 
|  | 236 | // objects may get destroyed before all callbacks are complete. | 
| Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 237 | TerminateProcessing(); | 
| Amin Hassani | 0cd9d77 | 2018-07-31 23:55:43 -0700 | [diff] [blame] | 238 | return false; | 
| Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 239 | } | 
| David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 240 |  | 
| Amin Hassani | 0cd9d77 | 2018-07-31 23:55:43 -0700 | [diff] [blame] | 241 | return true; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 244 | void DownloadAction::TransferComplete(HttpFetcher* fetcher, bool successful) { | 
| Kelvin Zhang | 22b62e4 | 2020-12-14 14:50:40 -0500 | [diff] [blame] | 245 | if (delta_performer_) { | 
|  | 246 | LOG_IF(WARNING, delta_performer_->Close() != 0) | 
|  | 247 | << "Error closing the writer."; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 248 | } | 
| Alex Deymo | 1b3556c | 2016-02-03 09:54:02 -0800 | [diff] [blame] | 249 | download_active_ = false; | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 250 | ErrorCode code = | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 251 | successful ? ErrorCode::kSuccess : ErrorCode::kDownloadTransferError; | 
| Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 252 | if (code == ErrorCode::kSuccess) { | 
|  | 253 | if (delta_performer_ && !payload_->already_applied) | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 254 | code = delta_performer_->VerifyPayload(payload_->hash, payload_->size); | 
| Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 255 | if (code == ErrorCode::kSuccess) { | 
| Kelvin Zhang | 5c1451f | 2020-12-02 17:01:54 -0500 | [diff] [blame] | 256 | CHECK_EQ(install_plan_.payloads.size(), 1UL); | 
| Sen Jiang | 7ebfccf | 2018-03-15 13:55:55 -0700 | [diff] [blame] | 257 | // All payloads have been applied and verified. | 
|  | 258 | if (delegate_) | 
|  | 259 | delegate_->DownloadComplete(); | 
|  | 260 |  | 
| Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 261 | // Log UpdateEngine.DownloadAction.* histograms to help diagnose | 
| Sen Jiang | 7ebfccf | 2018-03-15 13:55:55 -0700 | [diff] [blame] | 262 | // long-blocking operations. | 
| Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 263 | std::string histogram_output; | 
| Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 264 | base::StatisticsRecorder::WriteGraph("UpdateEngine.DownloadAction.", | 
|  | 265 | &histogram_output); | 
| Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 266 | LOG(INFO) << histogram_output; | 
|  | 267 | } else { | 
| Darin Petkov | 7ed561b | 2011-10-04 02:59:03 -0700 | [diff] [blame] | 268 | LOG(ERROR) << "Download of " << install_plan_.download_url | 
|  | 269 | << " failed due to payload verification error."; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 270 | } | 
|  | 271 | } | 
| Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 272 |  | 
| Darin Petkov | c97435c | 2010-07-20 12:37:43 -0700 | [diff] [blame] | 273 | // Write the path to the output pipe if we're successful. | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 274 | if (code == ErrorCode::kSuccess && HasOutputPipe()) | 
| Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 275 | SetOutputObject(install_plan_); | 
| Darin Petkov | c97435c | 2010-07-20 12:37:43 -0700 | [diff] [blame] | 276 | processor_->ActionComplete(this, code); | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 277 | } | 
|  | 278 |  | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 279 | void DownloadAction::TransferTerminated(HttpFetcher* fetcher) { | 
| Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 280 | if (code_ != ErrorCode::kSuccess) { | 
| Darin Petkov | 9ce452b | 2010-11-17 14:33:28 -0800 | [diff] [blame] | 281 | processor_->ActionComplete(this, code_); | 
| Sen Jiang | 5ae865b | 2017-04-18 14:24:40 -0700 | [diff] [blame] | 282 | } else if (payload_->already_applied) { | 
|  | 283 | LOG(INFO) << "TransferTerminated with ErrorCode::kSuccess when the current " | 
|  | 284 | "payload has already applied, treating as TransferComplete."; | 
|  | 285 | TransferComplete(fetcher, true); | 
| Darin Petkov | 9ce452b | 2010-11-17 14:33:28 -0800 | [diff] [blame] | 286 | } | 
|  | 287 | } | 
|  | 288 |  | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 289 | }  // namespace chromeos_update_engine |