Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/update_attempter.h" |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 6 | |
| 7 | // From 'man clock_gettime': feature test macro: _POSIX_C_SOURCE >= 199309L |
| 8 | #ifndef _POSIX_C_SOURCE |
| 9 | #define _POSIX_C_SOURCE 199309L |
| 10 | #endif // _POSIX_C_SOURCE |
| 11 | #include <time.h> |
| 12 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 13 | #include <string> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 14 | #include <tr1/memory> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 15 | #include <vector> |
Darin Petkov | 9d65b7b | 2010-07-20 09:13:01 -0700 | [diff] [blame] | 16 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 17 | #include <base/rand_util.h> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 18 | #include <glib.h> |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 19 | #include <metrics/metrics_library.h> |
Darin Petkov | 9d65b7b | 2010-07-20 09:13:01 -0700 | [diff] [blame] | 20 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 21 | #include "update_engine/dbus_service.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 22 | #include "update_engine/download_action.h" |
| 23 | #include "update_engine/filesystem_copier_action.h" |
| 24 | #include "update_engine/libcurl_http_fetcher.h" |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 25 | #include "update_engine/multi_http_fetcher.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 26 | #include "update_engine/omaha_request_action.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 27 | #include "update_engine/omaha_request_params.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 28 | #include "update_engine/omaha_response_handler_action.h" |
| 29 | #include "update_engine/postinstall_runner_action.h" |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 30 | #include "update_engine/prefs_interface.h" |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 31 | #include "update_engine/update_check_scheduler.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 32 | |
Darin Petkov | af18305 | 2010-08-23 12:07:13 -0700 | [diff] [blame] | 33 | using base::TimeDelta; |
| 34 | using base::TimeTicks; |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 35 | using std::make_pair; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 36 | using std::tr1::shared_ptr; |
| 37 | using std::string; |
| 38 | using std::vector; |
| 39 | |
| 40 | namespace chromeos_update_engine { |
| 41 | |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 42 | const int UpdateAttempter::kMaxDeltaUpdateFailures = 3; |
| 43 | |
Darin Petkov | cd1666f | 2010-09-23 09:53:44 -0700 | [diff] [blame] | 44 | const char* kUpdateCompletedMarker = |
| 45 | "/var/run/update_engine_autoupdate_completed"; |
Andrew de los Reyes | 6b78e29 | 2010-05-10 15:54:39 -0700 | [diff] [blame] | 46 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 47 | namespace { |
| 48 | const int kMaxConsecutiveObeyProxyRequests = 20; |
| 49 | } // namespace {} |
| 50 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 51 | const char* UpdateStatusToString(UpdateStatus status) { |
| 52 | switch (status) { |
| 53 | case UPDATE_STATUS_IDLE: |
| 54 | return "UPDATE_STATUS_IDLE"; |
| 55 | case UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 56 | return "UPDATE_STATUS_CHECKING_FOR_UPDATE"; |
| 57 | case UPDATE_STATUS_UPDATE_AVAILABLE: |
| 58 | return "UPDATE_STATUS_UPDATE_AVAILABLE"; |
| 59 | case UPDATE_STATUS_DOWNLOADING: |
| 60 | return "UPDATE_STATUS_DOWNLOADING"; |
| 61 | case UPDATE_STATUS_VERIFYING: |
| 62 | return "UPDATE_STATUS_VERIFYING"; |
| 63 | case UPDATE_STATUS_FINALIZING: |
| 64 | return "UPDATE_STATUS_FINALIZING"; |
| 65 | case UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 66 | return "UPDATE_STATUS_UPDATED_NEED_REBOOT"; |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 67 | case UPDATE_STATUS_REPORTING_ERROR_EVENT: |
| 68 | return "UPDATE_STATUS_REPORTING_ERROR_EVENT"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 69 | default: |
| 70 | return "unknown status"; |
| 71 | } |
| 72 | } |
| 73 | |
Darin Petkov | 777dbfa | 2010-07-20 15:03:37 -0700 | [diff] [blame] | 74 | // Turns a generic kActionCodeError to a generic error code specific |
| 75 | // to |action| (e.g., kActionCodeFilesystemCopierError). If |code| is |
| 76 | // not kActionCodeError, or the action is not matched, returns |code| |
| 77 | // unchanged. |
| 78 | ActionExitCode GetErrorCodeForAction(AbstractAction* action, |
| 79 | ActionExitCode code) { |
| 80 | if (code != kActionCodeError) |
| 81 | return code; |
| 82 | |
| 83 | const string type = action->Type(); |
| 84 | if (type == OmahaRequestAction::StaticType()) |
| 85 | return kActionCodeOmahaRequestError; |
| 86 | if (type == OmahaResponseHandlerAction::StaticType()) |
| 87 | return kActionCodeOmahaResponseHandlerError; |
| 88 | if (type == FilesystemCopierAction::StaticType()) |
| 89 | return kActionCodeFilesystemCopierError; |
| 90 | if (type == PostinstallRunnerAction::StaticType()) |
| 91 | return kActionCodePostinstallRunnerError; |
Darin Petkov | 777dbfa | 2010-07-20 15:03:37 -0700 | [diff] [blame] | 92 | |
| 93 | return code; |
| 94 | } |
| 95 | |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 96 | UpdateAttempter::UpdateAttempter(PrefsInterface* prefs, |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 97 | MetricsLibraryInterface* metrics_lib, |
| 98 | DbusGlibInterface* dbus_iface) |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 99 | : processor_(new ActionProcessor()), |
| 100 | dbus_service_(NULL), |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 101 | prefs_(prefs), |
| 102 | metrics_lib_(metrics_lib), |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 103 | update_check_scheduler_(NULL), |
| 104 | http_response_code_(0), |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 105 | priority_(utils::kProcessPriorityNormal), |
| 106 | manage_priority_source_(NULL), |
Darin Petkov | 9d911fa | 2010-08-19 09:36:08 -0700 | [diff] [blame] | 107 | download_active_(false), |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 108 | status_(UPDATE_STATUS_IDLE), |
| 109 | download_progress_(0.0), |
| 110 | last_checked_time_(0), |
| 111 | new_version_("0.0.0.0"), |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 112 | new_size_(0), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 113 | is_full_update_(false), |
| 114 | proxy_manual_checks_(0), |
| 115 | obeying_proxies_(true), |
| 116 | chrome_proxy_resolver_(dbus_iface) { |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 117 | if (utils::FileExists(kUpdateCompletedMarker)) |
| 118 | status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT; |
| 119 | } |
| 120 | |
| 121 | UpdateAttempter::~UpdateAttempter() { |
| 122 | CleanupPriorityManagement(); |
| 123 | } |
| 124 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 125 | void UpdateAttempter::Update(const std::string& app_version, |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 126 | const std::string& omaha_url, |
| 127 | bool obey_proxies) { |
Andrew de los Reyes | 6b78e29 | 2010-05-10 15:54:39 -0700 | [diff] [blame] | 128 | if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 129 | LOG(INFO) << "Not updating b/c we already updated and we're waiting for " |
| 130 | << "reboot"; |
| 131 | return; |
| 132 | } |
| 133 | if (status_ != UPDATE_STATUS_IDLE) { |
| 134 | // Update in progress. Do nothing |
| 135 | return; |
| 136 | } |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 137 | http_response_code_ = 0; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 138 | if (!omaha_request_params_.Init(app_version, omaha_url)) { |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 139 | LOG(ERROR) << "Unable to initialize Omaha request device params."; |
| 140 | return; |
| 141 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame^] | 142 | |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 143 | obeying_proxies_ = true; |
| 144 | if (obey_proxies || proxy_manual_checks_ == 0) { |
| 145 | LOG(INFO) << "forced to obey proxies"; |
| 146 | // If forced to obey proxies, every 20th request will not use proxies |
| 147 | proxy_manual_checks_++; |
| 148 | LOG(INFO) << "proxy manual checks: " << proxy_manual_checks_; |
| 149 | if (proxy_manual_checks_ >= kMaxConsecutiveObeyProxyRequests) { |
| 150 | proxy_manual_checks_ = 0; |
| 151 | obeying_proxies_ = false; |
| 152 | } |
| 153 | } else if (base::RandInt(0, 4) == 0) { |
| 154 | obeying_proxies_ = false; |
| 155 | } |
| 156 | LOG_IF(INFO, !obeying_proxies_) << "To help ensure updates work, this update " |
| 157 | "check we are ignoring the proxy settings and using " |
| 158 | "direct connections."; |
| 159 | |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 160 | DisableDeltaUpdateIfNeeded(); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 161 | CHECK(!processor_->IsRunning()); |
| 162 | processor_->set_delegate(this); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 163 | |
| 164 | // Actions: |
Darin Petkov | a092955 | 2010-11-29 14:19:06 -0800 | [diff] [blame] | 165 | LibcurlHttpFetcher* update_check_fetcher = |
| 166 | new LibcurlHttpFetcher(GetProxyResolver()); |
Andrew de los Reyes | 5d0783d | 2010-11-29 18:14:16 -0800 | [diff] [blame] | 167 | // Try harder to connect to the network. See comment in |
| 168 | // libcurl_http_fetcher.cc. |
| 169 | update_check_fetcher->set_no_network_max_retries(3); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 170 | shared_ptr<OmahaRequestAction> update_check_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 171 | new OmahaRequestAction(prefs_, |
| 172 | omaha_request_params_, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 173 | NULL, |
Darin Petkov | a092955 | 2010-11-29 14:19:06 -0800 | [diff] [blame] | 174 | update_check_fetcher)); // passes ownership |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 175 | shared_ptr<OmahaResponseHandlerAction> response_handler_action( |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 176 | new OmahaResponseHandlerAction(prefs_)); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 177 | shared_ptr<FilesystemCopierAction> filesystem_copier_action( |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame^] | 178 | new FilesystemCopierAction(false, false)); |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 179 | shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action( |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame^] | 180 | new FilesystemCopierAction(true, false)); |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 181 | shared_ptr<OmahaRequestAction> download_started_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 182 | new OmahaRequestAction(prefs_, |
| 183 | omaha_request_params_, |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 184 | new OmahaEvent( |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 185 | OmahaEvent::kTypeUpdateDownloadStarted), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 186 | new LibcurlHttpFetcher(GetProxyResolver()))); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 187 | shared_ptr<DownloadAction> download_action( |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 188 | new DownloadAction(prefs_, new MultiHttpFetcher<LibcurlHttpFetcher>( |
| 189 | GetProxyResolver()))); |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 190 | shared_ptr<OmahaRequestAction> download_finished_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 191 | new OmahaRequestAction(prefs_, |
| 192 | omaha_request_params_, |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 193 | new OmahaEvent( |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 194 | OmahaEvent::kTypeUpdateDownloadFinished), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 195 | new LibcurlHttpFetcher(GetProxyResolver()))); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame^] | 196 | shared_ptr<FilesystemCopierAction> filesystem_verifier_action( |
| 197 | new FilesystemCopierAction(false, true)); |
| 198 | shared_ptr<FilesystemCopierAction> kernel_filesystem_verifier_action( |
| 199 | new FilesystemCopierAction(true, true)); |
Darin Petkov | 6d5dbf6 | 2010-11-08 16:09:55 -0800 | [diff] [blame] | 200 | shared_ptr<PostinstallRunnerAction> postinstall_runner_action( |
| 201 | new PostinstallRunnerAction); |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 202 | shared_ptr<OmahaRequestAction> update_complete_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 203 | new OmahaRequestAction(prefs_, |
| 204 | omaha_request_params_, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 205 | new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 206 | new LibcurlHttpFetcher(GetProxyResolver()))); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 207 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 208 | download_action->set_delegate(this); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 209 | response_handler_action_ = response_handler_action; |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 210 | download_action_ = download_action; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 211 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 212 | actions_.push_back(shared_ptr<AbstractAction>(update_check_action)); |
| 213 | actions_.push_back(shared_ptr<AbstractAction>(response_handler_action)); |
| 214 | actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action)); |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 215 | actions_.push_back(shared_ptr<AbstractAction>( |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 216 | kernel_filesystem_copier_action)); |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 217 | actions_.push_back(shared_ptr<AbstractAction>(download_started_action)); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 218 | actions_.push_back(shared_ptr<AbstractAction>(download_action)); |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 219 | actions_.push_back(shared_ptr<AbstractAction>(download_finished_action)); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame^] | 220 | actions_.push_back(shared_ptr<AbstractAction>(filesystem_verifier_action)); |
| 221 | actions_.push_back(shared_ptr<AbstractAction>( |
| 222 | kernel_filesystem_verifier_action)); |
Darin Petkov | 6d5dbf6 | 2010-11-08 16:09:55 -0800 | [diff] [blame] | 223 | actions_.push_back(shared_ptr<AbstractAction>(postinstall_runner_action)); |
Darin Petkov | 8c2980e | 2010-07-16 15:16:49 -0700 | [diff] [blame] | 224 | actions_.push_back(shared_ptr<AbstractAction>(update_complete_action)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 225 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 226 | // Enqueue the actions |
| 227 | for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin(); |
| 228 | it != actions_.end(); ++it) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 229 | processor_->EnqueueAction(it->get()); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // Bond them together. We have to use the leaf-types when calling |
| 233 | // BondActions(). |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 234 | BondActions(update_check_action.get(), |
| 235 | response_handler_action.get()); |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 236 | BondActions(response_handler_action.get(), |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 237 | filesystem_copier_action.get()); |
| 238 | BondActions(filesystem_copier_action.get(), |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 239 | kernel_filesystem_copier_action.get()); |
| 240 | BondActions(kernel_filesystem_copier_action.get(), |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 241 | download_action.get()); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 242 | BondActions(download_action.get(), |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame^] | 243 | filesystem_verifier_action.get()); |
| 244 | BondActions(filesystem_verifier_action.get(), |
| 245 | kernel_filesystem_verifier_action.get()); |
| 246 | BondActions(kernel_filesystem_verifier_action.get(), |
Darin Petkov | 6d5dbf6 | 2010-11-08 16:09:55 -0800 | [diff] [blame] | 247 | postinstall_runner_action.get()); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 248 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 249 | SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 250 | processor_->StartProcessing(); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 253 | void UpdateAttempter::CheckForUpdate(const std::string& app_version, |
| 254 | const std::string& omaha_url) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 255 | if (status_ != UPDATE_STATUS_IDLE) { |
| 256 | LOG(INFO) << "Check for update requested, but status is " |
| 257 | << UpdateStatusToString(status_) << ", so not checking."; |
| 258 | return; |
| 259 | } |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 260 | Update(app_version, omaha_url, true); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 263 | bool UpdateAttempter::RebootIfNeeded() { |
| 264 | if (status_ != UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 265 | LOG(INFO) << "Reboot requested, but status is " |
| 266 | << UpdateStatusToString(status_) << ", so not rebooting."; |
| 267 | return false; |
| 268 | } |
| 269 | TEST_AND_RETURN_FALSE(utils::Reboot()); |
| 270 | return true; |
| 271 | } |
| 272 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 273 | // Delegate methods: |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 274 | void UpdateAttempter::ProcessingDone(const ActionProcessor* processor, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 275 | ActionExitCode code) { |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 276 | CHECK(response_handler_action_); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 277 | LOG(INFO) << "Processing Done."; |
Andrew de los Reyes | 6b78e29 | 2010-05-10 15:54:39 -0700 | [diff] [blame] | 278 | actions_.clear(); |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 279 | |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 280 | // Reset process priority back to normal. |
| 281 | CleanupPriorityManagement(); |
| 282 | |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 283 | if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { |
| 284 | LOG(INFO) << "Error event sent."; |
| 285 | SetStatusAndNotify(UPDATE_STATUS_IDLE); |
| 286 | return; |
| 287 | } |
| 288 | |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 289 | if (code == kActionCodeSuccess) { |
Andrew de los Reyes | 6b78e29 | 2010-05-10 15:54:39 -0700 | [diff] [blame] | 290 | utils::WriteFile(kUpdateCompletedMarker, "", 0); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 291 | prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 292 | DeltaPerformer::ResetUpdateProgress(prefs_, false); |
| 293 | SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT); |
Darin Petkov | 9d65b7b | 2010-07-20 09:13:01 -0700 | [diff] [blame] | 294 | |
| 295 | // Report the time it took to update the system. |
| 296 | int64_t update_time = time(NULL) - last_checked_time_; |
| 297 | metrics_lib_->SendToUMA("Installer.UpdateTime", |
| 298 | static_cast<int>(update_time), // sample |
| 299 | 1, // min = 1 second |
| 300 | 20 * 60, // max = 20 minutes |
| 301 | 50); // buckets |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 302 | return; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 303 | } |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 304 | |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 305 | if (ScheduleErrorEventAction()) { |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 306 | return; |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 307 | } |
| 308 | LOG(INFO) << "No update."; |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 309 | SetStatusAndNotify(UPDATE_STATUS_IDLE); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void UpdateAttempter::ProcessingStopped(const ActionProcessor* processor) { |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 313 | // Reset process priority back to normal. |
| 314 | CleanupPriorityManagement(); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 315 | download_progress_ = 0.0; |
| 316 | SetStatusAndNotify(UPDATE_STATUS_IDLE); |
Andrew de los Reyes | 6b78e29 | 2010-05-10 15:54:39 -0700 | [diff] [blame] | 317 | actions_.clear(); |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 318 | error_event_.reset(NULL); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | // Called whenever an action has finished processing, either successfully |
| 322 | // or otherwise. |
| 323 | void UpdateAttempter::ActionCompleted(ActionProcessor* processor, |
| 324 | AbstractAction* action, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 325 | ActionExitCode code) { |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 326 | // Reset download progress regardless of whether or not the download |
| 327 | // action succeeded. Also, get the response code from HTTP request |
| 328 | // actions (update download as well as the initial update check |
| 329 | // actions). |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 330 | const string type = action->Type(); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 331 | if (type == DownloadAction::StaticType()) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 332 | download_progress_ = 0.0; |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 333 | DownloadAction* download_action = dynamic_cast<DownloadAction*>(action); |
| 334 | http_response_code_ = download_action->GetHTTPResponseCode(); |
| 335 | } else if (type == OmahaRequestAction::StaticType()) { |
| 336 | OmahaRequestAction* omaha_request_action = |
| 337 | dynamic_cast<OmahaRequestAction*>(action); |
| 338 | // If the request is not an event, then it's the update-check. |
| 339 | if (!omaha_request_action->IsEvent()) { |
| 340 | http_response_code_ = omaha_request_action->GetHTTPResponseCode(); |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 341 | // Forward the server-dictated poll interval to the update check |
| 342 | // scheduler, if any. |
| 343 | if (update_check_scheduler_) { |
| 344 | update_check_scheduler_->set_poll_interval( |
| 345 | omaha_request_action->GetOutputObject().poll_interval); |
| 346 | } |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 349 | if (code != kActionCodeSuccess) { |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 350 | // If this was a delta update attempt and the current state is at or past |
| 351 | // the download phase, count the failure in case a switch to full update |
| 352 | // becomes necessary. Ignore network transfer timeouts and failures. |
| 353 | if (status_ >= UPDATE_STATUS_DOWNLOADING && |
| 354 | !is_full_update_ && |
| 355 | code != kActionCodeDownloadTransferError) { |
| 356 | MarkDeltaUpdateFailure(); |
| 357 | } |
Darin Petkov | 777dbfa | 2010-07-20 15:03:37 -0700 | [diff] [blame] | 358 | // On failure, schedule an error event to be sent to Omaha. |
| 359 | CreatePendingErrorEvent(action, code); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 360 | return; |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 361 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 362 | // Find out which action completed. |
| 363 | if (type == OmahaResponseHandlerAction::StaticType()) { |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 364 | // Note that the status will be updated to DOWNLOADING when some bytes get |
| 365 | // actually downloaded from the server and the BytesReceived callback is |
| 366 | // invoked. This avoids notifying the user that a download has started in |
| 367 | // cases when the server and the client are unable to initiate the download. |
| 368 | CHECK(action == response_handler_action_.get()); |
| 369 | const InstallPlan& plan = response_handler_action_->install_plan(); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 370 | last_checked_time_ = time(NULL); |
| 371 | // TODO(adlr): put version in InstallPlan |
| 372 | new_version_ = "0.0.0.0"; |
| 373 | new_size_ = plan.size; |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 374 | is_full_update_ = plan.is_full_update; |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 375 | SetupDownload(); |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 376 | SetupPriorityManagement(); |
Darin Petkov | b00bccc | 2010-10-26 14:13:08 -0700 | [diff] [blame] | 377 | SetStatusAndNotify(UPDATE_STATUS_UPDATE_AVAILABLE); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 378 | } else if (type == DownloadAction::StaticType()) { |
| 379 | SetStatusAndNotify(UPDATE_STATUS_FINALIZING); |
| 380 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // Stop updating. An attempt will be made to record status to the disk |
| 384 | // so that updates can be resumed later. |
| 385 | void UpdateAttempter::Terminate() { |
| 386 | // TODO(adlr): implement this method. |
| 387 | NOTIMPLEMENTED(); |
| 388 | } |
| 389 | |
| 390 | // Try to resume from a previously Terminate()d update. |
| 391 | void UpdateAttempter::ResumeUpdating() { |
| 392 | // TODO(adlr): implement this method. |
| 393 | NOTIMPLEMENTED(); |
| 394 | } |
| 395 | |
Darin Petkov | 9d911fa | 2010-08-19 09:36:08 -0700 | [diff] [blame] | 396 | void UpdateAttempter::SetDownloadStatus(bool active) { |
| 397 | download_active_ = active; |
| 398 | LOG(INFO) << "Download status: " << (active ? "active" : "inactive"); |
| 399 | } |
| 400 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 401 | void UpdateAttempter::BytesReceived(uint64_t bytes_received, uint64_t total) { |
Darin Petkov | 9d911fa | 2010-08-19 09:36:08 -0700 | [diff] [blame] | 402 | if (!download_active_) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 403 | LOG(ERROR) << "BytesReceived called while not downloading."; |
| 404 | return; |
| 405 | } |
Darin Petkov | af18305 | 2010-08-23 12:07:13 -0700 | [diff] [blame] | 406 | double progress = static_cast<double>(bytes_received) / |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 407 | static_cast<double>(total); |
Darin Petkov | af18305 | 2010-08-23 12:07:13 -0700 | [diff] [blame] | 408 | // Self throttle based on progress. Also send notifications if |
| 409 | // progress is too slow. |
| 410 | const double kDeltaPercent = 0.01; // 1% |
| 411 | if (status_ != UPDATE_STATUS_DOWNLOADING || |
| 412 | bytes_received == total || |
| 413 | progress - download_progress_ >= kDeltaPercent || |
| 414 | TimeTicks::Now() - last_notify_time_ >= TimeDelta::FromSeconds(10)) { |
| 415 | download_progress_ = progress; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 416 | SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING); |
| 417 | } |
| 418 | } |
| 419 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 420 | bool UpdateAttempter::GetStatus(int64_t* last_checked_time, |
| 421 | double* progress, |
| 422 | std::string* current_operation, |
| 423 | std::string* new_version, |
| 424 | int64_t* new_size) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 425 | *last_checked_time = last_checked_time_; |
| 426 | *progress = download_progress_; |
| 427 | *current_operation = UpdateStatusToString(status_); |
| 428 | *new_version = new_version_; |
| 429 | *new_size = new_size_; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 430 | return true; |
| 431 | } |
| 432 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 433 | void UpdateAttempter::SetStatusAndNotify(UpdateStatus status) { |
| 434 | status_ = status; |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 435 | if (update_check_scheduler_) { |
| 436 | update_check_scheduler_->SetUpdateStatus(status_); |
| 437 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 438 | if (!dbus_service_) |
| 439 | return; |
Darin Petkov | af18305 | 2010-08-23 12:07:13 -0700 | [diff] [blame] | 440 | last_notify_time_ = TimeTicks::Now(); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 441 | update_engine_service_emit_status_update( |
| 442 | dbus_service_, |
| 443 | last_checked_time_, |
| 444 | download_progress_, |
| 445 | UpdateStatusToString(status_), |
| 446 | new_version_.c_str(), |
| 447 | new_size_); |
| 448 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 449 | |
Darin Petkov | 777dbfa | 2010-07-20 15:03:37 -0700 | [diff] [blame] | 450 | void UpdateAttempter::CreatePendingErrorEvent(AbstractAction* action, |
| 451 | ActionExitCode code) { |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 452 | if (error_event_.get()) { |
| 453 | // This shouldn't really happen. |
| 454 | LOG(WARNING) << "There's already an existing pending error event."; |
| 455 | return; |
| 456 | } |
Darin Petkov | 777dbfa | 2010-07-20 15:03:37 -0700 | [diff] [blame] | 457 | |
| 458 | // For now assume that Omaha response action failure means that |
| 459 | // there's no update so don't send an event. Also, double check that |
| 460 | // the failure has not occurred while sending an error event -- in |
| 461 | // which case don't schedule another. This shouldn't really happen |
| 462 | // but just in case... |
| 463 | if (action->Type() == OmahaResponseHandlerAction::StaticType() || |
| 464 | status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) { |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | code = GetErrorCodeForAction(action, code); |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 469 | error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, |
| 470 | OmahaEvent::kResultError, |
| 471 | code)); |
| 472 | } |
| 473 | |
| 474 | bool UpdateAttempter::ScheduleErrorEventAction() { |
| 475 | if (error_event_.get() == NULL) |
| 476 | return false; |
| 477 | |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 478 | LOG(INFO) << "Update failed -- reporting the error event."; |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 479 | shared_ptr<OmahaRequestAction> error_event_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 480 | new OmahaRequestAction(prefs_, |
| 481 | omaha_request_params_, |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 482 | error_event_.release(), // Pass ownership. |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 483 | new LibcurlHttpFetcher(GetProxyResolver()))); |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 484 | actions_.push_back(shared_ptr<AbstractAction>(error_event_action)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 485 | processor_->EnqueueAction(error_event_action.get()); |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 486 | SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 487 | processor_->StartProcessing(); |
Darin Petkov | 09f96c3 | 2010-07-20 09:24:57 -0700 | [diff] [blame] | 488 | return true; |
| 489 | } |
| 490 | |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 491 | void UpdateAttempter::SetPriority(utils::ProcessPriority priority) { |
| 492 | if (priority_ == priority) { |
| 493 | return; |
| 494 | } |
| 495 | if (utils::SetProcessPriority(priority)) { |
| 496 | priority_ = priority; |
| 497 | LOG(INFO) << "Process priority = " << priority_; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | void UpdateAttempter::SetupPriorityManagement() { |
| 502 | if (manage_priority_source_) { |
| 503 | LOG(ERROR) << "Process priority timeout source hasn't been destroyed."; |
| 504 | CleanupPriorityManagement(); |
| 505 | } |
Darin Petkov | f622ef7 | 2010-10-26 13:49:24 -0700 | [diff] [blame] | 506 | const int kPriorityTimeout = 2 * 60 * 60; // 2 hours |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 507 | manage_priority_source_ = g_timeout_source_new_seconds(kPriorityTimeout); |
| 508 | g_source_set_callback(manage_priority_source_, |
| 509 | StaticManagePriorityCallback, |
| 510 | this, |
| 511 | NULL); |
| 512 | g_source_attach(manage_priority_source_, NULL); |
| 513 | SetPriority(utils::kProcessPriorityLow); |
| 514 | } |
| 515 | |
| 516 | void UpdateAttempter::CleanupPriorityManagement() { |
| 517 | if (manage_priority_source_) { |
| 518 | g_source_destroy(manage_priority_source_); |
| 519 | manage_priority_source_ = NULL; |
| 520 | } |
| 521 | SetPriority(utils::kProcessPriorityNormal); |
| 522 | } |
| 523 | |
| 524 | gboolean UpdateAttempter::StaticManagePriorityCallback(gpointer data) { |
| 525 | return reinterpret_cast<UpdateAttempter*>(data)->ManagePriorityCallback(); |
| 526 | } |
| 527 | |
| 528 | bool UpdateAttempter::ManagePriorityCallback() { |
Darin Petkov | f622ef7 | 2010-10-26 13:49:24 -0700 | [diff] [blame] | 529 | SetPriority(utils::kProcessPriorityNormal); |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 530 | manage_priority_source_ = NULL; |
Darin Petkov | f622ef7 | 2010-10-26 13:49:24 -0700 | [diff] [blame] | 531 | return false; // Destroy the timeout source. |
Darin Petkov | c6c135c | 2010-08-11 13:36:18 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 534 | void UpdateAttempter::DisableDeltaUpdateIfNeeded() { |
| 535 | int64_t delta_failures; |
| 536 | if (omaha_request_params_.delta_okay && |
| 537 | prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) && |
| 538 | delta_failures >= kMaxDeltaUpdateFailures) { |
| 539 | LOG(WARNING) << "Too many delta update failures, forcing full update."; |
| 540 | omaha_request_params_.delta_okay = false; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void UpdateAttempter::MarkDeltaUpdateFailure() { |
| 545 | CHECK(!is_full_update_); |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 546 | // Don't try to resume a failed delta update. |
| 547 | DeltaPerformer::ResetUpdateProgress(prefs_, false); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 548 | int64_t delta_failures; |
| 549 | if (!prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) || |
| 550 | delta_failures < 0) { |
| 551 | delta_failures = 0; |
| 552 | } |
| 553 | prefs_->SetInt64(kPrefsDeltaUpdateFailures, ++delta_failures); |
| 554 | } |
| 555 | |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 556 | void UpdateAttempter::SetupDownload() { |
| 557 | MultiHttpFetcher<LibcurlHttpFetcher>* fetcher = |
| 558 | dynamic_cast<MultiHttpFetcher<LibcurlHttpFetcher>*>( |
| 559 | download_action_->http_fetcher()); |
| 560 | MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect ranges; |
| 561 | if (response_handler_action_->install_plan().is_resume) { |
Darin Petkov | b21ce5d | 2010-10-21 16:03:05 -0700 | [diff] [blame] | 562 | // Resuming an update so fetch the update manifest metadata first. |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 563 | int64_t manifest_metadata_size = 0; |
| 564 | prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size); |
Darin Petkov | b21ce5d | 2010-10-21 16:03:05 -0700 | [diff] [blame] | 565 | ranges.push_back(make_pair(0, manifest_metadata_size)); |
| 566 | // If there're remaining unprocessed data blobs, fetch them. Be careful not |
| 567 | // to request data beyond the end of the payload to avoid 416 HTTP response |
| 568 | // error codes. |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 569 | int64_t next_data_offset = 0; |
| 570 | prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset); |
Darin Petkov | b21ce5d | 2010-10-21 16:03:05 -0700 | [diff] [blame] | 571 | uint64_t resume_offset = manifest_metadata_size + next_data_offset; |
| 572 | if (resume_offset < response_handler_action_->install_plan().size) { |
| 573 | ranges.push_back(make_pair(resume_offset, -1)); |
| 574 | } |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 575 | } else { |
| 576 | ranges.push_back(make_pair(0, -1)); |
| 577 | } |
| 578 | fetcher->set_ranges(ranges); |
| 579 | } |
| 580 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 581 | } // namespace chromeos_update_engine |