| 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" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" |
| 13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 16 #include "base/time.h" | 17 #include "base/time.h" |
| 17 #include "base/timer.h" | 18 #include "base/timer.h" |
| 18 #include "chromeos/dbus/power_manager/input_event.pb.h" | 19 #include "chromeos/dbus/power_manager/input_event.pb.h" |
| 19 #include "chromeos/dbus/power_manager/suspend.pb.h" | 20 #include "chromeos/dbus/power_manager/suspend.pb.h" |
| 20 #include "chromeos/dbus/power_state_control.pb.h" | 21 #include "chromeos/dbus/power_state_control.pb.h" |
| 21 #include "chromeos/dbus/power_supply_properties.pb.h" | 22 #include "chromeos/dbus/power_supply_properties.pb.h" |
| 22 #include "chromeos/dbus/video_activity_update.pb.h" | 23 #include "chromeos/dbus/video_activity_update.pb.h" |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 } | 800 } |
| 800 | 801 |
| 801 virtual void RequestRestart() OVERRIDE {} | 802 virtual void RequestRestart() OVERRIDE {} |
| 802 virtual void RequestShutdown() OVERRIDE {} | 803 virtual void RequestShutdown() OVERRIDE {} |
| 803 | 804 |
| 804 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) | 805 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) |
| 805 OVERRIDE { | 806 OVERRIDE { |
| 806 callback.Run(0); | 807 callback.Run(0); |
| 807 } | 808 } |
| 808 | 809 |
| 809 virtual void RequestIdleNotification(int64 threshold) OVERRIDE {} | 810 virtual void RequestIdleNotification(int64 threshold) OVERRIDE { |
| 811 MessageLoop::current()->PostDelayedTask( |
| 812 FROM_HERE, |
| 813 base::Bind(&PowerManagerClientStubImpl::TriggerIdleNotify, |
| 814 base::Unretained(this), |
| 815 threshold), |
| 816 base::TimeDelta::FromMilliseconds(threshold)); |
| 817 } |
| 818 |
| 810 virtual void NotifyUserActivity( | 819 virtual void NotifyUserActivity( |
| 811 const base::TimeTicks& last_activity_time) OVERRIDE {} | 820 const base::TimeTicks& last_activity_time) OVERRIDE {} |
| 812 virtual void NotifyVideoActivity( | 821 virtual void NotifyVideoActivity( |
| 813 const base::TimeTicks& last_activity_time, | 822 const base::TimeTicks& last_activity_time, |
| 814 bool is_fullscreen) OVERRIDE {} | 823 bool is_fullscreen) OVERRIDE {} |
| 815 virtual void RequestPowerStateOverrides( | 824 virtual void RequestPowerStateOverrides( |
| 816 uint32 request_id, | 825 uint32 request_id, |
| 817 base::TimeDelta duration, | 826 base::TimeDelta duration, |
| 818 int overrides, | 827 int overrides, |
| 819 const PowerStateRequestIdCallback& callback) OVERRIDE { | 828 const PowerStateRequestIdCallback& callback) OVERRIDE { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status_)); | 871 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status_)); |
| 863 } | 872 } |
| 864 | 873 |
| 865 void SetBrightness(double percent, bool user_initiated) { | 874 void SetBrightness(double percent, bool user_initiated) { |
| 866 brightness_ = std::min(std::max(0.0, percent), 100.0); | 875 brightness_ = std::min(std::max(0.0, percent), 100.0); |
| 867 int brightness_level = static_cast<int>(brightness_); | 876 int brightness_level = static_cast<int>(brightness_); |
| 868 FOR_EACH_OBSERVER(Observer, observers_, | 877 FOR_EACH_OBSERVER(Observer, observers_, |
| 869 BrightnessChanged(brightness_level, user_initiated)); | 878 BrightnessChanged(brightness_level, user_initiated)); |
| 870 } | 879 } |
| 871 | 880 |
| 881 void TriggerIdleNotify(int64 threshold) { |
| 882 FOR_EACH_OBSERVER(Observer, observers_, IdleNotify(threshold)); |
| 883 } |
| 884 |
| 872 bool discharging_; | 885 bool discharging_; |
| 873 int battery_percentage_; | 886 int battery_percentage_; |
| 874 double brightness_; | 887 double brightness_; |
| 875 int pause_count_; | 888 int pause_count_; |
| 876 ObserverList<Observer> observers_; | 889 ObserverList<Observer> observers_; |
| 877 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; | 890 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; |
| 878 PowerSupplyStatus status_; | 891 PowerSupplyStatus status_; |
| 879 uint32 next_request_id_; | 892 uint32 next_request_id_; |
| 880 }; | 893 }; |
| 881 | 894 |
| 882 PowerManagerClient::PowerManagerClient() { | 895 PowerManagerClient::PowerManagerClient() { |
| 883 } | 896 } |
| 884 | 897 |
| 885 PowerManagerClient::~PowerManagerClient() { | 898 PowerManagerClient::~PowerManagerClient() { |
| 886 } | 899 } |
| 887 | 900 |
| 888 PowerManagerClient* PowerManagerClient::Create( | 901 PowerManagerClient* PowerManagerClient::Create( |
| 889 DBusClientImplementationType type, | 902 DBusClientImplementationType type, |
| 890 dbus::Bus* bus) { | 903 dbus::Bus* bus) { |
| 891 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 904 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 892 return new PowerManagerClientImpl(bus); | 905 return new PowerManagerClientImpl(bus); |
| 893 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 906 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 894 return new PowerManagerClientStubImpl(); | 907 return new PowerManagerClientStubImpl(); |
| 895 } | 908 } |
| 896 | 909 |
| 897 } // namespace chromeos | 910 } // namespace chromeos |
| OLD | NEW |