ServiceWorker: Initialize member variable in ctor of ServiceWorkerDatabase
[chromium-blink-merge.git] / chromeos / dbus / update_engine_client.h
blob31af6168c3d95a530c5b3a7551e698da50e4f889
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 "base/callback.h"
9 #include "base/observer_list.h"
10 #include "chromeos/chromeos_export.h"
11 #include "chromeos/dbus/dbus_client.h"
12 #include "chromeos/dbus/dbus_client_implementation_type.h"
14 #include <string>
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
40 // The status of the ongoing update attempt.
41 struct Status {
42 Status() : status(UPDATE_STATUS_IDLE),
43 download_progress(0.0),
44 last_checked_time(0),
45 new_size(0) {
48 UpdateStatusOperation status;
49 double download_progress; // 0.0 - 1.0
50 int64_t last_checked_time; // As reported by std::time().
51 std::string new_version;
52 int64_t new_size; // Valid during DOWNLOADING, in bytes.
55 // The result code used for RequestUpdateCheck().
56 enum UpdateCheckResult {
57 UPDATE_RESULT_SUCCESS,
58 UPDATE_RESULT_FAILED,
59 UPDATE_RESULT_NOTIMPLEMENTED,
62 // Interface for observing changes from the update engine.
63 class Observer {
64 public:
65 // Called when the status is updated.
66 virtual void UpdateStatusChanged(const Status& status) {}
69 virtual ~UpdateEngineClient();
71 // Adds and removes the observer.
72 virtual void AddObserver(Observer* observer) = 0;
73 virtual void RemoveObserver(Observer* observer) = 0;
74 // Returns true if this object has the given observer.
75 virtual bool HasObserver(Observer* observer) = 0;
77 // Called once RequestUpdateCheck() is complete. Takes one parameter:
78 // - UpdateCheckResult: the result of the update check.
79 typedef base::Callback<void(UpdateCheckResult)> UpdateCheckCallback;
81 // Requests an update check and calls |callback| when completed.
82 virtual void RequestUpdateCheck(const UpdateCheckCallback& callback) = 0;
84 // Reboots if update has been performed.
85 virtual void RebootAfterUpdate() = 0;
87 // Starts Rollback.
88 virtual void Rollback() = 0;
90 // Called once CanRollbackCheck() is complete. Takes one parameter:
91 // - bool: the result of the rollback availability check.
92 typedef base::Callback<void(bool can_rollback)> RollbackCheckCallback;
94 // Checks if Rollback is available and calls |callback| when completed.
95 virtual void CanRollbackCheck(
96 const RollbackCheckCallback& callback) = 0;
98 // Called once GetChannel() is complete. Takes one parameter;
99 // - string: the channel name like "beta-channel".
100 typedef base::Callback<void(const std::string& channel_name)>
101 GetChannelCallback;
103 // Returns the last status the object received from the update engine.
105 // Ideally, the D-Bus client should be state-less, but there are clients
106 // that need this information.
107 virtual Status GetLastStatus() = 0;
109 // Changes the current channel of the device to the target
110 // channel. If the target channel is a less stable channel than the
111 // current channel, then the channel change happens immediately (at
112 // the next update check). If the target channel is a more stable
113 // channel, then if |is_powerwash_allowed| is set to true, then also
114 // the change happens immediately but with a powerwash if
115 // required. Otherwise, the change takes effect eventually (when the
116 // version on the target channel goes above the version number of
117 // what the device currently has). |target_channel| should look like
118 // "dev-channel", "beta-channel" or "stable-channel".
119 virtual void SetChannel(const std::string& target_channel,
120 bool is_powerwash_allowed) = 0;
122 // If |get_current_channel| is set to true, calls |callback| with
123 // the name of the channel that the device is currently
124 // on. Otherwise, it calls it with the name of the channel the
125 // device is supposed to be (in case of a pending channel
126 // change). On error, calls |callback| with an empty string.
127 virtual void GetChannel(bool get_current_channel,
128 const GetChannelCallback& callback) = 0;
130 // Returns an empty UpdateCheckCallback that does nothing.
131 static UpdateCheckCallback EmptyUpdateCheckCallback();
133 // Creates the instance.
134 static UpdateEngineClient* Create(DBusClientImplementationType type);
136 protected:
137 // Create() should be used instead.
138 UpdateEngineClient();
140 private:
141 DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient);
144 } // namespace chromeos
146 #endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_