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 d772d0074513b7cbf9ddf6cd6ab55430c37faf95..b10835c9232a2edd84ffcc10f64a570ac632df55 100644 |
| --- a/chromeos/dbus/update_engine_client.cc |
| +++ b/chromeos/dbus/update_engine_client.cc |
| @@ -46,6 +46,10 @@ const int kStateTransitionDownloadingDelayMs = 250; |
| // |kStateTransitionDownloadingDelayMs| during fake AU. |
| const int64_t kDownloadSizeDelta = 1 << 19; |
| +// String which begins failure messages in SetUpdateOverCellularPermission. |
| +constexpr char kFailureMessageStub[] = |
| + "Failed to set UpdateEngine to allow updates over cellular: "; |
|
xiyuan
2017/02/28 22:29:42
nit: you can define a const close to where they ar
kumarniranjan
2017/02/28 22:52:21
Done.
|
| + |
| // Returns UPDATE_STATUS_ERROR on error. |
| UpdateEngineClient::UpdateStatusOperation UpdateStatusFromString( |
| const std::string& str) { |
| @@ -218,6 +222,23 @@ class UpdateEngineClientImpl : public UpdateEngineClient { |
| weak_ptr_factory_.GetWeakPtr(), callback)); |
| } |
| + void SetUpdateOverCellularPermission(bool allowed, |
| + const base::Closure& callback) override { |
| + dbus::MethodCall method_call( |
| + update_engine::kUpdateEngineInterface, |
| + update_engine::kSetUpdateOverCellularPermission); |
| + dbus::MessageWriter writer(&method_call); |
| + writer.AppendBool(allowed); |
| + |
| + VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit") |
| + << " updates over cellular."; |
| + |
| + return update_engine_proxy_->CallMethod( |
| + &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| + base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| + } |
| + |
| protected: |
| void Init(dbus::Bus* bus) override { |
| update_engine_proxy_ = bus->GetObjectProxy( |
| @@ -394,6 +415,32 @@ class UpdateEngineClientImpl : public UpdateEngineClient { |
| callback.Run(static_cast<update_engine::EndOfLifeStatus>(status)); |
| } |
| + // Called when a response for SetUpdateOverCellularPermission() is received. |
| + void OnSetUpdateOverCellularPermission(const base::Closure& callback, |
| + dbus::Response* response) { |
| + if (response) { |
| + switch (response->GetMessageType()) { |
| + case dbus::Message::MESSAGE_ERROR: |
| + LOG(ERROR) << kFailureMessageStub |
| + << "DBus responded with error: " << response->ToString(); |
| + break; |
| + case dbus::Message::MESSAGE_INVALID: |
| + LOG(ERROR) << kFailureMessageStub |
| + << "Invalid response from DBus (cannot be parsed)."; |
| + break; |
| + default: |
| + VLOG(1) << "Successfully set UpdateEngine to allow update over cell."; |
| + break; |
| + } |
| + } else { |
| + LOG(ERROR) << kFailureMessageStub << "No response from DBus."; |
| + } |
| + |
| + // Callback should run anyway, regardless of whether DBus call to enable |
| + // update over cellular succeeded or failed. |
| + callback.Run(); |
| + } |
| + |
| // Called when a status update signal is received. |
| void StatusUpdateReceived(dbus::Signal* signal) { |
| VLOG(1) << "Status update signal received: " << signal->ToString(); |
| @@ -487,6 +534,11 @@ class UpdateEngineClientStubImpl : public UpdateEngineClient { |
| callback.Run(update_engine::EndOfLifeStatus::kSupported); |
| } |
| + void SetUpdateOverCellularPermission(bool allowed, |
| + const base::Closure& callback) override { |
| + callback.Run(); |
| + } |
| + |
| std::string current_channel_; |
| std::string target_channel_; |
| }; |