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

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

Issue 2694923005: Appropriate handling for Cellular First devices. (Closed)
Patch Set: made some changes 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 28 matching lines...) Expand all
39 const int kStateTransitionDefaultDelayMs = 3000; 39 const int kStateTransitionDefaultDelayMs = 3000;
40 40
41 // Delay between successive notifications about downloading progress 41 // Delay between successive notifications about downloading progress
42 // during fake AU. 42 // during fake AU.
43 const int kStateTransitionDownloadingDelayMs = 250; 43 const int kStateTransitionDownloadingDelayMs = 250;
44 44
45 // Size of parts of a "new" image which are downloaded each 45 // Size of parts of a "new" image which are downloaded each
46 // |kStateTransitionDownloadingDelayMs| during fake AU. 46 // |kStateTransitionDownloadingDelayMs| during fake AU.
47 const int64_t kDownloadSizeDelta = 1 << 19; 47 const int64_t kDownloadSizeDelta = 1 << 19;
48 48
49 // String which begins failure messages in SetUpdateOverCellularPermission.
50 constexpr char kFailureMessageStub[] =
51 "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.
52
49 // Returns UPDATE_STATUS_ERROR on error. 53 // Returns UPDATE_STATUS_ERROR on error.
50 UpdateEngineClient::UpdateStatusOperation UpdateStatusFromString( 54 UpdateEngineClient::UpdateStatusOperation UpdateStatusFromString(
51 const std::string& str) { 55 const std::string& str) {
52 VLOG(1) << "UpdateStatusFromString got " << str << " as input."; 56 VLOG(1) << "UpdateStatusFromString got " << str << " as input.";
53 if (str == update_engine::kUpdateStatusIdle) 57 if (str == update_engine::kUpdateStatusIdle)
54 return UpdateEngineClient::UPDATE_STATUS_IDLE; 58 return UpdateEngineClient::UPDATE_STATUS_IDLE;
55 if (str == update_engine::kUpdateStatusCheckingForUpdate) 59 if (str == update_engine::kUpdateStatusCheckingForUpdate)
56 return UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE; 60 return UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE;
57 if (str == update_engine::kUpdateStatusUpdateAvailable) 61 if (str == update_engine::kUpdateStatusUpdateAvailable)
58 return UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE; 62 return UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 dbus::MethodCall method_call(update_engine::kUpdateEngineInterface, 215 dbus::MethodCall method_call(update_engine::kUpdateEngineInterface,
212 update_engine::kGetEolStatus); 216 update_engine::kGetEolStatus);
213 217
214 VLOG(1) << "Requesting to get end of life status"; 218 VLOG(1) << "Requesting to get end of life status";
215 update_engine_proxy_->CallMethod( 219 update_engine_proxy_->CallMethod(
216 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 220 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
217 base::Bind(&UpdateEngineClientImpl::OnGetEolStatus, 221 base::Bind(&UpdateEngineClientImpl::OnGetEolStatus,
218 weak_ptr_factory_.GetWeakPtr(), callback)); 222 weak_ptr_factory_.GetWeakPtr(), callback));
219 } 223 }
220 224
225 void SetUpdateOverCellularPermission(bool allowed,
226 const base::Closure& callback) override {
227 dbus::MethodCall method_call(
228 update_engine::kUpdateEngineInterface,
229 update_engine::kSetUpdateOverCellularPermission);
230 dbus::MessageWriter writer(&method_call);
231 writer.AppendBool(allowed);
232
233 VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit")
234 << " updates over cellular.";
235
236 return update_engine_proxy_->CallMethod(
237 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
238 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission,
239 weak_ptr_factory_.GetWeakPtr(), callback));
240 }
241
221 protected: 242 protected:
222 void Init(dbus::Bus* bus) override { 243 void Init(dbus::Bus* bus) override {
223 update_engine_proxy_ = bus->GetObjectProxy( 244 update_engine_proxy_ = bus->GetObjectProxy(
224 update_engine::kUpdateEngineServiceName, 245 update_engine::kUpdateEngineServiceName,
225 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); 246 dbus::ObjectPath(update_engine::kUpdateEngineServicePath));
226 update_engine_proxy_->ConnectToSignal( 247 update_engine_proxy_->ConnectToSignal(
227 update_engine::kUpdateEngineInterface, 248 update_engine::kUpdateEngineInterface,
228 update_engine::kStatusUpdate, 249 update_engine::kStatusUpdate,
229 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, 250 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived,
230 weak_ptr_factory_.GetWeakPtr()), 251 weak_ptr_factory_.GetWeakPtr()),
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 status < update_engine::EndOfLifeStatus::kSupported) { 408 status < update_engine::EndOfLifeStatus::kSupported) {
388 LOG(ERROR) << "Incorrect status value: " << status; 409 LOG(ERROR) << "Incorrect status value: " << status;
389 callback.Run(update_engine::EndOfLifeStatus::kSupported); 410 callback.Run(update_engine::EndOfLifeStatus::kSupported);
390 return; 411 return;
391 } 412 }
392 413
393 VLOG(1) << "Eol status received: " << status; 414 VLOG(1) << "Eol status received: " << status;
394 callback.Run(static_cast<update_engine::EndOfLifeStatus>(status)); 415 callback.Run(static_cast<update_engine::EndOfLifeStatus>(status));
395 } 416 }
396 417
418 // Called when a response for SetUpdateOverCellularPermission() is received.
419 void OnSetUpdateOverCellularPermission(const base::Closure& callback,
420 dbus::Response* response) {
421 if (response) {
422 switch (response->GetMessageType()) {
423 case dbus::Message::MESSAGE_ERROR:
424 LOG(ERROR) << kFailureMessageStub
425 << "DBus responded with error: " << response->ToString();
426 break;
427 case dbus::Message::MESSAGE_INVALID:
428 LOG(ERROR) << kFailureMessageStub
429 << "Invalid response from DBus (cannot be parsed).";
430 break;
431 default:
432 VLOG(1) << "Successfully set UpdateEngine to allow update over cell.";
433 break;
434 }
435 } else {
436 LOG(ERROR) << kFailureMessageStub << "No response from DBus.";
437 }
438
439 // Callback should run anyway, regardless of whether DBus call to enable
440 // update over cellular succeeded or failed.
441 callback.Run();
442 }
443
397 // Called when a status update signal is received. 444 // Called when a status update signal is received.
398 void StatusUpdateReceived(dbus::Signal* signal) { 445 void StatusUpdateReceived(dbus::Signal* signal) {
399 VLOG(1) << "Status update signal received: " << signal->ToString(); 446 VLOG(1) << "Status update signal received: " << signal->ToString();
400 dbus::MessageReader reader(signal); 447 dbus::MessageReader reader(signal);
401 int64_t last_checked_time = 0; 448 int64_t last_checked_time = 0;
402 double progress = 0.0; 449 double progress = 0.0;
403 std::string current_operation; 450 std::string current_operation;
404 std::string new_version; 451 std::string new_version;
405 int64_t new_size = 0; 452 int64_t new_size = 0;
406 if (!(reader.PopInt64(&last_checked_time) && 453 if (!(reader.PopInt64(&last_checked_time) &&
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if (get_current_channel) 527 if (get_current_channel)
481 callback.Run(current_channel_); 528 callback.Run(current_channel_);
482 else 529 else
483 callback.Run(target_channel_); 530 callback.Run(target_channel_);
484 } 531 }
485 532
486 void GetEolStatus(const GetEolStatusCallback& callback) override { 533 void GetEolStatus(const GetEolStatusCallback& callback) override {
487 callback.Run(update_engine::EndOfLifeStatus::kSupported); 534 callback.Run(update_engine::EndOfLifeStatus::kSupported);
488 } 535 }
489 536
537 void SetUpdateOverCellularPermission(bool allowed,
538 const base::Closure& callback) override {
539 callback.Run();
540 }
541
490 std::string current_channel_; 542 std::string current_channel_;
491 std::string target_channel_; 543 std::string target_channel_;
492 }; 544 };
493 545
494 // The UpdateEngineClient implementation used on Linux desktop, which 546 // The UpdateEngineClient implementation used on Linux desktop, which
495 // tries to emulate real update engine client. 547 // tries to emulate real update engine client.
496 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { 548 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl {
497 public: 549 public:
498 UpdateEngineClientFakeImpl() : weak_factory_(this) { 550 UpdateEngineClientFakeImpl() : weak_factory_(this) {
499 } 551 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 const char** cix = std::find( 670 const char** cix = std::find(
619 kReleaseChannelsList, 671 kReleaseChannelsList,
620 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel); 672 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel);
621 const char** tix = std::find( 673 const char** tix = std::find(
622 kReleaseChannelsList, 674 kReleaseChannelsList,
623 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel); 675 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel);
624 return tix > cix; 676 return tix > cix;
625 } 677 }
626 678
627 } // namespace chromeos 679 } // namespace chromeos
OLDNEW
« chrome/browser/ui/webui/help/help_utils_chromeos.cc ('K') | « chromeos/dbus/update_engine_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698