Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 269 |
| 270 // PowerManagerClient override. | 270 // PowerManagerClient override. |
| 271 virtual void IncreaseScreenBrightness() OVERRIDE { | 271 virtual void IncreaseScreenBrightness() OVERRIDE { |
| 272 VLOG(1) << "Requested to increase screen brightness"; | 272 VLOG(1) << "Requested to increase screen brightness"; |
| 273 } | 273 } |
| 274 | 274 |
| 275 virtual void RequestStatusUpdate() OVERRIDE { | 275 virtual void RequestStatusUpdate() OVERRIDE { |
| 276 if (!timer_.IsRunning()) { | 276 if (!timer_.IsRunning()) { |
| 277 timer_.Start( | 277 timer_.Start( |
| 278 FROM_HERE, | 278 FROM_HERE, |
| 279 base::TimeDelta::FromMilliseconds(100), | 279 base::TimeDelta::FromMilliseconds(1000), |
| 280 this, | 280 this, |
| 281 &PowerManagerClientStubImpl::Update); | 281 &PowerManagerClientStubImpl::Update); |
| 282 } else { | 282 } else { |
| 283 timer_.Stop(); | 283 timer_.Stop(); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 virtual void RequestRestart() OVERRIDE {} | 287 virtual void RequestRestart() OVERRIDE {} |
| 288 | 288 |
| 289 virtual void RequestShutdown() OVERRIDE {} | 289 virtual void RequestShutdown() OVERRIDE {} |
| 290 | 290 |
| 291 private: | 291 private: |
| 292 void Update() { | 292 void Update() { |
| 293 // We pause at 0 and 100% so that it's easier to check those conditions. | 293 // We pause at 0 and 100% so that it's easier to check those conditions. |
| 294 if (pause_count_ > 1) { | 294 if (pause_count_ > 1) { |
| 295 pause_count_--; | 295 pause_count_--; |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 if (battery_percentage_ == 0 || battery_percentage_ == 100) { | 299 if (battery_percentage_ == 0 || battery_percentage_ == 100) { |
| 300 if (pause_count_) { | 300 if (pause_count_) { |
| 301 pause_count_ = 0; | 301 pause_count_ = 0; |
| 302 discharging_ = !discharging_; | 302 discharging_ = !discharging_; |
| 303 } else { | 303 } else { |
| 304 pause_count_ = 20; | 304 pause_count_ = 2; |
|
satorux1
2011/11/14 23:46:57
Not your fault, but this logic looks rather awkwar
| |
| 305 return; | 305 return; |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 battery_percentage_ += (discharging_ ? -1 : 1); | 308 battery_percentage_ += (discharging_ ? -1 : 1); |
| 309 | 309 |
| 310 const int kSecondsToEmptyFullBattery(3 * 60 * 60); // 3 hours. | |
|
satorux1
2011/11/14 23:46:57
two spaces before // per our style guide.
| |
| 311 | |
| 310 PowerSupplyStatus status; | 312 PowerSupplyStatus status; |
| 311 status.line_power_on = !discharging_; | 313 status.line_power_on = !discharging_; |
| 312 status.battery_is_present = true; | 314 status.battery_is_present = true; |
| 313 status.battery_percentage = battery_percentage_; | 315 status.battery_percentage = battery_percentage_; |
| 314 status.battery_seconds_to_empty = | 316 status.battery_seconds_to_empty = |
| 315 std::max(1, battery_percentage_ * 180 / 100); | 317 std::max(1, battery_percentage_ * kSecondsToEmptyFullBattery / 100); |
| 316 status.battery_seconds_to_full = | 318 status.battery_seconds_to_full = |
| 317 std::max(static_cast<int64>(1), 180 - status.battery_seconds_to_empty); | 319 std::max(static_cast<int64>(1), |
| 320 kSecondsToEmptyFullBattery - status.battery_seconds_to_empty); | |
| 318 | 321 |
| 319 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); | 322 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); |
| 320 } | 323 } |
| 321 | 324 |
| 322 bool discharging_; | 325 bool discharging_; |
| 323 int battery_percentage_; | 326 int battery_percentage_; |
| 324 int pause_count_; | 327 int pause_count_; |
| 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 |
| OLD | NEW |