OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/observer_list.h" | |
10 | |
11 #include <string> | |
12 | |
13 namespace dbus { | |
14 class Bus; | |
15 } // namespace | |
16 | |
17 namespace chromeos { | |
18 | |
19 // UpdateEngineClient is used to communicate with the update engine. | |
20 class UpdateEngineClient { | |
21 public: | |
22 // Edges for state machine | |
23 // IDLE->CHECKING_FOR_UPDATE | |
24 // CHECKING_FOR_UPDATE->IDLE | |
25 // CHECKING_FOR_UPDATE->UPDATE_AVAILABLE | |
26 // ... | |
27 // FINALIZING->UPDATE_NEED_REBOOT | |
28 // Any state can transition to REPORTING_ERROR_EVENT and then on to IDLE. | |
29 enum UpdateStatusOperation { | |
30 UPDATE_STATUS_ERROR = -1, | |
31 UPDATE_STATUS_IDLE = 0, | |
32 UPDATE_STATUS_CHECKING_FOR_UPDATE, | |
33 UPDATE_STATUS_UPDATE_AVAILABLE, | |
34 UPDATE_STATUS_DOWNLOADING, | |
35 UPDATE_STATUS_VERIFYING, | |
36 UPDATE_STATUS_FINALIZING, | |
37 UPDATE_STATUS_UPDATED_NEED_REBOOT, | |
38 UPDATE_STATUS_REPORTING_ERROR_EVENT | |
39 }; | |
40 | |
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) { | |
47 } | |
48 | |
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. | |
54 }; | |
55 | |
56 // The result code used for RequestUpdateCheck(). | |
57 enum UpdateCheckResult { | |
58 UPDATE_RESULT_SUCCESS, | |
59 UPDATE_RESULT_FAILED, | |
60 }; | |
61 | |
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) {} | |
67 }; | |
68 | |
69 // Adds and removes the observer. | |
70 virtual void AddObserver(Observer* observer) = 0; | |
71 virtual void RemoveObserver(Observer* observer) = 0; | |
72 // Returns true if this object has the given observer. | |
73 virtual bool HasObserver(Observer* observer) = 0; | |
74 | |
75 // Called once RequestUpdateCheck() is complete. Takes one parameter: | |
76 // - UpdateCheckResult: the result of the update check. | |
77 typedef base::Callback<void(UpdateCheckResult)> UpdateCheckCallback; | |
78 | |
79 // Requests an update check and calls |callback| when completed. | |
80 virtual void RequestUpdateCheck(UpdateCheckCallback callback) = 0; | |
81 | |
82 // Reboots if update has been performed. | |
83 virtual void RebootAfterUpdate() = 0; | |
84 | |
85 // Requests to set the release track (channel). |track| should look like | |
86 // "beta-channel" and "dev-channel". | |
stevenjb
2011/11/16 01:14:29
nit: s/and/or
satorux1
2011/11/17 02:58:05
Done.
| |
87 virtual void SetReleaseTrack(const std::string& track) = 0; | |
88 | |
89 // Called once GetReleaseTrack() is complete. Takes one parameter; | |
90 // - string: the release track name like "beta-channel". | |
91 typedef base::Callback<void(const std::string&)> GetReleaseTrackCallback; | |
92 | |
93 // Requests to get the release trackand calls |callback| with the | |
stevenjb
2011/11/16 01:14:29
nit: "track and"
satorux1
2011/11/17 02:58:05
Done.
| |
94 // release track (channel). On error, calls |callback| with an empty | |
95 // string. | |
96 virtual void GetReleaseTrack(GetReleaseTrackCallback callback) = 0; | |
97 | |
98 // Returns the last status the object received from the update engine. | |
99 // | |
100 // Ideally, the D-Bus client shoudl be state-less, but there are clients | |
stevenjb
2011/11/16 01:14:29
nit: should
satorux1
2011/11/17 02:58:05
Done.
| |
101 // that need this information. | |
102 virtual Status GetLastStatus() = 0; | |
103 | |
104 // Returns an empty UpdateCheckCallback that does nothing. | |
105 static UpdateCheckCallback EmptyUpdateCheckCallback(); | |
106 | |
107 // Creates the instance. | |
108 static UpdateEngineClient* Create(dbus::Bus* bus); | |
109 | |
110 virtual ~UpdateEngineClient(); | |
stevenjb
2011/11/16 01:14:29
nit: should be first function, not last (further a
satorux1
2011/11/17 02:58:05
Done.
| |
111 | |
112 protected: | |
113 // Create() should be used instead. | |
114 UpdateEngineClient(); | |
115 | |
116 private: | |
117 DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); | |
118 }; | |
119 | |
120 } // namespace chromeos | |
121 | |
122 #endif // CHROME_BROWSER_CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ | |
OLD | NEW |