| OLD | NEW |
| 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 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, | 98 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, |
| 99 MetricsLibraryInterface* metrics_lib, | 99 MetricsLibraryInterface* metrics_lib, |
| 100 DbusGlibInterface* dbus_iface) | 100 DbusGlibInterface* dbus_iface) |
| 101 : processor_(new ActionProcessor()), | 101 : processor_(new ActionProcessor()), |
| 102 dbus_service_(NULL), | 102 dbus_service_(NULL), |
| 103 prefs_(prefs), | 103 prefs_(prefs), |
| 104 metrics_lib_(metrics_lib), | 104 metrics_lib_(metrics_lib), |
| 105 update_check_scheduler_(NULL), | 105 update_check_scheduler_(NULL), |
| 106 fake_update_success_(false), |
| 106 http_response_code_(0), | 107 http_response_code_(0), |
| 107 priority_(utils::kProcessPriorityNormal), | 108 priority_(utils::kProcessPriorityNormal), |
| 108 manage_priority_source_(NULL), | 109 manage_priority_source_(NULL), |
| 109 download_active_(false), | 110 download_active_(false), |
| 110 status_(UPDATE_STATUS_IDLE), | 111 status_(UPDATE_STATUS_IDLE), |
| 111 download_progress_(0.0), | 112 download_progress_(0.0), |
| 112 last_checked_time_(0), | 113 last_checked_time_(0), |
| 113 new_version_("0.0.0.0"), | 114 new_version_("0.0.0.0"), |
| 114 new_size_(0), | 115 new_size_(0), |
| 115 is_full_update_(false), | 116 is_full_update_(false), |
| 116 proxy_manual_checks_(0), | 117 proxy_manual_checks_(0), |
| 117 obeying_proxies_(true), | 118 obeying_proxies_(true), |
| 118 chrome_proxy_resolver_(dbus_iface), | 119 chrome_proxy_resolver_(dbus_iface), |
| 119 updated_boot_flags_(false) { | 120 updated_boot_flags_(false) { |
| 120 if (utils::FileExists(kUpdateCompletedMarker)) | 121 if (utils::FileExists(kUpdateCompletedMarker)) |
| 121 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; | 122 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; |
| 122 } | 123 } |
| 123 | 124 |
| 124 UpdateAttempter::~UpdateAttempter() { | 125 UpdateAttempter::~UpdateAttempter() { |
| 125 CleanupPriorityManagement(); | 126 CleanupPriorityManagement(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void UpdateAttempter::Update(const std::string& app_version, | 129 void UpdateAttempter::Update(const std::string& app_version, |
| 129 const std::string& omaha_url, | 130 const std::string& omaha_url, |
| 130 bool obey_proxies) { | 131 bool obey_proxies) { |
| 131 chrome_proxy_resolver_.Init(); | 132 chrome_proxy_resolver_.Init(); |
| 133 fake_update_success_ = false; |
| 132 UpdateBootFlags(); // Just in case we didn't do this yet. | 134 UpdateBootFlags(); // Just in case we didn't do this yet. |
| 133 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 135 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 134 // Although we have applied an update, we still want to ping Omaha | 136 // Although we have applied an update, we still want to ping Omaha |
| 135 // to ensure the number of active statistics is accurate. | 137 // to ensure the number of active statistics is accurate. |
| 136 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " | 138 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " |
| 137 << "reboot, we'll ping Omaha instead"; | 139 << "reboot, we'll ping Omaha instead"; |
| 138 PingOmaha(); | 140 PingOmaha(); |
| 139 return; | 141 return; |
| 140 } | 142 } |
| 141 if (status_ != UPDATE_STATUS_IDLE) { | 143 if (status_ != UPDATE_STATUS_IDLE) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 CHECK(response_handler_action_); | 309 CHECK(response_handler_action_); |
| 308 LOG(INFO) << "Processing Done."; | 310 LOG(INFO) << "Processing Done."; |
| 309 actions_.clear(); | 311 actions_.clear(); |
| 310 | 312 |
| 311 // Reset process priority back to normal. | 313 // Reset process priority back to normal. |
| 312 CleanupPriorityManagement(); | 314 CleanupPriorityManagement(); |
| 313 | 315 |
| 314 if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { | 316 if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { |
| 315 LOG(INFO) << "Error event sent."; | 317 LOG(INFO) << "Error event sent."; |
| 316 SetStatusAndNotify(UPDATE_STATUS_IDLE); | 318 SetStatusAndNotify(UPDATE_STATUS_IDLE); |
| 317 return; | 319 if (!fake_update_success_) { |
| 320 return; |
| 321 } |
| 322 LOG(INFO) << "Booted from FW B and tried to install new firmware, " |
| 323 "so requesting reboot from user."; |
| 318 } | 324 } |
| 319 | 325 |
| 320 if (code == kActionCodeSuccess) { | 326 if (code == kActionCodeSuccess) { |
| 321 utils::WriteFile(kUpdateCompletedMarker, "", 0); | 327 utils::WriteFile(kUpdateCompletedMarker, "", 0); |
| 322 prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0); | 328 prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0); |
| 323 prefs_->SetString(kPrefsPreviousVersion, omaha_request_params_.app_version); | 329 prefs_->SetString(kPrefsPreviousVersion, omaha_request_params_.app_version); |
| 324 DeltaPerformer::ResetUpdateProgress(prefs_, false); | 330 DeltaPerformer::ResetUpdateProgress(prefs_, false); |
| 325 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); | 331 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); |
| 326 | 332 |
| 327 // Report the time it took to update the system. | 333 // Report the time it took to update the system. |
| 328 int64_t update_time = time(NULL) - last_checked_time_; | 334 int64_t update_time = time(NULL) - last_checked_time_; |
| 329 metrics_lib_->SendToUMA("Installer.UpdateTime", | 335 if (!fake_update_success_) |
| 330 static_cast<int>(update_time), // sample | 336 metrics_lib_->SendToUMA("Installer.UpdateTime", |
| 331 1, // min = 1 second | 337 static_cast<int>(update_time), // sample |
| 332 20 * 60, // max = 20 minutes | 338 1, // min = 1 second |
| 333 50); // buckets | 339 20 * 60, // max = 20 minutes |
| 340 50); // buckets |
| 334 return; | 341 return; |
| 335 } | 342 } |
| 336 | 343 |
| 337 if (ScheduleErrorEventAction()) { | 344 if (ScheduleErrorEventAction()) { |
| 338 return; | 345 return; |
| 339 } | 346 } |
| 340 LOG(INFO) << "No update."; | 347 LOG(INFO) << "No update."; |
| 341 SetStatusAndNotify(UPDATE_STATUS_IDLE); | 348 SetStatusAndNotify(UPDATE_STATUS_IDLE); |
| 342 } | 349 } |
| 343 | 350 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // there's no update so don't send an event. Also, double check that the | 511 // there's no update so don't send an event. Also, double check that the |
| 505 // failure has not occurred while sending an error event -- in which case | 512 // failure has not occurred while sending an error event -- in which case |
| 506 // don't schedule another. This shouldn't really happen but just in case... | 513 // don't schedule another. This shouldn't really happen but just in case... |
| 507 if ((action->Type() == OmahaResponseHandlerAction::StaticType() && | 514 if ((action->Type() == OmahaResponseHandlerAction::StaticType() && |
| 508 code == kActionCodeError) || | 515 code == kActionCodeError) || |
| 509 status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { | 516 status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { |
| 510 return; | 517 return; |
| 511 } | 518 } |
| 512 | 519 |
| 513 code = GetErrorCodeForAction(action, code); | 520 code = GetErrorCodeForAction(action, code); |
| 521 fake_update_success_ = code == kActionCodePostinstallBootedFromFirmwareB; |
| 514 error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, | 522 error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, |
| 515 OmahaEvent::kResultError, | 523 OmahaEvent::kResultError, |
| 516 code)); | 524 code)); |
| 517 } | 525 } |
| 518 | 526 |
| 519 bool UpdateAttempter::ScheduleErrorEventAction() { | 527 bool UpdateAttempter::ScheduleErrorEventAction() { |
| 520 if (error_event_.get() == NULL) | 528 if (error_event_.get() == NULL) |
| 521 return false; | 529 return false; |
| 522 | 530 |
| 523 LOG(INFO) << "Update failed -- reporting the error event."; | 531 LOG(INFO) << "Update failed -- reporting the error event."; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 true)); | 644 true)); |
| 637 actions_.push_back(shared_ptr<OmahaRequestAction>(ping_action)); | 645 actions_.push_back(shared_ptr<OmahaRequestAction>(ping_action)); |
| 638 CHECK(!processor_->IsRunning()); | 646 CHECK(!processor_->IsRunning()); |
| 639 processor_->set_delegate(NULL); | 647 processor_->set_delegate(NULL); |
| 640 processor_->EnqueueAction(ping_action.get()); | 648 processor_->EnqueueAction(ping_action.get()); |
| 641 g_idle_add(&StaticStartProcessing, this); | 649 g_idle_add(&StaticStartProcessing, this); |
| 642 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); | 650 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); |
| 643 } | 651 } |
| 644 | 652 |
| 645 } // namespace chromeos_update_engine | 653 } // namespace chromeos_update_engine |
| OLD | NEW |