[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 | |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 5 | #ifndef CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |
| 6 | #define CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 7 | |
ygorshenin | 9903cf4 | 2014-10-07 06:47:11 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 10 | #include "base/callback.h" |
| 11 | #include "base/observer_list.h" |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 12 | #include "chromeos/chromeos_export.h" |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 13 | #include "chromeos/dbus/dbus_client.h" |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 14 | #include "chromeos/dbus/dbus_client_implementation_type.h" |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 15 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 16 | namespace chromeos { |
| 17 | |
| 18 | // UpdateEngineClient is used to communicate with the update engine. |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 19 | class CHROMEOS_EXPORT UpdateEngineClient : public DBusClient { |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 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, |
[email protected] | da15e07 | 2014-06-03 13:24:37 | [diff] [blame] | 37 | UPDATE_STATUS_REPORTING_ERROR_EVENT, |
| 38 | UPDATE_STATUS_ATTEMPTING_ROLLBACK |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 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: |
Mitsuru Oshima | c01e405 | 2014-10-24 19:26:25 | [diff] [blame^] | 66 | virtual ~Observer() {} |
| 67 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 68 | // Called when the status is updated. |
| 69 | virtual void UpdateStatusChanged(const Status& status) {} |
| 70 | }; |
| 71 | |
| 72 | virtual ~UpdateEngineClient(); |
| 73 | |
| 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; |
| 79 | |
| 80 | // Called once RequestUpdateCheck() is complete. Takes one parameter: |
| 81 | // - UpdateCheckResult: the result of the update check. |
| 82 | typedef base::Callback<void(UpdateCheckResult)> UpdateCheckCallback; |
| 83 | |
| 84 | // Requests an update check and calls |callback| when completed. |
[email protected] | 4a404e5 | 2012-04-11 02:25:35 | [diff] [blame] | 85 | virtual void RequestUpdateCheck(const UpdateCheckCallback& callback) = 0; |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 86 | |
| 87 | // Reboots if update has been performed. |
| 88 | virtual void RebootAfterUpdate() = 0; |
| 89 | |
[email protected] | 81c8ad4 | 2014-03-21 13:06:25 | [diff] [blame] | 90 | // Starts Rollback. |
| 91 | virtual void Rollback() = 0; |
| 92 | |
| 93 | // Called once CanRollbackCheck() is complete. Takes one parameter: |
| 94 | // - bool: the result of the rollback availability check. |
| 95 | typedef base::Callback<void(bool can_rollback)> RollbackCheckCallback; |
| 96 | |
| 97 | // Checks if Rollback is available and calls |callback| when completed. |
| 98 | virtual void CanRollbackCheck( |
| 99 | const RollbackCheckCallback& callback) = 0; |
| 100 | |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 101 | // Called once GetChannel() is complete. Takes one parameter; |
| 102 | // - string: the channel name like "beta-channel". |
| 103 | typedef base::Callback<void(const std::string& channel_name)> |
| 104 | GetChannelCallback; |
| 105 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 106 | // Returns the last status the object received from the update engine. |
| 107 | // |
| 108 | // Ideally, the D-Bus client should be state-less, but there are clients |
| 109 | // that need this information. |
| 110 | virtual Status GetLastStatus() = 0; |
| 111 | |
[email protected] | f1ed3ad | 2013-06-26 10:10:00 | [diff] [blame] | 112 | // Changes the current channel of the device to the target |
| 113 | // channel. If the target channel is a less stable channel than the |
| 114 | // current channel, then the channel change happens immediately (at |
| 115 | // the next update check). If the target channel is a more stable |
| 116 | // channel, then if |is_powerwash_allowed| is set to true, then also |
| 117 | // the change happens immediately but with a powerwash if |
| 118 | // required. Otherwise, the change takes effect eventually (when the |
| 119 | // version on the target channel goes above the version number of |
| 120 | // what the device currently has). |target_channel| should look like |
| 121 | // "dev-channel", "beta-channel" or "stable-channel". |
| 122 | virtual void SetChannel(const std::string& target_channel, |
| 123 | bool is_powerwash_allowed) = 0; |
| 124 | |
| 125 | // If |get_current_channel| is set to true, calls |callback| with |
| 126 | // the name of the channel that the device is currently |
| 127 | // on. Otherwise, it calls it with the name of the channel the |
| 128 | // device is supposed to be (in case of a pending channel |
| 129 | // change). On error, calls |callback| with an empty string. |
| 130 | virtual void GetChannel(bool get_current_channel, |
| 131 | const GetChannelCallback& callback) = 0; |
| 132 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 133 | // Returns an empty UpdateCheckCallback that does nothing. |
| 134 | static UpdateCheckCallback EmptyUpdateCheckCallback(); |
| 135 | |
| 136 | // Creates the instance. |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 137 | static UpdateEngineClient* Create(DBusClientImplementationType type); |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 138 | |
ygorshenin | 9903cf4 | 2014-10-07 06:47:11 | [diff] [blame] | 139 | // Returns true if |target_channel| is more stable than |current_channel|. |
| 140 | static bool IsTargetChannelMoreStable(const std::string& current_channel, |
| 141 | const std::string& target_channel); |
| 142 | |
[email protected] | b107dc0 | 2011-11-17 07:39:53 | [diff] [blame] | 143 | protected: |
| 144 | // Create() should be used instead. |
| 145 | UpdateEngineClient(); |
| 146 | |
| 147 | private: |
| 148 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); |
| 149 | }; |
| 150 | |
| 151 | } // namespace chromeos |
| 152 | |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 153 | #endif // CHROMEOS_DBUS_UPDATE_ENGINE_CLIENT_H_ |