blob: b804822039e98a0cc059dd0c2a7e9382c330e500 [file] [log] [blame]
Jay Srinivasan6f6ea002012-12-14 11:26:28 -08001// Copyright (c) 2012 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/payload_state.h"
6
Jay Srinivasan08262882012-12-28 19:29:43 -08007#include <algorithm>
8
Jay Srinivasan6f6ea002012-12-14 11:26:28 -08009#include <base/logging.h>
Jay Srinivasan19409b72013-04-12 19:23:36 -070010#include "base/string_util.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080011#include <base/stringprintf.h>
12
David Zeuthenf413fe52013-04-22 14:04:39 -070013#include "update_engine/clock.h"
Jay Srinivasand29695d2013-04-08 15:08:05 -070014#include "update_engine/constants.h"
Jay Srinivasan19409b72013-04-12 19:23:36 -070015#include "update_engine/prefs.h"
16#include "update_engine/system_state.h"
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080017#include "update_engine/utils.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080018
Jay Srinivasan08262882012-12-28 19:29:43 -080019using base::Time;
20using base::TimeDelta;
21using std::min;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080022using std::string;
23
24namespace chromeos_update_engine {
25
David Zeuthen9a017f22013-04-11 16:10:26 -070026const TimeDelta PayloadState::kDurationSlack = TimeDelta::FromSeconds(600);
27
Jay Srinivasan08262882012-12-28 19:29:43 -080028// We want to upperbound backoffs to 16 days
29static const uint32_t kMaxBackoffDays = 16;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080030
Jay Srinivasan08262882012-12-28 19:29:43 -080031// We want to randomize retry attempts after the backoff by +/- 6 hours.
32static const uint32_t kMaxBackoffFuzzMinutes = 12 * 60;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080033
Jay Srinivasan19409b72013-04-12 19:23:36 -070034PayloadState::PayloadState()
35 : prefs_(NULL),
36 payload_attempt_number_(0),
37 url_index_(0),
David Zeuthencc6f9962013-04-18 11:57:24 -070038 url_failure_count_(0),
39 url_switch_count_(0) {
Jay Srinivasan19409b72013-04-12 19:23:36 -070040 for (int i = 0; i <= kNumDownloadSources; i++)
41 total_bytes_downloaded_[i] = current_bytes_downloaded_[i] = 0;
42}
43
44bool PayloadState::Initialize(SystemState* system_state) {
45 system_state_ = system_state;
46 prefs_ = system_state_->prefs();
Jay Srinivasan08262882012-12-28 19:29:43 -080047 LoadResponseSignature();
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080048 LoadPayloadAttemptNumber();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080049 LoadUrlIndex();
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080050 LoadUrlFailureCount();
David Zeuthencc6f9962013-04-18 11:57:24 -070051 LoadUrlSwitchCount();
Jay Srinivasan08262882012-12-28 19:29:43 -080052 LoadBackoffExpiryTime();
David Zeuthen9a017f22013-04-11 16:10:26 -070053 LoadUpdateTimestampStart();
54 // The LoadUpdateDurationUptime() method relies on LoadUpdateTimestampStart()
55 // being called before it. Don't reorder.
56 LoadUpdateDurationUptime();
Jay Srinivasan19409b72013-04-12 19:23:36 -070057 for (int i = 0; i < kNumDownloadSources; i++) {
58 DownloadSource source = static_cast<DownloadSource>(i);
59 LoadCurrentBytesDownloaded(source);
60 LoadTotalBytesDownloaded(source);
61 }
Chris Sosabe45bef2013-04-09 18:25:12 -070062 LoadNumReboots();
David Zeuthena573d6f2013-06-14 16:13:36 -070063 LoadNumResponsesSeen();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080064 return true;
65}
66
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080067void PayloadState::SetResponse(const OmahaResponse& omaha_response) {
Jay Srinivasan08262882012-12-28 19:29:43 -080068 // Always store the latest response.
69 response_ = omaha_response;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080070
Jay Srinivasan53173b92013-05-17 17:13:01 -070071 // Compute the candidate URLs first as they are used to calculate the
72 // response signature so that a change in enterprise policy for
73 // HTTP downloads being enabled or not could be honored as soon as the
74 // next update check happens.
75 ComputeCandidateUrls();
76
Jay Srinivasan08262882012-12-28 19:29:43 -080077 // Check if the "signature" of this response (i.e. the fields we care about)
78 // has changed.
79 string new_response_signature = CalculateResponseSignature();
80 bool has_response_changed = (response_signature_ != new_response_signature);
81
82 // If the response has changed, we should persist the new signature and
83 // clear away all the existing state.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080084 if (has_response_changed) {
Jay Srinivasan08262882012-12-28 19:29:43 -080085 LOG(INFO) << "Resetting all persisted state as this is a new response";
David Zeuthena573d6f2013-06-14 16:13:36 -070086 SetNumResponsesSeen(num_responses_seen_ + 1);
Jay Srinivasan08262882012-12-28 19:29:43 -080087 SetResponseSignature(new_response_signature);
88 ResetPersistedState();
89 return;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080090 }
91
Jay Srinivasan08262882012-12-28 19:29:43 -080092 // This is the earliest point at which we can validate whether the URL index
93 // we loaded from the persisted state is a valid value. If the response
94 // hasn't changed but the URL index is invalid, it's indicative of some
95 // tampering of the persisted state.
Jay Srinivasan53173b92013-05-17 17:13:01 -070096 if (static_cast<uint32_t>(url_index_) >= candidate_urls_.size()) {
Jay Srinivasan08262882012-12-28 19:29:43 -080097 LOG(INFO) << "Resetting all payload state as the url index seems to have "
98 "been tampered with";
99 ResetPersistedState();
100 return;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800101 }
Jay Srinivasan19409b72013-04-12 19:23:36 -0700102
103 // Update the current download source which depends on the latest value of
104 // the response.
105 UpdateCurrentDownloadSource();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800106}
107
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800108void PayloadState::DownloadComplete() {
109 LOG(INFO) << "Payload downloaded successfully";
110 IncrementPayloadAttemptNumber();
111}
112
113void PayloadState::DownloadProgress(size_t count) {
114 if (count == 0)
115 return;
116
David Zeuthen9a017f22013-04-11 16:10:26 -0700117 CalculateUpdateDurationUptime();
Jay Srinivasan19409b72013-04-12 19:23:36 -0700118 UpdateBytesDownloaded(count);
David Zeuthen9a017f22013-04-11 16:10:26 -0700119
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800120 // We've received non-zero bytes from a recent download operation. Since our
121 // URL failure count is meant to penalize a URL only for consecutive
122 // failures, downloading bytes successfully means we should reset the failure
123 // count (as we know at least that the URL is working). In future, we can
124 // design this to be more sophisticated to check for more intelligent failure
125 // patterns, but right now, even 1 byte downloaded will mark the URL to be
126 // good unless it hits 10 (or configured number of) consecutive failures
127 // again.
128
129 if (GetUrlFailureCount() == 0)
130 return;
131
132 LOG(INFO) << "Resetting failure count of Url" << GetUrlIndex()
133 << " to 0 as we received " << count << " bytes successfully";
134 SetUrlFailureCount(0);
135}
136
Chris Sosabe45bef2013-04-09 18:25:12 -0700137void PayloadState::UpdateResumed() {
138 LOG(INFO) << "Resuming an update that was previously started.";
139 UpdateNumReboots();
140}
141
Jay Srinivasan19409b72013-04-12 19:23:36 -0700142void PayloadState::UpdateRestarted() {
143 LOG(INFO) << "Starting a new update";
144 ResetDownloadSourcesOnNewUpdate();
Chris Sosabe45bef2013-04-09 18:25:12 -0700145 SetNumReboots(0);
Jay Srinivasan19409b72013-04-12 19:23:36 -0700146}
147
David Zeuthen9a017f22013-04-11 16:10:26 -0700148void PayloadState::UpdateSucceeded() {
Jay Srinivasan19409b72013-04-12 19:23:36 -0700149 // Send the relevant metrics that are tracked in this class to UMA.
David Zeuthen9a017f22013-04-11 16:10:26 -0700150 CalculateUpdateDurationUptime();
David Zeuthenf413fe52013-04-22 14:04:39 -0700151 SetUpdateTimestampEnd(system_state_->clock()->GetWallclockTime());
Jay Srinivasan19409b72013-04-12 19:23:36 -0700152 ReportBytesDownloadedMetrics();
David Zeuthencc6f9962013-04-18 11:57:24 -0700153 ReportUpdateUrlSwitchesMetric();
Chris Sosabe45bef2013-04-09 18:25:12 -0700154 ReportRebootMetrics();
David Zeuthen674c3182013-04-18 14:05:20 -0700155 ReportDurationMetrics();
David Zeuthena573d6f2013-06-14 16:13:36 -0700156 ReportUpdatesAbandonedCountMetric();
157
158 // Reset the number of responses seen since it counts from the last
159 // successful update, e.g. now.
160 SetNumResponsesSeen(0);
David Zeuthen9a017f22013-04-11 16:10:26 -0700161}
162
David Zeuthena99981f2013-04-29 13:42:47 -0700163void PayloadState::UpdateFailed(ErrorCode error) {
164 ErrorCode base_error = utils::GetBaseErrorCode(error);
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800165 LOG(INFO) << "Updating payload state for error code: " << base_error
166 << " (" << utils::CodeToString(base_error) << ")";
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800167
Jay Srinivasan53173b92013-05-17 17:13:01 -0700168 if (candidate_urls_.size() == 0) {
169 // This means we got this error even before we got a valid Omaha response
170 // or don't have any valid candidates in the Omaha response.
Jay Srinivasan08262882012-12-28 19:29:43 -0800171 // So we should not advance the url_index_ in such cases.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800172 LOG(INFO) << "Ignoring failures until we get a valid Omaha response.";
173 return;
174 }
175
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800176 switch (base_error) {
177 // Errors which are good indicators of a problem with a particular URL or
178 // the protocol used in the URL or entities in the communication channel
179 // (e.g. proxies). We should try the next available URL in the next update
180 // check to quickly recover from these errors.
David Zeuthena99981f2013-04-29 13:42:47 -0700181 case kErrorCodePayloadHashMismatchError:
182 case kErrorCodePayloadSizeMismatchError:
183 case kErrorCodeDownloadPayloadVerificationError:
184 case kErrorCodeDownloadPayloadPubKeyVerificationError:
185 case kErrorCodeSignedDeltaPayloadExpectedError:
186 case kErrorCodeDownloadInvalidMetadataMagicString:
187 case kErrorCodeDownloadSignatureMissingInManifest:
188 case kErrorCodeDownloadManifestParseError:
189 case kErrorCodeDownloadMetadataSignatureError:
190 case kErrorCodeDownloadMetadataSignatureVerificationError:
191 case kErrorCodeDownloadMetadataSignatureMismatch:
192 case kErrorCodeDownloadOperationHashVerificationError:
193 case kErrorCodeDownloadOperationExecutionError:
194 case kErrorCodeDownloadOperationHashMismatch:
195 case kErrorCodeDownloadInvalidMetadataSize:
196 case kErrorCodeDownloadInvalidMetadataSignature:
197 case kErrorCodeDownloadOperationHashMissingError:
198 case kErrorCodeDownloadMetadataSignatureMissingError:
Gilad Arnold21504f02013-05-24 08:51:22 -0700199 case kErrorCodePayloadMismatchedType:
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800200 IncrementUrlIndex();
201 break;
202
203 // Errors which seem to be just transient network/communication related
204 // failures and do not indicate any inherent problem with the URL itself.
205 // So, we should keep the current URL but just increment the
206 // failure count to give it more chances. This way, while we maximize our
207 // chances of downloading from the URLs that appear earlier in the response
208 // (because download from a local server URL that appears earlier in a
209 // response is preferable than downloading from the next URL which could be
210 // a internet URL and thus could be more expensive).
David Zeuthena99981f2013-04-29 13:42:47 -0700211 case kErrorCodeError:
212 case kErrorCodeDownloadTransferError:
213 case kErrorCodeDownloadWriteError:
214 case kErrorCodeDownloadStateInitializationError:
215 case kErrorCodeOmahaErrorInHTTPResponse: // Aggregate code for HTTP errors.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800216 IncrementFailureCount();
217 break;
218
219 // Errors which are not specific to a URL and hence shouldn't result in
220 // the URL being penalized. This can happen in two cases:
221 // 1. We haven't started downloading anything: These errors don't cost us
222 // anything in terms of actual payload bytes, so we should just do the
223 // regular retries at the next update check.
224 // 2. We have successfully downloaded the payload: In this case, the
225 // payload attempt number would have been incremented and would take care
Jay Srinivasan08262882012-12-28 19:29:43 -0800226 // of the backoff at the next update check.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800227 // In either case, there's no need to update URL index or failure count.
David Zeuthena99981f2013-04-29 13:42:47 -0700228 case kErrorCodeOmahaRequestError:
229 case kErrorCodeOmahaResponseHandlerError:
230 case kErrorCodePostinstallRunnerError:
231 case kErrorCodeFilesystemCopierError:
232 case kErrorCodeInstallDeviceOpenError:
233 case kErrorCodeKernelDeviceOpenError:
234 case kErrorCodeDownloadNewPartitionInfoError:
235 case kErrorCodeNewRootfsVerificationError:
236 case kErrorCodeNewKernelVerificationError:
237 case kErrorCodePostinstallBootedFromFirmwareB:
238 case kErrorCodeOmahaRequestEmptyResponseError:
239 case kErrorCodeOmahaRequestXMLParseError:
240 case kErrorCodeOmahaResponseInvalid:
241 case kErrorCodeOmahaUpdateIgnoredPerPolicy:
242 case kErrorCodeOmahaUpdateDeferredPerPolicy:
243 case kErrorCodeOmahaUpdateDeferredForBackoff:
244 case kErrorCodePostinstallPowerwashError:
245 case kErrorCodeUpdateCanceledByChannelChange:
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800246 LOG(INFO) << "Not incrementing URL index or failure count for this error";
247 break;
248
David Zeuthena99981f2013-04-29 13:42:47 -0700249 case kErrorCodeSuccess: // success code
David Zeuthena99981f2013-04-29 13:42:47 -0700250 case kErrorCodeUmaReportedMax: // not an error code
251 case kErrorCodeOmahaRequestHTTPResponseBase: // aggregated already
252 case kErrorCodeDevModeFlag: // not an error code
253 case kErrorCodeResumedFlag: // not an error code
254 case kErrorCodeTestImageFlag: // not an error code
255 case kErrorCodeTestOmahaUrlFlag: // not an error code
256 case kErrorCodeSpecialFlags: // not an error code
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800257 // These shouldn't happen. Enumerating these explicitly here so that we
258 // can let the compiler warn about new error codes that are added to
259 // action_processor.h but not added here.
260 LOG(WARNING) << "Unexpected error code for UpdateFailed";
261 break;
262
263 // Note: Not adding a default here so as to let the compiler warn us of
264 // any new enums that were added in the .h but not listed in this switch.
265 }
266}
267
Jay Srinivasan08262882012-12-28 19:29:43 -0800268bool PayloadState::ShouldBackoffDownload() {
269 if (response_.disable_payload_backoff) {
270 LOG(INFO) << "Payload backoff logic is disabled. "
271 "Can proceed with the download";
272 return false;
273 }
274
275 if (response_.is_delta_payload) {
276 // If delta payloads fail, we want to fallback quickly to full payloads as
277 // they are more likely to succeed. Exponential backoffs would greatly
278 // slow down the fallback to full payloads. So we don't backoff for delta
279 // payloads.
280 LOG(INFO) << "No backoffs for delta payloads. "
281 << "Can proceed with the download";
282 return false;
283 }
284
285 if (!utils::IsOfficialBuild()) {
286 // Backoffs are needed only for official builds. We do not want any delays
287 // or update failures due to backoffs during testing or development.
288 LOG(INFO) << "No backoffs for test/dev images. "
289 << "Can proceed with the download";
290 return false;
291 }
292
293 if (backoff_expiry_time_.is_null()) {
294 LOG(INFO) << "No backoff expiry time has been set. "
295 << "Can proceed with the download";
296 return false;
297 }
298
299 if (backoff_expiry_time_ < Time::Now()) {
300 LOG(INFO) << "The backoff expiry time ("
301 << utils::ToString(backoff_expiry_time_)
302 << ") has elapsed. Can proceed with the download";
303 return false;
304 }
305
306 LOG(INFO) << "Cannot proceed with downloads as we need to backoff until "
307 << utils::ToString(backoff_expiry_time_);
308 return true;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800309}
310
311void PayloadState::IncrementPayloadAttemptNumber() {
Jay Srinivasan08262882012-12-28 19:29:43 -0800312 if (response_.is_delta_payload) {
313 LOG(INFO) << "Not incrementing payload attempt number for delta payloads";
314 return;
315 }
316
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800317 LOG(INFO) << "Incrementing the payload attempt number";
318 SetPayloadAttemptNumber(GetPayloadAttemptNumber() + 1);
Jay Srinivasan08262882012-12-28 19:29:43 -0800319 UpdateBackoffExpiryTime();
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800320}
321
322void PayloadState::IncrementUrlIndex() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800323 uint32_t next_url_index = GetUrlIndex() + 1;
Jay Srinivasan53173b92013-05-17 17:13:01 -0700324 if (next_url_index < candidate_urls_.size()) {
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800325 LOG(INFO) << "Incrementing the URL index for next attempt";
326 SetUrlIndex(next_url_index);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800327 } else {
328 LOG(INFO) << "Resetting the current URL index (" << GetUrlIndex() << ") to "
Jay Srinivasan53173b92013-05-17 17:13:01 -0700329 << "0 as we only have " << candidate_urls_.size()
330 << " candidate URL(s)";
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800331 SetUrlIndex(0);
332 IncrementPayloadAttemptNumber();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800333 }
Jay Srinivasan08262882012-12-28 19:29:43 -0800334
David Zeuthencc6f9962013-04-18 11:57:24 -0700335 // If we have multiple URLs, record that we just switched to another one
Jay Srinivasan53173b92013-05-17 17:13:01 -0700336 if (candidate_urls_.size() > 1)
David Zeuthencc6f9962013-04-18 11:57:24 -0700337 SetUrlSwitchCount(url_switch_count_ + 1);
338
Jay Srinivasan08262882012-12-28 19:29:43 -0800339 // Whenever we update the URL index, we should also clear the URL failure
340 // count so we can start over fresh for the new URL.
341 SetUrlFailureCount(0);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800342}
343
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800344void PayloadState::IncrementFailureCount() {
345 uint32_t next_url_failure_count = GetUrlFailureCount() + 1;
Jay Srinivasan08262882012-12-28 19:29:43 -0800346 if (next_url_failure_count < response_.max_failure_count_per_url) {
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800347 LOG(INFO) << "Incrementing the URL failure count";
348 SetUrlFailureCount(next_url_failure_count);
349 } else {
350 LOG(INFO) << "Reached max number of failures for Url" << GetUrlIndex()
351 << ". Trying next available URL";
352 IncrementUrlIndex();
353 }
354}
355
Jay Srinivasan08262882012-12-28 19:29:43 -0800356void PayloadState::UpdateBackoffExpiryTime() {
357 if (response_.disable_payload_backoff) {
358 LOG(INFO) << "Resetting backoff expiry time as payload backoff is disabled";
359 SetBackoffExpiryTime(Time());
360 return;
361 }
362
363 if (GetPayloadAttemptNumber() == 0) {
364 SetBackoffExpiryTime(Time());
365 return;
366 }
367
368 // Since we're doing left-shift below, make sure we don't shift more
369 // than this. E.g. if uint32_t is 4-bytes, don't left-shift more than 30 bits,
370 // since we don't expect value of kMaxBackoffDays to be more than 100 anyway.
371 uint32_t num_days = 1; // the value to be shifted.
372 const uint32_t kMaxShifts = (sizeof(num_days) * 8) - 2;
373
374 // Normal backoff days is 2 raised to (payload_attempt_number - 1).
375 // E.g. if payload_attempt_number is over 30, limit power to 30.
376 uint32_t power = min(GetPayloadAttemptNumber() - 1, kMaxShifts);
377
378 // The number of days is the minimum of 2 raised to (payload_attempt_number
379 // - 1) or kMaxBackoffDays.
380 num_days = min(num_days << power, kMaxBackoffDays);
381
382 // We don't want all retries to happen exactly at the same time when
383 // retrying after backoff. So add some random minutes to fuzz.
384 int fuzz_minutes = utils::FuzzInt(0, kMaxBackoffFuzzMinutes);
385 TimeDelta next_backoff_interval = TimeDelta::FromDays(num_days) +
386 TimeDelta::FromMinutes(fuzz_minutes);
387 LOG(INFO) << "Incrementing the backoff expiry time by "
388 << utils::FormatTimeDelta(next_backoff_interval);
389 SetBackoffExpiryTime(Time::Now() + next_backoff_interval);
390}
391
Jay Srinivasan19409b72013-04-12 19:23:36 -0700392void PayloadState::UpdateCurrentDownloadSource() {
393 current_download_source_ = kNumDownloadSources;
394
Jay Srinivasan53173b92013-05-17 17:13:01 -0700395 if (GetUrlIndex() < candidate_urls_.size()) {
396 string current_url = candidate_urls_[GetUrlIndex()];
Jay Srinivasan19409b72013-04-12 19:23:36 -0700397 if (StartsWithASCII(current_url, "https://", false))
398 current_download_source_ = kDownloadSourceHttpsServer;
399 else if (StartsWithASCII(current_url, "http://", false))
400 current_download_source_ = kDownloadSourceHttpServer;
401 }
402
403 LOG(INFO) << "Current download source: "
404 << utils::ToString(current_download_source_);
405}
406
407void PayloadState::UpdateBytesDownloaded(size_t count) {
408 SetCurrentBytesDownloaded(
409 current_download_source_,
410 GetCurrentBytesDownloaded(current_download_source_) + count,
411 false);
412 SetTotalBytesDownloaded(
413 current_download_source_,
414 GetTotalBytesDownloaded(current_download_source_) + count,
415 false);
416}
417
418void PayloadState::ReportBytesDownloadedMetrics() {
419 // Report metrics collected from all known download sources to UMA.
420 // The reported data is in Megabytes in order to represent a larger
421 // sample range.
Jay Srinivasandbd9ea22013-04-22 17:45:19 -0700422 int download_sources_used = 0;
423 string metric;
424 uint64_t successful_mbs = 0;
425 uint64_t total_mbs = 0;
Jay Srinivasan19409b72013-04-12 19:23:36 -0700426 for (int i = 0; i < kNumDownloadSources; i++) {
427 DownloadSource source = static_cast<DownloadSource>(i);
428 const int kMaxMiBs = 10240; // Anything above 10GB goes in the last bucket.
429
Jay Srinivasandbd9ea22013-04-22 17:45:19 -0700430 metric = "Installer.SuccessfulMBsDownloadedFrom" + utils::ToString(source);
Jay Srinivasan19409b72013-04-12 19:23:36 -0700431 uint64_t mbs = GetCurrentBytesDownloaded(source) / kNumBytesInOneMiB;
Jay Srinivasandbd9ea22013-04-22 17:45:19 -0700432
433 // Count this download source as having been used if we downloaded any
434 // bytes that contributed to the final success of the update.
435 if (mbs)
436 download_sources_used |= (1 << source);
437
438 successful_mbs += mbs;
439 LOG(INFO) << "Uploading " << mbs << " (MBs) for metric " << metric;
Jay Srinivasan19409b72013-04-12 19:23:36 -0700440 system_state_->metrics_lib()->SendToUMA(metric,
441 mbs,
442 0, // min
443 kMaxMiBs,
444 kNumDefaultUmaBuckets);
445 SetCurrentBytesDownloaded(source, 0, true);
446
447 metric = "Installer.TotalMBsDownloadedFrom" + utils::ToString(source);
448 mbs = GetTotalBytesDownloaded(source) / kNumBytesInOneMiB;
Jay Srinivasandbd9ea22013-04-22 17:45:19 -0700449 total_mbs += mbs;
450 LOG(INFO) << "Uploading " << mbs << " (MBs) for metric " << metric;
Jay Srinivasan19409b72013-04-12 19:23:36 -0700451 system_state_->metrics_lib()->SendToUMA(metric,
452 mbs,
453 0, // min
454 kMaxMiBs,
455 kNumDefaultUmaBuckets);
456
457 SetTotalBytesDownloaded(source, 0, true);
458 }
Jay Srinivasandbd9ea22013-04-22 17:45:19 -0700459
460 metric = "Installer.DownloadSourcesUsed";
461 LOG(INFO) << "Uploading 0x" << std::hex << download_sources_used
462 << " (bit flags) for metric " << metric;
463 int num_buckets = std::min(1 << kNumDownloadSources, kNumDefaultUmaBuckets);
464 system_state_->metrics_lib()->SendToUMA(metric,
465 download_sources_used,
466 0, // min
467 1 << kNumDownloadSources,
468 num_buckets);
469
470 if (successful_mbs) {
471 metric = "Installer.DownloadOverheadPercentage";
472 int percent_overhead = (total_mbs - successful_mbs) * 100 / successful_mbs;
473 LOG(INFO) << "Uploading " << percent_overhead << "% for metric " << metric;
474 system_state_->metrics_lib()->SendToUMA(metric,
475 percent_overhead,
476 0, // min: 0% overhead
477 1000, // max: 1000% overhead
478 kNumDefaultUmaBuckets);
479 }
Jay Srinivasan19409b72013-04-12 19:23:36 -0700480}
481
David Zeuthencc6f9962013-04-18 11:57:24 -0700482void PayloadState::ReportUpdateUrlSwitchesMetric() {
483 string metric = "Installer.UpdateURLSwitches";
484 int value = static_cast<int>(url_switch_count_);
485
486 LOG(INFO) << "Uploading " << value << " (count) for metric " << metric;
487 system_state_->metrics_lib()->SendToUMA(
488 metric,
489 value,
490 0, // min value
491 100, // max value
492 kNumDefaultUmaBuckets);
493}
494
Chris Sosabe45bef2013-04-09 18:25:12 -0700495void PayloadState::ReportRebootMetrics() {
496 // Report the number of num_reboots.
497 string metric = "Installer.UpdateNumReboots";
498 uint32_t num_reboots = GetNumReboots();
499 LOG(INFO) << "Uploading reboot count of " << num_reboots << " for metric "
500 << metric;
501 system_state_->metrics_lib()->SendToUMA(
502 metric,
503 static_cast<int>(num_reboots), // sample
504 0, // min = 0.
505 50, // max
506 25); // buckets
507 SetNumReboots(0);
508}
509
510void PayloadState::UpdateNumReboots() {
511 // We only update the reboot count when the system has been detected to have
512 // been rebooted.
513 if (!system_state_->system_rebooted()) {
514 return;
515 }
516
517 SetNumReboots(GetNumReboots() + 1);
518}
519
520void PayloadState::SetNumReboots(uint32_t num_reboots) {
521 CHECK(prefs_);
522 num_reboots_ = num_reboots;
523 prefs_->SetInt64(kPrefsNumReboots, num_reboots);
524 LOG(INFO) << "Number of Reboots during current update attempt = "
525 << num_reboots_;
526}
527
Jay Srinivasan08262882012-12-28 19:29:43 -0800528void PayloadState::ResetPersistedState() {
529 SetPayloadAttemptNumber(0);
530 SetUrlIndex(0);
531 SetUrlFailureCount(0);
David Zeuthencc6f9962013-04-18 11:57:24 -0700532 SetUrlSwitchCount(0);
Jay Srinivasan08262882012-12-28 19:29:43 -0800533 UpdateBackoffExpiryTime(); // This will reset the backoff expiry time.
David Zeuthenf413fe52013-04-22 14:04:39 -0700534 SetUpdateTimestampStart(system_state_->clock()->GetWallclockTime());
David Zeuthen9a017f22013-04-11 16:10:26 -0700535 SetUpdateTimestampEnd(Time()); // Set to null time
536 SetUpdateDurationUptime(TimeDelta::FromSeconds(0));
Jay Srinivasan19409b72013-04-12 19:23:36 -0700537 ResetDownloadSourcesOnNewUpdate();
538}
539
540void PayloadState::ResetDownloadSourcesOnNewUpdate() {
541 for (int i = 0; i < kNumDownloadSources; i++) {
542 DownloadSource source = static_cast<DownloadSource>(i);
543 SetCurrentBytesDownloaded(source, 0, true);
544 // Note: Not resetting the TotalBytesDownloaded as we want that metric
545 // to count the bytes downloaded across various update attempts until
546 // we have successfully applied the update.
547 }
548}
549
550int64_t PayloadState::GetPersistedValue(const string& key) {
551 CHECK(prefs_);
552 if (!prefs_->Exists(key))
553 return 0;
554
555 int64_t stored_value;
556 if (!prefs_->GetInt64(key, &stored_value))
557 return 0;
558
559 if (stored_value < 0) {
560 LOG(ERROR) << key << ": Invalid value (" << stored_value
561 << ") in persisted state. Defaulting to 0";
562 return 0;
563 }
564
565 return stored_value;
Jay Srinivasan08262882012-12-28 19:29:43 -0800566}
567
568string PayloadState::CalculateResponseSignature() {
569 string response_sign = StringPrintf("NumURLs = %d\n",
Jay Srinivasan53173b92013-05-17 17:13:01 -0700570 candidate_urls_.size());
Jay Srinivasan08262882012-12-28 19:29:43 -0800571
Jay Srinivasan53173b92013-05-17 17:13:01 -0700572 for (size_t i = 0; i < candidate_urls_.size(); i++)
573 response_sign += StringPrintf("Candidate Url%d = %s\n",
574 i, candidate_urls_[i].c_str());
Jay Srinivasan08262882012-12-28 19:29:43 -0800575
576 response_sign += StringPrintf("Payload Size = %llu\n"
577 "Payload Sha256 Hash = %s\n"
578 "Metadata Size = %llu\n"
579 "Metadata Signature = %s\n"
580 "Is Delta Payload = %d\n"
581 "Max Failure Count Per Url = %d\n"
582 "Disable Payload Backoff = %d\n",
583 response_.size,
584 response_.hash.c_str(),
585 response_.metadata_size,
586 response_.metadata_signature.c_str(),
587 response_.is_delta_payload,
588 response_.max_failure_count_per_url,
589 response_.disable_payload_backoff);
590 return response_sign;
591}
592
593void PayloadState::LoadResponseSignature() {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800594 CHECK(prefs_);
595 string stored_value;
Jay Srinivasan08262882012-12-28 19:29:43 -0800596 if (prefs_->Exists(kPrefsCurrentResponseSignature) &&
597 prefs_->GetString(kPrefsCurrentResponseSignature, &stored_value)) {
598 SetResponseSignature(stored_value);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800599 }
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800600}
601
Jay Srinivasan19409b72013-04-12 19:23:36 -0700602void PayloadState::SetResponseSignature(const string& response_signature) {
Jay Srinivasan08262882012-12-28 19:29:43 -0800603 CHECK(prefs_);
604 response_signature_ = response_signature;
605 LOG(INFO) << "Current Response Signature = \n" << response_signature_;
606 prefs_->SetString(kPrefsCurrentResponseSignature, response_signature_);
607}
608
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800609void PayloadState::LoadPayloadAttemptNumber() {
Jay Srinivasan19409b72013-04-12 19:23:36 -0700610 SetPayloadAttemptNumber(GetPersistedValue(kPrefsPayloadAttemptNumber));
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800611}
612
613void PayloadState::SetPayloadAttemptNumber(uint32_t payload_attempt_number) {
614 CHECK(prefs_);
615 payload_attempt_number_ = payload_attempt_number;
616 LOG(INFO) << "Payload Attempt Number = " << payload_attempt_number_;
617 prefs_->SetInt64(kPrefsPayloadAttemptNumber, payload_attempt_number_);
618}
619
620void PayloadState::LoadUrlIndex() {
Jay Srinivasan19409b72013-04-12 19:23:36 -0700621 SetUrlIndex(GetPersistedValue(kPrefsCurrentUrlIndex));
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800622}
623
624void PayloadState::SetUrlIndex(uint32_t url_index) {
625 CHECK(prefs_);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800626 url_index_ = url_index;
627 LOG(INFO) << "Current URL Index = " << url_index_;
628 prefs_->SetInt64(kPrefsCurrentUrlIndex, url_index_);
Jay Srinivasan19409b72013-04-12 19:23:36 -0700629
630 // Also update the download source, which is purely dependent on the
631 // current URL index alone.
632 UpdateCurrentDownloadSource();
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800633}
634
David Zeuthencc6f9962013-04-18 11:57:24 -0700635void PayloadState::LoadUrlSwitchCount() {
636 SetUrlSwitchCount(GetPersistedValue(kPrefsUrlSwitchCount));
637}
638
639void PayloadState::SetUrlSwitchCount(uint32_t url_switch_count) {
640 CHECK(prefs_);
641 url_switch_count_ = url_switch_count;
642 LOG(INFO) << "URL Switch Count = " << url_switch_count_;
643 prefs_->SetInt64(kPrefsUrlSwitchCount, url_switch_count_);
644}
645
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800646void PayloadState::LoadUrlFailureCount() {
Jay Srinivasan19409b72013-04-12 19:23:36 -0700647 SetUrlFailureCount(GetPersistedValue(kPrefsCurrentUrlFailureCount));
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800648}
649
650void PayloadState::SetUrlFailureCount(uint32_t url_failure_count) {
651 CHECK(prefs_);
652 url_failure_count_ = url_failure_count;
653 LOG(INFO) << "Current URL (Url" << GetUrlIndex()
654 << ")'s Failure Count = " << url_failure_count_;
655 prefs_->SetInt64(kPrefsCurrentUrlFailureCount, url_failure_count_);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800656}
657
Jay Srinivasan08262882012-12-28 19:29:43 -0800658void PayloadState::LoadBackoffExpiryTime() {
659 CHECK(prefs_);
660 int64_t stored_value;
661 if (!prefs_->Exists(kPrefsBackoffExpiryTime))
662 return;
663
664 if (!prefs_->GetInt64(kPrefsBackoffExpiryTime, &stored_value))
665 return;
666
667 Time stored_time = Time::FromInternalValue(stored_value);
668 if (stored_time > Time::Now() + TimeDelta::FromDays(kMaxBackoffDays)) {
669 LOG(ERROR) << "Invalid backoff expiry time ("
670 << utils::ToString(stored_time)
671 << ") in persisted state. Resetting.";
672 stored_time = Time();
673 }
674 SetBackoffExpiryTime(stored_time);
675}
676
677void PayloadState::SetBackoffExpiryTime(const Time& new_time) {
678 CHECK(prefs_);
679 backoff_expiry_time_ = new_time;
680 LOG(INFO) << "Backoff Expiry Time = "
681 << utils::ToString(backoff_expiry_time_);
682 prefs_->SetInt64(kPrefsBackoffExpiryTime,
683 backoff_expiry_time_.ToInternalValue());
684}
685
David Zeuthen9a017f22013-04-11 16:10:26 -0700686TimeDelta PayloadState::GetUpdateDuration() {
David Zeuthenf413fe52013-04-22 14:04:39 -0700687 Time end_time = update_timestamp_end_.is_null()
688 ? system_state_->clock()->GetWallclockTime() :
689 update_timestamp_end_;
David Zeuthen9a017f22013-04-11 16:10:26 -0700690 return end_time - update_timestamp_start_;
691}
692
693void PayloadState::LoadUpdateTimestampStart() {
694 int64_t stored_value;
695 Time stored_time;
696
697 CHECK(prefs_);
698
David Zeuthenf413fe52013-04-22 14:04:39 -0700699 Time now = system_state_->clock()->GetWallclockTime();
David Zeuthen9a017f22013-04-11 16:10:26 -0700700
701 if (!prefs_->Exists(kPrefsUpdateTimestampStart)) {
702 // The preference missing is not unexpected - in that case, just
703 // use the current time as start time
704 stored_time = now;
705 } else if (!prefs_->GetInt64(kPrefsUpdateTimestampStart, &stored_value)) {
706 LOG(ERROR) << "Invalid UpdateTimestampStart value. Resetting.";
707 stored_time = now;
708 } else {
709 stored_time = Time::FromInternalValue(stored_value);
710 }
711
712 // Sanity check: If the time read from disk is in the future
713 // (modulo some slack to account for possible NTP drift
714 // adjustments), something is fishy and we should report and
715 // reset.
716 TimeDelta duration_according_to_stored_time = now - stored_time;
717 if (duration_according_to_stored_time < -kDurationSlack) {
718 LOG(ERROR) << "The UpdateTimestampStart value ("
719 << utils::ToString(stored_time)
720 << ") in persisted state is "
David Zeuthen674c3182013-04-18 14:05:20 -0700721 << utils::FormatTimeDelta(duration_according_to_stored_time)
722 << " in the future. Resetting.";
David Zeuthen9a017f22013-04-11 16:10:26 -0700723 stored_time = now;
724 }
725
726 SetUpdateTimestampStart(stored_time);
727}
728
729void PayloadState::SetUpdateTimestampStart(const Time& value) {
730 CHECK(prefs_);
731 update_timestamp_start_ = value;
732 prefs_->SetInt64(kPrefsUpdateTimestampStart,
733 update_timestamp_start_.ToInternalValue());
734 LOG(INFO) << "Update Timestamp Start = "
735 << utils::ToString(update_timestamp_start_);
736}
737
738void PayloadState::SetUpdateTimestampEnd(const Time& value) {
739 update_timestamp_end_ = value;
740 LOG(INFO) << "Update Timestamp End = "
741 << utils::ToString(update_timestamp_end_);
742}
743
744TimeDelta PayloadState::GetUpdateDurationUptime() {
745 return update_duration_uptime_;
746}
747
748void PayloadState::LoadUpdateDurationUptime() {
749 int64_t stored_value;
750 TimeDelta stored_delta;
751
752 CHECK(prefs_);
753
754 if (!prefs_->Exists(kPrefsUpdateDurationUptime)) {
755 // The preference missing is not unexpected - in that case, just
756 // we'll use zero as the delta
757 } else if (!prefs_->GetInt64(kPrefsUpdateDurationUptime, &stored_value)) {
758 LOG(ERROR) << "Invalid UpdateDurationUptime value. Resetting.";
759 stored_delta = TimeDelta::FromSeconds(0);
760 } else {
761 stored_delta = TimeDelta::FromInternalValue(stored_value);
762 }
763
764 // Sanity-check: Uptime can never be greater than the wall-clock
765 // difference (modulo some slack). If it is, report and reset
766 // to the wall-clock difference.
767 TimeDelta diff = GetUpdateDuration() - stored_delta;
768 if (diff < -kDurationSlack) {
769 LOG(ERROR) << "The UpdateDurationUptime value ("
David Zeuthen674c3182013-04-18 14:05:20 -0700770 << utils::FormatTimeDelta(stored_delta)
David Zeuthen9a017f22013-04-11 16:10:26 -0700771 << ") in persisted state is "
David Zeuthen674c3182013-04-18 14:05:20 -0700772 << utils::FormatTimeDelta(diff)
773 << " larger than the wall-clock delta. Resetting.";
David Zeuthen9a017f22013-04-11 16:10:26 -0700774 stored_delta = update_duration_current_;
775 }
776
777 SetUpdateDurationUptime(stored_delta);
778}
779
Chris Sosabe45bef2013-04-09 18:25:12 -0700780void PayloadState::LoadNumReboots() {
781 SetNumReboots(GetPersistedValue(kPrefsNumReboots));
782}
783
David Zeuthen9a017f22013-04-11 16:10:26 -0700784void PayloadState::SetUpdateDurationUptimeExtended(const TimeDelta& value,
785 const Time& timestamp,
786 bool use_logging) {
787 CHECK(prefs_);
788 update_duration_uptime_ = value;
789 update_duration_uptime_timestamp_ = timestamp;
790 prefs_->SetInt64(kPrefsUpdateDurationUptime,
791 update_duration_uptime_.ToInternalValue());
792 if (use_logging) {
793 LOG(INFO) << "Update Duration Uptime = "
David Zeuthen674c3182013-04-18 14:05:20 -0700794 << utils::FormatTimeDelta(update_duration_uptime_);
David Zeuthen9a017f22013-04-11 16:10:26 -0700795 }
796}
797
798void PayloadState::SetUpdateDurationUptime(const TimeDelta& value) {
David Zeuthenf413fe52013-04-22 14:04:39 -0700799 Time now = system_state_->clock()->GetMonotonicTime();
800 SetUpdateDurationUptimeExtended(value, now, true);
David Zeuthen9a017f22013-04-11 16:10:26 -0700801}
802
803void PayloadState::CalculateUpdateDurationUptime() {
David Zeuthenf413fe52013-04-22 14:04:39 -0700804 Time now = system_state_->clock()->GetMonotonicTime();
David Zeuthen9a017f22013-04-11 16:10:26 -0700805 TimeDelta uptime_since_last_update = now - update_duration_uptime_timestamp_;
806 TimeDelta new_uptime = update_duration_uptime_ + uptime_since_last_update;
807 // We're frequently called so avoid logging this write
808 SetUpdateDurationUptimeExtended(new_uptime, now, false);
809}
810
David Zeuthen674c3182013-04-18 14:05:20 -0700811void PayloadState::ReportDurationMetrics() {
812 TimeDelta duration = GetUpdateDuration();
813 TimeDelta duration_uptime = GetUpdateDurationUptime();
814 string metric;
815
816 metric = "Installer.UpdateDurationMinutes";
817 system_state_->metrics_lib()->SendToUMA(
818 metric,
819 static_cast<int>(duration.InMinutes()),
820 1, // min: 1 minute
821 365*24*60, // max: 1 year (approx)
822 kNumDefaultUmaBuckets);
823 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration)
824 << " for metric " << metric;
825
826 metric = "Installer.UpdateDurationUptimeMinutes";
827 system_state_->metrics_lib()->SendToUMA(
828 metric,
829 static_cast<int>(duration_uptime.InMinutes()),
830 1, // min: 1 minute
831 30*24*60, // max: 1 month (approx)
832 kNumDefaultUmaBuckets);
833 LOG(INFO) << "Uploading " << utils::FormatTimeDelta(duration_uptime)
834 << " for metric " << metric;
835
836 prefs_->Delete(kPrefsUpdateTimestampStart);
837 prefs_->Delete(kPrefsUpdateDurationUptime);
838}
839
Jay Srinivasan19409b72013-04-12 19:23:36 -0700840string PayloadState::GetPrefsKey(const string& prefix, DownloadSource source) {
841 return prefix + "-from-" + utils::ToString(source);
842}
843
844void PayloadState::LoadCurrentBytesDownloaded(DownloadSource source) {
845 string key = GetPrefsKey(kPrefsCurrentBytesDownloaded, source);
846 SetCurrentBytesDownloaded(source, GetPersistedValue(key), true);
847}
848
849void PayloadState::SetCurrentBytesDownloaded(
850 DownloadSource source,
851 uint64_t current_bytes_downloaded,
852 bool log) {
853 CHECK(prefs_);
854
855 if (source >= kNumDownloadSources)
856 return;
857
858 // Update the in-memory value.
859 current_bytes_downloaded_[source] = current_bytes_downloaded;
860
861 string prefs_key = GetPrefsKey(kPrefsCurrentBytesDownloaded, source);
862 prefs_->SetInt64(prefs_key, current_bytes_downloaded);
863 LOG_IF(INFO, log) << "Current bytes downloaded for "
864 << utils::ToString(source) << " = "
865 << GetCurrentBytesDownloaded(source);
866}
867
868void PayloadState::LoadTotalBytesDownloaded(DownloadSource source) {
869 string key = GetPrefsKey(kPrefsTotalBytesDownloaded, source);
870 SetTotalBytesDownloaded(source, GetPersistedValue(key), true);
871}
872
873void PayloadState::SetTotalBytesDownloaded(
874 DownloadSource source,
875 uint64_t total_bytes_downloaded,
876 bool log) {
877 CHECK(prefs_);
878
879 if (source >= kNumDownloadSources)
880 return;
881
882 // Update the in-memory value.
883 total_bytes_downloaded_[source] = total_bytes_downloaded;
884
885 // Persist.
886 string prefs_key = GetPrefsKey(kPrefsTotalBytesDownloaded, source);
887 prefs_->SetInt64(prefs_key, total_bytes_downloaded);
888 LOG_IF(INFO, log) << "Total bytes downloaded for "
889 << utils::ToString(source) << " = "
890 << GetTotalBytesDownloaded(source);
891}
892
David Zeuthena573d6f2013-06-14 16:13:36 -0700893void PayloadState::LoadNumResponsesSeen() {
894 SetNumResponsesSeen(GetPersistedValue(kPrefsNumResponsesSeen));
895}
896
897void PayloadState::SetNumResponsesSeen(int num_responses_seen) {
898 CHECK(prefs_);
899 num_responses_seen_ = num_responses_seen;
900 LOG(INFO) << "Num Responses Seen = " << num_responses_seen_;
901 prefs_->SetInt64(kPrefsNumResponsesSeen, num_responses_seen_);
902}
903
904void PayloadState::ReportUpdatesAbandonedCountMetric() {
905 string metric = "Installer.UpdatesAbandonedCount";
906 int value = num_responses_seen_ - 1;
907
908 LOG(INFO) << "Uploading " << value << " (count) for metric " << metric;
909 system_state_->metrics_lib()->SendToUMA(
910 metric,
911 value,
912 0, // min value
913 100, // max value
914 kNumDefaultUmaBuckets);
915}
916
Jay Srinivasan53173b92013-05-17 17:13:01 -0700917void PayloadState::ComputeCandidateUrls() {
918 bool http_url_ok = false;
919
920 if (system_state_->IsOfficialBuild()) {
921 const policy::DevicePolicy* policy = system_state_->device_policy();
922 if (!(policy && policy->GetHttpDownloadsEnabled(&http_url_ok) &&
923 http_url_ok))
924 LOG(INFO) << "Downloads via HTTP Url are not enabled by device policy";
925 } else {
926 LOG(INFO) << "Allowing HTTP downloads for unofficial builds";
927 http_url_ok = true;
928 }
929
930 candidate_urls_.clear();
931 for (size_t i = 0; i < response_.payload_urls.size(); i++) {
932 string candidate_url = response_.payload_urls[i];
933 if (StartsWithASCII(candidate_url, "http://", false) && !http_url_ok)
934 continue;
935 candidate_urls_.push_back(candidate_url);
936 LOG(INFO) << "Candidate Url" << (candidate_urls_.size() - 1)
937 << ": " << candidate_url;
938 }
939
940 LOG(INFO) << "Found " << candidate_urls_.size() << " candidate URLs "
941 << "out of " << response_.payload_urls.size() << " URLs supplied";
942}
943
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800944} // namespace chromeos_update_engine