Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / dbus / update_engine_client.h
blob914094e162663d9e88ae53d6cd928682283cada0
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_implementation_type.h"
13 #include <string>
15 namespace dbus {
16 class Bus;
17 } // namespace
19 namespace chromeos {
21 // UpdateEngineClient is used to communicate with the update engine.
22 class CHROMEOS_EXPORT UpdateEngineClient {
23 public:
24 // Edges for state machine
25 // IDLE->CHECKING_FOR_UPDATE
26 // CHECKING_FOR_UPDATE->IDLE
27 // CHECKING_FOR_UPDATE->UPDATE_AVAILABLE
28 // ...
29 // FINALIZING->UPDATE_NEED_REBOOT
30 // Any state can transition to REPORTING_ERROR_EVENT and then on to IDLE.
31 enum UpdateStatusOperation {
32 UPDATE_STATUS_ERROR = -1,
33 UPDATE_STATUS_IDLE = 0,
34 UPDATE_STATUS_CHECKING_FOR_UPDATE,
35 UPDATE_STATUS_UPDATE_AVAILABLE,
36 UPDATE_STATUS_DOWNLOADING,
37 UPDATE_STATUS_VERIFYING,
38 UPDATE_STATUS_FINALIZING,
39 UPDATE_STATUS_UPDATED_NEED_REBOOT,
40 UPDATE_STATUS_REPORTING_ERROR_EVENT
43 // The status of the ongoing update attempt.
44 struct Status {
45 Status() : status(UPDATE_STATUS_IDLE),
46 download_progress(0.0),
47 last_checked_time(0),
48 new_size(0) {
51 UpdateStatusOperation status;
52 double download_progress; // 0.0 - 1.0
53 int64_t last_checked_time; // As reported by std::time().
54 std::string new_version;
55 int64_t new_size; // Valid during DOWNLOADING, in bytes.
58 // The result code used for RequestUpdateCheck().
59 enum UpdateCheckResult {
60 UPDATE_RESULT_SUCCESS,
61 UPDATE_RESULT_FAILED,
62 UPDATE_RESULT_NOTIMPLEMENTED,
65 // Interface for observing changes from the update engine.
66 class Observer {
67 public:
68 // Called when the status is updated.
69 virtual void UpdateStatusChanged(const Status& status) {}
72 virtual ~UpdateEngineClient();
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(Observer* observer) = 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 // Requests to set the release track (channel). |track| should look like
91 // "beta-channel" or "dev-channel".
92 virtual void SetReleaseTrack(const std::string& track) = 0;
94 // Called once GetReleaseTrack() is complete. Takes one parameter;
95 // - string: the release track name like "beta-channel".
96 typedef base::Callback<void(const std::string&)> GetReleaseTrackCallback;
98 // Requests to get the release track and calls |callback| with the
99 // release track (channel). On error, calls |callback| with an empty
100 // string.
101 virtual void GetReleaseTrack(const GetReleaseTrackCallback& callback) = 0;
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 // Returns an empty UpdateCheckCallback that does nothing.
110 static UpdateCheckCallback EmptyUpdateCheckCallback();
112 // Creates the instance.
113 static UpdateEngineClient* Create(DBusClientImplementationType type,
114 dbus::Bus* bus);
116 protected:
117 // Create() should be used instead.
118 UpdateEngineClient();
120 private:
121 DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient);
124 } // namespace chromeos
126 #endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_