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

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

Issue 2795603002: Add an update warning for downloading over mobile data (Closed)
Patch Set: Ignore this as I uploaded a new CL Created 3 years, 7 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
« no previous file with comments | « chromeos/dbus/update_engine_client.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (str == update_engine::kUpdateStatusVerifying) 62 if (str == update_engine::kUpdateStatusVerifying)
63 return UpdateEngineClient::UPDATE_STATUS_VERIFYING; 63 return UpdateEngineClient::UPDATE_STATUS_VERIFYING;
64 if (str == update_engine::kUpdateStatusFinalizing) 64 if (str == update_engine::kUpdateStatusFinalizing)
65 return UpdateEngineClient::UPDATE_STATUS_FINALIZING; 65 return UpdateEngineClient::UPDATE_STATUS_FINALIZING;
66 if (str == update_engine::kUpdateStatusUpdatedNeedReboot) 66 if (str == update_engine::kUpdateStatusUpdatedNeedReboot)
67 return UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; 67 return UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
68 if (str == update_engine::kUpdateStatusReportingErrorEvent) 68 if (str == update_engine::kUpdateStatusReportingErrorEvent)
69 return UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT; 69 return UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT;
70 if (str == update_engine::kUpdateStatusAttemptingRollback) 70 if (str == update_engine::kUpdateStatusAttemptingRollback)
71 return UpdateEngineClient::UPDATE_STATUS_ATTEMPTING_ROLLBACK; 71 return UpdateEngineClient::UPDATE_STATUS_ATTEMPTING_ROLLBACK;
72 if (str == update_engine::kUpdateStatusNeedPermissionToUpdate)
73 return UpdateEngineClient::UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE;
72 return UpdateEngineClient::UPDATE_STATUS_ERROR; 74 return UpdateEngineClient::UPDATE_STATUS_ERROR;
73 } 75 }
74 76
75 // Used in UpdateEngineClient::EmptyUpdateCheckCallback(). 77 // Used in UpdateEngineClient::EmptyUpdateCheckCallback().
76 void EmptyUpdateCheckCallbackBody( 78 void EmptyUpdateCheckCallbackBody(
77 UpdateEngineClient::UpdateCheckResult unused_result) { 79 UpdateEngineClient::UpdateCheckResult unused_result) {
78 } 80 }
79 81
80 bool IsValidChannel(const std::string& channel) { 82 bool IsValidChannel(const std::string& channel) {
81 return channel == kReleaseChannelDev || channel == kReleaseChannelBeta || 83 return channel == kReleaseChannelDev || channel == kReleaseChannelBeta ||
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 240
239 VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit") 241 VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit")
240 << " updates over cellular."; 242 << " updates over cellular.";
241 243
242 return update_engine_proxy_->CallMethod( 244 return update_engine_proxy_->CallMethod(
243 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 245 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
244 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission, 246 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission,
245 weak_ptr_factory_.GetWeakPtr(), callback)); 247 weak_ptr_factory_.GetWeakPtr(), callback));
246 } 248 }
247 249
250 void SetUpdateOverCellularTarget(const std::string& target_version,
251 int64_t target_size,
252 const SetTargetCallback& callback) override {
253 dbus::MethodCall method_call(update_engine::kUpdateEngineInterface,
254 update_engine::kSetUpdateOverCellularTarget);
255 dbus::MessageWriter writer(&method_call);
256 writer.AppendString(target_version);
257 writer.AppendInt64(target_size);
258
259 VLOG(1) << "Requesting UpdateEngine to allow updates over cellular "
260 << "to target version: \"" << target_version << "\" "
261 << "target_size: " << target_size;
262
263 return update_engine_proxy_->CallMethod(
264 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
265 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularTarget,
266 weak_ptr_factory_.GetWeakPtr(), callback));
267 }
268
248 protected: 269 protected:
249 void Init(dbus::Bus* bus) override { 270 void Init(dbus::Bus* bus) override {
250 update_engine_proxy_ = bus->GetObjectProxy( 271 update_engine_proxy_ = bus->GetObjectProxy(
251 update_engine::kUpdateEngineServiceName, 272 update_engine::kUpdateEngineServiceName,
252 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); 273 dbus::ObjectPath(update_engine::kUpdateEngineServicePath));
253 update_engine_proxy_->ConnectToSignal( 274 update_engine_proxy_->ConnectToSignal(
254 update_engine::kUpdateEngineInterface, 275 update_engine::kUpdateEngineInterface,
255 update_engine::kStatusUpdate, 276 update_engine::kStatusUpdate,
256 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, 277 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived,
257 weak_ptr_factory_.GetWeakPtr()), 278 weak_ptr_factory_.GetWeakPtr()),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 472 }
452 } else { 473 } else {
453 LOG(ERROR) << kFailureMessage << "No response from DBus."; 474 LOG(ERROR) << kFailureMessage << "No response from DBus.";
454 } 475 }
455 476
456 // Callback should run anyway, regardless of whether DBus call to enable 477 // Callback should run anyway, regardless of whether DBus call to enable
457 // update over cellular succeeded or failed. 478 // update over cellular succeeded or failed.
458 callback.Run(); 479 callback.Run();
459 } 480 }
460 481
482 // Called when a response for SetUpdateOverCellularPermission() is received.
483 void OnSetUpdateOverCellularTarget(const SetTargetCallback& callback,
484 dbus::Response* response) {
485 constexpr char kFailureMessage[] =
486 "Failed to set UpdateEngine to allow updates over cellular to a given "
487 "target: ";
488
489 if (response) {
490 switch (response->GetMessageType()) {
491 case dbus::Message::MESSAGE_ERROR:
492 LOG(ERROR) << kFailureMessage
493 << "DBus responded with error: " << response->ToString();
494 break;
495 case dbus::Message::MESSAGE_INVALID:
496 LOG(ERROR) << kFailureMessage
497 << "Invalid response from DBus (cannot be parsed).";
498 break;
499 default:
500 VLOG(1) << "Successfully set UpdateEngine to allow update over cell "
501 "to a given target.";
502 callback.Run(true);
503 return;
504 }
505 } else {
506 LOG(ERROR) << kFailureMessage << "No response from DBus.";
507 }
508 callback.Run(false);
509 }
510
461 // Called when a status update signal is received. 511 // Called when a status update signal is received.
462 void StatusUpdateReceived(dbus::Signal* signal) { 512 void StatusUpdateReceived(dbus::Signal* signal) {
463 VLOG(1) << "Status update signal received: " << signal->ToString(); 513 VLOG(1) << "Status update signal received: " << signal->ToString();
464 dbus::MessageReader reader(signal); 514 dbus::MessageReader reader(signal);
465 int64_t last_checked_time = 0; 515 int64_t last_checked_time = 0;
466 double progress = 0.0; 516 double progress = 0.0;
467 std::string current_operation; 517 std::string current_operation;
468 std::string new_version; 518 std::string new_version;
469 int64_t new_size = 0; 519 int64_t new_size = 0;
470 if (!(reader.PopInt64(&last_checked_time) && 520 if (!(reader.PopInt64(&last_checked_time) &&
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 605 }
556 606
557 void GetEolStatus(const GetEolStatusCallback& callback) override { 607 void GetEolStatus(const GetEolStatusCallback& callback) override {
558 callback.Run(update_engine::EndOfLifeStatus::kSupported); 608 callback.Run(update_engine::EndOfLifeStatus::kSupported);
559 } 609 }
560 610
561 void SetUpdateOverCellularPermission(bool allowed, 611 void SetUpdateOverCellularPermission(bool allowed,
562 const base::Closure& callback) override { 612 const base::Closure& callback) override {
563 callback.Run(); 613 callback.Run();
564 } 614 }
615 void SetUpdateOverCellularTarget(const std::string& target_version,
616 int64_t target_size,
617 const SetTargetCallback& callback) override {
618 // Do nothing.
619 }
565 620
566 std::string current_channel_; 621 std::string current_channel_;
567 std::string target_channel_; 622 std::string target_channel_;
568 }; 623 };
569 624
570 // The UpdateEngineClient implementation used on Linux desktop, which 625 // The UpdateEngineClient implementation used on Linux desktop, which
571 // tries to emulate real update engine client. 626 // tries to emulate real update engine client.
572 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { 627 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl {
573 public: 628 public:
574 UpdateEngineClientFakeImpl() : weak_factory_(this) { 629 UpdateEngineClientFakeImpl() : weak_factory_(this) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 private: 667 private:
613 void StateTransition() { 668 void StateTransition() {
614 UpdateStatusOperation next_status = UPDATE_STATUS_ERROR; 669 UpdateStatusOperation next_status = UPDATE_STATUS_ERROR;
615 int delay_ms = kStateTransitionDefaultDelayMs; 670 int delay_ms = kStateTransitionDefaultDelayMs;
616 switch (last_status_.status) { 671 switch (last_status_.status) {
617 case UPDATE_STATUS_ERROR: 672 case UPDATE_STATUS_ERROR:
618 case UPDATE_STATUS_IDLE: 673 case UPDATE_STATUS_IDLE:
619 case UPDATE_STATUS_UPDATED_NEED_REBOOT: 674 case UPDATE_STATUS_UPDATED_NEED_REBOOT:
620 case UPDATE_STATUS_REPORTING_ERROR_EVENT: 675 case UPDATE_STATUS_REPORTING_ERROR_EVENT:
621 case UPDATE_STATUS_ATTEMPTING_ROLLBACK: 676 case UPDATE_STATUS_ATTEMPTING_ROLLBACK:
677 case UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE:
622 return; 678 return;
623 case UPDATE_STATUS_CHECKING_FOR_UPDATE: 679 case UPDATE_STATUS_CHECKING_FOR_UPDATE:
624 next_status = UPDATE_STATUS_UPDATE_AVAILABLE; 680 next_status = UPDATE_STATUS_UPDATE_AVAILABLE;
625 break; 681 break;
626 case UPDATE_STATUS_UPDATE_AVAILABLE: 682 case UPDATE_STATUS_UPDATE_AVAILABLE:
627 next_status = UPDATE_STATUS_DOWNLOADING; 683 next_status = UPDATE_STATUS_DOWNLOADING;
628 break; 684 break;
629 case UPDATE_STATUS_DOWNLOADING: 685 case UPDATE_STATUS_DOWNLOADING:
630 if (last_status_.download_progress >= 1.0) { 686 if (last_status_.download_progress >= 1.0) {
631 next_status = UPDATE_STATUS_VERIFYING; 687 next_status = UPDATE_STATUS_VERIFYING;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 const char** cix = std::find( 750 const char** cix = std::find(
695 kReleaseChannelsList, 751 kReleaseChannelsList,
696 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel); 752 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel);
697 const char** tix = std::find( 753 const char** tix = std::find(
698 kReleaseChannelsList, 754 kReleaseChannelsList,
699 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel); 755 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel);
700 return tix > cix; 756 return tix > cix;
701 } 757 }
702 758
703 } // namespace chromeos 759 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/update_engine_client.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698