| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 UpdateAttempter::~UpdateAttempter() { | 122 UpdateAttempter::~UpdateAttempter() { |
| 123 CleanupPriorityManagement(); | 123 CleanupPriorityManagement(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void UpdateAttempter::Update(const std::string& app_version, | 126 void UpdateAttempter::Update(const std::string& app_version, |
| 127 const std::string& omaha_url, | 127 const std::string& omaha_url, |
| 128 bool obey_proxies) { | 128 bool obey_proxies) { |
| 129 chrome_proxy_resolver_.Init(); | 129 chrome_proxy_resolver_.Init(); |
| 130 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 130 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 131 // Although we have applied an update, we still want to ping Omaha |
| 132 // to ensure the number of active statistics is accurate. |
| 131 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " | 133 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " |
| 132 << "reboot"; | 134 << "reboot, we'll ping Omaha instead"; |
| 135 PingOmaha(); |
| 133 return; | 136 return; |
| 134 } | 137 } |
| 135 if (status_ != UPDATE_STATUS_IDLE) { | 138 if (status_ != UPDATE_STATUS_IDLE) { |
| 136 // Update in progress. Do nothing | 139 // Update in progress. Do nothing |
| 137 return; | 140 return; |
| 138 } | 141 } |
| 139 http_response_code_ = 0; | 142 http_response_code_ = 0; |
| 140 if (!omaha_request_params_.Init(app_version, omaha_url)) { | 143 if (!omaha_request_params_.Init(app_version, omaha_url)) { |
| 141 LOG(ERROR) << "Unable to initialize Omaha request device params."; | 144 LOG(ERROR) << "Unable to initialize Omaha request device params."; |
| 142 return; | 145 return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 166 // Actions: | 169 // Actions: |
| 167 LibcurlHttpFetcher* update_check_fetcher = | 170 LibcurlHttpFetcher* update_check_fetcher = |
| 168 new LibcurlHttpFetcher(GetProxyResolver()); | 171 new LibcurlHttpFetcher(GetProxyResolver()); |
| 169 // Try harder to connect to the network. See comment in | 172 // Try harder to connect to the network. See comment in |
| 170 // libcurl_http_fetcher.cc. | 173 // libcurl_http_fetcher.cc. |
| 171 update_check_fetcher->set_no_network_max_retries(3); | 174 update_check_fetcher->set_no_network_max_retries(3); |
| 172 shared_ptr<OmahaRequestAction> update_check_action( | 175 shared_ptr<OmahaRequestAction> update_check_action( |
| 173 new OmahaRequestAction(prefs_, | 176 new OmahaRequestAction(prefs_, |
| 174 omaha_request_params_, | 177 omaha_request_params_, |
| 175 NULL, | 178 NULL, |
| 176 update_check_fetcher)); // passes ownership | 179 update_check_fetcher, // passes ownership |
| 180 false)); |
| 177 shared_ptr<OmahaResponseHandlerAction> response_handler_action( | 181 shared_ptr<OmahaResponseHandlerAction> response_handler_action( |
| 178 new OmahaResponseHandlerAction(prefs_)); | 182 new OmahaResponseHandlerAction(prefs_)); |
| 179 shared_ptr<FilesystemCopierAction> filesystem_copier_action( | 183 shared_ptr<FilesystemCopierAction> filesystem_copier_action( |
| 180 new FilesystemCopierAction(false, false)); | 184 new FilesystemCopierAction(false, false)); |
| 181 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( | 185 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( |
| 182 new FilesystemCopierAction(true, false)); | 186 new FilesystemCopierAction(true, false)); |
| 183 shared_ptr<OmahaRequestAction> download_started_action( | 187 shared_ptr<OmahaRequestAction> download_started_action( |
| 184 new OmahaRequestAction(prefs_, | 188 new OmahaRequestAction(prefs_, |
| 185 omaha_request_params_, | 189 omaha_request_params_, |
| 186 new OmahaEvent( | 190 new OmahaEvent( |
| 187 OmahaEvent::kTypeUpdateDownloadStarted), | 191 OmahaEvent::kTypeUpdateDownloadStarted), |
| 188 new LibcurlHttpFetcher(GetProxyResolver()))); | 192 new LibcurlHttpFetcher(GetProxyResolver()), |
| 193 false)); |
| 189 shared_ptr<DownloadAction> download_action( | 194 shared_ptr<DownloadAction> download_action( |
| 190 new DownloadAction(prefs_, new MultiRangeHTTPFetcher( | 195 new DownloadAction(prefs_, new MultiRangeHTTPFetcher( |
| 191 new LibcurlHttpFetcher(GetProxyResolver())))); | 196 new LibcurlHttpFetcher(GetProxyResolver())))); |
| 192 // This action is always initially in place to warn OS vendor of a | 197 // This action is always initially in place to warn OS vendor of a |
| 193 // signature failure. If it's not needed, it will be told to skip. | 198 // signature failure. If it's not needed, it will be told to skip. |
| 194 shared_ptr<OmahaRequestAction> download_signature_warning( | 199 shared_ptr<OmahaRequestAction> download_signature_warning( |
| 195 new OmahaRequestAction( | 200 new OmahaRequestAction( |
| 196 prefs_, | 201 prefs_, |
| 197 omaha_request_params_, | 202 omaha_request_params_, |
| 198 new OmahaEvent( | 203 new OmahaEvent( |
| 199 OmahaEvent::kTypeUpdateDownloadFinished, | 204 OmahaEvent::kTypeUpdateDownloadFinished, |
| 200 OmahaEvent::kResultError, | 205 OmahaEvent::kResultError, |
| 201 kActionCodeDownloadPayloadPubKeyVerificationError), | 206 kActionCodeDownloadPayloadPubKeyVerificationError), |
| 202 new LibcurlHttpFetcher(GetProxyResolver()))); | 207 new LibcurlHttpFetcher(GetProxyResolver()), |
| 208 false)); |
| 203 download_action->set_skip_reporting_signature_fail( | 209 download_action->set_skip_reporting_signature_fail( |
| 204 NewPermanentCallback(download_signature_warning.get(), | 210 NewPermanentCallback(download_signature_warning.get(), |
| 205 &OmahaRequestAction::set_should_skip, | 211 &OmahaRequestAction::set_should_skip, |
| 206 true)); | 212 true)); |
| 207 shared_ptr<OmahaRequestAction> download_finished_action( | 213 shared_ptr<OmahaRequestAction> download_finished_action( |
| 208 new OmahaRequestAction(prefs_, | 214 new OmahaRequestAction(prefs_, |
| 209 omaha_request_params_, | 215 omaha_request_params_, |
| 210 new OmahaEvent( | 216 new OmahaEvent( |
| 211 OmahaEvent::kTypeUpdateDownloadFinished), | 217 OmahaEvent::kTypeUpdateDownloadFinished), |
| 212 new LibcurlHttpFetcher(GetProxyResolver()))); | 218 new LibcurlHttpFetcher(GetProxyResolver()), |
| 219 false)); |
| 213 shared_ptr<FilesystemCopierAction> filesystem_verifier_action( | 220 shared_ptr<FilesystemCopierAction> filesystem_verifier_action( |
| 214 new FilesystemCopierAction(false, true)); | 221 new FilesystemCopierAction(false, true)); |
| 215 shared_ptr<FilesystemCopierAction> kernel_filesystem_verifier_action( | 222 shared_ptr<FilesystemCopierAction> kernel_filesystem_verifier_action( |
| 216 new FilesystemCopierAction(true, true)); | 223 new FilesystemCopierAction(true, true)); |
| 217 shared_ptr<PostinstallRunnerAction> postinstall_runner_action( | 224 shared_ptr<PostinstallRunnerAction> postinstall_runner_action( |
| 218 new PostinstallRunnerAction); | 225 new PostinstallRunnerAction); |
| 219 shared_ptr<OmahaRequestAction> update_complete_action( | 226 shared_ptr<OmahaRequestAction> update_complete_action( |
| 220 new OmahaRequestAction(prefs_, | 227 new OmahaRequestAction(prefs_, |
| 221 omaha_request_params_, | 228 omaha_request_params_, |
| 222 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), | 229 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
| 223 new LibcurlHttpFetcher(GetProxyResolver()))); | 230 new LibcurlHttpFetcher(GetProxyResolver()), |
| 231 false)); |
| 224 | 232 |
| 225 download_action->set_delegate(this); | 233 download_action->set_delegate(this); |
| 226 response_handler_action_ = response_handler_action; | 234 response_handler_action_ = response_handler_action; |
| 227 download_action_ = download_action; | 235 download_action_ = download_action; |
| 228 | 236 |
| 229 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); | 237 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); |
| 230 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); | 238 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); |
| 231 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); | 239 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); |
| 232 actions_.push_back(shared_ptr<AbstractAction>( | 240 actions_.push_back(shared_ptr<AbstractAction>( |
| 233 kernel_filesystem_copier_action)); | 241 kernel_filesystem_copier_action)); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 502 |
| 495 bool UpdateAttempter::ScheduleErrorEventAction() { | 503 bool UpdateAttempter::ScheduleErrorEventAction() { |
| 496 if (error_event_.get() == NULL) | 504 if (error_event_.get() == NULL) |
| 497 return false; | 505 return false; |
| 498 | 506 |
| 499 LOG(INFO) << "Update failed -- reporting the error event."; | 507 LOG(INFO) << "Update failed -- reporting the error event."; |
| 500 shared_ptr<OmahaRequestAction> error_event_action( | 508 shared_ptr<OmahaRequestAction> error_event_action( |
| 501 new OmahaRequestAction(prefs_, | 509 new OmahaRequestAction(prefs_, |
| 502 omaha_request_params_, | 510 omaha_request_params_, |
| 503 error_event_.release(), // Pass ownership. | 511 error_event_.release(), // Pass ownership. |
| 504 new LibcurlHttpFetcher(GetProxyResolver()))); | 512 new LibcurlHttpFetcher(GetProxyResolver()), |
| 513 false)); |
| 505 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); | 514 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); |
| 506 processor_->EnqueueAction(error_event_action.get()); | 515 processor_->EnqueueAction(error_event_action.get()); |
| 507 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); | 516 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); |
| 508 processor_->StartProcessing(); | 517 processor_->StartProcessing(); |
| 509 return true; | 518 return true; |
| 510 } | 519 } |
| 511 | 520 |
| 512 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { | 521 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { |
| 513 if (priority_ == priority) { | 522 if (priority_ == priority) { |
| 514 return; | 523 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset); | 604 prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset); |
| 596 uint64_t resume_offset = manifest_metadata_size + next_data_offset; | 605 uint64_t resume_offset = manifest_metadata_size + next_data_offset; |
| 597 if (resume_offset < response_handler_action_->install_plan().size) { | 606 if (resume_offset < response_handler_action_->install_plan().size) { |
| 598 fetcher->AddRange(resume_offset, -1); | 607 fetcher->AddRange(resume_offset, -1); |
| 599 } | 608 } |
| 600 } else { | 609 } else { |
| 601 fetcher->AddRange(0, -1); | 610 fetcher->AddRange(0, -1); |
| 602 } | 611 } |
| 603 } | 612 } |
| 604 | 613 |
| 614 void UpdateAttempter::PingOmaha() { |
| 615 shared_ptr<OmahaRequestAction> ping_action( |
| 616 new OmahaRequestAction(prefs_, |
| 617 omaha_request_params_, |
| 618 NULL, |
| 619 new LibcurlHttpFetcher(GetProxyResolver()), |
| 620 true)); |
| 621 actions_.push_back(shared_ptr<OmahaRequestAction>(ping_action)); |
| 622 CHECK(!processor_->IsRunning()); |
| 623 processor_->set_delegate(NULL); |
| 624 processor_->EnqueueAction(ping_action.get()); |
| 625 g_idle_add(&StaticStartProcessing, this); |
| 626 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); |
| 627 } |
| 628 |
| 605 } // namespace chromeos_update_engine | 629 } // namespace chromeos_update_engine |
| OLD | NEW |