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

Side by Side Diff: chrome/browser/chromeos/cros/power_library.cc

Issue 7920019: Add PowerLibrary::RequestStatusUpdate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove deprecated libcros call. Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 virtual void RequestRestart() OVERRIDE { 103 virtual void RequestRestart() OVERRIDE {
104 if (CrosLibrary::Get()->EnsureLoaded()) 104 if (CrosLibrary::Get()->EnsureLoaded())
105 chromeos::RequestRestart(); 105 chromeos::RequestRestart();
106 } 106 }
107 107
108 virtual void RequestShutdown() OVERRIDE { 108 virtual void RequestShutdown() OVERRIDE {
109 if (CrosLibrary::Get()->EnsureLoaded()) 109 if (CrosLibrary::Get()->EnsureLoaded())
110 chromeos::RequestShutdown(); 110 chromeos::RequestShutdown();
111 } 111 }
112
113 virtual void RequestStatusUpdate() OVERRIDE {
114 // TODO(stevenjb): chromeos::RetrievePowerInformation has been deprecated;
115 // we should add a mechanism to immediately request an update, probably
116 // when we migrate the DBus code from libcros to here.
117 }
118
112 // End PowerLibrary implementation. 119 // End PowerLibrary implementation.
113 120
114 private: 121 private:
115 static void GetIdleTimeCallback(void* object, 122 static void GetIdleTimeCallback(void* object,
116 int64_t time_idle_ms, 123 int64_t time_idle_ms,
117 bool success) { 124 bool success) {
118 DCHECK(object); 125 DCHECK(object);
119 CalculateIdleTimeCallback* notify = 126 CalculateIdleTimeCallback* notify =
120 static_cast<CalculateIdleTimeCallback*>(object); 127 static_cast<CalculateIdleTimeCallback*>(object);
121 if (success) { 128 if (success) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 190
184 DISALLOW_COPY_AND_ASSIGN(PowerLibraryImpl); 191 DISALLOW_COPY_AND_ASSIGN(PowerLibraryImpl);
185 }; 192 };
186 193
187 // The stub implementation runs the battery up and down, pausing at the 194 // The stub implementation runs the battery up and down, pausing at the
188 // fully charged and fully depleted states. 195 // fully charged and fully depleted states.
189 class PowerLibraryStubImpl : public PowerLibrary { 196 class PowerLibraryStubImpl : public PowerLibrary {
190 public: 197 public:
191 PowerLibraryStubImpl() 198 PowerLibraryStubImpl()
192 : discharging_(true), 199 : discharging_(true),
193 battery_percentage_(20), 200 battery_percentage_(80),
194 pause_count_(0) { 201 pause_count_(0) {
195 timer_.Start(
196 FROM_HERE,
197 base::TimeDelta::FromMilliseconds(100),
198 this,
199 &PowerLibraryStubImpl::Update);
200 } 202 }
201 203
202 virtual ~PowerLibraryStubImpl() {} 204 virtual ~PowerLibraryStubImpl() {}
203 205
204 // Begin PowerLibrary implementation. 206 // Begin PowerLibrary implementation.
205 virtual void Init() OVERRIDE {} 207 virtual void Init() OVERRIDE {}
206 virtual void AddObserver(Observer* observer) OVERRIDE { 208 virtual void AddObserver(Observer* observer) OVERRIDE {
207 observers_.AddObserver(observer); 209 observers_.AddObserver(observer);
208 } 210 }
209 211
(...skipping 28 matching lines...) Expand all
238 if (battery_percentage_ == 100) 240 if (battery_percentage_ == 100)
239 return base::TimeDelta::FromSeconds(1); 241 return base::TimeDelta::FromSeconds(1);
240 else 242 else
241 return base::TimeDelta::FromHours(3) - battery_time_to_empty(); 243 return base::TimeDelta::FromHours(3) - battery_time_to_empty();
242 } 244 }
243 245
244 virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) OVERRIDE { 246 virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) OVERRIDE {
245 callback->Run(0); 247 callback->Run(0);
246 delete callback; 248 delete callback;
247 } 249 }
250
248 virtual void EnableScreenLock(bool enable) OVERRIDE {} 251 virtual void EnableScreenLock(bool enable) OVERRIDE {}
252
249 virtual void RequestRestart() OVERRIDE {} 253 virtual void RequestRestart() OVERRIDE {}
254
250 virtual void RequestShutdown() OVERRIDE {} 255 virtual void RequestShutdown() OVERRIDE {}
256
257 virtual void RequestStatusUpdate() OVERRIDE {
258 if (!timer_.IsRunning()) {
259 timer_.Start(
260 FROM_HERE,
261 base::TimeDelta::FromMilliseconds(100),
262 this,
263 &PowerLibraryStubImpl::Update);
264 } else {
265 timer_.Stop();
266 }
267 }
268
251 // End PowerLibrary implementation. 269 // End PowerLibrary implementation.
252 270
253 private: 271 private:
254 void Update() { 272 void Update() {
255 // We pause at 0 and 100% so that it's easier to check those conditions. 273 // We pause at 0 and 100% so that it's easier to check those conditions.
256 if (pause_count_ > 1) { 274 if (pause_count_ > 1) {
257 pause_count_--; 275 pause_count_--;
258 return; 276 return;
259 } 277 }
260 278
(...skipping 26 matching lines...) Expand all
287 impl = new PowerLibraryImpl(); 305 impl = new PowerLibraryImpl();
288 impl->Init(); 306 impl->Init();
289 return impl; 307 return impl;
290 } 308 }
291 309
292 } // namespace chromeos 310 } // namespace chromeos
293 311
294 // Allows InvokeLater without adding refcounting. This class is a Singleton and 312 // Allows InvokeLater without adding refcounting. This class is a Singleton and
295 // won't be deleted until it's last InvokeLater is run. 313 // won't be deleted until it's last InvokeLater is run.
296 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PowerLibraryImpl); 314 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::PowerLibraryImpl);
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/power_library.h ('k') | chrome/browser/chromeos/status/power_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698