Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 1 | // 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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H_ |
| 6 | #define UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H_ |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "update_engine/action_processor.h" |
Alex Vakulenko | 44cab30 | 2014-07-23 13:12:15 -0700 | [diff] [blame] | 11 | #include "update_engine/constants.h" |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 12 | #include "update_engine/omaha_response.h" |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 13 | |
| 14 | namespace chromeos_update_engine { |
| 15 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 16 | // 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. |
| 19 | class 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 Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 43 | // This method should be called every time we resume an update attempt. |
| 44 | virtual void UpdateResumed() = 0; |
| 45 | |
Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 46 | // 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 Zeuthen | 9a017f2 | 2013-04-11 16:10:26 -0700 | [diff] [blame] | 54 | virtual void UpdateSucceeded() = 0; |
| 55 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 56 | // 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 Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 59 | virtual void UpdateFailed(ErrorCode error) = 0; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 60 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 61 | // This method should be called whenever a succeeded update is canceled, and |
| 62 | // thus can only be called after UpdateSucceeded(). This is currently used |
| 63 | // only for manual testing using the update_engine_client. |
| 64 | virtual void ResetUpdateStatus() = 0; |
| 65 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 66 | // This method should be called every time we initiate a Rollback. |
| 67 | virtual void Rollback() = 0; |
| 68 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 69 | // Sets the expectations to boot into the new version in the next reboot. |
| 70 | // This function is called every time a new update is marked as ready by |
| 71 | // UpdateSuccess(). |target_version_uid| is an unique identifier of the |
| 72 | // applied payload. It can be any string, as long as the same string is used |
| 73 | // for the same payload. |
| 74 | virtual void ExpectRebootInNewVersion( |
| 75 | const std::string& target_version_uid) = 0; |
| 76 | |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 77 | // Sets whether p2p is being used to download the update payload. This |
| 78 | // is used to keep track download sources being used and should be called |
| 79 | // before the transfer begins. |
| 80 | virtual void SetUsingP2PForDownloading(bool value) = 0; |
| 81 | |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 82 | // Returns true if we should backoff the current download attempt. |
| 83 | // False otherwise. |
| 84 | virtual bool ShouldBackoffDownload() = 0; |
| 85 | |
| 86 | // Returns the currently stored response "signature". The signature is a |
| 87 | // subset of fields that are of interest to the PayloadState behavior. |
| 88 | virtual std::string GetResponseSignature() = 0; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 89 | |
| 90 | // Returns the payload attempt number. |
Alex Deymo | 820cc70 | 2013-06-28 15:43:46 -0700 | [diff] [blame] | 91 | virtual int GetPayloadAttemptNumber() = 0; |
| 92 | |
| 93 | // Returns the payload attempt number of the attempted full payload. Returns |
| 94 | // 0 for delta payloads. |
| 95 | virtual int GetFullPayloadAttemptNumber() = 0; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 96 | |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 97 | // Returns the current URL. Returns an empty string if there's no valid URL. |
| 98 | virtual std::string GetCurrentUrl() = 0; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 99 | |
| 100 | // Returns the current URL's failure count. |
| 101 | virtual uint32_t GetUrlFailureCount() = 0; |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 102 | |
David Zeuthen | cc6f996 | 2013-04-18 11:57:24 -0700 | [diff] [blame] | 103 | // Returns the total number of times a new URL has been switched to |
| 104 | // for the current response. |
| 105 | virtual uint32_t GetUrlSwitchCount() = 0; |
| 106 | |
David Zeuthen | a573d6f | 2013-06-14 16:13:36 -0700 | [diff] [blame] | 107 | // Returns the total number of different responses seen since the |
| 108 | // last successful update. |
| 109 | virtual int GetNumResponsesSeen() = 0; |
| 110 | |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 111 | // Returns the expiry time for the current backoff period. |
| 112 | virtual base::Time GetBackoffExpiryTime() = 0; |
David Zeuthen | 9a017f2 | 2013-04-11 16:10:26 -0700 | [diff] [blame] | 113 | |
| 114 | // Returns the elapsed time used for this update, including time |
| 115 | // where the device is powered off and sleeping. If the |
| 116 | // update has not completed, returns the time spent so far. |
| 117 | virtual base::TimeDelta GetUpdateDuration() = 0; |
| 118 | |
| 119 | // Returns the time used for this update not including time when |
| 120 | // the device is powered off or sleeping. If the update has not |
| 121 | // completed, returns the time spent so far. |
| 122 | virtual base::TimeDelta GetUpdateDurationUptime() = 0; |
Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 123 | |
| 124 | // Returns the number of bytes that have been downloaded for each source for |
| 125 | // each new update attempt. If we resume an update, we'll continue from the |
| 126 | // previous value, but if we get a new response or if the previous attempt |
| 127 | // failed, we'll reset this to 0 to start afresh. |
| 128 | virtual uint64_t GetCurrentBytesDownloaded(DownloadSource source) = 0; |
| 129 | |
| 130 | // Returns the total number of bytes that have been downloaded for each |
| 131 | // source since the the last successful update. This is used to compute the |
| 132 | // overhead we incur. |
| 133 | virtual uint64_t GetTotalBytesDownloaded(DownloadSource source) = 0; |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 134 | |
| 135 | // Returns the reboot count for this update attempt. |
| 136 | virtual uint32_t GetNumReboots() = 0; |
David Zeuthen | e4c58bf | 2013-06-18 17:26:50 -0700 | [diff] [blame] | 137 | |
| 138 | // Called at update_engine startup to do various house-keeping. |
| 139 | virtual void UpdateEngineStarted() = 0; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 140 | |
| 141 | // Returns the version from before a rollback if our last update was a |
| 142 | // rollback. |
| 143 | virtual std::string GetRollbackVersion() = 0; |
David Zeuthen | dcba809 | 2013-08-06 12:16:35 -0700 | [diff] [blame] | 144 | |
| 145 | // Returns the value of number of attempts we've attempted to |
| 146 | // download the payload via p2p. |
| 147 | virtual int GetP2PNumAttempts() = 0; |
| 148 | |
| 149 | // Returns the value of timestamp of the first time we've attempted |
| 150 | // to download the payload via p2p. |
| 151 | virtual base::Time GetP2PFirstAttemptTimestamp() = 0; |
| 152 | |
| 153 | // Should be called every time we decide to use p2p for an update |
| 154 | // attempt. This is used to increase the p2p attempt counter and |
| 155 | // set the timestamp for first attempt. |
| 156 | virtual void P2PNewAttempt() = 0; |
| 157 | |
| 158 | // Returns |true| if we are allowed to continue using p2p for |
| 159 | // downloading and |false| otherwise. This is done by recording |
| 160 | // and examining how many attempts have been done already as well |
| 161 | // as when the first attempt was. |
| 162 | virtual bool P2PAttemptAllowed() = 0; |
David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 163 | |
| 164 | // Gets the value previously set with SetUsingP2PForDownloading(). |
| 165 | virtual bool GetUsingP2PForDownloading() = 0; |
David Zeuthen | dcba809 | 2013-08-06 12:16:35 -0700 | [diff] [blame] | 166 | }; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 167 | |
| 168 | } // namespace chromeos_update_engine |
| 169 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 170 | #endif // UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H_ |