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

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

Issue 470803008: chromeos: Avoid a startup crash when powerd isn't running. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | no next file » | 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/power_manager_client.h" 5 #include "chromeos/dbus/power_manager_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 431 }
432 dbus::MessageReader reader(response); 432 dbus::MessageReader reader(response);
433 double percent = 0.0; 433 double percent = 0.0;
434 if (!reader.PopDouble(&percent)) 434 if (!reader.PopDouble(&percent))
435 LOG(ERROR) << "Error reading response from powerd: " 435 LOG(ERROR) << "Error reading response from powerd: "
436 << response->ToString(); 436 << response->ToString();
437 callback.Run(percent); 437 callback.Run(percent);
438 } 438 }
439 439
440 void HandleRegisterSuspendDelayReply(bool dark_suspend, 440 void HandleRegisterSuspendDelayReply(bool dark_suspend,
441 const std::string& method_name,
441 dbus::Response* response) { 442 dbus::Response* response) {
442 if (!response) { 443 if (!response) {
443 LOG(ERROR) << "Error calling " << response->GetMember(); 444 LOG(ERROR) << "Error calling " << method_name;
444 return; 445 return;
445 } 446 }
446 447
447 dbus::MessageReader reader(response); 448 dbus::MessageReader reader(response);
448 power_manager::RegisterSuspendDelayReply protobuf; 449 power_manager::RegisterSuspendDelayReply protobuf;
449 if (!reader.PopArrayOfBytesAsProto(&protobuf)) { 450 if (!reader.PopArrayOfBytesAsProto(&protobuf)) {
450 LOG(ERROR) << "Unable to parse reply from " << response->GetMember(); 451 LOG(ERROR) << "Unable to parse reply from " << method_name;
451 return; 452 return;
452 } 453 }
453 454
454 if (dark_suspend) { 455 if (dark_suspend) {
455 dark_suspend_delay_id_ = protobuf.delay_id(); 456 dark_suspend_delay_id_ = protobuf.delay_id();
456 has_dark_suspend_delay_id_ = true; 457 has_dark_suspend_delay_id_ = true;
457 VLOG(1) << "Registered dark suspend delay " << dark_suspend_delay_id_; 458 VLOG(1) << "Registered dark suspend delay " << dark_suspend_delay_id_;
458 } else { 459 } else {
459 suspend_delay_id_ = protobuf.delay_id(); 460 suspend_delay_id_ = protobuf.delay_id();
460 has_suspend_delay_id_ = true; 461 has_suspend_delay_id_ = true;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 613
613 power_manager::RegisterSuspendDelayRequest protobuf_request; 614 power_manager::RegisterSuspendDelayRequest protobuf_request;
614 base::TimeDelta timeout = 615 base::TimeDelta timeout =
615 base::TimeDelta::FromMilliseconds(kSuspendDelayTimeoutMs); 616 base::TimeDelta::FromMilliseconds(kSuspendDelayTimeoutMs);
616 protobuf_request.set_timeout(timeout.ToInternalValue()); 617 protobuf_request.set_timeout(timeout.ToInternalValue());
617 protobuf_request.set_description(kSuspendDelayDescription); 618 protobuf_request.set_description(kSuspendDelayDescription);
618 619
619 RegisterSuspendDelayImpl( 620 RegisterSuspendDelayImpl(
620 power_manager::kRegisterSuspendDelayMethod, 621 power_manager::kRegisterSuspendDelayMethod,
621 protobuf_request, 622 protobuf_request,
622 base::Bind( 623 base::Bind(&PowerManagerClientImpl::HandleRegisterSuspendDelayReply,
623 &PowerManagerClientImpl::HandleRegisterSuspendDelayReply, 624 weak_ptr_factory_.GetWeakPtr(), false,
624 weak_ptr_factory_.GetWeakPtr(), false)); 625 power_manager::kRegisterSuspendDelayMethod));
625 RegisterSuspendDelayImpl( 626 RegisterSuspendDelayImpl(
626 power_manager::kRegisterDarkSuspendDelayMethod, 627 power_manager::kRegisterDarkSuspendDelayMethod,
627 protobuf_request, 628 protobuf_request,
628 base::Bind( 629 base::Bind(&PowerManagerClientImpl::HandleRegisterSuspendDelayReply,
629 &PowerManagerClientImpl::HandleRegisterSuspendDelayReply, 630 weak_ptr_factory_.GetWeakPtr(), true,
630 weak_ptr_factory_.GetWeakPtr(), true)); 631 power_manager::kRegisterDarkSuspendDelayMethod));
631 } 632 }
632 633
633 // Records the fact that an observer has finished doing asynchronous work 634 // Records the fact that an observer has finished doing asynchronous work
634 // that was blocking a pending suspend attempt and possibly reports 635 // that was blocking a pending suspend attempt and possibly reports
635 // suspend readiness to powerd. Called by callbacks returned via 636 // suspend readiness to powerd. Called by callbacks returned via
636 // GetSuspendReadinessCallback(). 637 // GetSuspendReadinessCallback().
637 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) { 638 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) {
638 DCHECK(OnOriginThread()); 639 DCHECK(OnOriginThread());
639 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ || 640 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ ||
640 in_dark_resume != suspending_from_dark_resume_) 641 in_dark_resume != suspending_from_dark_resume_)
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 // static 951 // static
951 PowerManagerClient* PowerManagerClient::Create( 952 PowerManagerClient* PowerManagerClient::Create(
952 DBusClientImplementationType type) { 953 DBusClientImplementationType type) {
953 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 954 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
954 return new PowerManagerClientImpl(); 955 return new PowerManagerClientImpl();
955 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 956 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
956 return new PowerManagerClientStubImpl(); 957 return new PowerManagerClientStubImpl();
957 } 958 }
958 959
959 } // namespace chromeos 960 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698