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 virtual ~UpdateEngineClient(); |
| 70 |
| 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; |
| 76 |
| 77 // Called once RequestUpdateCheck() is complete. Takes one parameter: |
| 78 // - UpdateCheckResult: the result of the update check. |
| 79 typedef base::Callback<void(UpdateCheckResult)> UpdateCheckCallback; |
| 80 |
| 81 // Requests an update check and calls |callback| when completed. |
| 82 virtual void RequestUpdateCheck(UpdateCheckCallback callback) = 0; |
| 83 |
| 84 // Reboots if update has been performed. |
| 85 virtual void RebootAfterUpdate() = 0; |
| 86 |
| 87 // Requests to set the release track (channel). |track| should look like |
| 88 // "beta-channel" or "dev-channel". |
| 89 virtual void SetReleaseTrack(const std::string& track) = 0; |
| 90 |
| 91 // Called once GetReleaseTrack() is complete. Takes one parameter; |
| 92 // - string: the release track name like "beta-channel". |
| 93 typedef base::Callback<void(const std::string&)> GetReleaseTrackCallback; |
| 94 |
| 95 // Requests to get the release track and calls |callback| with the |
| 96 // release track (channel). On error, calls |callback| with an empty |
| 97 // string. |
| 98 virtual void GetReleaseTrack(GetReleaseTrackCallback callback) = 0; |
| 99 |
| 100 // Returns the last status the object received from the update engine. |
| 101 // |
| 102 // Ideally, the D-Bus client should be state-less, but there are clients |
| 103 // that need this information. |
| 104 virtual Status GetLastStatus() = 0; |
| 105 |
| 106 // Returns an empty UpdateCheckCallback that does nothing. |
| 107 static UpdateCheckCallback EmptyUpdateCheckCallback(); |
| 108 |
| 109 // Creates the instance. |
| 110 static UpdateEngineClient* Create(dbus::Bus* bus); |
| 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 |