Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chromeos/dbus/update_engine_client.cc

Issue 2694923005: Appropriate handling for Cellular First devices. (Closed)
Patch Set: now with tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/update_engine_client.h" 5 #include "chromeos/dbus/update_engine_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 dbus::MethodCall method_call(update_engine::kUpdateEngineInterface, 211 dbus::MethodCall method_call(update_engine::kUpdateEngineInterface,
212 update_engine::kGetEolStatus); 212 update_engine::kGetEolStatus);
213 213
214 VLOG(1) << "Requesting to get end of life status"; 214 VLOG(1) << "Requesting to get end of life status";
215 update_engine_proxy_->CallMethod( 215 update_engine_proxy_->CallMethod(
216 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 216 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
217 base::Bind(&UpdateEngineClientImpl::OnGetEolStatus, 217 base::Bind(&UpdateEngineClientImpl::OnGetEolStatus,
218 weak_ptr_factory_.GetWeakPtr(), callback)); 218 weak_ptr_factory_.GetWeakPtr(), callback));
219 } 219 }
220 220
221 void SetUpdateOverCellularPermission(bool allowed,
222 const base::Closure& callback) override {
223 dbus::MethodCall method_call(
224 update_engine::kUpdateEngineInterface,
225 update_engine::kSetUpdateOverCellularPermission);
226 dbus::MessageWriter writer(&method_call);
227 writer.AppendBool(allowed);
228
229 VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit")
230 << " updates over cellular.";
231
232 return update_engine_proxy_->CallMethod(
233 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
234 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission,
235 weak_ptr_factory_.GetWeakPtr(), callback));
236 }
237
221 protected: 238 protected:
222 void Init(dbus::Bus* bus) override { 239 void Init(dbus::Bus* bus) override {
223 update_engine_proxy_ = bus->GetObjectProxy( 240 update_engine_proxy_ = bus->GetObjectProxy(
224 update_engine::kUpdateEngineServiceName, 241 update_engine::kUpdateEngineServiceName,
225 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); 242 dbus::ObjectPath(update_engine::kUpdateEngineServicePath));
226 update_engine_proxy_->ConnectToSignal( 243 update_engine_proxy_->ConnectToSignal(
227 update_engine::kUpdateEngineInterface, 244 update_engine::kUpdateEngineInterface,
228 update_engine::kStatusUpdate, 245 update_engine::kStatusUpdate,
229 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, 246 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived,
230 weak_ptr_factory_.GetWeakPtr()), 247 weak_ptr_factory_.GetWeakPtr()),
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 status < update_engine::EndOfLifeStatus::kSupported) { 404 status < update_engine::EndOfLifeStatus::kSupported) {
388 LOG(ERROR) << "Incorrect status value: " << status; 405 LOG(ERROR) << "Incorrect status value: " << status;
389 callback.Run(update_engine::EndOfLifeStatus::kSupported); 406 callback.Run(update_engine::EndOfLifeStatus::kSupported);
390 return; 407 return;
391 } 408 }
392 409
393 VLOG(1) << "Eol status received: " << status; 410 VLOG(1) << "Eol status received: " << status;
394 callback.Run(static_cast<update_engine::EndOfLifeStatus>(status)); 411 callback.Run(static_cast<update_engine::EndOfLifeStatus>(status));
395 } 412 }
396 413
414 // Called when a response for SetUpdateOverCellularPermission() is received.
415 void OnSetUpdateOverCellularPermission(const base::Closure& callback,
416 dbus::Response* response) {
417 std::string failure_message_stub =
xiyuan 2017/02/28 20:26:41 nit: std::string failure_message_stub = -> constex
kumarniranjan 2017/02/28 21:49:34 Done.
418 "Failed to set UpdateEngine to allow updates over cellular: ";
419
420 if (response) {
421 switch (response->GetMessageType()) {
422 case dbus::Message::MESSAGE_ERROR:
423 LOG(ERROR) << failure_message_stub
424 << "DBus responded with error: " << response->ToString();
425 break;
426 case dbus::Message::MESSAGE_INVALID:
427 LOG(ERROR) << failure_message_stub
428 << "Invalid response from DBus (cannot be parsed).";
429 break;
430 default:
431 VLOG(1) << "Successfully set UpdateEngine to allow update over cell.";
432 break;
433 }
434 } else {
435 LOG(ERROR) << failure_message_stub << "No response from DBus.";
436 }
437
438 // Callback should run anyway, regardless of whether DBus call to enable
439 // update over cellular succeeded or failed.
440 callback.Run();
441 }
442
397 // Called when a status update signal is received. 443 // Called when a status update signal is received.
398 void StatusUpdateReceived(dbus::Signal* signal) { 444 void StatusUpdateReceived(dbus::Signal* signal) {
399 VLOG(1) << "Status update signal received: " << signal->ToString(); 445 VLOG(1) << "Status update signal received: " << signal->ToString();
400 dbus::MessageReader reader(signal); 446 dbus::MessageReader reader(signal);
401 int64_t last_checked_time = 0; 447 int64_t last_checked_time = 0;
402 double progress = 0.0; 448 double progress = 0.0;
403 std::string current_operation; 449 std::string current_operation;
404 std::string new_version; 450 std::string new_version;
405 int64_t new_size = 0; 451 int64_t new_size = 0;
406 if (!(reader.PopInt64(&last_checked_time) && 452 if (!(reader.PopInt64(&last_checked_time) &&
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if (get_current_channel) 526 if (get_current_channel)
481 callback.Run(current_channel_); 527 callback.Run(current_channel_);
482 else 528 else
483 callback.Run(target_channel_); 529 callback.Run(target_channel_);
484 } 530 }
485 531
486 void GetEolStatus(const GetEolStatusCallback& callback) override { 532 void GetEolStatus(const GetEolStatusCallback& callback) override {
487 callback.Run(update_engine::EndOfLifeStatus::kSupported); 533 callback.Run(update_engine::EndOfLifeStatus::kSupported);
488 } 534 }
489 535
536 void SetUpdateOverCellularPermission(bool allowed,
537 const base::Closure& callback) override {
538 callback.Run();
539 }
540
490 std::string current_channel_; 541 std::string current_channel_;
491 std::string target_channel_; 542 std::string target_channel_;
492 }; 543 };
493 544
494 // The UpdateEngineClient implementation used on Linux desktop, which 545 // The UpdateEngineClient implementation used on Linux desktop, which
495 // tries to emulate real update engine client. 546 // tries to emulate real update engine client.
496 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { 547 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl {
497 public: 548 public:
498 UpdateEngineClientFakeImpl() : weak_factory_(this) { 549 UpdateEngineClientFakeImpl() : weak_factory_(this) {
499 } 550 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 const char** cix = std::find( 669 const char** cix = std::find(
619 kReleaseChannelsList, 670 kReleaseChannelsList,
620 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel); 671 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel);
621 const char** tix = std::find( 672 const char** tix = std::find(
622 kReleaseChannelsList, 673 kReleaseChannelsList,
623 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel); 674 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel);
624 return tix > cix; 675 return tix > cix;
625 } 676 }
626 677
627 } // namespace chromeos 678 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698