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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 class PowerManagerClientImpl : public PowerManagerClient { | 42 class PowerManagerClientImpl : public PowerManagerClient { |
43 public: | 43 public: |
44 explicit PowerManagerClientImpl(dbus::Bus* bus) | 44 explicit PowerManagerClientImpl(dbus::Bus* bus) |
45 : origin_thread_id_(base::PlatformThread::CurrentId()), | 45 : origin_thread_id_(base::PlatformThread::CurrentId()), |
46 power_manager_proxy_(NULL), | 46 power_manager_proxy_(NULL), |
47 suspend_delay_id_(-1), | 47 suspend_delay_id_(-1), |
48 has_suspend_delay_id_(false), | 48 has_suspend_delay_id_(false), |
49 pending_suspend_id_(-1), | 49 pending_suspend_id_(-1), |
50 suspend_is_pending_(false), | 50 suspend_is_pending_(false), |
51 num_pending_suspend_readiness_callbacks_(0), | 51 num_pending_suspend_readiness_callbacks_(0), |
| 52 last_is_projecting_(false), |
52 weak_ptr_factory_(this) { | 53 weak_ptr_factory_(this) { |
53 power_manager_proxy_ = bus->GetObjectProxy( | 54 power_manager_proxy_ = bus->GetObjectProxy( |
54 power_manager::kPowerManagerServiceName, | 55 power_manager::kPowerManagerServiceName, |
55 dbus::ObjectPath(power_manager::kPowerManagerServicePath)); | 56 dbus::ObjectPath(power_manager::kPowerManagerServicePath)); |
56 | 57 |
57 power_manager_proxy_->SetNameOwnerChangedCallback( | 58 power_manager_proxy_->SetNameOwnerChangedCallback( |
58 base::Bind(&PowerManagerClientImpl::NameOwnerChangedReceived, | 59 base::Bind(&PowerManagerClientImpl::NameOwnerChangedReceived, |
59 weak_ptr_factory_.GetWeakPtr())); | 60 weak_ptr_factory_.GetWeakPtr())); |
60 | 61 |
61 // Monitor the D-Bus signal for brightness changes. Only the power | 62 // Monitor the D-Bus signal for brightness changes. Only the power |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 virtual void SetIsProjecting(bool is_projecting) OVERRIDE { | 293 virtual void SetIsProjecting(bool is_projecting) OVERRIDE { |
293 dbus::MethodCall method_call( | 294 dbus::MethodCall method_call( |
294 power_manager::kPowerManagerInterface, | 295 power_manager::kPowerManagerInterface, |
295 power_manager::kSetIsProjectingMethod); | 296 power_manager::kSetIsProjectingMethod); |
296 dbus::MessageWriter writer(&method_call); | 297 dbus::MessageWriter writer(&method_call); |
297 writer.AppendBool(is_projecting); | 298 writer.AppendBool(is_projecting); |
298 power_manager_proxy_->CallMethod( | 299 power_manager_proxy_->CallMethod( |
299 &method_call, | 300 &method_call, |
300 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 301 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
301 dbus::ObjectProxy::EmptyResponseCallback()); | 302 dbus::ObjectProxy::EmptyResponseCallback()); |
| 303 last_is_projecting_ = is_projecting; |
302 } | 304 } |
303 | 305 |
304 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { | 306 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { |
305 DCHECK(OnOriginThread()); | 307 DCHECK(OnOriginThread()); |
306 DCHECK(suspend_is_pending_); | 308 DCHECK(suspend_is_pending_); |
307 num_pending_suspend_readiness_callbacks_++; | 309 num_pending_suspend_readiness_callbacks_++; |
308 return base::Bind(&PowerManagerClientImpl::HandleObserverSuspendReadiness, | 310 return base::Bind(&PowerManagerClientImpl::HandleObserverSuspendReadiness, |
309 weak_ptr_factory_.GetWeakPtr(), pending_suspend_id_); | 311 weak_ptr_factory_.GetWeakPtr(), pending_suspend_id_); |
310 } | 312 } |
311 | 313 |
(...skipping 17 matching lines...) Expand all Loading... |
329 method_name); | 331 method_name); |
330 power_manager_proxy_->CallMethod( | 332 power_manager_proxy_->CallMethod( |
331 &method_call, | 333 &method_call, |
332 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 334 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
333 dbus::ObjectProxy::EmptyResponseCallback()); | 335 dbus::ObjectProxy::EmptyResponseCallback()); |
334 } | 336 } |
335 | 337 |
336 void NameOwnerChangedReceived(dbus::Signal* signal) { | 338 void NameOwnerChangedReceived(dbus::Signal* signal) { |
337 VLOG(1) << "Power manager restarted"; | 339 VLOG(1) << "Power manager restarted"; |
338 RegisterSuspendDelay(); | 340 RegisterSuspendDelay(); |
| 341 SetIsProjecting(last_is_projecting_); |
339 FOR_EACH_OBSERVER(Observer, observers_, PowerManagerRestarted()); | 342 FOR_EACH_OBSERVER(Observer, observers_, PowerManagerRestarted()); |
340 } | 343 } |
341 | 344 |
342 void BrightnessChangedReceived(dbus::Signal* signal) { | 345 void BrightnessChangedReceived(dbus::Signal* signal) { |
343 dbus::MessageReader reader(signal); | 346 dbus::MessageReader reader(signal); |
344 int32 brightness_level = 0; | 347 int32 brightness_level = 0; |
345 bool user_initiated = 0; | 348 bool user_initiated = 0; |
346 if (!(reader.PopInt32(&brightness_level) && | 349 if (!(reader.PopInt32(&brightness_level) && |
347 reader.PopBool(&user_initiated))) { | 350 reader.PopBool(&user_initiated))) { |
348 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " | 351 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 686 |
684 // Number of callbacks that have been returned by | 687 // Number of callbacks that have been returned by |
685 // GetSuspendReadinessCallback() during the currently-pending suspend | 688 // GetSuspendReadinessCallback() during the currently-pending suspend |
686 // attempt but have not yet been called. | 689 // attempt but have not yet been called. |
687 int num_pending_suspend_readiness_callbacks_; | 690 int num_pending_suspend_readiness_callbacks_; |
688 | 691 |
689 // Wall time from the latest signal telling us that the system was about to | 692 // Wall time from the latest signal telling us that the system was about to |
690 // suspend to memory. | 693 // suspend to memory. |
691 base::Time last_suspend_wall_time_; | 694 base::Time last_suspend_wall_time_; |
692 | 695 |
| 696 // Last state passed to SetIsProjecting(). |
| 697 bool last_is_projecting_; |
| 698 |
693 // Note: This should remain the last member so it'll be destroyed and | 699 // Note: This should remain the last member so it'll be destroyed and |
694 // invalidate its weak pointers before any other members are destroyed. | 700 // invalidate its weak pointers before any other members are destroyed. |
695 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 701 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
696 | 702 |
697 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 703 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
698 }; | 704 }; |
699 | 705 |
700 // The PowerManagerClient implementation used on Linux desktop, | 706 // The PowerManagerClient implementation used on Linux desktop, |
701 // which does nothing. | 707 // which does nothing. |
702 class PowerManagerClientStubImpl : public PowerManagerClient { | 708 class PowerManagerClientStubImpl : public PowerManagerClient { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 PowerManagerClient* PowerManagerClient::Create( | 875 PowerManagerClient* PowerManagerClient::Create( |
870 DBusClientImplementationType type, | 876 DBusClientImplementationType type, |
871 dbus::Bus* bus) { | 877 dbus::Bus* bus) { |
872 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 878 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
873 return new PowerManagerClientImpl(bus); | 879 return new PowerManagerClientImpl(bus); |
874 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 880 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
875 return new PowerManagerClientStubImpl(); | 881 return new PowerManagerClientStubImpl(); |
876 } | 882 } |
877 | 883 |
878 } // namespace chromeos | 884 } // namespace chromeos |
OLD | NEW |