OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/chromeos/cros/power_library.h" | 5 #include "chrome/browser/chromeos/cros/power_library.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 base::TimeDelta battery_time_to_empty() const { | 54 base::TimeDelta battery_time_to_empty() const { |
55 return base::TimeDelta::FromSeconds(status_.battery_time_to_empty); | 55 return base::TimeDelta::FromSeconds(status_.battery_time_to_empty); |
56 } | 56 } |
57 | 57 |
58 base::TimeDelta battery_time_to_full() const { | 58 base::TimeDelta battery_time_to_full() const { |
59 return base::TimeDelta::FromSeconds(status_.battery_time_to_full); | 59 return base::TimeDelta::FromSeconds(status_.battery_time_to_full); |
60 } | 60 } |
61 | 61 |
| 62 virtual void EnableScreenLock(bool enable) { |
| 63 if (!CrosLibrary::Get()->EnsureLoaded()) |
| 64 return; |
| 65 |
| 66 // Make sure we run on FILE thread becuase chromeos::EnableScreenLock |
| 67 // would write power manager config file to disk. |
| 68 if (!ChromeThread::CurrentlyOn(ChromeThread::FILE)) { |
| 69 ChromeThread::PostTask( |
| 70 ChromeThread::FILE, FROM_HERE, |
| 71 NewRunnableMethod(this, &PowerLibraryImpl::EnableScreenLock, enable)); |
| 72 return; |
| 73 } |
| 74 |
| 75 chromeos::EnableScreenLock(enable); |
| 76 } |
| 77 |
62 private: | 78 private: |
63 static void PowerStatusChangedHandler(void* object, | 79 static void PowerStatusChangedHandler(void* object, |
64 const chromeos::PowerStatus& status) { | 80 const chromeos::PowerStatus& status) { |
65 PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object); | 81 PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object); |
66 power->UpdatePowerStatus(status); | 82 power->UpdatePowerStatus(status); |
67 } | 83 } |
68 | 84 |
69 void Init() { | 85 void Init() { |
70 power_status_connection_ = chromeos::MonitorPowerStatus( | 86 power_status_connection_ = chromeos::MonitorPowerStatus( |
71 &PowerStatusChangedHandler, this); | 87 &PowerStatusChangedHandler, this); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 bool line_power_on() const { return false; } | 128 bool line_power_on() const { return false; } |
113 bool battery_is_present() const { return false; } | 129 bool battery_is_present() const { return false; } |
114 bool battery_fully_charged() const { return false; } | 130 bool battery_fully_charged() const { return false; } |
115 double battery_percentage() const { return false; } | 131 double battery_percentage() const { return false; } |
116 base::TimeDelta battery_time_to_empty() const { | 132 base::TimeDelta battery_time_to_empty() const { |
117 return base::TimeDelta::FromSeconds(0); | 133 return base::TimeDelta::FromSeconds(0); |
118 } | 134 } |
119 base::TimeDelta battery_time_to_full() const { | 135 base::TimeDelta battery_time_to_full() const { |
120 return base::TimeDelta::FromSeconds(0); | 136 return base::TimeDelta::FromSeconds(0); |
121 } | 137 } |
| 138 virtual void EnableScreenLock(bool enable) {} |
122 }; | 139 }; |
123 | 140 |
124 // static | 141 // static |
125 PowerLibrary* PowerLibrary::GetImpl(bool stub) { | 142 PowerLibrary* PowerLibrary::GetImpl(bool stub) { |
126 if (stub) | 143 if (stub) |
127 return new PowerLibraryStubImpl(); | 144 return new PowerLibraryStubImpl(); |
128 else | 145 else |
129 return new PowerLibraryImpl(); | 146 return new PowerLibraryImpl(); |
130 } | 147 } |
131 | 148 |
132 } // namespace chromeos | 149 } // namespace chromeos |
133 | 150 |
134 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 151 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
135 // won't be deleted until it's last InvokeLater is run. | 152 // won't be deleted until it's last InvokeLater is run. |
136 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PowerLibraryImpl); | 153 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PowerLibraryImpl); |
137 | 154 |
OLD | NEW |