blob: d0211c581d477d9f0ac55821d96cc4a6cb4402fd [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
Alex Deymo759c2752014-03-17 21:09:36 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H_
Jay Srinivasan6f6ea002012-12-14 11:26:28 -08007
Alex Vakulenko75039d72014-03-25 12:36:28 -07008#include <base/time/time.h>
Alex Deymo42432912013-07-12 20:21:15 -07009#include <gtest/gtest_prod.h> // for FRIEND_TEST
Jay Srinivasan08262882012-12-28 19:29:43 -080010
David Zeuthenb281f072014-04-02 10:20:19 -070011#include "update_engine/metrics.h"
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080012#include "update_engine/payload_state_interface.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080013#include "update_engine/prefs_interface.h"
14
15namespace chromeos_update_engine {
16
Jay Srinivasan19409b72013-04-12 19:23:36 -070017class SystemState;
18
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080019// Encapsulates all the payload state required for download. This includes the
Jay Srinivasan08262882012-12-28 19:29:43 -080020// state necessary for handling multiple URLs in Omaha response, the backoff
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080021// state, etc. All state is persisted so that we use the most recently saved
22// value when resuming the update_engine process. All state is also cached in
23// memory so that we ensure we always make progress based on last known good
24// state even when there's any issue in reading/writing from the file system.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080025class PayloadState : public PayloadStateInterface {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080026 public:
Jay Srinivasan19409b72013-04-12 19:23:36 -070027 PayloadState();
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080028 virtual ~PayloadState() {}
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080029
Jay Srinivasan19409b72013-04-12 19:23:36 -070030 // Initializes a payload state object using the given global system state.
31 // It performs the initial loading of all persisted state into memory and
32 // dumps the initial state for debugging purposes. Note: the other methods
33 // should be called only after calling Initialize on this object.
34 bool Initialize(SystemState* system_state);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080035
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080036 // Implementation of PayloadStateInterface methods.
37 virtual void SetResponse(const OmahaResponse& response);
38 virtual void DownloadComplete();
39 virtual void DownloadProgress(size_t count);
Chris Sosabe45bef2013-04-09 18:25:12 -070040 virtual void UpdateResumed();
Jay Srinivasan19409b72013-04-12 19:23:36 -070041 virtual void UpdateRestarted();
David Zeuthen9a017f22013-04-11 16:10:26 -070042 virtual void UpdateSucceeded();
David Zeuthena99981f2013-04-29 13:42:47 -070043 virtual void UpdateFailed(ErrorCode error);
Alex Deymo42432912013-07-12 20:21:15 -070044 virtual void ResetUpdateStatus();
Jay Srinivasan08262882012-12-28 19:29:43 -080045 virtual bool ShouldBackoffDownload();
Chris Sosaaa18e162013-06-20 13:20:30 -070046 virtual void Rollback();
Alex Deymo42432912013-07-12 20:21:15 -070047 virtual void ExpectRebootInNewVersion(const std::string& target_version_uid);
David Zeuthenbb8bdc72013-09-03 13:43:48 -070048 virtual void SetUsingP2PForDownloading(bool value);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080049
Jay Srinivasan08262882012-12-28 19:29:43 -080050 virtual inline std::string GetResponseSignature() {
51 return response_signature_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080052 }
53
Alex Deymo820cc702013-06-28 15:43:46 -070054 virtual inline int GetFullPayloadAttemptNumber() {
55 return full_payload_attempt_number_;
56 }
57
58 virtual inline int GetPayloadAttemptNumber() {
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080059 return payload_attempt_number_;
60 }
61
Jay Srinivasan53173b92013-05-17 17:13:01 -070062 virtual inline std::string GetCurrentUrl() {
63 return candidate_urls_.size() ? candidate_urls_[url_index_] : "";
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080064 }
65
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080066 virtual inline uint32_t GetUrlFailureCount() {
67 return url_failure_count_;
68 }
69
David Zeuthencc6f9962013-04-18 11:57:24 -070070 virtual inline uint32_t GetUrlSwitchCount() {
71 return url_switch_count_;
72 }
73
David Zeuthena573d6f2013-06-14 16:13:36 -070074 virtual inline int GetNumResponsesSeen() {
75 return num_responses_seen_;
76 }
77
Jay Srinivasan08262882012-12-28 19:29:43 -080078 virtual inline base::Time GetBackoffExpiryTime() {
79 return backoff_expiry_time_;
80 }
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080081
David Zeuthen9a017f22013-04-11 16:10:26 -070082 virtual base::TimeDelta GetUpdateDuration();
83
84 virtual base::TimeDelta GetUpdateDurationUptime();
85
Jay Srinivasan19409b72013-04-12 19:23:36 -070086 virtual inline uint64_t GetCurrentBytesDownloaded(DownloadSource source) {
87 return source < kNumDownloadSources ? current_bytes_downloaded_[source] : 0;
88 }
89
90 virtual inline uint64_t GetTotalBytesDownloaded(DownloadSource source) {
91 return source < kNumDownloadSources ? total_bytes_downloaded_[source] : 0;
92 }
93
Chris Sosabe45bef2013-04-09 18:25:12 -070094 virtual inline uint32_t GetNumReboots() {
95 return num_reboots_;
96 }
97
David Zeuthene4c58bf2013-06-18 17:26:50 -070098 virtual void UpdateEngineStarted();
99
Chris Sosaaa18e162013-06-20 13:20:30 -0700100 virtual inline std::string GetRollbackVersion() {
101 return rollback_version_;
102 }
103
David Zeuthendcba8092013-08-06 12:16:35 -0700104 virtual int GetP2PNumAttempts();
105 virtual base::Time GetP2PFirstAttemptTimestamp();
106 virtual void P2PNewAttempt();
107 virtual bool P2PAttemptAllowed();
108
David Zeuthenbb8bdc72013-09-03 13:43:48 -0700109 virtual bool GetUsingP2PForDownloading() {
110 return using_p2p_for_downloading_;
111 }
112
Jay Srinivasan08262882012-12-28 19:29:43 -0800113 private:
Alex Deymo42432912013-07-12 20:21:15 -0700114 friend class PayloadStateTest;
115 FRIEND_TEST(PayloadStateTest, RebootAfterUpdateFailedMetric);
116 FRIEND_TEST(PayloadStateTest, RebootAfterUpdateSucceed);
117 FRIEND_TEST(PayloadStateTest, RebootAfterCanceledUpdate);
Chris Sosab3dcdb32013-09-04 15:22:12 -0700118 FRIEND_TEST(PayloadStateTest, RollbackVersion);
Alex Deymo42432912013-07-12 20:21:15 -0700119 FRIEND_TEST(PayloadStateTest, UpdateSuccessWithWipedPrefs);
120
David Zeuthen33bae492014-02-25 16:16:18 -0800121 // Helper called when an attempt has begun, is called by
122 // UpdateResumed() and UpdateRestarted().
123 void AttemptStarted();
124
Alex Deymo820cc702013-06-28 15:43:46 -0700125 // Increments the payload attempt number used for metrics.
126 void IncrementPayloadAttemptNumber();
127
Jay Srinivasan08262882012-12-28 19:29:43 -0800128 // Increments the payload attempt number which governs the backoff behavior
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800129 // at the time of the next update check.
Alex Deymo820cc702013-06-28 15:43:46 -0700130 void IncrementFullPayloadAttemptNumber();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800131
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800132 // Advances the current URL index to the next available one. If all URLs have
133 // been exhausted during the current payload download attempt (as indicated
134 // by the payload attempt number), then it will increment the payload attempt
David Zeuthencc6f9962013-04-18 11:57:24 -0700135 // number and wrap around again with the first URL in the list. This also
136 // updates the URL switch count, if needed.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800137 void IncrementUrlIndex();
138
139 // Increments the failure count of the current URL. If the configured max
140 // failure count is reached for this URL, it advances the current URL index
141 // to the next URL and resets the failure count for that URL.
142 void IncrementFailureCount();
143
Jay Srinivasan08262882012-12-28 19:29:43 -0800144 // Updates the backoff expiry time exponentially based on the current
145 // payload attempt number.
146 void UpdateBackoffExpiryTime();
147
Jay Srinivasan19409b72013-04-12 19:23:36 -0700148 // Updates the value of current download source based on the current URL
149 // index. If the download source is not one of the known sources, it's set
150 // to kNumDownloadSources.
151 void UpdateCurrentDownloadSource();
152
153 // Updates the various metrics corresponding with the given number of bytes
154 // that were downloaded recently.
155 void UpdateBytesDownloaded(size_t count);
156
David Zeuthen33bae492014-02-25 16:16:18 -0800157 // Calculates the PayloadType we're using.
158 PayloadType CalculatePayloadType();
Jay Srinivasan19409b72013-04-12 19:23:36 -0700159
David Zeuthen33bae492014-02-25 16:16:18 -0800160 // Collects and reports the various metrics related to an update attempt.
161 void CollectAndReportAttemptMetrics(ErrorCode code);
David Zeuthencc6f9962013-04-18 11:57:24 -0700162
David Zeuthen33bae492014-02-25 16:16:18 -0800163 // Collects and reports the various metrics related to a successful update.
164 void CollectAndReportSuccessfulUpdateMetrics();
Alex Deymo820cc702013-06-28 15:43:46 -0700165
Alex Deymo42432912013-07-12 20:21:15 -0700166 // Checks if we were expecting to be running in the new version but the
167 // boot into the new version failed for some reason. If that's the case, an
168 // UMA metric is sent reporting the number of attempts the same applied
169 // payload was attempted to reboot. This function is called by UpdateAttempter
170 // every time the update engine starts and there's no reboot pending.
171 void ReportFailedBootIfNeeded();
172
Jay Srinivasan08262882012-12-28 19:29:43 -0800173 // Resets all the persisted state values which are maintained relative to the
174 // current response signature. The response signature itself is not reset.
175 void ResetPersistedState();
176
Jay Srinivasan19409b72013-04-12 19:23:36 -0700177 // Resets the appropriate state related to download sources that need to be
178 // reset on a new update.
179 void ResetDownloadSourcesOnNewUpdate();
180
Chris Sosab3dcdb32013-09-04 15:22:12 -0700181 // Returns the persisted value from prefs_ for the given key. It also
182 // validates that the value returned is non-negative.
183 int64_t GetPersistedValue(const std::string& key);
Jay Srinivasan19409b72013-04-12 19:23:36 -0700184
Jay Srinivasan08262882012-12-28 19:29:43 -0800185 // Calculates the response "signature", which is basically a string composed
186 // of the subset of the fields in the current response that affect the
187 // behavior of the PayloadState.
188 std::string CalculateResponseSignature();
189
190 // Initializes the current response signature from the persisted state.
191 void LoadResponseSignature();
192
193 // Sets the response signature to the given value. Also persists the value
194 // being set so that we resume from the save value in case of a process
195 // restart.
Jay Srinivasan19409b72013-04-12 19:23:36 -0700196 void SetResponseSignature(const std::string& response_signature);
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800197
198 // Initializes the payload attempt number from the persisted state.
199 void LoadPayloadAttemptNumber();
200
Alex Deymo820cc702013-06-28 15:43:46 -0700201 // Initializes the payload attempt number for full payloads from the persisted
202 // state.
203 void LoadFullPayloadAttemptNumber();
204
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800205 // Sets the payload attempt number to the given value. Also persists the
206 // value being set so that we resume from the same value in case of a process
207 // restart.
Alex Deymo820cc702013-06-28 15:43:46 -0700208 void SetPayloadAttemptNumber(int payload_attempt_number);
209
210 // Sets the payload attempt number for full updates to the given value. Also
211 // persists the value being set so that we resume from the same value in case
212 // of a process restart.
213 void SetFullPayloadAttemptNumber(int payload_attempt_number);
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800214
215 // Initializes the current URL index from the persisted state.
216 void LoadUrlIndex();
217
218 // Sets the current URL index to the given value. Also persists the value
219 // being set so that we resume from the same value in case of a process
220 // restart.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800221 void SetUrlIndex(uint32_t url_index);
222
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800223 // Initializes the current URL's failure count from the persisted stae.
224 void LoadUrlFailureCount();
225
226 // Sets the current URL's failure count to the given value. Also persists the
227 // value being set so that we resume from the same value in case of a process
228 // restart.
229 void SetUrlFailureCount(uint32_t url_failure_count);
230
David Zeuthencc6f9962013-04-18 11:57:24 -0700231 // Sets |url_switch_count_| to the given value and persists the value.
232 void SetUrlSwitchCount(uint32_t url_switch_count);
233
234 // Initializes |url_switch_count_| from the persisted stae.
235 void LoadUrlSwitchCount();
236
Jay Srinivasan08262882012-12-28 19:29:43 -0800237 // Initializes the backoff expiry time from the persisted state.
238 void LoadBackoffExpiryTime();
239
240 // Sets the backoff expiry time to the given value. Also persists the value
241 // being set so that we resume from the same value in case of a process
242 // restart.
243 void SetBackoffExpiryTime(const base::Time& new_time);
244
David Zeuthen9a017f22013-04-11 16:10:26 -0700245 // Initializes |update_timestamp_start_| from the persisted state.
246 void LoadUpdateTimestampStart();
247
248 // Sets |update_timestamp_start_| to the given value and persists the value.
249 void SetUpdateTimestampStart(const base::Time& value);
250
251 // Sets |update_timestamp_end_| to the given value. This is not persisted
252 // as it happens at the end of the update process where state is deleted
253 // anyway.
254 void SetUpdateTimestampEnd(const base::Time& value);
255
256 // Initializes |update_duration_uptime_| from the persisted state.
257 void LoadUpdateDurationUptime();
258
259 // Helper method used in SetUpdateDurationUptime() and
260 // CalculateUpdateDurationUptime().
261 void SetUpdateDurationUptimeExtended(const base::TimeDelta& value,
262 const base::Time& timestamp,
263 bool use_logging);
264
265 // Sets |update_duration_uptime_| to the given value and persists
266 // the value and sets |update_duration_uptime_timestamp_| to the
267 // current monotonic time.
268 void SetUpdateDurationUptime(const base::TimeDelta& value);
269
270 // Adds the difference between current monotonic time and
271 // |update_duration_uptime_timestamp_| to |update_duration_uptime_| and
272 // sets |update_duration_uptime_timestamp_| to current monotonic time.
273 void CalculateUpdateDurationUptime();
274
Jay Srinivasan19409b72013-04-12 19:23:36 -0700275 // Returns the full key for a download source given the prefix.
276 std::string GetPrefsKey(const std::string& prefix, DownloadSource source);
277
278 // Loads the number of bytes that have been currently downloaded through the
279 // previous attempts from the persisted state for the given source. It's
280 // reset to 0 everytime we begin a full update and is continued from previous
281 // attempt if we're resuming the update.
282 void LoadCurrentBytesDownloaded(DownloadSource source);
283
284 // Sets the number of bytes that have been currently downloaded for the
285 // given source. This value is also persisted.
286 void SetCurrentBytesDownloaded(DownloadSource source,
287 uint64_t current_bytes_downloaded,
288 bool log);
289
290 // Loads the total number of bytes that have been downloaded (since the last
291 // successful update) from the persisted state for the given source. It's
292 // reset to 0 everytime we successfully apply an update and counts the bytes
293 // downloaded for both successful and failed attempts since then.
294 void LoadTotalBytesDownloaded(DownloadSource source);
295
296 // Sets the total number of bytes that have been downloaded so far for the
297 // given source. This value is also persisted.
298 void SetTotalBytesDownloaded(DownloadSource source,
299 uint64_t total_bytes_downloaded,
300 bool log);
301
Chris Sosaaa18e162013-06-20 13:20:30 -0700302 // Loads the blacklisted version from our prefs file.
303 void LoadRollbackVersion();
304
305 // Blacklists this version from getting AU'd to until we receive a new update
306 // response.
307 void SetRollbackVersion(const std::string& rollback_version);
308
309 // Clears any blacklisted version.
310 void ResetRollbackVersion();
311
Jay Srinivasan53173b92013-05-17 17:13:01 -0700312 inline uint32_t GetUrlIndex() {
313 return url_index_;
314 }
315
316 // Computes the list of candidate URLs from the total list of payload URLs in
317 // the Omaha response.
318 void ComputeCandidateUrls();
319
David Zeuthena573d6f2013-06-14 16:13:36 -0700320 // Sets |num_responses_seen_| and persist it to disk.
321 void SetNumResponsesSeen(int num_responses_seen);
322
323 // Initializes |num_responses_seen_| from persisted state.
324 void LoadNumResponsesSeen();
325
Alex Deymob33b0f02013-08-08 21:10:02 -0700326 // Reports metric conveying how many times updates were abandoned since
327 // the last update was applied. The difference between this metric and the
328 // previous ReportUpdatesAbandonedCountMetric() one is that this metric is
329 // reported every time an update is abandoned, as oposed to the mentioned
330 // metric that is reported once the new update was applied.
331 void ReportUpdatesAbandonedEventCountMetric();
332
Jay Srinivasan19409b72013-04-12 19:23:36 -0700333 // The global state of the system.
334 SystemState* system_state_;
335
Chris Sosabe45bef2013-04-09 18:25:12 -0700336 // Initializes |num_reboots_| from the persisted state.
337 void LoadNumReboots();
338
339 // Sets |num_reboots| for the update attempt. Also persists the
340 // value being set so that we resume from the same value in case of a process
341 // restart.
342 void SetNumReboots(uint32_t num_reboots);
343
344 // Checks to see if the device rebooted since the last call and if so
345 // increments num_reboots.
346 void UpdateNumReboots();
347
David Zeuthene4c58bf2013-06-18 17:26:50 -0700348 // Writes the current wall-clock time to the kPrefsSystemUpdatedMarker
349 // state variable.
350 void CreateSystemUpdatedMarkerFile();
351
352 // Called at program startup if the device booted into a new update.
353 // The |time_to_reboot| parameter contains the (wall-clock) duration
354 // from when the update successfully completed (the value written
355 // into the kPrefsSystemUpdatedMarker state variable) until the device
356 // was booted into the update (current wall-clock time).
357 void BootedIntoUpdate(base::TimeDelta time_to_reboot);
358
David Zeuthendcba8092013-08-06 12:16:35 -0700359 // Loads the |kPrefsP2PFirstAttemptTimestamp| state variable from disk
360 // into |p2p_first_attempt_timestamp_|.
361 void LoadP2PFirstAttemptTimestamp();
362
363 // Loads the |kPrefsP2PNumAttempts| state variable into |p2p_num_attempts_|.
364 void LoadP2PNumAttempts();
365
366 // Sets the |kPrefsP2PNumAttempts| state variable to |value|.
367 void SetP2PNumAttempts(int value);
368
369 // Sets the |kPrefsP2PFirstAttemptTimestamp| state variable to |time|.
370 void SetP2PFirstAttemptTimestamp(const base::Time& time);
371
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800372 // Interface object with which we read/write persisted state. This must
373 // be set by calling the Initialize method before calling any other method.
374 PrefsInterface* prefs_;
375
Chris Sosaaa18e162013-06-20 13:20:30 -0700376 // Interface object with which we read/write persisted state. This must
377 // be set by calling the Initialize method before calling any other method.
378 // This object persists across powerwashes.
379 PrefsInterface* powerwash_safe_prefs_;
380
Jay Srinivasan08262882012-12-28 19:29:43 -0800381 // This is the current response object from Omaha.
382 OmahaResponse response_;
383
David Zeuthenbb8bdc72013-09-03 13:43:48 -0700384 // Whether p2p is being used for downloading as set with the
385 // SetUsingP2PForDownloading() method.
386 bool using_p2p_for_downloading_;
387
Jay Srinivasan08262882012-12-28 19:29:43 -0800388 // This stores a "signature" of the current response. The signature here
389 // refers to a subset of the current response from Omaha. Each update to
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800390 // this value is persisted so we resume from the same value in case of a
391 // process restart.
Jay Srinivasan08262882012-12-28 19:29:43 -0800392 std::string response_signature_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800393
Alex Deymo820cc702013-06-28 15:43:46 -0700394 // The number of times we've tried to download the payload. This is
395 // incremented each time we download the payload successsfully or when we
396 // exhaust all failure limits for all URLs and are about to wrap around back
397 // to the first URL. Each update to this value is persisted so we resume from
398 // the same value in case of a process restart.
399 int payload_attempt_number_;
400
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800401 // The number of times we've tried to download the payload in full. This is
402 // incremented each time we download the payload in full successsfully or
403 // when we exhaust all failure limits for all URLs and are about to wrap
404 // around back to the first URL. Each update to this value is persisted so
405 // we resume from the same value in case of a process restart.
Alex Deymo820cc702013-06-28 15:43:46 -0700406 int full_payload_attempt_number_;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800407
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800408 // The index of the current URL. This type is different from the one in the
409 // accessor methods because PrefsInterface supports only int64_t but we want
410 // to provide a stronger abstraction of uint32_t. Each update to this value
411 // is persisted so we resume from the same value in case of a process
412 // restart.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800413 int64_t url_index_;
414
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800415 // The count of failures encountered in the current attempt to download using
416 // the current URL (specified by url_index_). Each update to this value is
417 // persisted so we resume from the same value in case of a process restart.
418 int64_t url_failure_count_;
419
David Zeuthencc6f9962013-04-18 11:57:24 -0700420 // The number of times we've switched URLs.
421 int32_t url_switch_count_;
422
Jay Srinivasan19409b72013-04-12 19:23:36 -0700423 // The current download source based on the current URL. This value is
424 // not persisted as it can be recomputed everytime we update the URL.
425 // We're storing this so as not to recompute this on every few bytes of
426 // data we read from the socket.
427 DownloadSource current_download_source_;
428
David Zeuthena573d6f2013-06-14 16:13:36 -0700429 // The number of different Omaha responses seen. Increases every time
430 // a new response is seen. Resets to 0 only when the system has been
431 // successfully updated.
432 int num_responses_seen_;
433
Chris Sosabe45bef2013-04-09 18:25:12 -0700434 // The number of system reboots during an update attempt. Technically since
435 // we don't go out of our way to not update it when not attempting an update,
436 // also records the number of reboots before the next update attempt starts.
437 uint32_t num_reboots_;
438
Jay Srinivasan08262882012-12-28 19:29:43 -0800439 // The timestamp until which we've to wait before attempting to download the
440 // payload again, so as to backoff repeated downloads.
441 base::Time backoff_expiry_time_;
442
David Zeuthen9a017f22013-04-11 16:10:26 -0700443 // The most recently calculated value of the update duration.
444 base::TimeDelta update_duration_current_;
445
446 // The point in time (wall-clock) that the update was started.
447 base::Time update_timestamp_start_;
448
449 // The point in time (wall-clock) that the update ended. If the update
450 // is still in progress, this is set to the Epoch (e.g. 0).
451 base::Time update_timestamp_end_;
452
453 // The update duration uptime
454 base::TimeDelta update_duration_uptime_;
455
456 // The monotonic time when |update_duration_uptime_| was last set
457 base::Time update_duration_uptime_timestamp_;
458
Jay Srinivasan19409b72013-04-12 19:23:36 -0700459 // The number of bytes that have been downloaded for each source for each new
460 // update attempt. If we resume an update, we'll continue from the previous
461 // value, but if we get a new response or if the previous attempt failed,
462 // we'll reset this to 0 to start afresh. Each update to this value is
463 // persisted so we resume from the same value in case of a process restart.
464 // The extra index in the array is to no-op accidental access in case the
465 // return value from GetCurrentDownloadSource is used without validation.
466 uint64_t current_bytes_downloaded_[kNumDownloadSources + 1];
467
468 // The number of bytes that have been downloaded for each source since the
469 // the last successful update. This is used to compute the overhead we incur.
470 // Each update to this value is persisted so we resume from the same value in
471 // case of a process restart.
472 // The extra index in the array is to no-op accidental access in case the
473 // return value from GetCurrentDownloadSource is used without validation.
474 uint64_t total_bytes_downloaded_[kNumDownloadSources + 1];
475
David Zeuthen9a017f22013-04-11 16:10:26 -0700476 // A small timespan used when comparing wall-clock times for coping
477 // with the fact that clocks drift and consequently are adjusted
478 // (either forwards or backwards) via NTP.
479 static const base::TimeDelta kDurationSlack;
480
Jay Srinivasan53173b92013-05-17 17:13:01 -0700481 // The ordered list of the subset of payload URL candidates which are
482 // allowed as per device policy.
483 std::vector<std::string> candidate_urls_;
484
Chris Sosaaa18e162013-06-20 13:20:30 -0700485 // This stores a blacklisted version set as part of rollback. When we rollback
486 // we store the version of the os from which we are rolling back from in order
487 // to guarantee that we do not re-update to it on the next au attempt after
488 // reboot.
489 std::string rollback_version_;
490
David Zeuthendcba8092013-08-06 12:16:35 -0700491 // The cached value of |kPrefsP2PFirstAttemptTimestamp|.
492 base::Time p2p_first_attempt_timestamp_;
493
494 // The cached value of |kPrefsP2PNumAttempts|.
495 int p2p_num_attempts_;
496
David Zeuthen33bae492014-02-25 16:16:18 -0800497 // The number of bytes downloaded per attempt.
498 int64_t attempt_num_bytes_downloaded_;
499
500 // The boot time when the attempt was started.
501 base::Time attempt_start_time_boot_;
502
503 // The monotonic time when the attempt was started.
504 base::Time attempt_start_time_monotonic_;
505
David Zeuthenb281f072014-04-02 10:20:19 -0700506 // The connection type when the attempt started.
507 metrics::ConnectionType attempt_connection_type_;
508
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800509 DISALLOW_COPY_AND_ASSIGN(PayloadState);
510};
511
512} // namespace chromeos_update_engine
513
Alex Deymo759c2752014-03-17 21:09:36 -0700514#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H_