blob: 7446489de6f9e1dba0a59dda5c2418999f0ec7e7 [file] [log] [blame]
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07002// 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 Reyes63b96d72010-05-10 13:08:54 -07006
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 Reyes4e9b9f42010-04-26 15:06:43 -070013#include <string>
Darin Petkov9b230572010-10-08 10:20:09 -070014#include <tr1/memory>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070015#include <vector>
Darin Petkov9d65b7b2010-07-20 09:13:01 -070016
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -070017#include <base/file_util.h>
Andrew de los Reyes45168102010-11-22 11:13:50 -080018#include <base/rand_util.h>
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070019#include <glib.h>
Darin Petkov1023a602010-08-30 13:47:51 -070020#include <metrics/metrics_library.h>
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +020021#include <policy/libpolicy.h>
22#include <policy/device_policy.h>
Darin Petkov9d65b7b2010-07-20 09:13:01 -070023
Bruno Rocha7f9aea22011-09-12 14:31:24 -070024#include "update_engine/certificate_checker.h"
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070025#include "update_engine/dbus_service.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070026#include "update_engine/download_action.h"
27#include "update_engine/filesystem_copier_action.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080028#include "update_engine/gpio_handler.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070029#include "update_engine/libcurl_http_fetcher.h"
Andrew de los Reyes819fef22010-12-17 11:33:58 -080030#include "update_engine/multi_range_http_fetcher.h"
Darin Petkov6a5b3222010-07-13 14:55:28 -070031#include "update_engine/omaha_request_action.h"
Darin Petkova4a8a8c2010-07-15 22:21:12 -070032#include "update_engine/omaha_request_params.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070033#include "update_engine/omaha_response_handler_action.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080034#include "update_engine/payload_state_interface.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070035#include "update_engine/postinstall_runner_action.h"
Darin Petkov36275772010-10-01 11:40:57 -070036#include "update_engine/prefs_interface.h"
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -070037#include "update_engine/subprocess.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070038#include "update_engine/system_state.h"
Darin Petkov1023a602010-08-30 13:47:51 -070039#include "update_engine/update_check_scheduler.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070040
Darin Petkovaf183052010-08-23 12:07:13 -070041using base::TimeDelta;
42using base::TimeTicks;
Andrew de los Reyes21816e12011-04-07 14:18:56 -070043using google::protobuf::NewPermanentCallback;
Darin Petkov9b230572010-10-08 10:20:09 -070044using std::make_pair;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070045using std::tr1::shared_ptr;
Jay Srinivasan43488792012-06-19 00:25:31 -070046using std::set;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070047using std::string;
48using std::vector;
49
50namespace chromeos_update_engine {
51
Darin Petkov36275772010-10-01 11:40:57 -070052const int UpdateAttempter::kMaxDeltaUpdateFailures = 3;
53
Gilad Arnold1ebd8132012-03-05 10:19:29 -080054// Private test server URL w/ custom port number.
Gilad Arnolded747312012-03-15 18:20:41 -070055// TODO(garnold) This is a temporary hack to allow us to test the closed loop
56// automated update testing. To be replaced with an hard-coded local IP address.
57const char* const UpdateAttempter::kTestUpdateUrl(
58 "http://garnold.mtv.corp.google.com:8080/update");
Gilad Arnold28e2f392012-02-09 14:36:46 -080059
Darin Petkovcd1666f2010-09-23 09:53:44 -070060const char* kUpdateCompletedMarker =
61 "/var/run/update_engine_autoupdate_completed";
Andrew de los Reyes6b78e292010-05-10 15:54:39 -070062
Andrew de los Reyes45168102010-11-22 11:13:50 -080063namespace {
64const int kMaxConsecutiveObeyProxyRequests = 20;
65} // namespace {}
66
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070067const char* UpdateStatusToString(UpdateStatus status) {
68 switch (status) {
69 case UPDATE_STATUS_IDLE:
70 return "UPDATE_STATUS_IDLE";
71 case UPDATE_STATUS_CHECKING_FOR_UPDATE:
72 return "UPDATE_STATUS_CHECKING_FOR_UPDATE";
73 case UPDATE_STATUS_UPDATE_AVAILABLE:
74 return "UPDATE_STATUS_UPDATE_AVAILABLE";
75 case UPDATE_STATUS_DOWNLOADING:
76 return "UPDATE_STATUS_DOWNLOADING";
77 case UPDATE_STATUS_VERIFYING:
78 return "UPDATE_STATUS_VERIFYING";
79 case UPDATE_STATUS_FINALIZING:
80 return "UPDATE_STATUS_FINALIZING";
81 case UPDATE_STATUS_UPDATED_NEED_REBOOT:
82 return "UPDATE_STATUS_UPDATED_NEED_REBOOT";
Darin Petkov09f96c32010-07-20 09:24:57 -070083 case UPDATE_STATUS_REPORTING_ERROR_EVENT:
84 return "UPDATE_STATUS_REPORTING_ERROR_EVENT";
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070085 default:
86 return "unknown status";
87 }
88}
89
Darin Petkov777dbfa2010-07-20 15:03:37 -070090// Turns a generic kActionCodeError to a generic error code specific
91// to |action| (e.g., kActionCodeFilesystemCopierError). If |code| is
92// not kActionCodeError, or the action is not matched, returns |code|
93// unchanged.
94ActionExitCode GetErrorCodeForAction(AbstractAction* action,
95 ActionExitCode code) {
96 if (code != kActionCodeError)
97 return code;
98
99 const string type = action->Type();
100 if (type == OmahaRequestAction::StaticType())
101 return kActionCodeOmahaRequestError;
102 if (type == OmahaResponseHandlerAction::StaticType())
103 return kActionCodeOmahaResponseHandlerError;
104 if (type == FilesystemCopierAction::StaticType())
105 return kActionCodeFilesystemCopierError;
106 if (type == PostinstallRunnerAction::StaticType())
107 return kActionCodePostinstallRunnerError;
Darin Petkov777dbfa2010-07-20 15:03:37 -0700108
109 return code;
110}
111
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800112UpdateAttempter::UpdateAttempter(SystemState* system_state,
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800113 DbusGlibInterface* dbus_iface)
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700114 : processor_(new ActionProcessor()),
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800115 system_state_(system_state),
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700116 dbus_service_(NULL),
Darin Petkov1023a602010-08-30 13:47:51 -0700117 update_check_scheduler_(NULL),
Andrew de los Reyesc1d5c932011-04-20 17:15:47 -0700118 fake_update_success_(false),
Darin Petkov1023a602010-08-30 13:47:51 -0700119 http_response_code_(0),
Chris Sosa4f8ee272012-11-30 13:01:54 -0800120 shares_(utils::kCpuSharesNormal),
121 manage_shares_source_(NULL),
Darin Petkov9d911fa2010-08-19 09:36:08 -0700122 download_active_(false),
Darin Petkovc6c135c2010-08-11 13:36:18 -0700123 status_(UPDATE_STATUS_IDLE),
124 download_progress_(0.0),
125 last_checked_time_(0),
126 new_version_("0.0.0.0"),
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700127 new_payload_size_(0),
Andrew de los Reyes45168102010-11-22 11:13:50 -0800128 proxy_manual_checks_(0),
129 obeying_proxies_(true),
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -0700130 chrome_proxy_resolver_(dbus_iface),
Darin Petkov58dd1342011-05-06 12:05:13 -0700131 updated_boot_flags_(false),
132 update_boot_flags_running_(false),
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200133 start_action_processor_(false),
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800134 policy_provider_(NULL),
Gilad Arnold4d740eb2012-05-15 08:48:13 -0700135 is_using_test_url_(false),
Gilad Arnold7c04e762012-05-23 10:54:02 -0700136 is_test_mode_(false),
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800137 is_test_update_attempted_(false) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800138 prefs_ = system_state->prefs();
Darin Petkovc6c135c2010-08-11 13:36:18 -0700139 if (utils::FileExists(kUpdateCompletedMarker))
140 status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT;
141}
142
143UpdateAttempter::~UpdateAttempter() {
Chris Sosa4f8ee272012-11-30 13:01:54 -0800144 CleanupCpuSharesManagement();
Darin Petkovc6c135c2010-08-11 13:36:18 -0700145}
146
Gilad Arnold28e2f392012-02-09 14:36:46 -0800147void UpdateAttempter::Update(const string& app_version,
148 const string& omaha_url,
Andrew de los Reyesfb2f4612011-06-09 18:21:49 -0700149 bool obey_proxies,
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800150 bool interactive,
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800151 bool is_test_mode) {
Andrew de los Reyes000d8952011-03-02 15:21:14 -0800152 chrome_proxy_resolver_.Init();
Andrew de los Reyesc1d5c932011-04-20 17:15:47 -0700153 fake_update_success_ = false;
Andrew de los Reyes6b78e292010-05-10 15:54:39 -0700154 if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
Thieu Le116fda32011-04-19 11:01:54 -0700155 // Although we have applied an update, we still want to ping Omaha
156 // to ensure the number of active statistics is accurate.
Andrew de los Reyes6b78e292010-05-10 15:54:39 -0700157 LOG(INFO) << "Not updating b/c we already updated and we're waiting for "
Thieu Le116fda32011-04-19 11:01:54 -0700158 << "reboot, we'll ping Omaha instead";
159 PingOmaha();
Andrew de los Reyes6b78e292010-05-10 15:54:39 -0700160 return;
161 }
162 if (status_ != UPDATE_STATUS_IDLE) {
163 // Update in progress. Do nothing
164 return;
165 }
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700166
167 if (!CalculateUpdateParams(app_version,
168 omaha_url,
169 obey_proxies,
170 interactive,
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800171 is_test_mode)) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700172 return;
173 }
174
175 BuildUpdateActions(interactive);
176
177 SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE,
178 kUpdateNoticeUnspecified);
179
180 // Just in case we didn't update boot flags yet, make sure they're updated
181 // before any update processing starts.
182 start_action_processor_ = true;
183 UpdateBootFlags();
184}
185
186bool UpdateAttempter::CalculateUpdateParams(const string& app_version,
187 const string& omaha_url,
188 bool obey_proxies,
189 bool interactive,
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800190 bool is_test_mode) {
Darin Petkov1023a602010-08-30 13:47:51 -0700191 http_response_code_ = 0;
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200192
Gilad Arnold7c04e762012-05-23 10:54:02 -0700193 // Set the test mode flag for the current update attempt.
194 is_test_mode_ = is_test_mode;
195
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200196 // Lazy initialize the policy provider, or reload the latest policy data.
Julian Pastarmov5b3f3b92013-02-04 18:04:48 +0100197 if (!policy_provider_.get())
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200198 policy_provider_.reset(new policy::PolicyProvider());
Julian Pastarmov5b3f3b92013-02-04 18:04:48 +0100199 policy_provider_->Reload();
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200200
201 // If the release_track is specified by policy, that takes precedence.
202 string release_track;
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700203
Jay Srinivasan0a708742012-03-20 11:26:12 -0700204 if (policy_provider_->device_policy_is_loaded()) {
205 const policy::DevicePolicy& device_policy =
206 policy_provider_->GetDevicePolicy();
207 device_policy.GetReleaseChannel(&release_track);
208 device_policy.GetUpdateDisabled(&omaha_request_params_.update_disabled);
209 device_policy.GetTargetVersionPrefix(
210 &omaha_request_params_.target_version_prefix);
Jay Srinivasan43488792012-06-19 00:25:31 -0700211
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800212 system_state_->set_device_policy(&device_policy);
Jay Srinivasan43488792012-06-19 00:25:31 -0700213
214 set<string> allowed_types;
215 string allowed_types_str;
216 if (device_policy.GetAllowedConnectionTypesForUpdate(&allowed_types)) {
217 set<string>::const_iterator iter;
218 for (iter = allowed_types.begin(); iter != allowed_types.end(); ++iter)
219 allowed_types_str += *iter + " ";
220 }
221
222 LOG(INFO) << "Networks over which updates are allowed per policy : "
223 << (allowed_types_str.empty() ? "all" : allowed_types_str);
224 } else {
225 LOG(INFO) << "No device policies present.";
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800226 system_state_->set_device_policy(NULL);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700227 }
228
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800229 CalculateScatteringParams(interactive);
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200230
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800231 // Determine whether an alternative test address should be used.
Gilad Arnold28e2f392012-02-09 14:36:46 -0800232 string omaha_url_to_use = omaha_url;
Gilad Arnold7c04e762012-05-23 10:54:02 -0700233 if ((is_using_test_url_ = (omaha_url_to_use.empty() && is_test_mode_))) {
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800234 omaha_url_to_use = kTestUpdateUrl;
235 LOG(INFO) << "using alternative server address: " << omaha_url_to_use;
Gilad Arnold28e2f392012-02-09 14:36:46 -0800236 }
237
Jay Srinivasan0a708742012-03-20 11:26:12 -0700238 if (!omaha_request_params_.Init(app_version,
239 omaha_url_to_use,
Gilad Arnoldbbdd4902013-01-10 16:06:30 -0800240 release_track,
241 interactive)) {
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700242 LOG(ERROR) << "Unable to initialize Omaha request device params.";
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700243 return false;
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700244 }
Darin Petkov3aefa862010-12-07 14:45:00 -0800245
Jay Srinivasan0a708742012-03-20 11:26:12 -0700246 LOG(INFO) << "update_disabled = "
247 << (omaha_request_params_.update_disabled ? "true" : "false")
248 << ", target_version_prefix = "
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700249 << omaha_request_params_.target_version_prefix
250 << ", scatter_factor_in_seconds = "
251 << utils::FormatSecs(scatter_factor_.InSeconds());
252
253 LOG(INFO) << "Wall Clock Based Wait Enabled = "
254 << omaha_request_params_.wall_clock_based_wait_enabled
255 << ", Update Check Count Wait Enabled = "
256 << omaha_request_params_.update_check_count_wait_enabled
Jay Srinivasan21be0752012-07-25 15:44:56 -0700257 << ", Waiting Period = " << utils::FormatSecs(
258 omaha_request_params_.waiting_period.InSeconds());
Jay Srinivasan0a708742012-03-20 11:26:12 -0700259
Andrew de los Reyes45168102010-11-22 11:13:50 -0800260 obeying_proxies_ = true;
261 if (obey_proxies || proxy_manual_checks_ == 0) {
262 LOG(INFO) << "forced to obey proxies";
263 // If forced to obey proxies, every 20th request will not use proxies
264 proxy_manual_checks_++;
265 LOG(INFO) << "proxy manual checks: " << proxy_manual_checks_;
266 if (proxy_manual_checks_ >= kMaxConsecutiveObeyProxyRequests) {
267 proxy_manual_checks_ = 0;
268 obeying_proxies_ = false;
269 }
270 } else if (base::RandInt(0, 4) == 0) {
271 obeying_proxies_ = false;
272 }
273 LOG_IF(INFO, !obeying_proxies_) << "To help ensure updates work, this update "
274 "check we are ignoring the proxy settings and using "
275 "direct connections.";
276
Darin Petkov36275772010-10-01 11:40:57 -0700277 DisableDeltaUpdateIfNeeded();
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700278 return true;
279}
280
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800281void UpdateAttempter::CalculateScatteringParams(bool interactive) {
Jay Srinivasan21be0752012-07-25 15:44:56 -0700282 // Take a copy of the old scatter value before we update it, as
283 // we need to update the waiting period if this value changes.
284 TimeDelta old_scatter_factor = scatter_factor_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800285 const policy::DevicePolicy* device_policy = system_state_->device_policy();
Jay Srinivasan21be0752012-07-25 15:44:56 -0700286 if (device_policy) {
287 int64 new_scatter_factor_in_secs = 0;
288 device_policy->GetScatterFactorInSeconds(&new_scatter_factor_in_secs);
289 if (new_scatter_factor_in_secs < 0) // sanitize input, just in case.
290 new_scatter_factor_in_secs = 0;
291 scatter_factor_ = TimeDelta::FromSeconds(new_scatter_factor_in_secs);
292 }
293
294 bool is_scatter_enabled = false;
295 if (scatter_factor_.InSeconds() == 0) {
296 LOG(INFO) << "Scattering disabled since scatter factor is set to 0";
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800297 } else if (interactive) {
298 LOG(INFO) << "Scattering disabled as this is an interactive update check";
Jay Srinivasan21be0752012-07-25 15:44:56 -0700299 } else if (!system_state_->IsOOBEComplete()) {
300 LOG(INFO) << "Scattering disabled since OOBE is not complete yet";
301 } else {
302 is_scatter_enabled = true;
303 LOG(INFO) << "Scattering is enabled";
304 }
305
306 if (is_scatter_enabled) {
307 // This means the scattering policy is turned on.
308 // Now check if we need to update the waiting period. The two cases
309 // in which we'd need to update the waiting period are:
310 // 1. First time in process or a scheduled check after a user-initiated one.
311 // (omaha_request_params_.waiting_period will be zero in this case).
312 // 2. Admin has changed the scattering policy value.
313 // (new scattering value will be different from old one in this case).
314 int64 wait_period_in_secs = 0;
315 if (omaha_request_params_.waiting_period.InSeconds() == 0) {
316 // First case. Check if we have a suitable value to set for
317 // the waiting period.
318 if (prefs_->GetInt64(kPrefsWallClockWaitPeriod, &wait_period_in_secs) &&
319 wait_period_in_secs > 0 &&
320 wait_period_in_secs <= scatter_factor_.InSeconds()) {
321 // This means:
322 // 1. There's a persisted value for the waiting period available.
323 // 2. And that persisted value is still valid.
324 // So, in this case, we should reuse the persisted value instead of
325 // generating a new random value to improve the chances of a good
326 // distribution for scattering.
327 omaha_request_params_.waiting_period =
328 TimeDelta::FromSeconds(wait_period_in_secs);
329 LOG(INFO) << "Using persisted wall-clock waiting period: " <<
330 utils::FormatSecs(omaha_request_params_.waiting_period.InSeconds());
331 }
332 else {
333 // This means there's no persisted value for the waiting period
334 // available or its value is invalid given the new scatter_factor value.
335 // So, we should go ahead and regenerate a new value for the
336 // waiting period.
337 LOG(INFO) << "Persisted value not present or not valid ("
338 << utils::FormatSecs(wait_period_in_secs)
339 << ") for wall-clock waiting period.";
340 GenerateNewWaitingPeriod();
341 }
342 } else if (scatter_factor_ != old_scatter_factor) {
343 // This means there's already a waiting period value, but we detected
344 // a change in the scattering policy value. So, we should regenerate the
345 // waiting period to make sure it's within the bounds of the new scatter
346 // factor value.
347 GenerateNewWaitingPeriod();
348 } else {
349 // Neither the first time scattering is enabled nor the scattering value
350 // changed. Nothing to do.
351 LOG(INFO) << "Keeping current wall-clock waiting period: " <<
352 utils::FormatSecs(omaha_request_params_.waiting_period.InSeconds());
353 }
354
355 // The invariant at this point is that omaha_request_params_.waiting_period
356 // is non-zero no matter which path we took above.
357 LOG_IF(ERROR, omaha_request_params_.waiting_period.InSeconds() == 0)
358 << "Waiting Period should NOT be zero at this point!!!";
359
360 // Since scattering is enabled, wall clock based wait will always be
361 // enabled.
362 omaha_request_params_.wall_clock_based_wait_enabled = true;
363
364 // If we don't have any issues in accessing the file system to update
365 // the update check count value, we'll turn that on as well.
366 bool decrement_succeeded = DecrementUpdateCheckCount();
367 omaha_request_params_.update_check_count_wait_enabled = decrement_succeeded;
368 } else {
369 // This means the scattering feature is turned off or disabled for
370 // this particular update check. Make sure to disable
371 // all the knobs and artifacts so that we don't invoke any scattering
372 // related code.
373 omaha_request_params_.wall_clock_based_wait_enabled = false;
374 omaha_request_params_.update_check_count_wait_enabled = false;
375 omaha_request_params_.waiting_period = TimeDelta::FromSeconds(0);
376 prefs_->Delete(kPrefsWallClockWaitPeriod);
377 prefs_->Delete(kPrefsUpdateCheckCount);
378 // Don't delete the UpdateFirstSeenAt file as we don't want manual checks
379 // that result in no-updates (e.g. due to server side throttling) to
380 // cause update starvation by having the client generate a new
381 // UpdateFirstSeenAt for each scheduled check that follows a manual check.
382 }
383}
384
385void UpdateAttempter::GenerateNewWaitingPeriod() {
386 omaha_request_params_.waiting_period = TimeDelta::FromSeconds(
387 base::RandInt(1, scatter_factor_.InSeconds()));
388
389 LOG(INFO) << "Generated new wall-clock waiting period: " << utils::FormatSecs(
390 omaha_request_params_.waiting_period.InSeconds());
391
392 // Do a best-effort to persist this in all cases. Even if the persistence
393 // fails, we'll still be able to scatter based on our in-memory value.
394 // The persistence only helps in ensuring a good overall distribution
395 // across multiple devices if they tend to reboot too often.
396 prefs_->SetInt64(kPrefsWallClockWaitPeriod,
397 omaha_request_params_.waiting_period.InSeconds());
398}
399
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700400void UpdateAttempter::BuildUpdateActions(bool interactive) {
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700401 CHECK(!processor_->IsRunning());
402 processor_->set_delegate(this);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700403
404 // Actions:
Darin Petkova0929552010-11-29 14:19:06 -0800405 LibcurlHttpFetcher* update_check_fetcher =
Gilad Arnold7c04e762012-05-23 10:54:02 -0700406 new LibcurlHttpFetcher(GetProxyResolver(), system_state_, is_test_mode_);
Andrew de los Reyesfb2f4612011-06-09 18:21:49 -0700407 // Try harder to connect to the network, esp when not interactive.
408 // See comment in libcurl_http_fetcher.cc.
409 update_check_fetcher->set_no_network_max_retries(interactive ? 1 : 3);
Bruno Rocha7f9aea22011-09-12 14:31:24 -0700410 update_check_fetcher->set_check_certificate(CertificateChecker::kUpdate);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700411 shared_ptr<OmahaRequestAction> update_check_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800412 new OmahaRequestAction(system_state_,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700413 &omaha_request_params_,
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700414 NULL,
Thieu Le116fda32011-04-19 11:01:54 -0700415 update_check_fetcher, // passes ownership
416 false));
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700417 shared_ptr<OmahaResponseHandlerAction> response_handler_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800418 new OmahaResponseHandlerAction(system_state_));
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700419 shared_ptr<FilesystemCopierAction> filesystem_copier_action(
Gilad Arnold581c2ea2012-07-19 12:33:49 -0700420 new FilesystemCopierAction(false, false));
Andrew de los Reyesf9714432010-05-04 10:21:23 -0700421 shared_ptr<FilesystemCopierAction> kernel_filesystem_copier_action(
Gilad Arnold581c2ea2012-07-19 12:33:49 -0700422 new FilesystemCopierAction(true, false));
Darin Petkov8c2980e2010-07-16 15:16:49 -0700423 shared_ptr<OmahaRequestAction> download_started_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800424 new OmahaRequestAction(system_state_,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700425 &omaha_request_params_,
Darin Petkov8c2980e2010-07-16 15:16:49 -0700426 new OmahaEvent(
Darin Petkove17f86b2010-07-20 09:12:01 -0700427 OmahaEvent::kTypeUpdateDownloadStarted),
Jay Srinivasan08fce042012-06-07 16:31:01 -0700428 new LibcurlHttpFetcher(GetProxyResolver(),
Gilad Arnold7c04e762012-05-23 10:54:02 -0700429 system_state_,
430 is_test_mode_),
Thieu Le116fda32011-04-19 11:01:54 -0700431 false));
Bruno Rocha7f9aea22011-09-12 14:31:24 -0700432 LibcurlHttpFetcher* download_fetcher =
Gilad Arnold7c04e762012-05-23 10:54:02 -0700433 new LibcurlHttpFetcher(GetProxyResolver(), system_state_, is_test_mode_);
Bruno Rocha7f9aea22011-09-12 14:31:24 -0700434 download_fetcher->set_check_certificate(CertificateChecker::kDownload);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700435 shared_ptr<DownloadAction> download_action(
Bruno Rocha7f9aea22011-09-12 14:31:24 -0700436 new DownloadAction(prefs_,
Jay Srinivasanf0572052012-10-23 18:12:56 -0700437 system_state_,
Gilad Arnold9bedeb52011-11-17 16:19:57 -0800438 new MultiRangeHttpFetcher(
Bruno Rocha7f9aea22011-09-12 14:31:24 -0700439 download_fetcher))); // passes ownership
Darin Petkov8c2980e2010-07-16 15:16:49 -0700440 shared_ptr<OmahaRequestAction> download_finished_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800441 new OmahaRequestAction(system_state_,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700442 &omaha_request_params_,
Darin Petkov8c2980e2010-07-16 15:16:49 -0700443 new OmahaEvent(
Darin Petkove17f86b2010-07-20 09:12:01 -0700444 OmahaEvent::kTypeUpdateDownloadFinished),
Jay Srinivasan08fce042012-06-07 16:31:01 -0700445 new LibcurlHttpFetcher(GetProxyResolver(),
Gilad Arnold7c04e762012-05-23 10:54:02 -0700446 system_state_,
447 is_test_mode_),
Thieu Le116fda32011-04-19 11:01:54 -0700448 false));
Darin Petkov3aefa862010-12-07 14:45:00 -0800449 shared_ptr<FilesystemCopierAction> filesystem_verifier_action(
Gilad Arnold581c2ea2012-07-19 12:33:49 -0700450 new FilesystemCopierAction(false, true));
Darin Petkov3aefa862010-12-07 14:45:00 -0800451 shared_ptr<FilesystemCopierAction> kernel_filesystem_verifier_action(
Gilad Arnold581c2ea2012-07-19 12:33:49 -0700452 new FilesystemCopierAction(true, true));
Darin Petkov6d5dbf62010-11-08 16:09:55 -0800453 shared_ptr<PostinstallRunnerAction> postinstall_runner_action(
454 new PostinstallRunnerAction);
Darin Petkov8c2980e2010-07-16 15:16:49 -0700455 shared_ptr<OmahaRequestAction> update_complete_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800456 new OmahaRequestAction(system_state_,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700457 &omaha_request_params_,
Darin Petkove17f86b2010-07-20 09:12:01 -0700458 new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
Jay Srinivasan08fce042012-06-07 16:31:01 -0700459 new LibcurlHttpFetcher(GetProxyResolver(),
Gilad Arnold7c04e762012-05-23 10:54:02 -0700460 system_state_,
461 is_test_mode_),
Thieu Le116fda32011-04-19 11:01:54 -0700462 false));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700463
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700464 download_action->set_delegate(this);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700465 response_handler_action_ = response_handler_action;
Darin Petkov9b230572010-10-08 10:20:09 -0700466 download_action_ = download_action;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700467
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700468 actions_.push_back(shared_ptr<AbstractAction>(update_check_action));
469 actions_.push_back(shared_ptr<AbstractAction>(response_handler_action));
470 actions_.push_back(shared_ptr<AbstractAction>(filesystem_copier_action));
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700471 actions_.push_back(shared_ptr<AbstractAction>(
Andrew de los Reyesf9714432010-05-04 10:21:23 -0700472 kernel_filesystem_copier_action));
Darin Petkov8c2980e2010-07-16 15:16:49 -0700473 actions_.push_back(shared_ptr<AbstractAction>(download_started_action));
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700474 actions_.push_back(shared_ptr<AbstractAction>(download_action));
Darin Petkov8c2980e2010-07-16 15:16:49 -0700475 actions_.push_back(shared_ptr<AbstractAction>(download_finished_action));
Darin Petkov3aefa862010-12-07 14:45:00 -0800476 actions_.push_back(shared_ptr<AbstractAction>(filesystem_verifier_action));
477 actions_.push_back(shared_ptr<AbstractAction>(
478 kernel_filesystem_verifier_action));
Darin Petkov6d5dbf62010-11-08 16:09:55 -0800479 actions_.push_back(shared_ptr<AbstractAction>(postinstall_runner_action));
Darin Petkov8c2980e2010-07-16 15:16:49 -0700480 actions_.push_back(shared_ptr<AbstractAction>(update_complete_action));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700481
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700482 // Enqueue the actions
483 for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin();
484 it != actions_.end(); ++it) {
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700485 processor_->EnqueueAction(it->get());
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700486 }
487
488 // Bond them together. We have to use the leaf-types when calling
489 // BondActions().
Andrew de los Reyesf98bff82010-05-06 13:33:25 -0700490 BondActions(update_check_action.get(),
491 response_handler_action.get());
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700492 BondActions(response_handler_action.get(),
Andrew de los Reyesf98bff82010-05-06 13:33:25 -0700493 filesystem_copier_action.get());
494 BondActions(filesystem_copier_action.get(),
Andrew de los Reyesf9714432010-05-04 10:21:23 -0700495 kernel_filesystem_copier_action.get());
496 BondActions(kernel_filesystem_copier_action.get(),
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700497 download_action.get());
Andrew de los Reyesf98bff82010-05-06 13:33:25 -0700498 BondActions(download_action.get(),
Darin Petkov3aefa862010-12-07 14:45:00 -0800499 filesystem_verifier_action.get());
500 BondActions(filesystem_verifier_action.get(),
501 kernel_filesystem_verifier_action.get());
502 BondActions(kernel_filesystem_verifier_action.get(),
Darin Petkov6d5dbf62010-11-08 16:09:55 -0800503 postinstall_runner_action.get());
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700504}
505
Gilad Arnold28e2f392012-02-09 14:36:46 -0800506void UpdateAttempter::CheckForUpdate(const string& app_version,
Jay Srinivasane73acab2012-07-10 14:34:03 -0700507 const string& omaha_url,
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800508 bool interactive) {
Jay Srinivasan08fce042012-06-07 16:31:01 -0700509 LOG(INFO) << "New update check requested";
510
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700511 if (status_ != UPDATE_STATUS_IDLE) {
Jay Srinivasan08fce042012-06-07 16:31:01 -0700512 LOG(INFO) << "Skipping update check because current status is "
513 << UpdateStatusToString(status_);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700514 return;
515 }
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800516
517 // Read GPIO signals and determine whether this is an automated test scenario.
518 // For safety, we only allow a test update to be performed once; subsequent
519 // update requests will be carried out normally.
Gilad Arnoldbf7919b2013-01-08 13:07:37 -0800520 bool is_test_mode = (!is_test_update_attempted_ &&
521 system_state_->gpio_handler()->IsTestModeSignaled());
Gilad Arnold7c04e762012-05-23 10:54:02 -0700522 if (is_test_mode) {
523 LOG(WARNING) << "this is a test mode update attempt!";
Gilad Arnold4d740eb2012-05-15 08:48:13 -0700524 is_test_update_attempted_ = true;
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800525 }
526
Gilad Arnoldb92f0df2013-01-10 16:32:45 -0800527 // Pass through the interactive flag, in case we want to simulate a scheduled
528 // test.
529 Update(app_version, omaha_url, true, interactive, is_test_mode);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700530}
531
Darin Petkov296889c2010-07-23 16:20:54 -0700532bool UpdateAttempter::RebootIfNeeded() {
533 if (status_ != UPDATE_STATUS_UPDATED_NEED_REBOOT) {
534 LOG(INFO) << "Reboot requested, but status is "
535 << UpdateStatusToString(status_) << ", so not rebooting.";
536 return false;
537 }
538 TEST_AND_RETURN_FALSE(utils::Reboot());
539 return true;
540}
541
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700542// Delegate methods:
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700543void UpdateAttempter::ProcessingDone(const ActionProcessor* processor,
Darin Petkovc1a8b422010-07-19 11:34:49 -0700544 ActionExitCode code) {
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700545 CHECK(response_handler_action_);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700546 LOG(INFO) << "Processing Done.";
Andrew de los Reyes6b78e292010-05-10 15:54:39 -0700547 actions_.clear();
Darin Petkov09f96c32010-07-20 09:24:57 -0700548
Chris Sosa4f8ee272012-11-30 13:01:54 -0800549 // Reset cpu shares back to normal.
550 CleanupCpuSharesManagement();
Darin Petkovc6c135c2010-08-11 13:36:18 -0700551
Darin Petkov09f96c32010-07-20 09:24:57 -0700552 if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
553 LOG(INFO) << "Error event sent.";
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800554
555 // Inform scheduler of new status; also specifically inform about a failed
556 // update attempt with a test address.
557 SetStatusAndNotify(UPDATE_STATUS_IDLE,
558 (is_using_test_url_ ? kUpdateNoticeTestAddrFailed :
559 kUpdateNoticeUnspecified));
560
Andrew de los Reyesc1d5c932011-04-20 17:15:47 -0700561 if (!fake_update_success_) {
562 return;
563 }
564 LOG(INFO) << "Booted from FW B and tried to install new firmware, "
565 "so requesting reboot from user.";
Darin Petkov09f96c32010-07-20 09:24:57 -0700566 }
567
Darin Petkovc1a8b422010-07-19 11:34:49 -0700568 if (code == kActionCodeSuccess) {
Andrew de los Reyes6b78e292010-05-10 15:54:39 -0700569 utils::WriteFile(kUpdateCompletedMarker, "", 0);
Darin Petkov36275772010-10-01 11:40:57 -0700570 prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0);
Darin Petkov95508da2011-01-05 12:42:29 -0800571 prefs_->SetString(kPrefsPreviousVersion, omaha_request_params_.app_version);
Darin Petkov9b230572010-10-08 10:20:09 -0700572 DeltaPerformer::ResetUpdateProgress(prefs_, false);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700573
574 // Since we're done with scattering fully at this point, this is the
575 // safest point delete the state files, as we're sure that the status is
576 // set to reboot (which means no more updates will be applied until reboot)
577 // This deletion is required for correctness as we want the next update
578 // check to re-create a new random number for the update check count.
579 // Similarly, we also delete the wall-clock-wait period that was persisted
580 // so that we start with a new random value for the next update check
581 // after reboot so that the same device is not favored or punished in any
582 // way.
583 prefs_->Delete(kPrefsUpdateCheckCount);
584 prefs_->Delete(kPrefsWallClockWaitPeriod);
Jay Srinivasan34b5d862012-07-23 11:43:22 -0700585 prefs_->Delete(kPrefsUpdateFirstSeenAt);
Jay Srinivasanf0572052012-10-23 18:12:56 -0700586 LOG(INFO) << "Update successfully applied, waiting to reboot.";
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700587
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800588 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT,
589 kUpdateNoticeUnspecified);
Darin Petkov9d65b7b2010-07-20 09:13:01 -0700590
591 // Report the time it took to update the system.
592 int64_t update_time = time(NULL) - last_checked_time_;
Andrew de los Reyesc1d5c932011-04-20 17:15:47 -0700593 if (!fake_update_success_)
Jay Srinivasanf0572052012-10-23 18:12:56 -0700594 system_state_->metrics_lib()->SendToUMA(
595 "Installer.UpdateTime",
596 static_cast<int>(update_time), // sample
597 1, // min = 1 second
598 20 * 60, // max = 20 minutes
599 50); // buckets
600
601 // Also report the success code so that the percentiles can be
602 // interpreted properly for the remaining error codes in UMA.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800603 utils::SendErrorCodeToUma(system_state_, code);
Darin Petkov09f96c32010-07-20 09:24:57 -0700604 return;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700605 }
Darin Petkov09f96c32010-07-20 09:24:57 -0700606
Darin Petkov1023a602010-08-30 13:47:51 -0700607 if (ScheduleErrorEventAction()) {
Darin Petkov09f96c32010-07-20 09:24:57 -0700608 return;
Darin Petkov1023a602010-08-30 13:47:51 -0700609 }
610 LOG(INFO) << "No update.";
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800611 SetStatusAndNotify(UPDATE_STATUS_IDLE, kUpdateNoticeUnspecified);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700612}
613
614void UpdateAttempter::ProcessingStopped(const ActionProcessor* processor) {
Chris Sosa4f8ee272012-11-30 13:01:54 -0800615 // Reset cpu shares back to normal.
616 CleanupCpuSharesManagement();
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700617 download_progress_ = 0.0;
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800618 SetStatusAndNotify(UPDATE_STATUS_IDLE, kUpdateNoticeUnspecified);
Andrew de los Reyes6b78e292010-05-10 15:54:39 -0700619 actions_.clear();
Darin Petkov09f96c32010-07-20 09:24:57 -0700620 error_event_.reset(NULL);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700621}
622
623// Called whenever an action has finished processing, either successfully
624// or otherwise.
625void UpdateAttempter::ActionCompleted(ActionProcessor* processor,
626 AbstractAction* action,
Darin Petkovc1a8b422010-07-19 11:34:49 -0700627 ActionExitCode code) {
Darin Petkov1023a602010-08-30 13:47:51 -0700628 // Reset download progress regardless of whether or not the download
629 // action succeeded. Also, get the response code from HTTP request
630 // actions (update download as well as the initial update check
631 // actions).
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700632 const string type = action->Type();
Darin Petkov1023a602010-08-30 13:47:51 -0700633 if (type == DownloadAction::StaticType()) {
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700634 download_progress_ = 0.0;
Darin Petkov1023a602010-08-30 13:47:51 -0700635 DownloadAction* download_action = dynamic_cast<DownloadAction*>(action);
636 http_response_code_ = download_action->GetHTTPResponseCode();
637 } else if (type == OmahaRequestAction::StaticType()) {
638 OmahaRequestAction* omaha_request_action =
639 dynamic_cast<OmahaRequestAction*>(action);
640 // If the request is not an event, then it's the update-check.
641 if (!omaha_request_action->IsEvent()) {
642 http_response_code_ = omaha_request_action->GetHTTPResponseCode();
Darin Petkov85ced132010-09-01 10:20:56 -0700643 // Forward the server-dictated poll interval to the update check
644 // scheduler, if any.
645 if (update_check_scheduler_) {
646 update_check_scheduler_->set_poll_interval(
647 omaha_request_action->GetOutputObject().poll_interval);
648 }
Darin Petkov1023a602010-08-30 13:47:51 -0700649 }
650 }
Darin Petkov09f96c32010-07-20 09:24:57 -0700651 if (code != kActionCodeSuccess) {
Darin Petkov7ed561b2011-10-04 02:59:03 -0700652 // If the current state is at or past the download phase, count the failure
653 // in case a switch to full update becomes necessary. Ignore network
654 // transfer timeouts and failures.
Darin Petkov36275772010-10-01 11:40:57 -0700655 if (status_ >= UPDATE_STATUS_DOWNLOADING &&
Darin Petkov36275772010-10-01 11:40:57 -0700656 code != kActionCodeDownloadTransferError) {
657 MarkDeltaUpdateFailure();
658 }
Darin Petkov777dbfa2010-07-20 15:03:37 -0700659 // On failure, schedule an error event to be sent to Omaha.
660 CreatePendingErrorEvent(action, code);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700661 return;
Darin Petkov09f96c32010-07-20 09:24:57 -0700662 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700663 // Find out which action completed.
664 if (type == OmahaResponseHandlerAction::StaticType()) {
Darin Petkov9b230572010-10-08 10:20:09 -0700665 // Note that the status will be updated to DOWNLOADING when some bytes get
666 // actually downloaded from the server and the BytesReceived callback is
667 // invoked. This avoids notifying the user that a download has started in
668 // cases when the server and the client are unable to initiate the download.
669 CHECK(action == response_handler_action_.get());
670 const InstallPlan& plan = response_handler_action_->install_plan();
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700671 last_checked_time_ = time(NULL);
672 // TODO(adlr): put version in InstallPlan
673 new_version_ = "0.0.0.0";
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700674 new_payload_size_ = plan.payload_size;
Darin Petkov9b230572010-10-08 10:20:09 -0700675 SetupDownload();
Chris Sosa4f8ee272012-11-30 13:01:54 -0800676 SetupCpuSharesManagement();
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800677 SetStatusAndNotify(UPDATE_STATUS_UPDATE_AVAILABLE,
678 kUpdateNoticeUnspecified);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700679 } else if (type == DownloadAction::StaticType()) {
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800680 SetStatusAndNotify(UPDATE_STATUS_FINALIZING, kUpdateNoticeUnspecified);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700681 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700682}
683
684// Stop updating. An attempt will be made to record status to the disk
685// so that updates can be resumed later.
686void UpdateAttempter::Terminate() {
687 // TODO(adlr): implement this method.
688 NOTIMPLEMENTED();
689}
690
691// Try to resume from a previously Terminate()d update.
692void UpdateAttempter::ResumeUpdating() {
693 // TODO(adlr): implement this method.
694 NOTIMPLEMENTED();
695}
696
Darin Petkov9d911fa2010-08-19 09:36:08 -0700697void UpdateAttempter::SetDownloadStatus(bool active) {
698 download_active_ = active;
699 LOG(INFO) << "Download status: " << (active ? "active" : "inactive");
700}
701
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700702void UpdateAttempter::BytesReceived(uint64_t bytes_received, uint64_t total) {
Darin Petkov9d911fa2010-08-19 09:36:08 -0700703 if (!download_active_) {
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700704 LOG(ERROR) << "BytesReceived called while not downloading.";
705 return;
706 }
Darin Petkovaf183052010-08-23 12:07:13 -0700707 double progress = static_cast<double>(bytes_received) /
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700708 static_cast<double>(total);
Darin Petkovaf183052010-08-23 12:07:13 -0700709 // Self throttle based on progress. Also send notifications if
710 // progress is too slow.
711 const double kDeltaPercent = 0.01; // 1%
712 if (status_ != UPDATE_STATUS_DOWNLOADING ||
713 bytes_received == total ||
714 progress - download_progress_ >= kDeltaPercent ||
715 TimeTicks::Now() - last_notify_time_ >= TimeDelta::FromSeconds(10)) {
716 download_progress_ = progress;
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800717 SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING, kUpdateNoticeUnspecified);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700718 }
719}
720
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700721bool UpdateAttempter::ResetStatus() {
722 LOG(INFO) << "Attempting to reset state from "
723 << UpdateStatusToString(status_) << " to UPDATE_STATUS_IDLE";
724
725 switch (status_) {
726 case UPDATE_STATUS_IDLE:
727 // no-op.
728 return true;
729
730 case UPDATE_STATUS_UPDATED_NEED_REBOOT: {
731 status_ = UPDATE_STATUS_IDLE;
732 LOG(INFO) << "Reset Successful";
733
734 // also remove the reboot marker so that if the machine is rebooted
735 // after resetting to idle state, it doesn't go back to
736 // UPDATE_STATUS_UPDATED_NEED_REBOOT state.
737 const FilePath kUpdateCompletedMarkerPath(kUpdateCompletedMarker);
738 return file_util::Delete(kUpdateCompletedMarkerPath, false);
739 }
740
741 default:
742 LOG(ERROR) << "Reset not allowed in this state.";
743 return false;
744 }
745}
746
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700747bool UpdateAttempter::GetStatus(int64_t* last_checked_time,
748 double* progress,
Gilad Arnold28e2f392012-02-09 14:36:46 -0800749 string* current_operation,
750 string* new_version,
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700751 int64_t* new_payload_size) {
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700752 *last_checked_time = last_checked_time_;
753 *progress = download_progress_;
754 *current_operation = UpdateStatusToString(status_);
755 *new_version = new_version_;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700756 *new_payload_size = new_payload_size_;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700757 return true;
758}
759
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -0700760void UpdateAttempter::UpdateBootFlags() {
Darin Petkov58dd1342011-05-06 12:05:13 -0700761 if (update_boot_flags_running_) {
762 LOG(INFO) << "Update boot flags running, nothing to do.";
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -0700763 return;
764 }
Darin Petkov58dd1342011-05-06 12:05:13 -0700765 if (updated_boot_flags_) {
766 LOG(INFO) << "Already updated boot flags. Skipping.";
767 if (start_action_processor_) {
768 ScheduleProcessingStart();
769 }
770 return;
771 }
772 // This is purely best effort. Failures should be logged by Subprocess. Run
773 // the script asynchronously to avoid blocking the event loop regardless of
774 // the script runtime.
775 update_boot_flags_running_ = true;
776 LOG(INFO) << "Updating boot flags...";
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -0700777 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel");
Darin Petkov58dd1342011-05-06 12:05:13 -0700778 if (!Subprocess::Get().Exec(cmd, StaticCompleteUpdateBootFlags, this)) {
779 CompleteUpdateBootFlags(1);
780 }
781}
782
783void UpdateAttempter::CompleteUpdateBootFlags(int return_code) {
784 update_boot_flags_running_ = false;
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -0700785 updated_boot_flags_ = true;
Darin Petkov58dd1342011-05-06 12:05:13 -0700786 if (start_action_processor_) {
787 ScheduleProcessingStart();
788 }
789}
790
791void UpdateAttempter::StaticCompleteUpdateBootFlags(
792 int return_code,
Gilad Arnold28e2f392012-02-09 14:36:46 -0800793 const string& output,
Darin Petkov58dd1342011-05-06 12:05:13 -0700794 void* p) {
795 reinterpret_cast<UpdateAttempter*>(p)->CompleteUpdateBootFlags(return_code);
Andrew de los Reyes6dbf30a2011-04-19 10:58:16 -0700796}
797
Darin Petkov61635a92011-05-18 16:20:36 -0700798void UpdateAttempter::BroadcastStatus() {
799 if (!dbus_service_) {
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700800 return;
Darin Petkov61635a92011-05-18 16:20:36 -0700801 }
Darin Petkovaf183052010-08-23 12:07:13 -0700802 last_notify_time_ = TimeTicks::Now();
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700803 update_engine_service_emit_status_update(
804 dbus_service_,
805 last_checked_time_,
806 download_progress_,
807 UpdateStatusToString(status_),
808 new_version_.c_str(),
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700809 new_payload_size_);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700810}
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700811
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800812uint32_t UpdateAttempter::GetErrorCodeFlags() {
813 uint32_t flags = 0;
814
815 if (!utils::IsNormalBootMode())
816 flags |= kActionCodeDevModeFlag;
817
818 if (response_handler_action_.get() &&
819 response_handler_action_->install_plan().is_resume)
820 flags |= kActionCodeResumedFlag;
821
822 if (!utils::IsOfficialBuild())
823 flags |= kActionCodeTestImageFlag;
824
825 if (omaha_request_params_.update_url != kProductionOmahaUrl)
826 flags |= kActionCodeTestOmahaUrlFlag;
827
828 return flags;
829}
830
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800831void UpdateAttempter::SetStatusAndNotify(UpdateStatus status,
832 UpdateNotice notice) {
Darin Petkov61635a92011-05-18 16:20:36 -0700833 status_ = status;
834 if (update_check_scheduler_) {
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800835 update_check_scheduler_->SetUpdateStatus(status_, notice);
Darin Petkov61635a92011-05-18 16:20:36 -0700836 }
837 BroadcastStatus();
838}
839
Darin Petkov777dbfa2010-07-20 15:03:37 -0700840void UpdateAttempter::CreatePendingErrorEvent(AbstractAction* action,
841 ActionExitCode code) {
Darin Petkov09f96c32010-07-20 09:24:57 -0700842 if (error_event_.get()) {
843 // This shouldn't really happen.
844 LOG(WARNING) << "There's already an existing pending error event.";
845 return;
846 }
Darin Petkov777dbfa2010-07-20 15:03:37 -0700847
Darin Petkovabc7bc02011-02-23 14:39:43 -0800848 // For now assume that a generic Omaha response action failure means that
849 // there's no update so don't send an event. Also, double check that the
850 // failure has not occurred while sending an error event -- in which case
851 // don't schedule another. This shouldn't really happen but just in case...
852 if ((action->Type() == OmahaResponseHandlerAction::StaticType() &&
853 code == kActionCodeError) ||
Darin Petkov777dbfa2010-07-20 15:03:37 -0700854 status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
855 return;
856 }
857
Jay Srinivasan56d5aa42012-03-26 14:27:59 -0700858 // Classify the code to generate the appropriate result so that
859 // the Borgmon charts show up the results correctly.
860 // Do this before calling GetErrorCodeForAction which could potentially
861 // augment the bit representation of code and thus cause no matches for
862 // the switch cases below.
863 OmahaEvent::Result event_result;
864 switch (code) {
865 case kActionCodeOmahaUpdateIgnoredPerPolicy:
866 case kActionCodeOmahaUpdateDeferredPerPolicy:
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800867 case kActionCodeOmahaUpdateDeferredForBackoff:
Jay Srinivasan56d5aa42012-03-26 14:27:59 -0700868 event_result = OmahaEvent::kResultUpdateDeferred;
869 break;
870 default:
871 event_result = OmahaEvent::kResultError;
872 break;
873 }
874
Darin Petkov777dbfa2010-07-20 15:03:37 -0700875 code = GetErrorCodeForAction(action, code);
Andrew de los Reyesc1d5c932011-04-20 17:15:47 -0700876 fake_update_success_ = code == kActionCodePostinstallBootedFromFirmwareB;
Darin Petkov18c7bce2011-06-16 14:07:00 -0700877
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800878 // Compute the final error code with all the bit flags to be sent to Omaha.
879 code = static_cast<ActionExitCode>(code | GetErrorCodeFlags());
Darin Petkov09f96c32010-07-20 09:24:57 -0700880 error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete,
Jay Srinivasan56d5aa42012-03-26 14:27:59 -0700881 event_result,
Darin Petkov09f96c32010-07-20 09:24:57 -0700882 code));
883}
884
885bool UpdateAttempter::ScheduleErrorEventAction() {
886 if (error_event_.get() == NULL)
887 return false;
888
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800889 LOG(ERROR) << "Update failed.";
890 system_state_->payload_state()->UpdateFailed(error_event_->error_code);
891
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800892 // Send it to Uma.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800893 LOG(INFO) << "Reporting the error event";
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800894 utils::SendErrorCodeToUma(system_state_, error_event_->error_code);
895
896 // Send it to Omaha.
Darin Petkov09f96c32010-07-20 09:24:57 -0700897 shared_ptr<OmahaRequestAction> error_event_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800898 new OmahaRequestAction(system_state_,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700899 &omaha_request_params_,
Darin Petkov09f96c32010-07-20 09:24:57 -0700900 error_event_.release(), // Pass ownership.
Jay Srinivasan08fce042012-06-07 16:31:01 -0700901 new LibcurlHttpFetcher(GetProxyResolver(),
Gilad Arnold7c04e762012-05-23 10:54:02 -0700902 system_state_,
903 is_test_mode_),
Thieu Le116fda32011-04-19 11:01:54 -0700904 false));
Darin Petkov09f96c32010-07-20 09:24:57 -0700905 actions_.push_back(shared_ptr<AbstractAction>(error_event_action));
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700906 processor_->EnqueueAction(error_event_action.get());
Gilad Arnold1ebd8132012-03-05 10:19:29 -0800907 SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT,
908 kUpdateNoticeUnspecified);
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700909 processor_->StartProcessing();
Darin Petkov09f96c32010-07-20 09:24:57 -0700910 return true;
911}
912
Chris Sosa4f8ee272012-11-30 13:01:54 -0800913void UpdateAttempter::SetCpuShares(utils::CpuShares shares) {
914 if (shares_ == shares) {
Darin Petkovc6c135c2010-08-11 13:36:18 -0700915 return;
916 }
Chris Sosa4f8ee272012-11-30 13:01:54 -0800917 if (utils::SetCpuShares(shares)) {
918 shares_ = shares;
919 LOG(INFO) << "CPU shares = " << shares_;
Darin Petkovc6c135c2010-08-11 13:36:18 -0700920 }
921}
922
Chris Sosa4f8ee272012-11-30 13:01:54 -0800923void UpdateAttempter::SetupCpuSharesManagement() {
924 if (manage_shares_source_) {
925 LOG(ERROR) << "Cpu shares timeout source hasn't been destroyed.";
926 CleanupCpuSharesManagement();
Darin Petkovc6c135c2010-08-11 13:36:18 -0700927 }
Chris Sosa4f8ee272012-11-30 13:01:54 -0800928 const int kCpuSharesTimeout = 2 * 60 * 60; // 2 hours
929 manage_shares_source_ = g_timeout_source_new_seconds(kCpuSharesTimeout);
930 g_source_set_callback(manage_shares_source_,
931 StaticManageCpuSharesCallback,
Darin Petkovc6c135c2010-08-11 13:36:18 -0700932 this,
933 NULL);
Chris Sosa4f8ee272012-11-30 13:01:54 -0800934 g_source_attach(manage_shares_source_, NULL);
935 SetCpuShares(utils::kCpuSharesLow);
Darin Petkovc6c135c2010-08-11 13:36:18 -0700936}
937
Chris Sosa4f8ee272012-11-30 13:01:54 -0800938void UpdateAttempter::CleanupCpuSharesManagement() {
939 if (manage_shares_source_) {
940 g_source_destroy(manage_shares_source_);
941 manage_shares_source_ = NULL;
Darin Petkovc6c135c2010-08-11 13:36:18 -0700942 }
Chris Sosa4f8ee272012-11-30 13:01:54 -0800943 SetCpuShares(utils::kCpuSharesNormal);
Darin Petkovc6c135c2010-08-11 13:36:18 -0700944}
945
Chris Sosa4f8ee272012-11-30 13:01:54 -0800946gboolean UpdateAttempter::StaticManageCpuSharesCallback(gpointer data) {
947 return reinterpret_cast<UpdateAttempter*>(data)->ManageCpuSharesCallback();
Darin Petkovc6c135c2010-08-11 13:36:18 -0700948}
949
Darin Petkove6ef2f82011-03-07 17:31:11 -0800950gboolean UpdateAttempter::StaticStartProcessing(gpointer data) {
951 reinterpret_cast<UpdateAttempter*>(data)->processor_->StartProcessing();
952 return FALSE; // Don't call this callback again.
953}
954
Darin Petkov58dd1342011-05-06 12:05:13 -0700955void UpdateAttempter::ScheduleProcessingStart() {
956 LOG(INFO) << "Scheduling an action processor start.";
957 start_action_processor_ = false;
958 g_idle_add(&StaticStartProcessing, this);
959}
960
Chris Sosa4f8ee272012-11-30 13:01:54 -0800961bool UpdateAttempter::ManageCpuSharesCallback() {
962 SetCpuShares(utils::kCpuSharesNormal);
963 manage_shares_source_ = NULL;
Darin Petkovf622ef72010-10-26 13:49:24 -0700964 return false; // Destroy the timeout source.
Darin Petkovc6c135c2010-08-11 13:36:18 -0700965}
966
Darin Petkov36275772010-10-01 11:40:57 -0700967void UpdateAttempter::DisableDeltaUpdateIfNeeded() {
968 int64_t delta_failures;
969 if (omaha_request_params_.delta_okay &&
970 prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) &&
971 delta_failures >= kMaxDeltaUpdateFailures) {
972 LOG(WARNING) << "Too many delta update failures, forcing full update.";
973 omaha_request_params_.delta_okay = false;
974 }
975}
976
977void UpdateAttempter::MarkDeltaUpdateFailure() {
Darin Petkov2dd01092010-10-08 15:43:05 -0700978 // Don't try to resume a failed delta update.
979 DeltaPerformer::ResetUpdateProgress(prefs_, false);
Darin Petkov36275772010-10-01 11:40:57 -0700980 int64_t delta_failures;
981 if (!prefs_->GetInt64(kPrefsDeltaUpdateFailures, &delta_failures) ||
982 delta_failures < 0) {
983 delta_failures = 0;
984 }
985 prefs_->SetInt64(kPrefsDeltaUpdateFailures, ++delta_failures);
986}
987
Darin Petkov9b230572010-10-08 10:20:09 -0700988void UpdateAttempter::SetupDownload() {
Gilad Arnold9bedeb52011-11-17 16:19:57 -0800989 MultiRangeHttpFetcher* fetcher =
990 dynamic_cast<MultiRangeHttpFetcher*>(download_action_->http_fetcher());
Andrew de los Reyes819fef22010-12-17 11:33:58 -0800991 fetcher->ClearRanges();
Darin Petkov9b230572010-10-08 10:20:09 -0700992 if (response_handler_action_->install_plan().is_resume) {
Darin Petkovb21ce5d2010-10-21 16:03:05 -0700993 // Resuming an update so fetch the update manifest metadata first.
Darin Petkov9b230572010-10-08 10:20:09 -0700994 int64_t manifest_metadata_size = 0;
995 prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size);
Andrew de los Reyes819fef22010-12-17 11:33:58 -0800996 fetcher->AddRange(0, manifest_metadata_size);
Darin Petkovb21ce5d2010-10-21 16:03:05 -0700997 // If there're remaining unprocessed data blobs, fetch them. Be careful not
998 // to request data beyond the end of the payload to avoid 416 HTTP response
999 // error codes.
Darin Petkov9b230572010-10-08 10:20:09 -07001000 int64_t next_data_offset = 0;
1001 prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset);
Darin Petkovb21ce5d2010-10-21 16:03:05 -07001002 uint64_t resume_offset = manifest_metadata_size + next_data_offset;
Jay Srinivasan51dcf262012-09-13 17:24:32 -07001003 if (resume_offset < response_handler_action_->install_plan().payload_size) {
Gilad Arnolde4ad2502011-12-29 17:08:54 -08001004 fetcher->AddRange(resume_offset);
Darin Petkovb21ce5d2010-10-21 16:03:05 -07001005 }
Darin Petkov9b230572010-10-08 10:20:09 -07001006 } else {
Gilad Arnolde4ad2502011-12-29 17:08:54 -08001007 fetcher->AddRange(0);
Darin Petkov9b230572010-10-08 10:20:09 -07001008 }
Darin Petkov9b230572010-10-08 10:20:09 -07001009}
1010
Thieu Le116fda32011-04-19 11:01:54 -07001011void UpdateAttempter::PingOmaha() {
Thieu Led88a8572011-05-26 09:09:19 -07001012 if (!processor_->IsRunning()) {
1013 shared_ptr<OmahaRequestAction> ping_action(
Jay Srinivasan6f6ea002012-12-14 11:26:28 -08001014 new OmahaRequestAction(system_state_,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001015 &omaha_request_params_,
Thieu Led88a8572011-05-26 09:09:19 -07001016 NULL,
Jay Srinivasan08fce042012-06-07 16:31:01 -07001017 new LibcurlHttpFetcher(GetProxyResolver(),
Gilad Arnold7c04e762012-05-23 10:54:02 -07001018 system_state_,
1019 is_test_mode_),
Thieu Led88a8572011-05-26 09:09:19 -07001020 true));
1021 actions_.push_back(shared_ptr<OmahaRequestAction>(ping_action));
1022 processor_->set_delegate(NULL);
1023 processor_->EnqueueAction(ping_action.get());
1024 // Call StartProcessing() synchronously here to avoid any race conditions
1025 // caused by multiple outstanding ping Omaha requests. If we call
1026 // StartProcessing() asynchronously, the device can be suspended before we
1027 // get a chance to callback to StartProcessing(). When the device resumes
1028 // (assuming the device sleeps longer than the next update check period),
1029 // StartProcessing() is called back and at the same time, the next update
1030 // check is fired which eventually invokes StartProcessing(). A crash
1031 // can occur because StartProcessing() checks to make sure that the
1032 // processor is idle which it isn't due to the two concurrent ping Omaha
1033 // requests.
1034 processor_->StartProcessing();
1035 } else {
Darin Petkov58dd1342011-05-06 12:05:13 -07001036 LOG(WARNING) << "Action processor running, Omaha ping suppressed.";
Darin Petkov58dd1342011-05-06 12:05:13 -07001037 }
Thieu Led88a8572011-05-26 09:09:19 -07001038
1039 // Update the status which will schedule the next update check
Gilad Arnold1ebd8132012-03-05 10:19:29 -08001040 SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT,
1041 kUpdateNoticeUnspecified);
Thieu Le116fda32011-04-19 11:01:54 -07001042}
1043
Jay Srinivasan480ddfa2012-06-01 19:15:26 -07001044
1045bool UpdateAttempter::DecrementUpdateCheckCount() {
1046 int64 update_check_count_value;
1047
1048 if (!prefs_->Exists(kPrefsUpdateCheckCount)) {
1049 // This file does not exist. This means we haven't started our update
1050 // check count down yet, so nothing more to do. This file will be created
1051 // later when we first satisfy the wall-clock-based-wait period.
1052 LOG(INFO) << "No existing update check count. That's normal.";
1053 return true;
1054 }
1055
1056 if (prefs_->GetInt64(kPrefsUpdateCheckCount, &update_check_count_value)) {
1057 // Only if we're able to read a proper integer value, then go ahead
1058 // and decrement and write back the result in the same file, if needed.
1059 LOG(INFO) << "Update check count = " << update_check_count_value;
1060
1061 if (update_check_count_value == 0) {
1062 // It could be 0, if, for some reason, the file didn't get deleted
1063 // when we set our status to waiting for reboot. so we just leave it
1064 // as is so that we can prevent another update_check wait for this client.
1065 LOG(INFO) << "Not decrementing update check count as it's already 0.";
1066 return true;
1067 }
1068
1069 if (update_check_count_value > 0)
1070 update_check_count_value--;
1071 else
1072 update_check_count_value = 0;
1073
1074 // Write out the new value of update_check_count_value.
1075 if (prefs_->SetInt64(kPrefsUpdateCheckCount, update_check_count_value)) {
1076 // We successfully wrote out te new value, so enable the
1077 // update check based wait.
1078 LOG(INFO) << "New update check count = " << update_check_count_value;
1079 return true;
1080 }
1081 }
1082
1083 LOG(INFO) << "Deleting update check count state due to read/write errors.";
1084
1085 // We cannot read/write to the file, so disable the update check based wait
1086 // so that we don't get stuck in this OS version by any chance (which could
1087 // happen if there's some bug that causes to read/write incorrectly).
1088 // Also attempt to delete the file to do our best effort to cleanup.
1089 prefs_->Delete(kPrefsUpdateCheckCount);
1090 return false;
1091}
1092
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07001093} // namespace chromeos_update_engine