| 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 |
| 11 #include <time.h> | 11 #include <time.h> |
| 12 | 12 |
| 13 #include <tr1/memory> | 13 #include <tr1/memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 #include <glib.h> | 16 #include <glib.h> |
| 17 #include "update_engine/dbus_service.h" | 17 #include "update_engine/dbus_service.h" |
| 18 #include "update_engine/download_action.h" | 18 #include "update_engine/download_action.h" |
| 19 #include "update_engine/filesystem_copier_action.h" | 19 #include "update_engine/filesystem_copier_action.h" |
| 20 #include "update_engine/libcurl_http_fetcher.h" | 20 #include "update_engine/libcurl_http_fetcher.h" |
| 21 #include "update_engine/omaha_request_action.h" | 21 #include "update_engine/omaha_request_action.h" |
| 22 #include "update_engine/omaha_request_prep_action.h" | 22 #include "update_engine/omaha_request_params.h" |
| 23 #include "update_engine/omaha_response_handler_action.h" | 23 #include "update_engine/omaha_response_handler_action.h" |
| 24 #include "update_engine/postinstall_runner_action.h" | 24 #include "update_engine/postinstall_runner_action.h" |
| 25 #include "update_engine/set_bootable_flag_action.h" | 25 #include "update_engine/set_bootable_flag_action.h" |
| 26 | 26 |
| 27 using std::tr1::shared_ptr; | 27 using std::tr1::shared_ptr; |
| 28 using std::string; | 28 using std::string; |
| 29 using std::vector; | 29 using std::vector; |
| 30 | 30 |
| 31 namespace chromeos_update_engine { | 31 namespace chromeos_update_engine { |
| 32 | 32 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return "UPDATE_STATUS_VERIFYING"; | 78 return "UPDATE_STATUS_VERIFYING"; |
| 79 case UPDATE_STATUS_FINALIZING: | 79 case UPDATE_STATUS_FINALIZING: |
| 80 return "UPDATE_STATUS_FINALIZING"; | 80 return "UPDATE_STATUS_FINALIZING"; |
| 81 case UPDATE_STATUS_UPDATED_NEED_REBOOT: | 81 case UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 82 return "UPDATE_STATUS_UPDATED_NEED_REBOOT"; | 82 return "UPDATE_STATUS_UPDATED_NEED_REBOOT"; |
| 83 default: | 83 default: |
| 84 return "unknown status"; | 84 return "unknown status"; |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 void UpdateAttempter::Update(bool force_full_update) { | 88 void UpdateAttempter::Update() { |
| 89 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 89 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 90 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " | 90 LOG(INFO) << "Not updating b/c we already updated and we're waiting for " |
| 91 << "reboot"; | 91 << "reboot"; |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 if (status_ != UPDATE_STATUS_IDLE) { | 94 if (status_ != UPDATE_STATUS_IDLE) { |
| 95 // Update in progress. Do nothing | 95 // Update in progress. Do nothing |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 full_update_ = force_full_update; | 98 if (!omaha_request_params_.Init()) { |
| 99 LOG(ERROR) << "Unable to initialize Omaha request device params."; |
| 100 return; |
| 101 } |
| 99 CHECK(!processor_.IsRunning()); | 102 CHECK(!processor_.IsRunning()); |
| 100 processor_.set_delegate(this); | 103 processor_.set_delegate(this); |
| 101 | 104 |
| 102 // Actions: | 105 // Actions: |
| 103 shared_ptr<OmahaRequestPrepAction> update_check_prep_action( | |
| 104 new OmahaRequestPrepAction(force_full_update)); | |
| 105 shared_ptr<OmahaRequestAction> update_check_action( | 106 shared_ptr<OmahaRequestAction> update_check_action( |
| 106 new OmahaRequestAction(NULL, new LibcurlHttpFetcher)); | 107 new OmahaRequestAction(omaha_request_params_, |
| 108 NULL, |
| 109 new LibcurlHttpFetcher)); |
| 107 shared_ptr<OmahaResponseHandlerAction> response_handler_action( | 110 shared_ptr<OmahaResponseHandlerAction> response_handler_action( |
| 108 new OmahaResponseHandlerAction); | 111 new OmahaResponseHandlerAction); |
| 109 shared_ptr<FilesystemCopierAction> filesystem_copier_action( | 112 shared_ptr<FilesystemCopierAction> filesystem_copier_action( |
| 110 new FilesystemCopierAction(false)); | 113 new FilesystemCopierAction(false)); |
| 111 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( | 114 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( |
| 112 new FilesystemCopierAction(true)); | 115 new FilesystemCopierAction(true)); |
| 113 shared_ptr<DownloadAction> download_action( | 116 shared_ptr<DownloadAction> download_action( |
| 114 new DownloadAction(new LibcurlHttpFetcher)); | 117 new DownloadAction(new LibcurlHttpFetcher)); |
| 115 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_precommit( | 118 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_precommit( |
| 116 new PostinstallRunnerAction(true)); | 119 new PostinstallRunnerAction(true)); |
| 117 shared_ptr<SetBootableFlagAction> set_bootable_flag_action( | 120 shared_ptr<SetBootableFlagAction> set_bootable_flag_action( |
| 118 new SetBootableFlagAction); | 121 new SetBootableFlagAction); |
| 119 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_postcommit( | 122 shared_ptr<PostinstallRunnerAction> postinstall_runner_action_postcommit( |
| 120 new PostinstallRunnerAction(false)); | 123 new PostinstallRunnerAction(false)); |
| 121 shared_ptr<OmahaRequestPrepAction> install_success_prep_action( | |
| 122 new OmahaRequestPrepAction(false)); | |
| 123 shared_ptr<OmahaRequestAction> install_success_action( | 124 shared_ptr<OmahaRequestAction> install_success_action( |
| 124 new OmahaRequestAction(new OmahaEvent(OmahaEvent::kTypeInstallComplete, | 125 new OmahaRequestAction(omaha_request_params_, |
| 126 new OmahaEvent(OmahaEvent::kTypeInstallComplete, |
| 125 OmahaEvent::kResultSuccess, | 127 OmahaEvent::kResultSuccess, |
| 126 0), | 128 0), |
| 127 new LibcurlHttpFetcher)); | 129 new LibcurlHttpFetcher)); |
| 128 | 130 |
| 129 download_action->set_delegate(this); | 131 download_action->set_delegate(this); |
| 130 response_handler_action_ = response_handler_action; | 132 response_handler_action_ = response_handler_action; |
| 131 | 133 |
| 132 actions_.push_back(shared_ptr<AbstractAction>(update_check_prep_action)); | |
| 133 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); | 134 actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); |
| 134 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); | 135 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); |
| 135 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); | 136 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); |
| 136 actions_.push_back(shared_ptr<AbstractAction>( | 137 actions_.push_back(shared_ptr<AbstractAction>( |
| 137 kernel_filesystem_copier_action)); | 138 kernel_filesystem_copier_action)); |
| 138 actions_.push_back(shared_ptr<AbstractAction>(download_action)); | 139 actions_.push_back(shared_ptr<AbstractAction>(download_action)); |
| 139 actions_.push_back(shared_ptr<AbstractAction>( | 140 actions_.push_back(shared_ptr<AbstractAction>( |
| 140 postinstall_runner_action_precommit)); | 141 postinstall_runner_action_precommit)); |
| 141 actions_.push_back(shared_ptr<AbstractAction>(set_bootable_flag_action)); | 142 actions_.push_back(shared_ptr<AbstractAction>(set_bootable_flag_action)); |
| 142 actions_.push_back(shared_ptr<AbstractAction>( | 143 actions_.push_back(shared_ptr<AbstractAction>( |
| 143 postinstall_runner_action_postcommit)); | 144 postinstall_runner_action_postcommit)); |
| 144 actions_.push_back(shared_ptr<AbstractAction>(install_success_prep_action)); | |
| 145 actions_.push_back(shared_ptr<AbstractAction>(install_success_action)); | 145 actions_.push_back(shared_ptr<AbstractAction>(install_success_action)); |
| 146 | 146 |
| 147 // Enqueue the actions | 147 // Enqueue the actions |
| 148 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); | 148 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); |
| 149 it != actions_.end(); ++it) { | 149 it != actions_.end(); ++it) { |
| 150 processor_.EnqueueAction(it->get()); | 150 processor_.EnqueueAction(it->get()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Bond them together. We have to use the leaf-types when calling | 153 // Bond them together. We have to use the leaf-types when calling |
| 154 // BondActions(). | 154 // BondActions(). |
| 155 BondActions(update_check_prep_action.get(), | |
| 156 update_check_action.get()); | |
| 157 BondActions(update_check_action.get(), | 155 BondActions(update_check_action.get(), |
| 158 response_handler_action.get()); | 156 response_handler_action.get()); |
| 159 BondActions(response_handler_action.get(), | 157 BondActions(response_handler_action.get(), |
| 160 filesystem_copier_action.get()); | 158 filesystem_copier_action.get()); |
| 161 BondActions(filesystem_copier_action.get(), | 159 BondActions(filesystem_copier_action.get(), |
| 162 kernel_filesystem_copier_action.get()); | 160 kernel_filesystem_copier_action.get()); |
| 163 BondActions(kernel_filesystem_copier_action.get(), | 161 BondActions(kernel_filesystem_copier_action.get(), |
| 164 download_action.get()); | 162 download_action.get()); |
| 165 BondActions(download_action.get(), | 163 BondActions(download_action.get(), |
| 166 postinstall_runner_action_precommit.get()); | 164 postinstall_runner_action_precommit.get()); |
| 167 BondActions(postinstall_runner_action_precommit.get(), | 165 BondActions(postinstall_runner_action_precommit.get(), |
| 168 set_bootable_flag_action.get()); | 166 set_bootable_flag_action.get()); |
| 169 BondActions(set_bootable_flag_action.get(), | 167 BondActions(set_bootable_flag_action.get(), |
| 170 postinstall_runner_action_postcommit.get()); | 168 postinstall_runner_action_postcommit.get()); |
| 171 BondActions(install_success_prep_action.get(), | |
| 172 install_success_action.get()); | |
| 173 | 169 |
| 174 SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE); | 170 SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE); |
| 175 processor_.StartProcessing(); | 171 processor_.StartProcessing(); |
| 176 } | 172 } |
| 177 | 173 |
| 178 void UpdateAttempter::CheckForUpdate() { | 174 void UpdateAttempter::CheckForUpdate() { |
| 179 if (status_ != UPDATE_STATUS_IDLE) { | 175 if (status_ != UPDATE_STATUS_IDLE) { |
| 180 LOG(INFO) << "Check for update requested, but status is " | 176 LOG(INFO) << "Check for update requested, but status is " |
| 181 << UpdateStatusToString(status_) << ", so not checking."; | 177 << UpdateStatusToString(status_) << ", so not checking."; |
| 182 return; | 178 return; |
| 183 } | 179 } |
| 184 Update(false); | 180 Update(); |
| 185 } | 181 } |
| 186 | 182 |
| 187 // Delegate methods: | 183 // Delegate methods: |
| 188 void UpdateAttempter::ProcessingDone(const ActionProcessor* processor, | 184 void UpdateAttempter::ProcessingDone(const ActionProcessor* processor, |
| 189 bool success) { | 185 bool success) { |
| 190 CHECK(response_handler_action_); | 186 CHECK(response_handler_action_); |
| 191 LOG(INFO) << "Processing Done."; | 187 LOG(INFO) << "Processing Done."; |
| 192 actions_.clear(); | 188 actions_.clear(); |
| 193 if (success) { | 189 if (success) { |
| 194 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); | 190 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 update_engine_service_emit_status_update( | 281 update_engine_service_emit_status_update( |
| 286 dbus_service_, | 282 dbus_service_, |
| 287 last_checked_time_, | 283 last_checked_time_, |
| 288 download_progress_, | 284 download_progress_, |
| 289 UpdateStatusToString(status_), | 285 UpdateStatusToString(status_), |
| 290 new_version_.c_str(), | 286 new_version_.c_str(), |
| 291 new_size_); | 287 new_size_); |
| 292 } | 288 } |
| 293 | 289 |
| 294 } // namespace chromeos_update_engine | 290 } // namespace chromeos_update_engine |
| OLD | NEW |