blob: f0b74e5b5fbbb7048ac81df4130fbbe3cb138bb9 [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#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H__
7
Jay Srinivasan08262882012-12-28 19:29:43 -08008#include <base/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
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080011#include "update_engine/payload_state_interface.h"
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080012#include "update_engine/prefs_interface.h"
13
14namespace chromeos_update_engine {
15
Jay Srinivasan19409b72013-04-12 19:23:36 -070016class SystemState;
17
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080018// Encapsulates all the payload state required for download. This includes the
Jay Srinivasan08262882012-12-28 19:29:43 -080019// state necessary for handling multiple URLs in Omaha response, the backoff
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080020// state, etc. All state is persisted so that we use the most recently saved
21// value when resuming the update_engine process. All state is also cached in
22// memory so that we ensure we always make progress based on last known good
23// state even when there's any issue in reading/writing from the file system.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080024class PayloadState : public PayloadStateInterface {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080025 public:
Jay Srinivasan19409b72013-04-12 19:23:36 -070026 PayloadState();
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080027 virtual ~PayloadState() {}
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080028
Jay Srinivasan19409b72013-04-12 19:23:36 -070029 // Initializes a payload state object using the given global system state.
30 // It performs the initial loading of all persisted state into memory and
31 // dumps the initial state for debugging purposes. Note: the other methods
32 // should be called only after calling Initialize on this object.
33 bool Initialize(SystemState* system_state);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080034
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080035 // Implementation of PayloadStateInterface methods.
36 virtual void SetResponse(const OmahaResponse& response);
37 virtual void DownloadComplete();
38 virtual void DownloadProgress(size_t count);
Chris Sosabe45bef2013-04-09 18:25:12 -070039 virtual void UpdateResumed();
Jay Srinivasan19409b72013-04-12 19:23:36 -070040 virtual void UpdateRestarted();
David Zeuthen9a017f22013-04-11 16:10:26 -070041 virtual void UpdateSucceeded();
David Zeuthena99981f2013-04-29 13:42:47 -070042 virtual void UpdateFailed(ErrorCode error);
Alex Deymo42432912013-07-12 20:21:15 -070043 virtual void ResetUpdateStatus();
Jay Srinivasan08262882012-12-28 19:29:43 -080044 virtual bool ShouldBackoffDownload();
Chris Sosaaa18e162013-06-20 13:20:30 -070045 virtual void Rollback();
Alex Deymo42432912013-07-12 20:21:15 -070046 virtual void ExpectRebootInNewVersion(const std::string& target_version_uid);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080047
Jay Srinivasan08262882012-12-28 19:29:43 -080048 virtual inline std::string GetResponseSignature() {
49 return response_signature_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080050 }
51
Alex Deymo820cc702013-06-28 15:43:46 -070052 virtual inline int GetFullPayloadAttemptNumber() {
53 return full_payload_attempt_number_;
54 }
55
56 virtual inline int GetPayloadAttemptNumber() {
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080057 return payload_attempt_number_;
58 }
59
Jay Srinivasan53173b92013-05-17 17:13:01 -070060 virtual inline std::string GetCurrentUrl() {
61 return candidate_urls_.size() ? candidate_urls_[url_index_] : "";
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080062 }
63
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080064 virtual inline uint32_t GetUrlFailureCount() {
65 return url_failure_count_;
66 }
67
David Zeuthencc6f9962013-04-18 11:57:24 -070068 virtual inline uint32_t GetUrlSwitchCount() {
69 return url_switch_count_;
70 }
71
David Zeuthena573d6f2013-06-14 16:13:36 -070072 virtual inline int GetNumResponsesSeen() {
73 return num_responses_seen_;
74 }
75
Jay Srinivasan08262882012-12-28 19:29:43 -080076 virtual inline base::Time GetBackoffExpiryTime() {
77 return backoff_expiry_time_;
78 }
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080079
David Zeuthen9a017f22013-04-11 16:10:26 -070080 virtual base::TimeDelta GetUpdateDuration();
81
82 virtual base::TimeDelta GetUpdateDurationUptime();
83
Jay Srinivasan19409b72013-04-12 19:23:36 -070084 virtual inline uint64_t GetCurrentBytesDownloaded(DownloadSource source) {
85 return source < kNumDownloadSources ? current_bytes_downloaded_[source] : 0;
86 }
87
88 virtual inline uint64_t GetTotalBytesDownloaded(DownloadSource source) {
89 return source < kNumDownloadSources ? total_bytes_downloaded_[source] : 0;
90 }
91
Chris Sosabe45bef2013-04-09 18:25:12 -070092 virtual inline uint32_t GetNumReboots() {
93 return num_reboots_;
94 }
95
David Zeuthene4c58bf2013-06-18 17:26:50 -070096 virtual void UpdateEngineStarted();
97
Chris Sosaaa18e162013-06-20 13:20:30 -070098 virtual inline std::string GetRollbackVersion() {
99 return rollback_version_;
100 }
101
David Zeuthendcba8092013-08-06 12:16:35 -0700102 virtual int GetP2PNumAttempts();
103 virtual base::Time GetP2PFirstAttemptTimestamp();
104 virtual void P2PNewAttempt();
105 virtual bool P2PAttemptAllowed();
106
Jay Srinivasan08262882012-12-28 19:29:43 -0800107 private:
Alex Deymo42432912013-07-12 20:21:15 -0700108 friend class PayloadStateTest;
109 FRIEND_TEST(PayloadStateTest, RebootAfterUpdateFailedMetric);
110 FRIEND_TEST(PayloadStateTest, RebootAfterUpdateSucceed);
111 FRIEND_TEST(PayloadStateTest, RebootAfterCanceledUpdate);
112 FRIEND_TEST(PayloadStateTest, UpdateSuccessWithWipedPrefs);
113
Alex Deymo820cc702013-06-28 15:43:46 -0700114 // Increments the payload attempt number used for metrics.
115 void IncrementPayloadAttemptNumber();
116
Jay Srinivasan08262882012-12-28 19:29:43 -0800117 // Increments the payload attempt number which governs the backoff behavior
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800118 // at the time of the next update check.
Alex Deymo820cc702013-06-28 15:43:46 -0700119 void IncrementFullPayloadAttemptNumber();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800120
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800121 // Advances the current URL index to the next available one. If all URLs have
122 // been exhausted during the current payload download attempt (as indicated
123 // by the payload attempt number), then it will increment the payload attempt
David Zeuthencc6f9962013-04-18 11:57:24 -0700124 // number and wrap around again with the first URL in the list. This also
125 // updates the URL switch count, if needed.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800126 void IncrementUrlIndex();
127
128 // Increments the failure count of the current URL. If the configured max
129 // failure count is reached for this URL, it advances the current URL index
130 // to the next URL and resets the failure count for that URL.
131 void IncrementFailureCount();
132
Jay Srinivasan08262882012-12-28 19:29:43 -0800133 // Updates the backoff expiry time exponentially based on the current
134 // payload attempt number.
135 void UpdateBackoffExpiryTime();
136
Jay Srinivasan19409b72013-04-12 19:23:36 -0700137 // Updates the value of current download source based on the current URL
138 // index. If the download source is not one of the known sources, it's set
139 // to kNumDownloadSources.
140 void UpdateCurrentDownloadSource();
141
142 // Updates the various metrics corresponding with the given number of bytes
143 // that were downloaded recently.
144 void UpdateBytesDownloaded(size_t count);
145
146 // Reports the various metrics related to the number of bytes downloaded.
147 void ReportBytesDownloadedMetrics();
148
David Zeuthencc6f9962013-04-18 11:57:24 -0700149 // Reports the metric related to number of URL switches.
150 void ReportUpdateUrlSwitchesMetric();
151
Chris Sosabe45bef2013-04-09 18:25:12 -0700152 // Reports the various metrics related to rebooting during an update.
153 void ReportRebootMetrics();
154
David Zeuthen674c3182013-04-18 14:05:20 -0700155 // Reports the various metrics related to update duration.
156 void ReportDurationMetrics();
157
Alex Deymo1c656c42013-06-28 11:02:14 -0700158 // Reports the metric related to the applied payload type.
159 void ReportPayloadTypeMetric();
160
Alex Deymo820cc702013-06-28 15:43:46 -0700161 // Reports the various metrics related to update attempts counts.
162 void ReportAttemptsCountMetrics();
163
Alex Deymo42432912013-07-12 20:21:15 -0700164 // Checks if we were expecting to be running in the new version but the
165 // boot into the new version failed for some reason. If that's the case, an
166 // UMA metric is sent reporting the number of attempts the same applied
167 // payload was attempted to reboot. This function is called by UpdateAttempter
168 // every time the update engine starts and there's no reboot pending.
169 void ReportFailedBootIfNeeded();
170
Jay Srinivasan08262882012-12-28 19:29:43 -0800171 // Resets all the persisted state values which are maintained relative to the
172 // current response signature. The response signature itself is not reset.
173 void ResetPersistedState();
174
Jay Srinivasan19409b72013-04-12 19:23:36 -0700175 // Resets the appropriate state related to download sources that need to be
176 // reset on a new update.
177 void ResetDownloadSourcesOnNewUpdate();
178
179 // Returns the persisted value for the given key. It also validates that
Chris Sosaaa18e162013-06-20 13:20:30 -0700180 // the value returned is non-negative. If |across_powerwash| is True,
181 // get the value that will persist across a powerwash.
182 int64_t GetPersistedValue(const std::string& key, bool across_powerwash);
Jay Srinivasan19409b72013-04-12 19:23:36 -0700183
Jay Srinivasan08262882012-12-28 19:29:43 -0800184 // Calculates the response "signature", which is basically a string composed
185 // of the subset of the fields in the current response that affect the
186 // behavior of the PayloadState.
187 std::string CalculateResponseSignature();
188
189 // Initializes the current response signature from the persisted state.
190 void LoadResponseSignature();
191
192 // Sets the response signature to the given value. Also persists the value
193 // being set so that we resume from the save value in case of a process
194 // restart.
Jay Srinivasan19409b72013-04-12 19:23:36 -0700195 void SetResponseSignature(const std::string& response_signature);
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800196
197 // Initializes the payload attempt number from the persisted state.
198 void LoadPayloadAttemptNumber();
199
Alex Deymo820cc702013-06-28 15:43:46 -0700200 // Initializes the payload attempt number for full payloads from the persisted
201 // state.
202 void LoadFullPayloadAttemptNumber();
203
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800204 // Sets the payload attempt number to the given value. Also persists the
205 // value being set so that we resume from the same value in case of a process
206 // restart.
Alex Deymo820cc702013-06-28 15:43:46 -0700207 void SetPayloadAttemptNumber(int payload_attempt_number);
208
209 // Sets the payload attempt number for full updates to the given value. Also
210 // persists the value being set so that we resume from the same value in case
211 // of a process restart.
212 void SetFullPayloadAttemptNumber(int payload_attempt_number);
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800213
214 // Initializes the current URL index from the persisted state.
215 void LoadUrlIndex();
216
217 // Sets the current URL index to the given value. Also persists the value
218 // being set so that we resume from the same value in case of a process
219 // restart.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800220 void SetUrlIndex(uint32_t url_index);
221
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800222 // Initializes the current URL's failure count from the persisted stae.
223 void LoadUrlFailureCount();
224
225 // Sets the current URL's failure count to the given value. Also persists the
226 // value being set so that we resume from the same value in case of a process
227 // restart.
228 void SetUrlFailureCount(uint32_t url_failure_count);
229
David Zeuthencc6f9962013-04-18 11:57:24 -0700230 // Sets |url_switch_count_| to the given value and persists the value.
231 void SetUrlSwitchCount(uint32_t url_switch_count);
232
233 // Initializes |url_switch_count_| from the persisted stae.
234 void LoadUrlSwitchCount();
235
Jay Srinivasan08262882012-12-28 19:29:43 -0800236 // Initializes the backoff expiry time from the persisted state.
237 void LoadBackoffExpiryTime();
238
239 // Sets the backoff expiry time to the given value. Also persists the value
240 // being set so that we resume from the same value in case of a process
241 // restart.
242 void SetBackoffExpiryTime(const base::Time& new_time);
243
David Zeuthen9a017f22013-04-11 16:10:26 -0700244 // Initializes |update_timestamp_start_| from the persisted state.
245 void LoadUpdateTimestampStart();
246
247 // Sets |update_timestamp_start_| to the given value and persists the value.
248 void SetUpdateTimestampStart(const base::Time& value);
249
250 // Sets |update_timestamp_end_| to the given value. This is not persisted
251 // as it happens at the end of the update process where state is deleted
252 // anyway.
253 void SetUpdateTimestampEnd(const base::Time& value);
254
255 // Initializes |update_duration_uptime_| from the persisted state.
256 void LoadUpdateDurationUptime();
257
258 // Helper method used in SetUpdateDurationUptime() and
259 // CalculateUpdateDurationUptime().
260 void SetUpdateDurationUptimeExtended(const base::TimeDelta& value,
261 const base::Time& timestamp,
262 bool use_logging);
263
264 // Sets |update_duration_uptime_| to the given value and persists
265 // the value and sets |update_duration_uptime_timestamp_| to the
266 // current monotonic time.
267 void SetUpdateDurationUptime(const base::TimeDelta& value);
268
269 // Adds the difference between current monotonic time and
270 // |update_duration_uptime_timestamp_| to |update_duration_uptime_| and
271 // sets |update_duration_uptime_timestamp_| to current monotonic time.
272 void CalculateUpdateDurationUptime();
273
Jay Srinivasan19409b72013-04-12 19:23:36 -0700274 // Returns the full key for a download source given the prefix.
275 std::string GetPrefsKey(const std::string& prefix, DownloadSource source);
276
277 // Loads the number of bytes that have been currently downloaded through the
278 // previous attempts from the persisted state for the given source. It's
279 // reset to 0 everytime we begin a full update and is continued from previous
280 // attempt if we're resuming the update.
281 void LoadCurrentBytesDownloaded(DownloadSource source);
282
283 // Sets the number of bytes that have been currently downloaded for the
284 // given source. This value is also persisted.
285 void SetCurrentBytesDownloaded(DownloadSource source,
286 uint64_t current_bytes_downloaded,
287 bool log);
288
289 // Loads the total number of bytes that have been downloaded (since the last
290 // successful update) from the persisted state for the given source. It's
291 // reset to 0 everytime we successfully apply an update and counts the bytes
292 // downloaded for both successful and failed attempts since then.
293 void LoadTotalBytesDownloaded(DownloadSource source);
294
295 // Sets the total number of bytes that have been downloaded so far for the
296 // given source. This value is also persisted.
297 void SetTotalBytesDownloaded(DownloadSource source,
298 uint64_t total_bytes_downloaded,
299 bool log);
300
Chris Sosaaa18e162013-06-20 13:20:30 -0700301 // Loads the blacklisted version from our prefs file.
302 void LoadRollbackVersion();
303
304 // Blacklists this version from getting AU'd to until we receive a new update
305 // response.
306 void SetRollbackVersion(const std::string& rollback_version);
307
308 // Clears any blacklisted version.
309 void ResetRollbackVersion();
310
Jay Srinivasan53173b92013-05-17 17:13:01 -0700311 inline uint32_t GetUrlIndex() {
312 return url_index_;
313 }
314
315 // Computes the list of candidate URLs from the total list of payload URLs in
316 // the Omaha response.
317 void ComputeCandidateUrls();
318
David Zeuthena573d6f2013-06-14 16:13:36 -0700319 // Sets |num_responses_seen_| and persist it to disk.
320 void SetNumResponsesSeen(int num_responses_seen);
321
322 // Initializes |num_responses_seen_| from persisted state.
323 void LoadNumResponsesSeen();
324
325 // Reports metric conveying how many times updates were abandoned
Alex Deymob33b0f02013-08-08 21:10:02 -0700326 // before an update was applied. This metric is reported when an update is
327 // successfully applied.
David Zeuthena573d6f2013-06-14 16:13:36 -0700328 void ReportUpdatesAbandonedCountMetric();
329
Alex Deymob33b0f02013-08-08 21:10:02 -0700330 // Reports metric conveying how many times updates were abandoned since
331 // the last update was applied. The difference between this metric and the
332 // previous ReportUpdatesAbandonedCountMetric() one is that this metric is
333 // reported every time an update is abandoned, as oposed to the mentioned
334 // metric that is reported once the new update was applied.
335 void ReportUpdatesAbandonedEventCountMetric();
336
Jay Srinivasan19409b72013-04-12 19:23:36 -0700337 // The global state of the system.
338 SystemState* system_state_;
339
Chris Sosabe45bef2013-04-09 18:25:12 -0700340 // Initializes |num_reboots_| from the persisted state.
341 void LoadNumReboots();
342
343 // Sets |num_reboots| for the update attempt. Also persists the
344 // value being set so that we resume from the same value in case of a process
345 // restart.
346 void SetNumReboots(uint32_t num_reboots);
347
348 // Checks to see if the device rebooted since the last call and if so
349 // increments num_reboots.
350 void UpdateNumReboots();
351
David Zeuthene4c58bf2013-06-18 17:26:50 -0700352 // Writes the current wall-clock time to the kPrefsSystemUpdatedMarker
353 // state variable.
354 void CreateSystemUpdatedMarkerFile();
355
356 // Called at program startup if the device booted into a new update.
357 // The |time_to_reboot| parameter contains the (wall-clock) duration
358 // from when the update successfully completed (the value written
359 // into the kPrefsSystemUpdatedMarker state variable) until the device
360 // was booted into the update (current wall-clock time).
361 void BootedIntoUpdate(base::TimeDelta time_to_reboot);
362
David Zeuthendcba8092013-08-06 12:16:35 -0700363 // Loads the |kPrefsP2PFirstAttemptTimestamp| state variable from disk
364 // into |p2p_first_attempt_timestamp_|.
365 void LoadP2PFirstAttemptTimestamp();
366
367 // Loads the |kPrefsP2PNumAttempts| state variable into |p2p_num_attempts_|.
368 void LoadP2PNumAttempts();
369
370 // Sets the |kPrefsP2PNumAttempts| state variable to |value|.
371 void SetP2PNumAttempts(int value);
372
373 // Sets the |kPrefsP2PFirstAttemptTimestamp| state variable to |time|.
374 void SetP2PFirstAttemptTimestamp(const base::Time& time);
375
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800376 // 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 PrefsInterface* prefs_;
379
Chris Sosaaa18e162013-06-20 13:20:30 -0700380 // Interface object with which we read/write persisted state. This must
381 // be set by calling the Initialize method before calling any other method.
382 // This object persists across powerwashes.
383 PrefsInterface* powerwash_safe_prefs_;
384
Jay Srinivasan08262882012-12-28 19:29:43 -0800385 // This is the current response object from Omaha.
386 OmahaResponse response_;
387
388 // 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
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800497 DISALLOW_COPY_AND_ASSIGN(PayloadState);
498};
499
500} // namespace chromeos_update_engine
501
502#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H__