blob: 031fbec689cce9a35505cce02e5a1ce86b4a0fd9 [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
10#include "update_engine/action_processor.h"
11
12namespace chromeos_update_engine {
13
14// Forward declaration here because we get a circular dependency if
15// we include omaha_request_action.h directly.
16struct OmahaResponse;
17
18// Describes the methods that need to be implemented by the PayloadState class.
19// This interface has been carved out to support mocking of the PayloadState
20// object.
21class PayloadStateInterface {
22 public:
23 // Sets the internal payload state based on the given Omaha response. This
24 // response could be the same or different from the one for which we've stored
25 // the internal state. If it's different, then this method resets all the
26 // internal state corresponding to the old response. Since the Omaha response
27 // has a lot of fields that are not related to payload state, it uses only
28 // a subset of the fields in the Omaha response to compare equality.
29 virtual void SetResponse(const OmahaResponse& response) = 0;
30
31 // This method should be called whenever we have completed downloading all
32 // the bytes of a payload and have verified that its size and hash match the
33 // expected values. We use this notificaiton to increment the payload attempt
34 // number so that the throttle the next attempt to download the same payload
35 // (in case there's an error in subsequent steps such as post-install)
36 // appropriately.
37 virtual void DownloadComplete() = 0;
38
39 // This method should be called whenever we receive new bytes from the
40 // network for the current payload. We use this notification to reset the
41 // failure count for a given URL since receipt of some bytes means we are
42 // able to make forward progress with the current URL.
43 virtual void DownloadProgress(size_t count) = 0;
44
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
50 // Returns the currently stored response.
51 virtual std::string GetResponse() = 0;
52
53 // Returns the payload attempt number.
54 virtual uint32_t GetPayloadAttemptNumber() = 0;
55
56 // Returns the current URL index.
57 virtual uint32_t GetUrlIndex() = 0;
58
59 // Returns the current URL's failure count.
60 virtual uint32_t GetUrlFailureCount() = 0;
61 };
62
63} // namespace chromeos_update_engine
64
65#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_STATE_INTERFACE_H__