Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 power_manager_proxy_->ConnectToSignal( | 261 power_manager_proxy_->ConnectToSignal( |
| 262 power_manager::kPowerManagerInterface, | 262 power_manager::kPowerManagerInterface, |
| 263 power_manager::kInputEventSignal, | 263 power_manager::kInputEventSignal, |
| 264 base::Bind(&PowerManagerClientImpl::InputEventReceived, | 264 base::Bind(&PowerManagerClientImpl::InputEventReceived, |
| 265 weak_ptr_factory_.GetWeakPtr()), | 265 weak_ptr_factory_.GetWeakPtr()), |
| 266 base::Bind(&PowerManagerClientImpl::SignalConnected, | 266 base::Bind(&PowerManagerClientImpl::SignalConnected, |
| 267 weak_ptr_factory_.GetWeakPtr())); | 267 weak_ptr_factory_.GetWeakPtr())); |
| 268 | 268 |
| 269 power_manager_proxy_->ConnectToSignal( | 269 power_manager_proxy_->ConnectToSignal( |
| 270 power_manager::kPowerManagerInterface, | 270 power_manager::kPowerManagerInterface, |
| 271 power_manager::kSuspendStateChangedSignal, | |
| 272 base::Bind(&PowerManagerClientImpl::SuspendStateChangedReceived, | |
| 273 weak_ptr_factory_.GetWeakPtr()), | |
| 274 base::Bind(&PowerManagerClientImpl::SignalConnected, | |
| 275 weak_ptr_factory_.GetWeakPtr())); | |
| 276 | |
| 277 power_manager_proxy_->ConnectToSignal( | |
| 278 power_manager::kPowerManagerInterface, | |
| 279 power_manager::kSuspendImminentSignal, | 271 power_manager::kSuspendImminentSignal, |
| 280 base::Bind( | 272 base::Bind( |
| 281 &PowerManagerClientImpl::SuspendImminentReceived, | 273 &PowerManagerClientImpl::SuspendImminentReceived, |
| 282 weak_ptr_factory_.GetWeakPtr()), | 274 weak_ptr_factory_.GetWeakPtr()), |
| 283 base::Bind(&PowerManagerClientImpl::SignalConnected, | 275 base::Bind(&PowerManagerClientImpl::SignalConnected, |
| 284 weak_ptr_factory_.GetWeakPtr())); | 276 weak_ptr_factory_.GetWeakPtr())); |
| 285 | 277 |
| 278 power_manager_proxy_->ConnectToSignal( | |
| 279 power_manager::kPowerManagerInterface, | |
| 280 power_manager::kSuspendDoneSignal, | |
| 281 base::Bind(&PowerManagerClientImpl::SuspendDoneReceived, | |
| 282 weak_ptr_factory_.GetWeakPtr()), | |
| 283 base::Bind(&PowerManagerClientImpl::SignalConnected, | |
| 284 weak_ptr_factory_.GetWeakPtr())); | |
| 285 | |
| 286 power_manager_proxy_->ConnectToSignal( | 286 power_manager_proxy_->ConnectToSignal( |
| 287 power_manager::kPowerManagerInterface, | 287 power_manager::kPowerManagerInterface, |
| 288 power_manager::kIdleActionImminentSignal, | 288 power_manager::kIdleActionImminentSignal, |
| 289 base::Bind( | 289 base::Bind( |
| 290 &PowerManagerClientImpl::IdleActionImminentReceived, | 290 &PowerManagerClientImpl::IdleActionImminentReceived, |
| 291 weak_ptr_factory_.GetWeakPtr()), | 291 weak_ptr_factory_.GetWeakPtr()), |
| 292 base::Bind(&PowerManagerClientImpl::SignalConnected, | 292 base::Bind(&PowerManagerClientImpl::SignalConnected, |
| 293 weak_ptr_factory_.GetWeakPtr())); | 293 weak_ptr_factory_.GetWeakPtr())); |
| 294 | 294 |
| 295 power_manager_proxy_->ConnectToSignal( | 295 power_manager_proxy_->ConnectToSignal( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 } | 445 } |
| 446 | 446 |
| 447 void SuspendImminentReceived(dbus::Signal* signal) { | 447 void SuspendImminentReceived(dbus::Signal* signal) { |
| 448 if (!has_suspend_delay_id_) { | 448 if (!has_suspend_delay_id_) { |
| 449 LOG(ERROR) << "Received unrequested " | 449 LOG(ERROR) << "Received unrequested " |
| 450 << power_manager::kSuspendImminentSignal << " signal"; | 450 << power_manager::kSuspendImminentSignal << " signal"; |
| 451 return; | 451 return; |
| 452 } | 452 } |
| 453 | 453 |
| 454 dbus::MessageReader reader(signal); | 454 dbus::MessageReader reader(signal); |
| 455 power_manager::SuspendImminent protobuf_imminent; | 455 power_manager::SuspendImminent proto; |
| 456 if (!reader.PopArrayOfBytesAsProto(&protobuf_imminent)) { | 456 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
| 457 LOG(ERROR) << "Unable to decode protocol buffer from " | 457 LOG(ERROR) << "Unable to decode protocol buffer from " |
| 458 << power_manager::kSuspendImminentSignal << " signal"; | 458 << power_manager::kSuspendImminentSignal << " signal"; |
| 459 return; | 459 return; |
| 460 } | 460 } |
| 461 | 461 |
| 462 VLOG(1) << "Got " << power_manager::kSuspendImminentSignal << " signal " | |
| 463 << "announcing suspend attempt " << proto.suspend_id(); | |
| 462 if (suspend_is_pending_) { | 464 if (suspend_is_pending_) { |
| 463 LOG(WARNING) << "Got " << power_manager::kSuspendImminentSignal | 465 LOG(WARNING) << "Got " << power_manager::kSuspendImminentSignal |
| 464 << " signal about pending suspend attempt " | 466 << " signal about pending suspend attempt " |
| 465 << protobuf_imminent.suspend_id() << " while still waiting " | 467 << proto.suspend_id() << " while still waiting " |
| 466 << "on attempt " << pending_suspend_id_; | 468 << "on attempt " << pending_suspend_id_; |
| 467 } | 469 } |
| 468 | 470 |
| 469 pending_suspend_id_ = protobuf_imminent.suspend_id(); | 471 pending_suspend_id_ = proto.suspend_id(); |
| 470 suspend_is_pending_ = true; | 472 suspend_is_pending_ = true; |
| 471 num_pending_suspend_readiness_callbacks_ = 0; | 473 num_pending_suspend_readiness_callbacks_ = 0; |
| 472 FOR_EACH_OBSERVER(Observer, observers_, SuspendImminent()); | 474 FOR_EACH_OBSERVER(Observer, observers_, SuspendImminent()); |
| 473 MaybeReportSuspendReadiness(); | 475 MaybeReportSuspendReadiness(); |
| 474 } | 476 } |
| 475 | 477 |
| 478 void SuspendDoneReceived(dbus::Signal* signal) { | |
| 479 dbus::MessageReader reader(signal); | |
| 480 power_manager::SuspendDone proto; | |
| 481 if (!reader.PopArrayOfBytesAsProto(&proto)) { | |
| 482 LOG(ERROR) << "Unable to decode protocol buffer from " | |
| 483 << power_manager::kSuspendDoneSignal << " signal"; | |
| 484 return; | |
| 485 } | |
| 486 | |
| 487 const base::TimeDelta duration = | |
| 488 base::TimeDelta::FromInternalValue(proto.suspend_duration()); | |
| 489 VLOG(1) << "Got " << power_manager::kSuspendDoneSignal << " signal:" | |
| 490 << " suspend_id=" << proto.suspend_id() | |
| 491 << " duration=" << duration.InSeconds() << " sec"; | |
| 492 FOR_EACH_OBSERVER( | |
| 493 PowerManagerClient::Observer, observers_, SuspendDone(duration)); | |
| 494 } | |
| 495 | |
| 476 void IdleActionImminentReceived(dbus::Signal* signal) { | 496 void IdleActionImminentReceived(dbus::Signal* signal) { |
| 477 FOR_EACH_OBSERVER(Observer, observers_, IdleActionImminent()); | 497 dbus::MessageReader reader(signal); |
| 498 power_manager::IdleActionImminent proto; | |
| 499 if (!reader.PopArrayOfBytesAsProto(&proto)) { | |
| 500 LOG(ERROR) << "Unable to decode protocol buffer from " | |
| 501 << power_manager::kIdleActionImminentSignal << " signal"; | |
| 502 return; | |
| 503 } | |
| 504 FOR_EACH_OBSERVER(Observer, observers_, | |
| 505 IdleActionImminent(base::TimeDelta::FromInternalValue( | |
| 506 proto.time_until_idle_action()))); | |
|
bartfab (slow)
2014/04/23 11:49:30
Nit: This line should be indented four spaces from
Daniel Erat
2014/04/23 14:35:34
debatable unless the style guide has been updated
bartfab (slow)
2014/04/23 14:50:22
Neither of these is very likely. I guess I just li
| |
| 478 } | 507 } |
| 479 | 508 |
| 480 void IdleActionDeferredReceived(dbus::Signal* signal) { | 509 void IdleActionDeferredReceived(dbus::Signal* signal) { |
| 481 FOR_EACH_OBSERVER(Observer, observers_, IdleActionDeferred()); | 510 FOR_EACH_OBSERVER(Observer, observers_, IdleActionDeferred()); |
| 482 } | 511 } |
| 483 | 512 |
| 484 void InputEventReceived(dbus::Signal* signal) { | 513 void InputEventReceived(dbus::Signal* signal) { |
| 485 dbus::MessageReader reader(signal); | 514 dbus::MessageReader reader(signal); |
| 486 power_manager::InputEvent proto; | 515 power_manager::InputEvent proto; |
| 487 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 516 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 case power_manager::InputEvent_Type_LID_CLOSED: { | 549 case power_manager::InputEvent_Type_LID_CLOSED: { |
| 521 bool open = | 550 bool open = |
| 522 (proto.type() == power_manager::InputEvent_Type_LID_OPEN); | 551 (proto.type() == power_manager::InputEvent_Type_LID_OPEN); |
| 523 FOR_EACH_OBSERVER(PowerManagerClient::Observer, observers_, | 552 FOR_EACH_OBSERVER(PowerManagerClient::Observer, observers_, |
| 524 LidEventReceived(open, timestamp)); | 553 LidEventReceived(open, timestamp)); |
| 525 break; | 554 break; |
| 526 } | 555 } |
| 527 } | 556 } |
| 528 } | 557 } |
| 529 | 558 |
| 530 void SuspendStateChangedReceived(dbus::Signal* signal) { | |
| 531 dbus::MessageReader reader(signal); | |
| 532 power_manager::SuspendState proto; | |
| 533 if (!reader.PopArrayOfBytesAsProto(&proto)) { | |
| 534 LOG(ERROR) << "Unable to decode protocol buffer from " | |
| 535 << power_manager::kSuspendStateChangedSignal << " signal"; | |
| 536 return; | |
| 537 } | |
| 538 | |
| 539 VLOG(1) << "Got " << power_manager::kSuspendStateChangedSignal << " signal:" | |
| 540 << " type=" << proto.type() << " wall_time=" << proto.wall_time(); | |
| 541 base::Time wall_time = | |
| 542 base::Time::FromInternalValue(proto.wall_time()); | |
| 543 switch (proto.type()) { | |
| 544 case power_manager::SuspendState_Type_SUSPEND_TO_MEMORY: | |
| 545 last_suspend_wall_time_ = wall_time; | |
| 546 break; | |
| 547 case power_manager::SuspendState_Type_RESUME: | |
| 548 FOR_EACH_OBSERVER( | |
| 549 PowerManagerClient::Observer, observers_, | |
| 550 SystemResumed(wall_time - last_suspend_wall_time_)); | |
| 551 break; | |
| 552 } | |
| 553 } | |
| 554 | |
| 555 // Registers a suspend delay with the power manager. This is usually | 559 // Registers a suspend delay with the power manager. This is usually |
| 556 // only called at startup, but if the power manager restarts, we need to | 560 // only called at startup, but if the power manager restarts, we need to |
| 557 // create a new delay. | 561 // create a new delay. |
| 558 void RegisterSuspendDelay() { | 562 void RegisterSuspendDelay() { |
| 559 // Throw out any old delay that was registered. | 563 // Throw out any old delay that was registered. |
| 560 suspend_delay_id_ = -1; | 564 suspend_delay_id_ = -1; |
| 561 has_suspend_delay_id_ = false; | 565 has_suspend_delay_id_ = false; |
| 562 | 566 |
| 563 dbus::MethodCall method_call( | 567 dbus::MethodCall method_call( |
| 564 power_manager::kPowerManagerInterface, | 568 power_manager::kPowerManagerInterface, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 // suspend readiness callbacks. | 605 // suspend readiness callbacks. |
| 602 void MaybeReportSuspendReadiness() { | 606 void MaybeReportSuspendReadiness() { |
| 603 if (!suspend_is_pending_ || num_pending_suspend_readiness_callbacks_ > 0) | 607 if (!suspend_is_pending_ || num_pending_suspend_readiness_callbacks_ > 0) |
| 604 return; | 608 return; |
| 605 | 609 |
| 606 dbus::MethodCall method_call( | 610 dbus::MethodCall method_call( |
| 607 power_manager::kPowerManagerInterface, | 611 power_manager::kPowerManagerInterface, |
| 608 power_manager::kHandleSuspendReadinessMethod); | 612 power_manager::kHandleSuspendReadinessMethod); |
| 609 dbus::MessageWriter writer(&method_call); | 613 dbus::MessageWriter writer(&method_call); |
| 610 | 614 |
| 615 VLOG(1) << "Announcing readiness of suspend delay " << suspend_delay_id_ | |
| 616 << " for suspend attempt " << pending_suspend_id_; | |
| 611 power_manager::SuspendReadinessInfo protobuf_request; | 617 power_manager::SuspendReadinessInfo protobuf_request; |
| 612 protobuf_request.set_delay_id(suspend_delay_id_); | 618 protobuf_request.set_delay_id(suspend_delay_id_); |
| 613 protobuf_request.set_suspend_id(pending_suspend_id_); | 619 protobuf_request.set_suspend_id(pending_suspend_id_); |
| 614 | 620 |
| 615 pending_suspend_id_ = -1; | 621 pending_suspend_id_ = -1; |
| 616 suspend_is_pending_ = false; | 622 suspend_is_pending_ = false; |
| 617 | 623 |
| 618 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { | 624 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { |
| 619 LOG(ERROR) << "Error constructing message for " | 625 LOG(ERROR) << "Error constructing message for " |
| 620 << power_manager::kHandleSuspendReadinessMethod; | 626 << power_manager::kHandleSuspendReadinessMethod; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 639 // powerd-supplied ID corresponding to an imminent suspend attempt that is | 645 // powerd-supplied ID corresponding to an imminent suspend attempt that is |
| 640 // currently being delayed. | 646 // currently being delayed. |
| 641 int32 pending_suspend_id_; | 647 int32 pending_suspend_id_; |
| 642 bool suspend_is_pending_; | 648 bool suspend_is_pending_; |
| 643 | 649 |
| 644 // Number of callbacks that have been returned by | 650 // Number of callbacks that have been returned by |
| 645 // GetSuspendReadinessCallback() during the currently-pending suspend | 651 // GetSuspendReadinessCallback() during the currently-pending suspend |
| 646 // attempt but have not yet been called. | 652 // attempt but have not yet been called. |
| 647 int num_pending_suspend_readiness_callbacks_; | 653 int num_pending_suspend_readiness_callbacks_; |
| 648 | 654 |
| 649 // Wall time from the latest signal telling us that the system was about to | |
| 650 // suspend to memory. | |
| 651 base::Time last_suspend_wall_time_; | |
| 652 | |
| 653 // Last state passed to SetIsProjecting(). | 655 // Last state passed to SetIsProjecting(). |
| 654 bool last_is_projecting_; | 656 bool last_is_projecting_; |
| 655 | 657 |
| 656 // Note: This should remain the last member so it'll be destroyed and | 658 // Note: This should remain the last member so it'll be destroyed and |
| 657 // invalidate its weak pointers before any other members are destroyed. | 659 // invalidate its weak pointers before any other members are destroyed. |
| 658 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 660 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
| 659 | 661 |
| 660 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 662 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
| 661 }; | 663 }; |
| 662 | 664 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 887 // static | 889 // static |
| 888 PowerManagerClient* PowerManagerClient::Create( | 890 PowerManagerClient* PowerManagerClient::Create( |
| 889 DBusClientImplementationType type) { | 891 DBusClientImplementationType type) { |
| 890 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 892 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 891 return new PowerManagerClientImpl(); | 893 return new PowerManagerClientImpl(); |
| 892 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 894 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 893 return new PowerManagerClientStubImpl(); | 895 return new PowerManagerClientStubImpl(); |
| 894 } | 896 } |
| 895 | 897 |
| 896 } // namespace chromeos | 898 } // namespace chromeos |
| OLD | NEW |