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/status/power_menu_button.h" | 5 #include "chrome/browser/chromeos/status/power_menu_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // PowerMenuButton, PowerLibrary::Observer implementation: | 351 // PowerMenuButton, PowerLibrary::Observer implementation: |
352 | 352 |
353 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { | 353 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { |
354 UpdateIconAndLabelInfo(); | 354 UpdateIconAndLabelInfo(); |
355 } | 355 } |
356 | 356 |
357 //////////////////////////////////////////////////////////////////////////////// | 357 //////////////////////////////////////////////////////////////////////////////// |
358 // PowerMenuButton, StatusAreaButton implementation: | 358 // PowerMenuButton, StatusAreaButton implementation: |
359 | 359 |
360 void PowerMenuButton::UpdateIconAndLabelInfo() { | 360 void PowerMenuButton::UpdateIconAndLabelInfo() { |
361 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary(); | 361 PowerLibrary* power_lib = CrosLibrary::Get()->GetPowerLibrary(); |
362 | 362 |
363 battery_is_present_ = cros->battery_is_present(); | 363 battery_is_present_ = power_lib->IsBatteryPresent(); |
364 line_power_on_ = cros->line_power_on(); | 364 line_power_on_ = power_lib->IsLinePowerOn(); |
365 | 365 |
366 // If fully charged, always show 100% even if internal number is a bit less. | 366 // If fully charged, always show 100% even if internal number is a bit less. |
367 if (cros->battery_fully_charged()) { | 367 if (power_lib->IsBatteryFullyCharged()) { |
368 // We always call cros->battery_percentage() for test predictability. | 368 // We always call power_lib->GetBatteryPercentage() for test predictability. |
369 cros->battery_percentage(); | 369 power_lib->GetBatteryPercentage(); |
370 battery_percentage_ = 100.0; | 370 battery_percentage_ = 100.0; |
371 } else { | 371 } else { |
372 battery_percentage_ = cros->battery_percentage(); | 372 battery_percentage_ = power_lib->GetBatteryPercentage(); |
373 } | 373 } |
374 | 374 |
375 UpdateBatteryTime(&battery_time_to_full_, cros->battery_time_to_full()); | 375 UpdateBatteryTime(&battery_time_to_full_, power_lib->GetBatteryTimeToFull()); |
376 UpdateBatteryTime(&battery_time_to_empty_, cros->battery_time_to_empty()); | 376 UpdateBatteryTime(&battery_time_to_empty_, |
| 377 power_lib->GetBatteryTimeToEmpty()); |
377 | 378 |
378 string16 tooltip_text; | 379 string16 tooltip_text; |
379 if (!battery_is_present_) { | 380 if (!battery_is_present_) { |
380 battery_index_ = -1; | 381 battery_index_ = -1; |
381 SetIcon(GetMissingImage(SMALL)); | 382 SetIcon(GetMissingImage(SMALL)); |
382 tooltip_text = l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_BATTERY); | 383 tooltip_text = l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_BATTERY); |
383 } else { | 384 } else { |
384 // Preserve the fully charged icon for 100% only. | 385 // Preserve the fully charged icon for 100% only. |
385 if (battery_percentage_ >= 100) { | 386 if (battery_percentage_ >= 100) { |
386 battery_index_ = kNumPowerImages - 1; | 387 battery_index_ = kNumPowerImages - 1; |
(...skipping 28 matching lines...) Expand all Loading... |
415 // If previous is 0, then it either was never set (initial condition) | 416 // If previous is 0, then it either was never set (initial condition) |
416 // or got down to 0. | 417 // or got down to 0. |
417 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || | 418 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || |
418 diff < kMinDiff || | 419 diff < kMinDiff || |
419 diff > kMaxDiff) { | 420 diff > kMaxDiff) { |
420 *previous = current; | 421 *previous = current; |
421 } | 422 } |
422 } | 423 } |
423 | 424 |
424 } // namespace chromeos | 425 } // namespace chromeos |
OLD | NEW |