Chromium Code Reviews| Index: chromeos/dbus/update_engine_client.cc |
| diff --git a/chromeos/dbus/update_engine_client.cc b/chromeos/dbus/update_engine_client.cc |
| index d13ddcaeb46dfa48a75efa249b1d8c1df0ab9032..f33c4ffd78dfc17717c390495552128904dc1de4 100644 |
| --- a/chromeos/dbus/update_engine_client.cc |
| +++ b/chromeos/dbus/update_engine_client.cc |
| @@ -14,8 +14,13 @@ |
| #include "third_party/cros_system_api/dbus/service_constants.h" |
| namespace chromeos { |
| + |
| namespace { |
| +const char kReleaseChannelDev[] = "dev-channel"; |
| +const char kReleaseChannelBeta[] = "beta-channel"; |
| +const char kReleaseChannelStable[] = "stable-channel"; |
| + |
| // Returns UPDATE_STATUS_ERROR on error. |
| UpdateEngineClient::UpdateStatusOperation UpdateStatusFromString( |
| const std::string& str) { |
| @@ -43,6 +48,12 @@ void EmptyUpdateCheckCallbackBody( |
| UpdateEngineClient::UpdateCheckResult unused_result) { |
| } |
| +bool IsValidChannel(const std::string& channel) { |
| + return channel == kReleaseChannelDev || |
| + channel == kReleaseChannelBeta || |
| + channel == kReleaseChannelStable; |
| +} |
| + |
| } // namespace |
| // The UpdateEngineClient implementation used in production. |
| @@ -162,6 +173,50 @@ class UpdateEngineClientImpl : public UpdateEngineClient { |
| return last_status_; |
| } |
| + // UpdateEngineClient override. |
| + virtual void SetChannel(const std::string& target_channel, |
| + bool is_powerwash_allowed) OVERRIDE { |
| + if (!IsValidChannel(target_channel)) { |
| + LOG(ERROR) << "Invalid channel name: " << target_channel; |
| + return; |
| + } |
| + |
| + dbus::MethodCall method_call( |
| + update_engine::kUpdateEngineInterface, |
| + update_engine::kSetChannel); |
| + dbus::MessageWriter writer(&method_call); |
| + writer.AppendString(target_channel); |
| + writer.AppendBool(is_powerwash_allowed); |
| + |
| + VLOG(1) << "Requesting to set channel: " |
| + << "target_channel=" << target_channel << ", " |
| + << "is_powerwash_allowed=" << is_powerwash_allowed; |
| + update_engine_proxy_->CallMethod( |
| + &method_call, |
| + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| + base::Bind(&UpdateEngineClientImpl::OnSetChannel, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| + |
| + // UpdateEngineClient override. |
| + virtual void GetChannel(bool get_current_channel, |
| + const GetChannelCallback& callback) OVERRIDE { |
| + dbus::MethodCall method_call( |
| + update_engine::kUpdateEngineInterface, |
| + update_engine::kGetChannel); |
| + dbus::MessageWriter writer(&method_call); |
| + writer.AppendBool(get_current_channel); |
| + |
| + VLOG(1) << "Requesting to get channel, get_current_channel=" |
| + << get_current_channel; |
| + update_engine_proxy_->CallMethod( |
| + &method_call, |
| + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| + base::Bind(&UpdateEngineClientImpl::OnGetChannel, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + callback)); |
| + } |
| + |
| private: |
| void GetUpdateEngineStatus() { |
| dbus::MethodCall method_call( |
| @@ -251,6 +306,34 @@ class UpdateEngineClientImpl : public UpdateEngineClient { |
| LOG(ERROR) << "GetStatus request failed with error: " << error->ToString(); |
| } |
| + // Called when a response for SetReleaseTrack() is received. |
| + void OnSetChannel(dbus::Response* response) { |
| + if (!response) { |
| + LOG(ERROR) << "Failed to request setting channel"; |
| + return; |
| + } |
| + LOG(ERROR) << "Succeeded to set channel"; |
|
satorux1
2013/06/24 17:21:12
This is not an error. Make it a DVLOG?
ygorshenin1
2013/06/24 17:50:35
Renamed to VLOG() for consistency.
On 2013/06/24
|
| + } |
| + |
| + // Called when a response for GetChannel() is received. |
| + void OnGetChannel(const GetReleaseTrackCallback& callback, |
| + dbus::Response* response) { |
| + if (!response) { |
| + LOG(ERROR) << "Failed to request getting channel"; |
| + callback.Run(""); |
| + return; |
| + } |
| + dbus::MessageReader reader(response); |
| + std::string channel; |
| + if (!reader.PopString(&channel)) { |
| + LOG(ERROR) << "Incorrect response: " << response->ToString(); |
| + callback.Run(""); |
| + return; |
| + } |
| + VLOG(1) << "The channel received: " << channel; |
|
satorux1
2013/06/24 17:21:12
DVLOG? We usually prefer DVLOG over VLOG, as the l
ygorshenin1
2013/06/24 17:50:35
Done.
|
| + callback.Run(channel); |
| + } |
| + |
| // Called when a status update signal is received. |
| void StatusUpdateReceived(dbus::Signal* signal) { |
| VLOG(1) << "Status update signal received: " << signal->ToString(); |
| @@ -318,6 +401,18 @@ class UpdateEngineClientStubImpl : public UpdateEngineClient { |
| callback.Run("beta-channel"); |
| } |
| virtual Status GetLastStatus() OVERRIDE { return Status(); } |
| + virtual void SetChannel(const std::string& target_channel, |
| + bool is_powerwash_allowed) OVERRIDE { |
| + LOG(INFO) << "Requesting to set channel: " |
| + << "target_channel=" << target_channel << ", " |
| + << "is_powerwash_allowed=" << is_powerwash_allowed; |
| + } |
| + virtual void GetChannel(bool get_current_channel, |
| + const GetChannelCallback& callback) OVERRIDE { |
| + LOG(INFO) << "Requesting to get channel, get_current_channel=" |
| + << get_current_channel; |
| + callback.Run("beta-channel"); |
| + } |
| }; |
| UpdateEngineClient::UpdateEngineClient() { |