Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: update_attempter.cc

Issue 3620013: AU: Resume interrupted update attempts. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: fix setup download Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « update_attempter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "update_engine/update_attempter.h" 5 #include "update_engine/update_attempter.h"
6 6
7 // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L 7 // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L
8 #ifndef _POSIX_C_SOURCE 8 #ifndef _POSIX_C_SOURCE
9 #define _POSIX_C_SOURCE 199309L 9 #define _POSIX_C_SOURCE 199309L
10 #endif // _POSIX_C_SOURCE 10 #endif // _POSIX_C_SOURCE
11 #include <time.h> 11 #include <time.h>
12 12
13 #include <string>
13 #include <tr1/memory> 14 #include <tr1/memory>
14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include <glib.h> 17 #include <glib.h>
18 #include <metrics/metrics_library.h> 18 #include <metrics/metrics_library.h>
19 19
20 #include "update_engine/dbus_service.h" 20 #include "update_engine/dbus_service.h"
21 #include "update_engine/download_action.h" 21 #include "update_engine/download_action.h"
22 #include "update_engine/filesystem_copier_action.h" 22 #include "update_engine/filesystem_copier_action.h"
23 #include "update_engine/libcurl_http_fetcher.h" 23 #include "update_engine/libcurl_http_fetcher.h"
24 #include "update_engine/multi_http_fetcher.h"
24 #include "update_engine/omaha_request_action.h" 25 #include "update_engine/omaha_request_action.h"
25 #include "update_engine/omaha_request_params.h" 26 #include "update_engine/omaha_request_params.h"
26 #include "update_engine/omaha_response_handler_action.h" 27 #include "update_engine/omaha_response_handler_action.h"
27 #include "update_engine/postinstall_runner_action.h" 28 #include "update_engine/postinstall_runner_action.h"
28 #include "update_engine/prefs_interface.h" 29 #include "update_engine/prefs_interface.h"
29 #include "update_engine/set_bootable_flag_action.h" 30 #include "update_engine/set_bootable_flag_action.h"
30 #include "update_engine/update_check_scheduler.h" 31 #include "update_engine/update_check_scheduler.h"
31 32
32 using base::TimeDelta; 33 using base::TimeDelta;
33 using base::TimeTicks; 34 using base::TimeTicks;
35 using std::make_pair;
34 using std::tr1::shared_ptr; 36 using std::tr1::shared_ptr;
35 using std::string; 37 using std::string;
36 using std::vector; 38 using std::vector;
37 39
38 namespace chromeos_update_engine { 40 namespace chromeos_update_engine {
39 41
40 const int UpdateAttempter::kMaxDeltaUpdateFailures = 3; 42 const int UpdateAttempter::kMaxDeltaUpdateFailures = 3;
41 43
42 const char* kUpdateCompletedMarker = 44 const char* kUpdateCompletedMarker =
43 "/var/run/update_engine_autoupdate_completed"; 45 "/var/run/update_engine_autoupdate_completed";
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 new FilesystemCopierAction(false)); 148 new FilesystemCopierAction(false));
147 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( 149 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action(
148 new FilesystemCopierAction(true)); 150 new FilesystemCopierAction(true));
149 shared_ptr<OmahaRequestAction> download_started_action( 151 shared_ptr<OmahaRequestAction> download_started_action(
150 new OmahaRequestAction(prefs_, 152 new OmahaRequestAction(prefs_,
151 omaha_request_params_, 153 omaha_request_params_,
152 new OmahaEvent( 154 new OmahaEvent(
153 OmahaEvent::kTypeUpdateDownloadStarted), 155 OmahaEvent::kTypeUpdateDownloadStarted),
154 new LibcurlHttpFetcher)); 156 new LibcurlHttpFetcher));
155 shared_ptr<DownloadAction> download_action( 157 shared_ptr<DownloadAction> download_action(
156 new DownloadAction(prefs_, new LibcurlHttpFetcher)); 158 new DownloadAction(prefs_, new MultiHttpFetcher<LibcurlHttpFetcher>));
157 shared_ptr<OmahaRequestAction> download_finished_action( 159 shared_ptr<OmahaRequestAction> download_finished_action(
158 new OmahaRequestAction(prefs_, 160 new OmahaRequestAction(prefs_,
159 omaha_request_params_, 161 omaha_request_params_,
160 new OmahaEvent( 162 new OmahaEvent(
161 OmahaEvent::kTypeUpdateDownloadFinished), 163 OmahaEvent::kTypeUpdateDownloadFinished),
162 new LibcurlHttpFetcher)); 164 new LibcurlHttpFetcher));
163 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_precommit( 165 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_precommit(
164 new PostinstallRunnerAction(true)); 166 new PostinstallRunnerAction(true));
165 shared_ptr<SetBootableFlagAction> set_bootable_flag_action( 167 shared_ptr<SetBootableFlagAction> set_bootable_flag_action(
166 new SetBootableFlagAction); 168 new SetBootableFlagAction);
167 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_postcommit( 169 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_postcommit(
168 new PostinstallRunnerAction(false)); 170 new PostinstallRunnerAction(false));
169 shared_ptr<OmahaRequestAction> update_complete_action( 171 shared_ptr<OmahaRequestAction> update_complete_action(
170 new OmahaRequestAction(prefs_, 172 new OmahaRequestAction(prefs_,
171 omaha_request_params_, 173 omaha_request_params_,
172 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), 174 new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
173 new LibcurlHttpFetcher)); 175 new LibcurlHttpFetcher));
174 176
175 download_action->set_delegate(this); 177 download_action->set_delegate(this);
176 response_handler_action_ = response_handler_action; 178 response_handler_action_ = response_handler_action;
179 download_action_ = download_action;
177 180
178 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); 181 actions_.push_back(shared_ptr<AbstractAction>(update_check_action));
179 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); 182 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action));
180 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); 183 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action));
181 actions_.push_back(shared_ptr<AbstractAction>( 184 actions_.push_back(shared_ptr<AbstractAction>(
182 kernel_filesystem_copier_action)); 185 kernel_filesystem_copier_action));
183 actions_.push_back(shared_ptr<AbstractAction>(download_started_action)); 186 actions_.push_back(shared_ptr<AbstractAction>(download_started_action));
184 actions_.push_back(shared_ptr<AbstractAction>(download_action)); 187 actions_.push_back(shared_ptr<AbstractAction>(download_action));
185 actions_.push_back(shared_ptr<AbstractAction>(download_finished_action)); 188 actions_.push_back(shared_ptr<AbstractAction>(download_finished_action));
186 actions_.push_back(shared_ptr<AbstractAction>( 189 actions_.push_back(shared_ptr<AbstractAction>(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // Reset process priority back to normal. 250 // Reset process priority back to normal.
248 CleanupPriorityManagement(); 251 CleanupPriorityManagement();
249 252
250 if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { 253 if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
251 LOG(INFO) << "Error event sent."; 254 LOG(INFO) << "Error event sent.";
252 SetStatusAndNotify(UPDATE_STATUS_IDLE); 255 SetStatusAndNotify(UPDATE_STATUS_IDLE);
253 return; 256 return;
254 } 257 }
255 258
256 if (code == kActionCodeSuccess) { 259 if (code == kActionCodeSuccess) {
257 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT);
258 utils::WriteFile(kUpdateCompletedMarker, "", 0); 260 utils::WriteFile(kUpdateCompletedMarker, "", 0);
259 prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0); 261 prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0);
262 DeltaPerformer::ResetUpdateProgress(prefs_, false);
263 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT);
260 264
261 // Report the time it took to update the system. 265 // Report the time it took to update the system.
262 int64_t update_time = time(NULL) - last_checked_time_; 266 int64_t update_time = time(NULL) - last_checked_time_;
263 metrics_lib_->SendToUMA("Installer.UpdateTime", 267 metrics_lib_->SendToUMA("Installer.UpdateTime",
264 static_cast<int>(update_time), // sample 268 static_cast<int>(update_time), // sample
265 1, // min = 1 second 269 1, // min = 1 second
266 20 * 60, // max = 20 minutes 270 20 * 60, // max = 20 minutes
267 50); // buckets 271 50); // buckets
268 return; 272 return;
269 } 273 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 !is_full_update_ && 324 !is_full_update_ &&
321 code != kActionCodeDownloadTransferError) { 325 code != kActionCodeDownloadTransferError) {
322 MarkDeltaUpdateFailure(); 326 MarkDeltaUpdateFailure();
323 } 327 }
324 // On failure, schedule an error event to be sent to Omaha. 328 // On failure, schedule an error event to be sent to Omaha.
325 CreatePendingErrorEvent(action, code); 329 CreatePendingErrorEvent(action, code);
326 return; 330 return;
327 } 331 }
328 // Find out which action completed. 332 // Find out which action completed.
329 if (type == OmahaResponseHandlerAction::StaticType()) { 333 if (type == OmahaResponseHandlerAction::StaticType()) {
330 // Note that the status will be updated to DOWNLOADING when some 334 // Note that the status will be updated to DOWNLOADING when some bytes get
331 // bytes get actually downloaded from the server and the 335 // actually downloaded from the server and the BytesReceived callback is
332 // BytesReceived callback is invoked. This avoids notifying the 336 // invoked. This avoids notifying the user that a download has started in
333 // user that a download has started in cases when the server and 337 // cases when the server and the client are unable to initiate the download.
334 // the client are unable to initiate the download. 338 CHECK(action == response_handler_action_.get());
335 OmahaResponseHandlerAction* omaha_response_handler_action = 339 const InstallPlan& plan = response_handler_action_->install_plan();
336 dynamic_cast<OmahaResponseHandlerAction*>(action);
337 CHECK(omaha_response_handler_action);
338 const InstallPlan& plan = omaha_response_handler_action->install_plan();
339 last_checked_time_ = time(NULL); 340 last_checked_time_ = time(NULL);
340 // TODO(adlr): put version in InstallPlan 341 // TODO(adlr): put version in InstallPlan
341 new_version_ = "0.0.0.0"; 342 new_version_ = "0.0.0.0";
342 new_size_ = plan.size; 343 new_size_ = plan.size;
343 is_full_update_ = plan.is_full_update; 344 is_full_update_ = plan.is_full_update;
345 SetupDownload();
344 SetupPriorityManagement(); 346 SetupPriorityManagement();
345 } else if (type == DownloadAction::StaticType()) { 347 } else if (type == DownloadAction::StaticType()) {
346 SetStatusAndNotify(UPDATE_STATUS_FINALIZING); 348 SetStatusAndNotify(UPDATE_STATUS_FINALIZING);
347 } 349 }
348 } 350 }
349 351
350 // Stop updating. An attempt will be made to record status to the disk 352 // Stop updating. An attempt will be made to record status to the disk
351 // so that updates can be resumed later. 353 // so that updates can be resumed later.
352 void UpdateAttempter::Terminate() { 354 void UpdateAttempter::Terminate() {
353 // TODO(adlr): implement this method. 355 // TODO(adlr): implement this method.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (omaha_request_params_.delta_okay && 512 if (omaha_request_params_.delta_okay &&
511 prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) && 513 prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) &&
512 delta_failures >= kMaxDeltaUpdateFailures) { 514 delta_failures >= kMaxDeltaUpdateFailures) {
513 LOG(WARNING) << "Too many delta update failures, forcing full update."; 515 LOG(WARNING) << "Too many delta update failures, forcing full update.";
514 omaha_request_params_.delta_okay = false; 516 omaha_request_params_.delta_okay = false;
515 } 517 }
516 } 518 }
517 519
518 void UpdateAttempter::MarkDeltaUpdateFailure() { 520 void UpdateAttempter::MarkDeltaUpdateFailure() {
519 CHECK(!is_full_update_); 521 CHECK(!is_full_update_);
522 // If a delta update fails after the downloading phase, don't try to resume it
523 // the next time.
524 if (status_ > UPDATE_STATUS_DOWNLOADING) {
525 DeltaPerformer::ResetUpdateProgress(prefs_, false);
526 }
520 int64_t delta_failures; 527 int64_t delta_failures;
521 if (!prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) || 528 if (!prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) ||
522 delta_failures < 0) { 529 delta_failures < 0) {
523 delta_failures = 0; 530 delta_failures = 0;
524 } 531 }
525 prefs_->SetInt64(kPrefsDeltaUpdateFailures, ++delta_failures); 532 prefs_->SetInt64(kPrefsDeltaUpdateFailures, ++delta_failures);
526 } 533 }
527 534
535 void UpdateAttempter::SetupDownload() {
536 MultiHttpFetcher<LibcurlHttpFetcher>* fetcher =
537 dynamic_cast<MultiHttpFetcher<LibcurlHttpFetcher>*>(
538 download_action_->http_fetcher());
539 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect ranges;
540 if (response_handler_action_->install_plan().is_resume) {
541 int64_t manifest_metadata_size = 0;
542 prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size);
543 int64_t next_data_offset = 0;
544 prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset);
545 ranges.push_back(make_pair(0, manifest_metadata_size));
546 ranges.push_back(make_pair(manifest_metadata_size + next_data_offset, -1));
547 } else {
548 ranges.push_back(make_pair(0, -1));
549 }
550 fetcher->set_ranges(ranges);
551 }
552
528 } // namespace chromeos_update_engine 553 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_attempter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698