| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2012 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 16 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H_ | 
|  | 18 | #define UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H_ | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include <string> | 
|  | 21 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 22 | #include "update_engine/common/action_processor.h" | 
|  | 23 | #include "update_engine/common/constants.h" | 
| Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 24 | #include "update_engine/omaha_response.h" | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | namespace chromeos_update_engine { | 
|  | 27 |  | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 28 | // Describes the methods that need to be implemented by the PayloadState class. | 
|  | 29 | // This interface has been carved out to support mocking of the PayloadState | 
|  | 30 | // object. | 
|  | 31 | class PayloadStateInterface { | 
|  | 32 | public: | 
| Alex Deymo | e894870 | 2014-11-11 21:44:45 -0800 | [diff] [blame] | 33 | virtual ~PayloadStateInterface() = default; | 
|  | 34 |  | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 35 | // Sets the internal payload state based on the given Omaha response. This | 
|  | 36 | // response could be the same or different from the one for which we've stored | 
|  | 37 | // the internal state. If it's different, then this method resets all the | 
|  | 38 | // internal state corresponding to the old response. Since the Omaha response | 
|  | 39 | // has a lot of fields that are not related to payload state, it uses only | 
|  | 40 | // a subset of the fields in the Omaha response to compare equality. | 
|  | 41 | virtual void SetResponse(const OmahaResponse& response) = 0; | 
|  | 42 |  | 
|  | 43 | // This method should be called whenever we have completed downloading all | 
|  | 44 | // the bytes of a payload and have verified that its size and hash match the | 
|  | 45 | // expected values. We use this notificaiton to increment the payload attempt | 
|  | 46 | // number so that the throttle the next attempt to download the same payload | 
|  | 47 | // (in case there's an error in subsequent steps such as post-install) | 
|  | 48 | // appropriately. | 
|  | 49 | virtual void DownloadComplete() = 0; | 
|  | 50 |  | 
|  | 51 | // This method should be called whenever we receive new bytes from the | 
|  | 52 | // network for the current payload. We use this notification to reset the | 
|  | 53 | // failure count for a given URL since receipt of some bytes means we are | 
|  | 54 | // able to make forward progress with the current URL. | 
|  | 55 | virtual void DownloadProgress(size_t count) = 0; | 
|  | 56 |  | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 57 | // This method should be called every time we resume an update attempt. | 
|  | 58 | virtual void UpdateResumed() = 0; | 
|  | 59 |  | 
| Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 60 | // This method should be called every time we begin a new update. This method | 
|  | 61 | // should not be called when we resume an update from the previously | 
|  | 62 | // downloaded point. This is used to reset the metrics for each new update. | 
|  | 63 | virtual void UpdateRestarted() = 0; | 
|  | 64 |  | 
|  | 65 | // This method should be called once after an update attempt succeeds. This | 
|  | 66 | // is when the relevant UMA metrics that are tracked on a per-update-basis | 
|  | 67 | // are uploaded to the UMA server. | 
| David Zeuthen | 9a017f2 | 2013-04-11 16:10:26 -0700 | [diff] [blame] | 68 | virtual void UpdateSucceeded() = 0; | 
|  | 69 |  | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 70 | // This method should be called whenever an update attempt fails with the | 
|  | 71 | // given error code. We use this notification to update the payload state | 
|  | 72 | // depending on the type of the error that happened. | 
| David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 73 | virtual void UpdateFailed(ErrorCode error) = 0; | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 74 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 75 | // This method should be called whenever a succeeded update is canceled, and | 
|  | 76 | // thus can only be called after UpdateSucceeded(). This is currently used | 
|  | 77 | // only for manual testing using the update_engine_client. | 
|  | 78 | virtual void ResetUpdateStatus() = 0; | 
|  | 79 |  | 
| Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 80 | // This method should be called every time we initiate a Rollback. | 
|  | 81 | virtual void Rollback() = 0; | 
|  | 82 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 83 | // Sets the expectations to boot into the new version in the next reboot. | 
|  | 84 | // This function is called every time a new update is marked as ready by | 
|  | 85 | // UpdateSuccess(). |target_version_uid| is an unique identifier of the | 
|  | 86 | // applied payload. It can be any string, as long as the same string is used | 
|  | 87 | // for the same payload. | 
|  | 88 | virtual void ExpectRebootInNewVersion( | 
|  | 89 | const std::string& target_version_uid) = 0; | 
|  | 90 |  | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 91 | // Sets whether P2P is being used to download the update payload. This | 
|  | 92 | // is used to keep track of download sources being used and should be called | 
| David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 93 | // before the transfer begins. | 
|  | 94 | virtual void SetUsingP2PForDownloading(bool value) = 0; | 
|  | 95 |  | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 96 | // Sets whether P2P is being used for sharing the update payloads. | 
|  | 97 | virtual void SetUsingP2PForSharing(bool value) = 0; | 
|  | 98 |  | 
| Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 99 | // Returns true if we should backoff the current download attempt. | 
|  | 100 | // False otherwise. | 
|  | 101 | virtual bool ShouldBackoffDownload() = 0; | 
|  | 102 |  | 
|  | 103 | // Returns the currently stored response "signature". The signature  is a | 
|  | 104 | // subset of fields that are of interest to the PayloadState behavior. | 
|  | 105 | virtual std::string GetResponseSignature() = 0; | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 106 |  | 
|  | 107 | // Returns the payload attempt number. | 
| Alex Deymo | 820cc70 | 2013-06-28 15:43:46 -0700 | [diff] [blame] | 108 | virtual int GetPayloadAttemptNumber() = 0; | 
|  | 109 |  | 
|  | 110 | // Returns the payload attempt number of the attempted full payload. Returns | 
|  | 111 | // 0 for delta payloads. | 
|  | 112 | virtual int GetFullPayloadAttemptNumber() = 0; | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 113 |  | 
| Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 114 | // Returns the current URL. Returns an empty string if there's no valid URL. | 
|  | 115 | virtual std::string GetCurrentUrl() = 0; | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 116 |  | 
|  | 117 | // Returns the current URL's failure count. | 
|  | 118 | virtual uint32_t GetUrlFailureCount() = 0; | 
| Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 119 |  | 
| David Zeuthen | cc6f996 | 2013-04-18 11:57:24 -0700 | [diff] [blame] | 120 | // Returns the total number of times a new URL has been switched to | 
|  | 121 | // for the current response. | 
|  | 122 | virtual uint32_t GetUrlSwitchCount() = 0; | 
|  | 123 |  | 
| David Zeuthen | a573d6f | 2013-06-14 16:13:36 -0700 | [diff] [blame] | 124 | // Returns the total number of different responses seen since the | 
|  | 125 | // last successful update. | 
|  | 126 | virtual int GetNumResponsesSeen() = 0; | 
|  | 127 |  | 
| Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 128 | // Returns the expiry time for the current backoff period. | 
|  | 129 | virtual base::Time GetBackoffExpiryTime() = 0; | 
| David Zeuthen | 9a017f2 | 2013-04-11 16:10:26 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | // Returns the elapsed time used for this update, including time | 
|  | 132 | // where the device is powered off and sleeping. If the | 
|  | 133 | // update has not completed, returns the time spent so far. | 
|  | 134 | virtual base::TimeDelta GetUpdateDuration() = 0; | 
|  | 135 |  | 
|  | 136 | // Returns the time used for this update not including time when | 
|  | 137 | // the device is powered off or sleeping. If the update has not | 
|  | 138 | // completed, returns the time spent so far. | 
|  | 139 | virtual base::TimeDelta GetUpdateDurationUptime() = 0; | 
| Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 140 |  | 
|  | 141 | // Returns the number of bytes that have been downloaded for each source for | 
|  | 142 | // each new update attempt. If we resume an update, we'll continue from the | 
|  | 143 | // previous value, but if we get a new response or if the previous attempt | 
|  | 144 | // failed, we'll reset this to 0 to start afresh. | 
|  | 145 | virtual uint64_t GetCurrentBytesDownloaded(DownloadSource source) = 0; | 
|  | 146 |  | 
|  | 147 | // Returns the total number of bytes that have been downloaded for each | 
|  | 148 | // source since the the last successful update. This is used to compute the | 
|  | 149 | // overhead we incur. | 
|  | 150 | virtual uint64_t GetTotalBytesDownloaded(DownloadSource source) = 0; | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 151 |  | 
|  | 152 | // Returns the reboot count for this update attempt. | 
|  | 153 | virtual uint32_t GetNumReboots() = 0; | 
| David Zeuthen | e4c58bf | 2013-06-18 17:26:50 -0700 | [diff] [blame] | 154 |  | 
|  | 155 | // Called at update_engine startup to do various house-keeping. | 
|  | 156 | virtual void UpdateEngineStarted() = 0; | 
| Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 157 |  | 
|  | 158 | // Returns the version from before a rollback if our last update was a | 
|  | 159 | // rollback. | 
|  | 160 | virtual std::string GetRollbackVersion() = 0; | 
| David Zeuthen | dcba809 | 2013-08-06 12:16:35 -0700 | [diff] [blame] | 161 |  | 
|  | 162 | // Returns the value of number of attempts we've attempted to | 
|  | 163 | // download the payload via p2p. | 
|  | 164 | virtual int GetP2PNumAttempts() = 0; | 
|  | 165 |  | 
|  | 166 | // Returns the value of timestamp of the first time we've attempted | 
|  | 167 | // to download the payload via p2p. | 
|  | 168 | virtual base::Time GetP2PFirstAttemptTimestamp() = 0; | 
|  | 169 |  | 
|  | 170 | // Should be called every time we decide to use p2p for an update | 
|  | 171 | // attempt. This is used to increase the p2p attempt counter and | 
|  | 172 | // set the timestamp for first attempt. | 
|  | 173 | virtual void P2PNewAttempt() = 0; | 
|  | 174 |  | 
|  | 175 | // Returns |true| if we are allowed to continue using p2p for | 
|  | 176 | // downloading and |false| otherwise. This is done by recording | 
|  | 177 | // and examining how many attempts have been done already as well | 
|  | 178 | // as when the first attempt was. | 
|  | 179 | virtual bool P2PAttemptAllowed() = 0; | 
| David Zeuthen | bb8bdc7 | 2013-09-03 13:43:48 -0700 | [diff] [blame] | 180 |  | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 181 | // Gets the values previously set with SetUsingP2PForDownloading() and | 
|  | 182 | // SetUsingP2PForSharing(). | 
|  | 183 | virtual bool GetUsingP2PForDownloading() const = 0; | 
|  | 184 | virtual bool GetUsingP2PForSharing() const = 0; | 
| Gilad Arnold | 519cfc7 | 2014-10-02 10:34:54 -0700 | [diff] [blame] | 185 |  | 
|  | 186 | // Returns the current (persisted) scattering wallclock-based wait period. | 
|  | 187 | virtual base::TimeDelta GetScatteringWaitPeriod() = 0; | 
|  | 188 |  | 
|  | 189 | // Sets and persists the scattering wallclock-based wait period. | 
|  | 190 | virtual void SetScatteringWaitPeriod(base::TimeDelta wait_period) = 0; | 
| Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 191 |  | 
|  | 192 | // Sets/gets the P2P download URL, if one is to be used. | 
|  | 193 | virtual void SetP2PUrl(const std::string& url) = 0; | 
|  | 194 | virtual std::string GetP2PUrl() const = 0; | 
| David Zeuthen | dcba809 | 2013-08-06 12:16:35 -0700 | [diff] [blame] | 195 | }; | 
| Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 196 |  | 
|  | 197 | }  // namespace chromeos_update_engine | 
|  | 198 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 199 | #endif  // UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H_ |