blob: 4323b4f8a7ef9aeec8ce4805dcae08557c90f3c4 [file] [log] [blame]
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -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_INTERFACE_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H__
7
8#include <string>
9
Jay Srinivasan19409b72013-04-12 19:23:36 -070010#include "update_engine/constants.h"
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080011#include "update_engine/action_processor.h"
Jay Srinivasan08262882012-12-28 19:29:43 -080012#include "update_engine/omaha_response.h"
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080013
14namespace chromeos_update_engine {
15
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080016// Describes the methods that need to be implemented by the PayloadState class.
17// This interface has been carved out to support mocking of the PayloadState
18// object.
19class PayloadStateInterface {
20 public:
21 // Sets the internal payload state based on the given Omaha response. This
22 // response could be the same or different from the one for which we've stored
23 // the internal state. If it's different, then this method resets all the
24 // internal state corresponding to the old response. Since the Omaha response
25 // has a lot of fields that are not related to payload state, it uses only
26 // a subset of the fields in the Omaha response to compare equality.
27 virtual void SetResponse(const OmahaResponse& response) = 0;
28
29 // This method should be called whenever we have completed downloading all
30 // the bytes of a payload and have verified that its size and hash match the
31 // expected values. We use this notificaiton to increment the payload attempt
32 // number so that the throttle the next attempt to download the same payload
33 // (in case there's an error in subsequent steps such as post-install)
34 // appropriately.
35 virtual void DownloadComplete() = 0;
36
37 // This method should be called whenever we receive new bytes from the
38 // network for the current payload. We use this notification to reset the
39 // failure count for a given URL since receipt of some bytes means we are
40 // able to make forward progress with the current URL.
41 virtual void DownloadProgress(size_t count) = 0;
42
Chris Sosabe45bef2013-04-09 18:25:12 -070043 // This method should be called every time we resume an update attempt.
44 virtual void UpdateResumed() = 0;
45
Jay Srinivasan19409b72013-04-12 19:23:36 -070046 // This method should be called every time we begin a new update. This method
47 // should not be called when we resume an update from the previously
48 // downloaded point. This is used to reset the metrics for each new update.
49 virtual void UpdateRestarted() = 0;
50
51 // This method should be called once after an update attempt succeeds. This
52 // is when the relevant UMA metrics that are tracked on a per-update-basis
53 // are uploaded to the UMA server.
David Zeuthen9a017f22013-04-11 16:10:26 -070054 virtual void UpdateSucceeded() = 0;
55
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080056 // This method should be called whenever an update attempt fails with the
57 // given error code. We use this notification to update the payload state
58 // depending on the type of the error that happened.
David Zeuthena99981f2013-04-29 13:42:47 -070059 virtual void UpdateFailed(ErrorCode error) = 0;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080060
Chris Sosaaa18e162013-06-20 13:20:30 -070061 // This method should be called every time we initiate a Rollback.
62 virtual void Rollback() = 0;
63
Jay Srinivasan08262882012-12-28 19:29:43 -080064 // Returns true if we should backoff the current download attempt.
65 // False otherwise.
66 virtual bool ShouldBackoffDownload() = 0;
67
68 // Returns the currently stored response "signature". The signature is a
69 // subset of fields that are of interest to the PayloadState behavior.
70 virtual std::string GetResponseSignature() = 0;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080071
72 // Returns the payload attempt number.
Alex Deymo820cc702013-06-28 15:43:46 -070073 virtual int GetPayloadAttemptNumber() = 0;
74
75 // Returns the payload attempt number of the attempted full payload. Returns
76 // 0 for delta payloads.
77 virtual int GetFullPayloadAttemptNumber() = 0;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080078
Jay Srinivasan53173b92013-05-17 17:13:01 -070079 // Returns the current URL. Returns an empty string if there's no valid URL.
80 virtual std::string GetCurrentUrl() = 0;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080081
82 // Returns the current URL's failure count.
83 virtual uint32_t GetUrlFailureCount() = 0;
Jay Srinivasan08262882012-12-28 19:29:43 -080084
David Zeuthencc6f9962013-04-18 11:57:24 -070085 // Returns the total number of times a new URL has been switched to
86 // for the current response.
87 virtual uint32_t GetUrlSwitchCount() = 0;
88
David Zeuthena573d6f2013-06-14 16:13:36 -070089 // Returns the total number of different responses seen since the
90 // last successful update.
91 virtual int GetNumResponsesSeen() = 0;
92
Jay Srinivasan08262882012-12-28 19:29:43 -080093 // Returns the expiry time for the current backoff period.
94 virtual base::Time GetBackoffExpiryTime() = 0;
David Zeuthen9a017f22013-04-11 16:10:26 -070095
96 // Returns the elapsed time used for this update, including time
97 // where the device is powered off and sleeping. If the
98 // update has not completed, returns the time spent so far.
99 virtual base::TimeDelta GetUpdateDuration() = 0;
100
101 // Returns the time used for this update not including time when
102 // the device is powered off or sleeping. If the update has not
103 // completed, returns the time spent so far.
104 virtual base::TimeDelta GetUpdateDurationUptime() = 0;
Jay Srinivasan19409b72013-04-12 19:23:36 -0700105
106 // Returns the number of bytes that have been downloaded for each source for
107 // each new update attempt. If we resume an update, we'll continue from the
108 // previous value, but if we get a new response or if the previous attempt
109 // failed, we'll reset this to 0 to start afresh.
110 virtual uint64_t GetCurrentBytesDownloaded(DownloadSource source) = 0;
111
112 // Returns the total number of bytes that have been downloaded for each
113 // source since the the last successful update. This is used to compute the
114 // overhead we incur.
115 virtual uint64_t GetTotalBytesDownloaded(DownloadSource source) = 0;
Chris Sosabe45bef2013-04-09 18:25:12 -0700116
117 // Returns the reboot count for this update attempt.
118 virtual uint32_t GetNumReboots() = 0;
David Zeuthene4c58bf2013-06-18 17:26:50 -0700119
120 // Called at update_engine startup to do various house-keeping.
121 virtual void UpdateEngineStarted() = 0;
Chris Sosaaa18e162013-06-20 13:20:30 -0700122
123 // Returns the version from before a rollback if our last update was a
124 // rollback.
125 virtual std::string GetRollbackVersion() = 0;
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800126 };
127
128} // namespace chromeos_update_engine
129
130#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H__