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 | |
| 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 | |
| 10 | #include "update_engine/action_processor.h" |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 11 | #include "update_engine/omaha_response.h" |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 12 | |
| 13 | namespace chromeos_update_engine { |
| 14 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 15 | // Describes the methods that need to be implemented by the PayloadState class. |
| 16 | // This interface has been carved out to support mocking of the PayloadState |
| 17 | // object. |
| 18 | class PayloadStateInterface { |
| 19 | public: |
| 20 | // Sets the internal payload state based on the given Omaha response. This |
| 21 | // response could be the same or different from the one for which we've stored |
| 22 | // the internal state. If it's different, then this method resets all the |
| 23 | // internal state corresponding to the old response. Since the Omaha response |
| 24 | // has a lot of fields that are not related to payload state, it uses only |
| 25 | // a subset of the fields in the Omaha response to compare equality. |
| 26 | virtual void SetResponse(const OmahaResponse& response) = 0; |
| 27 | |
| 28 | // This method should be called whenever we have completed downloading all |
| 29 | // the bytes of a payload and have verified that its size and hash match the |
| 30 | // expected values. We use this notificaiton to increment the payload attempt |
| 31 | // number so that the throttle the next attempt to download the same payload |
| 32 | // (in case there's an error in subsequent steps such as post-install) |
| 33 | // appropriately. |
| 34 | virtual void DownloadComplete() = 0; |
| 35 | |
| 36 | // This method should be called whenever we receive new bytes from the |
| 37 | // network for the current payload. We use this notification to reset the |
| 38 | // failure count for a given URL since receipt of some bytes means we are |
| 39 | // able to make forward progress with the current URL. |
| 40 | virtual void DownloadProgress(size_t count) = 0; |
| 41 | |
David Zeuthen | 9a017f2 | 2013-04-11 16:10:26 -0700 | [diff] [blame] | 42 | // This method should be called whenever an update attempt succeeds. |
| 43 | virtual void UpdateSucceeded() = 0; |
| 44 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 45 | // This method should be called whenever an update attempt fails with the |
| 46 | // given error code. We use this notification to update the payload state |
| 47 | // depending on the type of the error that happened. |
| 48 | virtual void UpdateFailed(ActionExitCode error) = 0; |
| 49 | |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 50 | // Returns true if we should backoff the current download attempt. |
| 51 | // False otherwise. |
| 52 | virtual bool ShouldBackoffDownload() = 0; |
| 53 | |
| 54 | // Returns the currently stored response "signature". The signature is a |
| 55 | // subset of fields that are of interest to the PayloadState behavior. |
| 56 | virtual std::string GetResponseSignature() = 0; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 57 | |
| 58 | // Returns the payload attempt number. |
| 59 | virtual uint32_t GetPayloadAttemptNumber() = 0; |
| 60 | |
| 61 | // Returns the current URL index. |
| 62 | virtual uint32_t GetUrlIndex() = 0; |
| 63 | |
| 64 | // Returns the current URL's failure count. |
| 65 | virtual uint32_t GetUrlFailureCount() = 0; |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 66 | |
| 67 | // Returns the expiry time for the current backoff period. |
| 68 | virtual base::Time GetBackoffExpiryTime() = 0; |
David Zeuthen | 9a017f2 | 2013-04-11 16:10:26 -0700 | [diff] [blame] | 69 | |
| 70 | // Returns the elapsed time used for this update, including time |
| 71 | // where the device is powered off and sleeping. If the |
| 72 | // update has not completed, returns the time spent so far. |
| 73 | virtual base::TimeDelta GetUpdateDuration() = 0; |
| 74 | |
| 75 | // Returns the time used for this update not including time when |
| 76 | // the device is powered off or sleeping. If the update has not |
| 77 | // completed, returns the time spent so far. |
| 78 | virtual base::TimeDelta GetUpdateDurationUptime() = 0; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace chromeos_update_engine |
| 82 | |
| 83 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H__ |