[email protected] | 85eafad | 2012-03-07 00:49:48 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 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, |
[email protected] | 85eafad | 2012-03-07 00:49:48 | [diff] [blame^] | 60 | UPDATE_RESULT_NOTIMPLEMENTED, |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | // Interface for observing changes from the update engine. |
| 64 | class Observer { |
| 65 | public: |
| 66 | // Called when the status is updated. |
| 67 | virtual void UpdateStatusChanged(const Status& status) {} |
| 68 | }; |
| 69 | |
| 70 | virtual ~UpdateEngineClient(); |
| 71 | |
| 72 | // Adds and removes the observer. |
| 73 | virtual void AddObserver(Observer* observer) = 0; |
| 74 | virtual void RemoveObserver(Observer* observer) = 0; |
| 75 | // Returns true if this object has the given observer. |
| 76 | virtual bool HasObserver(Observer* observer) = 0; |
| 77 | |
| 78 | // Called once RequestUpdateCheck() is complete. Takes one parameter: |
| 79 | // - UpdateCheckResult: the result of the update check. |
| 80 | typedef base::Callback<void(UpdateCheckResult)> UpdateCheckCallback; |
| 81 | |
| 82 | // Requests an update check and calls |callback| when completed. |
| 83 | virtual void RequestUpdateCheck(UpdateCheckCallback callback) = 0; |
| 84 | |
| 85 | // Reboots if update has been performed. |
| 86 | virtual void RebootAfterUpdate() = 0; |
| 87 | |
| 88 | // Requests to set the release track (channel). |track| should look like |
| 89 | // "beta-channel" or "dev-channel". |
| 90 | virtual void SetReleaseTrack(const std::string& track) = 0; |
| 91 | |
| 92 | // Called once GetReleaseTrack() is complete. Takes one parameter; |
| 93 | // - string: the release track name like "beta-channel". |
| 94 | typedef base::Callback<void(const std::string&)> GetReleaseTrackCallback; |
| 95 | |
| 96 | // Requests to get the release track and calls |callback| with the |
| 97 | // release track (channel). On error, calls |callback| with an empty |
| 98 | // string. |
| 99 | virtual void GetReleaseTrack(GetReleaseTrackCallback callback) = 0; |
| 100 | |
| 101 | // Returns the last status the object received from the update engine. |
| 102 | // |
| 103 | // Ideally, the D-Bus client should be state-less, but there are clients |
| 104 | // that need this information. |
| 105 | virtual Status GetLastStatus() = 0; |
| 106 | |
| 107 | // Returns an empty UpdateCheckCallback that does nothing. |
| 108 | static UpdateCheckCallback EmptyUpdateCheckCallback(); |
| 109 | |
| 110 | // Creates the instance. |
| 111 | static UpdateEngineClient* Create(dbus::Bus* bus); |
| 112 | |
| 113 | protected: |
| 114 | // Create() should be used instead. |
| 115 | UpdateEngineClient(); |
| 116 | |
| 117 | private: |
| 118 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); |
| 119 | }; |
| 120 | |
| 121 | } // namespace chromeos |
| 122 | |
| 123 | #endif // CHROME_BROWSER_CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |