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

Side by Side Diff: chrome/browser/chromeos/dbus/power_manager_client.cc

Issue 8555018: Increased battery time to empty sent by power manager stub impl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: increased time to empty full battery Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/dbus/power_manager_client.h" 5 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); 240 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl);
241 }; 241 };
242 242
243 // The PowerManagerClient implementation used on Linux desktop, 243 // The PowerManagerClient implementation used on Linux desktop,
244 // which does nothing. 244 // which does nothing.
245 class PowerManagerClientStubImpl : public PowerManagerClient { 245 class PowerManagerClientStubImpl : public PowerManagerClient {
246 public: 246 public:
247 PowerManagerClientStubImpl() 247 PowerManagerClientStubImpl()
248 : discharging_(true), 248 : discharging_(true),
249 battery_percentage_(80), 249 battery_percentage_(80),
250 pause_count_(0) { 250 pause_count_(0),
251 kSecondsToEmptyFullBattery(3 * 60 * 60) /* 3 hours */ {
satorux1 2011/11/14 22:59:50 It's awkward to make it a member variable. see bel
tbarzic 2011/11/14 23:05:39 Done.
251 } 252 }
252 253
253 virtual ~PowerManagerClientStubImpl() {} 254 virtual ~PowerManagerClientStubImpl() {}
254 255
255 // PowerManagerClient override. 256 // PowerManagerClient override.
256 virtual void AddObserver(Observer* observer) OVERRIDE { 257 virtual void AddObserver(Observer* observer) OVERRIDE {
257 observers_.AddObserver(observer); 258 observers_.AddObserver(observer);
258 } 259 }
259 260
260 // PowerManagerClient override. 261 // PowerManagerClient override.
261 virtual void RemoveObserver(Observer* observer) OVERRIDE { 262 virtual void RemoveObserver(Observer* observer) OVERRIDE {
262 observers_.RemoveObserver(observer); 263 observers_.RemoveObserver(observer);
263 } 264 }
264 265
265 // PowerManagerClient override. 266 // PowerManagerClient override.
266 virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE { 267 virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE {
267 VLOG(1) << "Requested to descrease screen brightness"; 268 VLOG(1) << "Requested to descrease screen brightness";
268 } 269 }
269 270
270 // PowerManagerClient override. 271 // PowerManagerClient override.
271 virtual void IncreaseScreenBrightness() OVERRIDE { 272 virtual void IncreaseScreenBrightness() OVERRIDE {
272 VLOG(1) << "Requested to increase screen brightness"; 273 VLOG(1) << "Requested to increase screen brightness";
273 } 274 }
274 275
275 virtual void RequestStatusUpdate() OVERRIDE { 276 virtual void RequestStatusUpdate() OVERRIDE {
276 if (!timer_.IsRunning()) { 277 if (!timer_.IsRunning()) {
277 timer_.Start( 278 timer_.Start(
278 FROM_HERE, 279 FROM_HERE,
279 base::TimeDelta::FromMilliseconds(100), 280 base::TimeDelta::FromMilliseconds(200),
280 this, 281 this,
281 &PowerManagerClientStubImpl::Update); 282 &PowerManagerClientStubImpl::Update);
282 } else { 283 } else {
283 timer_.Stop(); 284 timer_.Stop();
284 } 285 }
285 } 286 }
286 287
287 virtual void RequestRestart() OVERRIDE {} 288 virtual void RequestRestart() OVERRIDE {}
288 289
289 virtual void RequestShutdown() OVERRIDE {} 290 virtual void RequestShutdown() OVERRIDE {}
290 291
291 private: 292 private:
292 void Update() { 293 void Update() {
293 // We pause at 0 and 100% so that it's easier to check those conditions. 294 // We pause at 0 and 100% so that it's easier to check those conditions.
294 if (pause_count_ > 1) { 295 if (pause_count_ > 1) {
295 pause_count_--; 296 pause_count_--;
296 return; 297 return;
297 } 298 }
298 299
299 if (battery_percentage_ == 0 || battery_percentage_ == 100) { 300 if (battery_percentage_ == 0 || battery_percentage_ == 100) {
300 if (pause_count_) { 301 if (pause_count_) {
301 pause_count_ = 0; 302 pause_count_ = 0;
302 discharging_ = !discharging_; 303 discharging_ = !discharging_;
303 } else { 304 } else {
304 pause_count_ = 20; 305 pause_count_ = 10;
305 return; 306 return;
306 } 307 }
307 } 308 }
308 battery_percentage_ += (discharging_ ? -1 : 1); 309 battery_percentage_ += (discharging_ ? -1 : 1);
309 310
310 PowerSupplyStatus status; 311 PowerSupplyStatus status;
satorux1 2011/11/14 22:59:50 You can define the constant here: const int kSeco
tbarzic 2011/11/14 23:05:39 Done.
311 status.line_power_on = !discharging_; 312 status.line_power_on = !discharging_;
312 status.battery_is_present = true; 313 status.battery_is_present = true;
313 status.battery_percentage = battery_percentage_; 314 status.battery_percentage = battery_percentage_;
314 status.battery_seconds_to_empty = 315 status.battery_seconds_to_empty =
315 std::max(1, battery_percentage_ * 180 / 100); 316 std::max(1, battery_percentage_ * kSecondsToEmptyFullBattery / 100);
316 status.battery_seconds_to_full = 317 status.battery_seconds_to_full =
317 std::max(static_cast<int64>(1), 180 - status.battery_seconds_to_empty); 318 std::max(static_cast<int64>(1),
319 kSecondsToEmptyFullBattery - status.battery_seconds_to_empty);
318 320
319 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); 321 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status));
320 } 322 }
321 323
322 bool discharging_; 324 bool discharging_;
323 int battery_percentage_; 325 int battery_percentage_;
324 int pause_count_; 326 int pause_count_;
327 const int kSecondsToEmptyFullBattery;
325 ObserverList<Observer> observers_; 328 ObserverList<Observer> observers_;
326 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; 329 base::RepeatingTimer<PowerManagerClientStubImpl> timer_;
327 }; 330 };
328 331
329 PowerManagerClient::PowerManagerClient() { 332 PowerManagerClient::PowerManagerClient() {
330 } 333 }
331 334
332 PowerManagerClient::~PowerManagerClient() { 335 PowerManagerClient::~PowerManagerClient() {
333 } 336 }
334 337
335 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { 338 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) {
336 if (system::runtime_environment::IsRunningOnChromeOS()) { 339 if (system::runtime_environment::IsRunningOnChromeOS()) {
337 return new PowerManagerClientImpl(bus); 340 return new PowerManagerClientImpl(bus);
338 } else { 341 } else {
339 return new PowerManagerClientStubImpl(); 342 return new PowerManagerClientStubImpl();
340 } 343 }
341 } 344 }
342 345
343 } // namespace chromeos 346 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698