Revert of Revert of Fix text clipping in CompositorFrameTime Display (patchset #1...
[chromium-blink-merge.git] / chromeos / dbus / update_engine_client.h
blob99de14295ea41e0c414f53b18242f0cb58c1656a
1 // Copyright (c) 2012 The Chromium 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.
5 #ifndef CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_
6 #define CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/observer_list.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "chromeos/dbus/dbus_client_implementation_type.h"
16 namespace chromeos {
18 // UpdateEngineClient is used to communicate with the update engine.
19 class CHROMEOS_EXPORT UpdateEngineClient : public DBusClient {
20 public:
21 // Edges for state machine
22 // IDLE->CHECKING_FOR_UPDATE
23 // CHECKING_FOR_UPDATE->IDLE
24 // CHECKING_FOR_UPDATE->UPDATE_AVAILABLE
25 // ...
26 // FINALIZING->UPDATE_NEED_REBOOT
27 // Any state can transition to REPORTING_ERROR_EVENT and then on to IDLE.
28 enum UpdateStatusOperation {
29 UPDATE_STATUS_ERROR = -1,
30 UPDATE_STATUS_IDLE = 0,
31 UPDATE_STATUS_CHECKING_FOR_UPDATE,
32 UPDATE_STATUS_UPDATE_AVAILABLE,
33 UPDATE_STATUS_DOWNLOADING,
34 UPDATE_STATUS_VERIFYING,
35 UPDATE_STATUS_FINALIZING,
36 UPDATE_STATUS_UPDATED_NEED_REBOOT,
37 UPDATE_STATUS_REPORTING_ERROR_EVENT,
38 UPDATE_STATUS_ATTEMPTING_ROLLBACK
41 // The status of the ongoing update attempt.
42 struct Status {
43 Status() : status(UPDATE_STATUS_IDLE),
44 download_progress(0.0),
45 last_checked_time(0),
46 new_size(0) {
49 UpdateStatusOperation status;
50 double download_progress; // 0.0 - 1.0
51 int64_t last_checked_time; // As reported by std::time().
52 std::string new_version;
53 int64_t new_size; // Valid during DOWNLOADING, in bytes.
56 // The result code used for RequestUpdateCheck().
57 enum UpdateCheckResult {
58 UPDATE_RESULT_SUCCESS,
59 UPDATE_RESULT_FAILED,
60 UPDATE_RESULT_NOTIMPLEMENTED,
63 // Interface for observing changes from the update engine.
64 class Observer {
65 public:
66 virtual ~Observer() {}
68 // Called when the status is updated.
69 virtual void UpdateStatusChanged(const Status& status) {}
72 ~UpdateEngineClient() override;
74 // Adds and removes the observer.
75 virtual void AddObserver(Observer* observer) = 0;
76 virtual void RemoveObserver(Observer* observer) = 0;
77 // Returns true if this object has the given observer.
78 virtual bool HasObserver(const Observer* observer) const = 0;
80 // Called once RequestUpdateCheck() is complete. Takes one parameter:
81 // - UpdateCheckResult: the result of the update check.
82 typedef base::Callback<void(UpdateCheckResult)> UpdateCheckCallback;
84 // Requests an update check and calls |callback| when completed.
85 virtual void RequestUpdateCheck(const UpdateCheckCallback& callback) = 0;
87 // Reboots if update has been performed.
88 virtual void RebootAfterUpdate() = 0;
90 // Starts Rollback.
91 virtual void Rollback() = 0;
93 // Called once CanRollbackCheck() is complete. Takes one parameter:
94 // - bool: the result of the rollback availability check.
95 typedef base::Callback<void(bool can_rollback)> RollbackCheckCallback;
97 // Checks if Rollback is available and calls |callback| when completed.
98 virtual void CanRollbackCheck(
99 const RollbackCheckCallback& callback) = 0;
101 // Called once GetChannel() is complete. Takes one parameter;
102 // - string: the channel name like "beta-channel".
103 typedef base::Callback<void(const std::string& channel_name)>
104 GetChannelCallback;
106 // Returns the last status the object received from the update engine.
108 // Ideally, the D-Bus client should be state-less, but there are clients
109 // that need this information.
110 virtual Status GetLastStatus() = 0;
112 // Changes the current channel of the device to the target
113 // channel. If the target channel is a less stable channel than the
114 // current channel, then the channel change happens immediately (at
115 // the next update check). If the target channel is a more stable
116 // channel, then if |is_powerwash_allowed| is set to true, then also
117 // the change happens immediately but with a powerwash if
118 // required. Otherwise, the change takes effect eventually (when the
119 // version on the target channel goes above the version number of
120 // what the device currently has). |target_channel| should look like
121 // "dev-channel", "beta-channel" or "stable-channel".
122 virtual void SetChannel(const std::string& target_channel,
123 bool is_powerwash_allowed) = 0;
125 // If |get_current_channel| is set to true, calls |callback| with
126 // the name of the channel that the device is currently
127 // on. Otherwise, it calls it with the name of the channel the
128 // device is supposed to be (in case of a pending channel
129 // change). On error, calls |callback| with an empty string.
130 virtual void GetChannel(bool get_current_channel,
131 const GetChannelCallback& callback) = 0;
133 // Returns an empty UpdateCheckCallback that does nothing.
134 static UpdateCheckCallback EmptyUpdateCheckCallback();
136 // Creates the instance.
137 static UpdateEngineClient* Create(DBusClientImplementationType type);
139 // Returns true if |target_channel| is more stable than |current_channel|.
140 static bool IsTargetChannelMoreStable(const std::string& current_channel,
141 const std::string& target_channel);
143 protected:
144 // Create() should be used instead.
145 UpdateEngineClient();
147 private:
148 DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient);
151 } // namespace chromeos
153 #endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_