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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 if (type == PostinstallRunnerAction::StaticType()) | 80 if (type == PostinstallRunnerAction::StaticType()) |
81 return kActionCodePostinstallRunnerError; | 81 return kActionCodePostinstallRunnerError; |
82 if (type == SetBootableFlagAction::StaticType()) | 82 if (type == SetBootableFlagAction::StaticType()) |
83 return kActionCodeSetBootableFlagError; | 83 return kActionCodeSetBootableFlagError; |
84 | 84 |
85 return code; | 85 return code; |
86 } | 86 } |
87 | 87 |
88 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, | 88 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, |
89 MetricsLibraryInterface* metrics_lib) | 89 MetricsLibraryInterface* metrics_lib) |
90 : dbus_service_(NULL), | 90 : processor_(new ActionProcessor()), |
| 91 dbus_service_(NULL), |
91 prefs_(prefs), | 92 prefs_(prefs), |
92 metrics_lib_(metrics_lib), | 93 metrics_lib_(metrics_lib), |
93 update_check_scheduler_(NULL), | 94 update_check_scheduler_(NULL), |
94 http_response_code_(0), | 95 http_response_code_(0), |
95 priority_(utils::kProcessPriorityNormal), | 96 priority_(utils::kProcessPriorityNormal), |
96 manage_priority_source_(NULL), | 97 manage_priority_source_(NULL), |
97 download_active_(false), | 98 download_active_(false), |
98 status_(UPDATE_STATUS_IDLE), | 99 status_(UPDATE_STATUS_IDLE), |
99 download_progress_(0.0), | 100 download_progress_(0.0), |
100 last_checked_time_(0), | 101 last_checked_time_(0), |
(...skipping 16 matching lines...) Expand all Loading... |
117 } | 118 } |
118 if (status_ != UPDATE_STATUS_IDLE) { | 119 if (status_ != UPDATE_STATUS_IDLE) { |
119 // Update in progress. Do nothing | 120 // Update in progress. Do nothing |
120 return; | 121 return; |
121 } | 122 } |
122 http_response_code_ = 0; | 123 http_response_code_ = 0; |
123 if (!omaha_request_params_.Init(app_version, omaha_url)) { | 124 if (!omaha_request_params_.Init(app_version, omaha_url)) { |
124 LOG(ERROR) << "Unable to initialize Omaha request device params."; | 125 LOG(ERROR) << "Unable to initialize Omaha request device params."; |
125 return; | 126 return; |
126 } | 127 } |
127 CHECK(!processor_.IsRunning()); | 128 CHECK(!processor_->IsRunning()); |
128 processor_.set_delegate(this); | 129 processor_->set_delegate(this); |
129 | 130 |
130 // Actions: | 131 // Actions: |
131 shared_ptr<OmahaRequestAction> update_check_action( | 132 shared_ptr<OmahaRequestAction> update_check_action( |
132 new OmahaRequestAction(prefs_, | 133 new OmahaRequestAction(prefs_, |
133 omaha_request_params_, | 134 omaha_request_params_, |
134 NULL, | 135 NULL, |
135 new LibcurlHttpFetcher)); | 136 new LibcurlHttpFetcher)); |
136 shared_ptr<OmahaResponseHandlerAction> response_handler_action( | 137 shared_ptr<OmahaResponseHandlerAction> response_handler_action( |
137 new OmahaResponseHandlerAction); | 138 new OmahaResponseHandlerAction); |
138 shared_ptr<FilesystemCopierAction> filesystem_copier_action( | 139 shared_ptr<FilesystemCopierAction> filesystem_copier_action( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 actions_.push_back(shared_ptr<AbstractAction>( | 180 actions_.push_back(shared_ptr<AbstractAction>( |
180 postinstall_runner_action_precommit)); | 181 postinstall_runner_action_precommit)); |
181 actions_.push_back(shared_ptr<AbstractAction>(set_bootable_flag_action)); | 182 actions_.push_back(shared_ptr<AbstractAction>(set_bootable_flag_action)); |
182 actions_.push_back(shared_ptr<AbstractAction>( | 183 actions_.push_back(shared_ptr<AbstractAction>( |
183 postinstall_runner_action_postcommit)); | 184 postinstall_runner_action_postcommit)); |
184 actions_.push_back(shared_ptr<AbstractAction>(update_complete_action)); | 185 actions_.push_back(shared_ptr<AbstractAction>(update_complete_action)); |
185 | 186 |
186 // Enqueue the actions | 187 // Enqueue the actions |
187 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); | 188 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); |
188 it != actions_.end(); ++it) { | 189 it != actions_.end(); ++it) { |
189 processor_.EnqueueAction(it->get()); | 190 processor_->EnqueueAction(it->get()); |
190 } | 191 } |
191 | 192 |
192 // Bond them together. We have to use the leaf-types when calling | 193 // Bond them together. We have to use the leaf-types when calling |
193 // BondActions(). | 194 // BondActions(). |
194 BondActions(update_check_action.get(), | 195 BondActions(update_check_action.get(), |
195 response_handler_action.get()); | 196 response_handler_action.get()); |
196 BondActions(response_handler_action.get(), | 197 BondActions(response_handler_action.get(), |
197 filesystem_copier_action.get()); | 198 filesystem_copier_action.get()); |
198 BondActions(filesystem_copier_action.get(), | 199 BondActions(filesystem_copier_action.get(), |
199 kernel_filesystem_copier_action.get()); | 200 kernel_filesystem_copier_action.get()); |
200 BondActions(kernel_filesystem_copier_action.get(), | 201 BondActions(kernel_filesystem_copier_action.get(), |
201 download_action.get()); | 202 download_action.get()); |
202 BondActions(download_action.get(), | 203 BondActions(download_action.get(), |
203 postinstall_runner_action_precommit.get()); | 204 postinstall_runner_action_precommit.get()); |
204 BondActions(postinstall_runner_action_precommit.get(), | 205 BondActions(postinstall_runner_action_precommit.get(), |
205 set_bootable_flag_action.get()); | 206 set_bootable_flag_action.get()); |
206 BondActions(set_bootable_flag_action.get(), | 207 BondActions(set_bootable_flag_action.get(), |
207 postinstall_runner_action_postcommit.get()); | 208 postinstall_runner_action_postcommit.get()); |
208 | 209 |
209 SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE); | 210 SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE); |
210 processor_.StartProcessing(); | 211 processor_->StartProcessing(); |
211 } | 212 } |
212 | 213 |
213 void UpdateAttempter::CheckForUpdate(const std::string& app_version, | 214 void UpdateAttempter::CheckForUpdate(const std::string& app_version, |
214 const std::string& omaha_url) { | 215 const std::string& omaha_url) { |
215 if (status_ != UPDATE_STATUS_IDLE) { | 216 if (status_ != UPDATE_STATUS_IDLE) { |
216 LOG(INFO) << "Check for update requested, but status is " | 217 LOG(INFO) << "Check for update requested, but status is " |
217 << UpdateStatusToString(status_) << ", so not checking."; | 218 << UpdateStatusToString(status_) << ", so not checking."; |
218 return; | 219 return; |
219 } | 220 } |
220 Update(app_version, omaha_url); | 221 Update(app_version, omaha_url); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 if (error_event_.get() == NULL) | 420 if (error_event_.get() == NULL) |
420 return false; | 421 return false; |
421 | 422 |
422 LOG(INFO) << "Update failed -- reporting the error event."; | 423 LOG(INFO) << "Update failed -- reporting the error event."; |
423 shared_ptr<OmahaRequestAction> error_event_action( | 424 shared_ptr<OmahaRequestAction> error_event_action( |
424 new OmahaRequestAction(prefs_, | 425 new OmahaRequestAction(prefs_, |
425 omaha_request_params_, | 426 omaha_request_params_, |
426 error_event_.release(), // Pass ownership. | 427 error_event_.release(), // Pass ownership. |
427 new LibcurlHttpFetcher)); | 428 new LibcurlHttpFetcher)); |
428 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); | 429 actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); |
429 processor_.EnqueueAction(error_event_action.get()); | 430 processor_->EnqueueAction(error_event_action.get()); |
430 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); | 431 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); |
431 processor_.StartProcessing(); | 432 processor_->StartProcessing(); |
432 return true; | 433 return true; |
433 } | 434 } |
434 | 435 |
435 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { | 436 void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { |
436 if (priority_ == priority) { | 437 if (priority_ == priority) { |
437 return; | 438 return; |
438 } | 439 } |
439 if (utils::SetProcessPriority(priority)) { | 440 if (utils::SetProcessPriority(priority)) { |
440 priority_ = priority; | 441 priority_ = priority; |
441 LOG(INFO) << "Process priority = " << priority_; | 442 LOG(INFO) << "Process priority = " << priority_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 SetPriority(utils::kProcessPriorityNormal); | 477 SetPriority(utils::kProcessPriorityNormal); |
477 return true; | 478 return true; |
478 } | 479 } |
479 // Set the priority to high and let GLib destroy the timeout source. | 480 // Set the priority to high and let GLib destroy the timeout source. |
480 SetPriority(utils::kProcessPriorityHigh); | 481 SetPriority(utils::kProcessPriorityHigh); |
481 manage_priority_source_ = NULL; | 482 manage_priority_source_ = NULL; |
482 return false; | 483 return false; |
483 } | 484 } |
484 | 485 |
485 } // namespace chromeos_update_engine | 486 } // namespace chromeos_update_engine |
OLD | NEW |