blob: 9ad4377fe205d10fbde237dac905c0edd151935b [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:
David Zeuthenafed4a12014-04-09 15:28:44 -0700114 enum class AttemptType {
115 kUpdate,
116 kRollback,
117 };
118
Alex Deymo42432912013-07-12 20:21:15 -0700119 friend class PayloadStateTest;
120 FRIEND_TEST(PayloadStateTest, RebootAfterUpdateFailedMetric);
121 FRIEND_TEST(PayloadStateTest, RebootAfterUpdateSucceed);
122 FRIEND_TEST(PayloadStateTest, RebootAfterCanceledUpdate);
Chris Sosab3dcdb32013-09-04 15:22:12 -0700123 FRIEND_TEST(PayloadStateTest, RollbackVersion);
Alex Deymo42432912013-07-12 20:21:15 -0700124 FRIEND_TEST(PayloadStateTest, UpdateSuccessWithWipedPrefs);
125
David Zeuthen33bae492014-02-25 16:16:18 -0800126 // Helper called when an attempt has begun, is called by
David Zeuthenafed4a12014-04-09 15:28:44 -0700127 // UpdateResumed(), UpdateRestarted() and Rollback().
128 void AttemptStarted(AttemptType attempt_type);
David Zeuthen33bae492014-02-25 16:16:18 -0800129
Alex Deymo820cc702013-06-28 15:43:46 -0700130 // Increments the payload attempt number used for metrics.
131 void IncrementPayloadAttemptNumber();
132
Jay Srinivasan08262882012-12-28 19:29:43 -0800133 // Increments the payload attempt number which governs the backoff behavior
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800134 // at the time of the next update check.
Alex Deymo820cc702013-06-28 15:43:46 -0700135 void IncrementFullPayloadAttemptNumber();
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800136
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800137 // Advances the current URL index to the next available one. If all URLs have
138 // been exhausted during the current payload download attempt (as indicated
139 // by the payload attempt number), then it will increment the payload attempt
David Zeuthencc6f9962013-04-18 11:57:24 -0700140 // number and wrap around again with the first URL in the list. This also
141 // updates the URL switch count, if needed.
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800142 void IncrementUrlIndex();
143
144 // Increments the failure count of the current URL. If the configured max
145 // failure count is reached for this URL, it advances the current URL index
146 // to the next URL and resets the failure count for that URL.
147 void IncrementFailureCount();
148
Jay Srinivasan08262882012-12-28 19:29:43 -0800149 // Updates the backoff expiry time exponentially based on the current
150 // payload attempt number.
151 void UpdateBackoffExpiryTime();
152
Jay Srinivasan19409b72013-04-12 19:23:36 -0700153 // Updates the value of current download source based on the current URL
154 // index. If the download source is not one of the known sources, it's set
155 // to kNumDownloadSources.
156 void UpdateCurrentDownloadSource();
157
158 // Updates the various metrics corresponding with the given number of bytes
159 // that were downloaded recently.
160 void UpdateBytesDownloaded(size_t count);
161
David Zeuthen33bae492014-02-25 16:16:18 -0800162 // Calculates the PayloadType we're using.
163 PayloadType CalculatePayloadType();
Jay Srinivasan19409b72013-04-12 19:23:36 -0700164
David Zeuthen33bae492014-02-25 16:16:18 -0800165 // Collects and reports the various metrics related to an update attempt.
166 void CollectAndReportAttemptMetrics(ErrorCode code);
David Zeuthencc6f9962013-04-18 11:57:24 -0700167
David Zeuthen33bae492014-02-25 16:16:18 -0800168 // Collects and reports the various metrics related to a successful update.
169 void CollectAndReportSuccessfulUpdateMetrics();
Alex Deymo820cc702013-06-28 15:43:46 -0700170
Alex Deymo42432912013-07-12 20:21:15 -0700171 // Checks if we were expecting to be running in the new version but the
172 // boot into the new version failed for some reason. If that's the case, an
173 // UMA metric is sent reporting the number of attempts the same applied
174 // payload was attempted to reboot. This function is called by UpdateAttempter
175 // every time the update engine starts and there's no reboot pending.
176 void ReportFailedBootIfNeeded();
177
Jay Srinivasan08262882012-12-28 19:29:43 -0800178 // Resets all the persisted state values which are maintained relative to the
179 // current response signature. The response signature itself is not reset.
180 void ResetPersistedState();
181
Jay Srinivasan19409b72013-04-12 19:23:36 -0700182 // Resets the appropriate state related to download sources that need to be
183 // reset on a new update.
184 void ResetDownloadSourcesOnNewUpdate();
185
Chris Sosab3dcdb32013-09-04 15:22:12 -0700186 // Returns the persisted value from prefs_ for the given key. It also
187 // validates that the value returned is non-negative.
188 int64_t GetPersistedValue(const std::string& key);
Jay Srinivasan19409b72013-04-12 19:23:36 -0700189
Jay Srinivasan08262882012-12-28 19:29:43 -0800190 // Calculates the response "signature", which is basically a string composed
191 // of the subset of the fields in the current response that affect the
192 // behavior of the PayloadState.
193 std::string CalculateResponseSignature();
194
195 // Initializes the current response signature from the persisted state.
196 void LoadResponseSignature();
197
198 // Sets the response signature to the given value. Also persists the value
199 // being set so that we resume from the save value in case of a process
200 // restart.
Jay Srinivasan19409b72013-04-12 19:23:36 -0700201 void SetResponseSignature(const std::string& response_signature);
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800202
203 // Initializes the payload attempt number from the persisted state.
204 void LoadPayloadAttemptNumber();
205
Alex Deymo820cc702013-06-28 15:43:46 -0700206 // Initializes the payload attempt number for full payloads from the persisted
207 // state.
208 void LoadFullPayloadAttemptNumber();
209
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800210 // Sets the payload attempt number to the given value. Also persists the
211 // value being set so that we resume from the same value in case of a process
212 // restart.
Alex Deymo820cc702013-06-28 15:43:46 -0700213 void SetPayloadAttemptNumber(int payload_attempt_number);
214
215 // Sets the payload attempt number for full updates to the given value. Also
216 // persists the value being set so that we resume from the same value in case
217 // of a process restart.
218 void SetFullPayloadAttemptNumber(int payload_attempt_number);
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800219
220 // Initializes the current URL index from the persisted state.
221 void LoadUrlIndex();
222
223 // Sets the current URL index to the given value. Also persists the value
224 // being set so that we resume from the same value in case of a process
225 // restart.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800226 void SetUrlIndex(uint32_t url_index);
227
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800228 // Initializes the current URL's failure count from the persisted stae.
229 void LoadUrlFailureCount();
230
231 // Sets the current URL's failure count to the given value. Also persists the
232 // value being set so that we resume from the same value in case of a process
233 // restart.
234 void SetUrlFailureCount(uint32_t url_failure_count);
235
David Zeuthencc6f9962013-04-18 11:57:24 -0700236 // Sets |url_switch_count_| to the given value and persists the value.
237 void SetUrlSwitchCount(uint32_t url_switch_count);
238
239 // Initializes |url_switch_count_| from the persisted stae.
240 void LoadUrlSwitchCount();
241
Jay Srinivasan08262882012-12-28 19:29:43 -0800242 // Initializes the backoff expiry time from the persisted state.
243 void LoadBackoffExpiryTime();
244
245 // Sets the backoff expiry time to the given value. Also persists the value
246 // being set so that we resume from the same value in case of a process
247 // restart.
248 void SetBackoffExpiryTime(const base::Time& new_time);
249
David Zeuthen9a017f22013-04-11 16:10:26 -0700250 // Initializes |update_timestamp_start_| from the persisted state.
251 void LoadUpdateTimestampStart();
252
253 // Sets |update_timestamp_start_| to the given value and persists the value.
254 void SetUpdateTimestampStart(const base::Time& value);
255
256 // Sets |update_timestamp_end_| to the given value. This is not persisted
257 // as it happens at the end of the update process where state is deleted
258 // anyway.
259 void SetUpdateTimestampEnd(const base::Time& value);
260
261 // Initializes |update_duration_uptime_| from the persisted state.
262 void LoadUpdateDurationUptime();
263
264 // Helper method used in SetUpdateDurationUptime() and
265 // CalculateUpdateDurationUptime().
266 void SetUpdateDurationUptimeExtended(const base::TimeDelta& value,
267 const base::Time& timestamp,
268 bool use_logging);
269
270 // Sets |update_duration_uptime_| to the given value and persists
271 // the value and sets |update_duration_uptime_timestamp_| to the
272 // current monotonic time.
273 void SetUpdateDurationUptime(const base::TimeDelta& value);
274
275 // Adds the difference between current monotonic time and
276 // |update_duration_uptime_timestamp_| to |update_duration_uptime_| and
277 // sets |update_duration_uptime_timestamp_| to current monotonic time.
278 void CalculateUpdateDurationUptime();
279
Jay Srinivasan19409b72013-04-12 19:23:36 -0700280 // Returns the full key for a download source given the prefix.
281 std::string GetPrefsKey(const std::string& prefix, DownloadSource source);
282
283 // Loads the number of bytes that have been currently downloaded through the
284 // previous attempts from the persisted state for the given source. It's
285 // reset to 0 everytime we begin a full update and is continued from previous
286 // attempt if we're resuming the update.
287 void LoadCurrentBytesDownloaded(DownloadSource source);
288
289 // Sets the number of bytes that have been currently downloaded for the
290 // given source. This value is also persisted.
291 void SetCurrentBytesDownloaded(DownloadSource source,
292 uint64_t current_bytes_downloaded,
293 bool log);
294
295 // Loads the total number of bytes that have been downloaded (since the last
296 // successful update) from the persisted state for the given source. It's
297 // reset to 0 everytime we successfully apply an update and counts the bytes
298 // downloaded for both successful and failed attempts since then.
299 void LoadTotalBytesDownloaded(DownloadSource source);
300
301 // Sets the total number of bytes that have been downloaded so far for the
302 // given source. This value is also persisted.
303 void SetTotalBytesDownloaded(DownloadSource source,
304 uint64_t total_bytes_downloaded,
305 bool log);
306
Chris Sosaaa18e162013-06-20 13:20:30 -0700307 // Loads the blacklisted version from our prefs file.
308 void LoadRollbackVersion();
309
310 // Blacklists this version from getting AU'd to until we receive a new update
311 // response.
312 void SetRollbackVersion(const std::string& rollback_version);
313
314 // Clears any blacklisted version.
315 void ResetRollbackVersion();
316
Jay Srinivasan53173b92013-05-17 17:13:01 -0700317 inline uint32_t GetUrlIndex() {
318 return url_index_;
319 }
320
321 // Computes the list of candidate URLs from the total list of payload URLs in
322 // the Omaha response.
323 void ComputeCandidateUrls();
324
David Zeuthena573d6f2013-06-14 16:13:36 -0700325 // Sets |num_responses_seen_| and persist it to disk.
326 void SetNumResponsesSeen(int num_responses_seen);
327
328 // Initializes |num_responses_seen_| from persisted state.
329 void LoadNumResponsesSeen();
330
Alex Deymob33b0f02013-08-08 21:10:02 -0700331 // Reports metric conveying how many times updates were abandoned since
332 // the last update was applied. The difference between this metric and the
333 // previous ReportUpdatesAbandonedCountMetric() one is that this metric is
334 // reported every time an update is abandoned, as oposed to the mentioned
335 // metric that is reported once the new update was applied.
336 void ReportUpdatesAbandonedEventCountMetric();
337
Jay Srinivasan19409b72013-04-12 19:23:36 -0700338 // The global state of the system.
339 SystemState* system_state_;
340
Chris Sosabe45bef2013-04-09 18:25:12 -0700341 // Initializes |num_reboots_| from the persisted state.
342 void LoadNumReboots();
343
344 // Sets |num_reboots| for the update attempt. Also persists the
345 // value being set so that we resume from the same value in case of a process
346 // restart.
347 void SetNumReboots(uint32_t num_reboots);
348
349 // Checks to see if the device rebooted since the last call and if so
350 // increments num_reboots.
351 void UpdateNumReboots();
352
David Zeuthene4c58bf2013-06-18 17:26:50 -0700353 // Writes the current wall-clock time to the kPrefsSystemUpdatedMarker
354 // state variable.
355 void CreateSystemUpdatedMarkerFile();
356
357 // Called at program startup if the device booted into a new update.
358 // The |time_to_reboot| parameter contains the (wall-clock) duration
359 // from when the update successfully completed (the value written
360 // into the kPrefsSystemUpdatedMarker state variable) until the device
361 // was booted into the update (current wall-clock time).
362 void BootedIntoUpdate(base::TimeDelta time_to_reboot);
363
David Zeuthendcba8092013-08-06 12:16:35 -0700364 // Loads the |kPrefsP2PFirstAttemptTimestamp| state variable from disk
365 // into |p2p_first_attempt_timestamp_|.
366 void LoadP2PFirstAttemptTimestamp();
367
368 // Loads the |kPrefsP2PNumAttempts| state variable into |p2p_num_attempts_|.
369 void LoadP2PNumAttempts();
370
371 // Sets the |kPrefsP2PNumAttempts| state variable to |value|.
372 void SetP2PNumAttempts(int value);
373
374 // Sets the |kPrefsP2PFirstAttemptTimestamp| state variable to |time|.
375 void SetP2PFirstAttemptTimestamp(const base::Time& time);
376
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800377 // Interface object with which we read/write persisted state. This must
378 // be set by calling the Initialize method before calling any other method.
379 PrefsInterface* prefs_;
380
Chris Sosaaa18e162013-06-20 13:20:30 -0700381 // Interface object with which we read/write persisted state. This must
382 // be set by calling the Initialize method before calling any other method.
383 // This object persists across powerwashes.
384 PrefsInterface* powerwash_safe_prefs_;
385
Jay Srinivasan08262882012-12-28 19:29:43 -0800386 // This is the current response object from Omaha.
387 OmahaResponse response_;
388
David Zeuthenbb8bdc72013-09-03 13:43:48 -0700389 // Whether p2p is being used for downloading as set with the
390 // SetUsingP2PForDownloading() method.
391 bool using_p2p_for_downloading_;
392
Jay Srinivasan08262882012-12-28 19:29:43 -0800393 // This stores a "signature" of the current response. The signature here
394 // refers to a subset of the current response from Omaha. Each update to
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800395 // this value is persisted so we resume from the same value in case of a
396 // process restart.
Jay Srinivasan08262882012-12-28 19:29:43 -0800397 std::string response_signature_;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800398
Alex Deymo820cc702013-06-28 15:43:46 -0700399 // The number of times we've tried to download the payload. This is
400 // incremented each time we download the payload successsfully or when we
401 // exhaust all failure limits for all URLs and are about to wrap around back
402 // to the first URL. Each update to this value is persisted so we resume from
403 // the same value in case of a process restart.
404 int payload_attempt_number_;
405
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800406 // The number of times we've tried to download the payload in full. This is
407 // incremented each time we download the payload in full successsfully or
408 // when we exhaust all failure limits for all URLs and are about to wrap
409 // around back to the first URL. Each update to this value is persisted so
410 // we resume from the same value in case of a process restart.
Alex Deymo820cc702013-06-28 15:43:46 -0700411 int full_payload_attempt_number_;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800412
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800413 // The index of the current URL. This type is different from the one in the
414 // accessor methods because PrefsInterface supports only int64_t but we want
415 // to provide a stronger abstraction of uint32_t. Each update to this value
416 // is persisted so we resume from the same value in case of a process
417 // restart.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800418 int64_t url_index_;
419
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800420 // The count of failures encountered in the current attempt to download using
421 // the current URL (specified by url_index_). Each update to this value is
422 // persisted so we resume from the same value in case of a process restart.
423 int64_t url_failure_count_;
424
David Zeuthencc6f9962013-04-18 11:57:24 -0700425 // The number of times we've switched URLs.
426 int32_t url_switch_count_;
427
Jay Srinivasan19409b72013-04-12 19:23:36 -0700428 // The current download source based on the current URL. This value is
429 // not persisted as it can be recomputed everytime we update the URL.
430 // We're storing this so as not to recompute this on every few bytes of
431 // data we read from the socket.
432 DownloadSource current_download_source_;
433
David Zeuthena573d6f2013-06-14 16:13:36 -0700434 // The number of different Omaha responses seen. Increases every time
435 // a new response is seen. Resets to 0 only when the system has been
436 // successfully updated.
437 int num_responses_seen_;
438
Chris Sosabe45bef2013-04-09 18:25:12 -0700439 // The number of system reboots during an update attempt. Technically since
440 // we don't go out of our way to not update it when not attempting an update,
441 // also records the number of reboots before the next update attempt starts.
442 uint32_t num_reboots_;
443
Jay Srinivasan08262882012-12-28 19:29:43 -0800444 // The timestamp until which we've to wait before attempting to download the
445 // payload again, so as to backoff repeated downloads.
446 base::Time backoff_expiry_time_;
447
David Zeuthen9a017f22013-04-11 16:10:26 -0700448 // The most recently calculated value of the update duration.
449 base::TimeDelta update_duration_current_;
450
451 // The point in time (wall-clock) that the update was started.
452 base::Time update_timestamp_start_;
453
454 // The point in time (wall-clock) that the update ended. If the update
455 // is still in progress, this is set to the Epoch (e.g. 0).
456 base::Time update_timestamp_end_;
457
458 // The update duration uptime
459 base::TimeDelta update_duration_uptime_;
460
461 // The monotonic time when |update_duration_uptime_| was last set
462 base::Time update_duration_uptime_timestamp_;
463
Jay Srinivasan19409b72013-04-12 19:23:36 -0700464 // The number of bytes that have been downloaded for each source for each new
465 // update attempt. If we resume an update, we'll continue from the previous
466 // value, but if we get a new response or if the previous attempt failed,
467 // we'll reset this to 0 to start afresh. Each update to this value is
468 // persisted so we resume from the same value in case of a process restart.
469 // The extra index in the array is to no-op accidental access in case the
470 // return value from GetCurrentDownloadSource is used without validation.
471 uint64_t current_bytes_downloaded_[kNumDownloadSources + 1];
472
473 // The number of bytes that have been downloaded for each source since the
474 // the last successful update. This is used to compute the overhead we incur.
475 // Each update to this value is persisted so we resume from the same value in
476 // case of a process restart.
477 // The extra index in the array is to no-op accidental access in case the
478 // return value from GetCurrentDownloadSource is used without validation.
479 uint64_t total_bytes_downloaded_[kNumDownloadSources + 1];
480
David Zeuthen9a017f22013-04-11 16:10:26 -0700481 // A small timespan used when comparing wall-clock times for coping
482 // with the fact that clocks drift and consequently are adjusted
483 // (either forwards or backwards) via NTP.
484 static const base::TimeDelta kDurationSlack;
485
Jay Srinivasan53173b92013-05-17 17:13:01 -0700486 // The ordered list of the subset of payload URL candidates which are
487 // allowed as per device policy.
488 std::vector<std::string> candidate_urls_;
489
Chris Sosaaa18e162013-06-20 13:20:30 -0700490 // This stores a blacklisted version set as part of rollback. When we rollback
491 // we store the version of the os from which we are rolling back from in order
492 // to guarantee that we do not re-update to it on the next au attempt after
493 // reboot.
494 std::string rollback_version_;
495
David Zeuthendcba8092013-08-06 12:16:35 -0700496 // The cached value of |kPrefsP2PFirstAttemptTimestamp|.
497 base::Time p2p_first_attempt_timestamp_;
498
499 // The cached value of |kPrefsP2PNumAttempts|.
500 int p2p_num_attempts_;
501
David Zeuthen33bae492014-02-25 16:16:18 -0800502 // The number of bytes downloaded per attempt.
503 int64_t attempt_num_bytes_downloaded_;
504
505 // The boot time when the attempt was started.
506 base::Time attempt_start_time_boot_;
507
508 // The monotonic time when the attempt was started.
509 base::Time attempt_start_time_monotonic_;
510
David Zeuthenb281f072014-04-02 10:20:19 -0700511 // The connection type when the attempt started.
512 metrics::ConnectionType attempt_connection_type_;
513
David Zeuthenafed4a12014-04-09 15:28:44 -0700514 // Whether we're currently rolling back.
515 AttemptType attempt_type_;
516
Jay Srinivasan6f6ea002012-12-14 11:26:28 -0800517 DISALLOW_COPY_AND_ASSIGN(PayloadState);
518};
519
520} // namespace chromeos_update_engine
521
Alex Deymo759c2752014-03-17 21:09:36 -0700522#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_H_