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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | 343 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
344 views::MenuRunner::MENU_DELETED) | 344 views::MenuRunner::MENU_DELETED) |
345 return; | 345 return; |
346 status_ = NULL; | 346 status_ = NULL; |
347 menu_runner_.reset(NULL); | 347 menu_runner_.reset(NULL); |
348 } | 348 } |
349 | 349 |
350 //////////////////////////////////////////////////////////////////////////////// | 350 //////////////////////////////////////////////////////////////////////////////// |
351 // PowerMenuButton, PowerLibrary::Observer implementation: | 351 // PowerMenuButton, PowerLibrary::Observer implementation: |
352 | 352 |
353 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { | 353 void PowerMenuButton::PowerChanged(const PowerSupplyStatus& power_status) { |
| 354 power_status_ = power_status; |
354 UpdateIconAndLabelInfo(); | 355 UpdateIconAndLabelInfo(); |
355 } | 356 } |
356 | 357 |
357 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
358 // PowerMenuButton, StatusAreaButton implementation: | 359 // PowerMenuButton, StatusAreaButton implementation: |
359 | 360 |
360 void PowerMenuButton::UpdateIconAndLabelInfo() { | 361 void PowerMenuButton::UpdateIconAndLabelInfo() { |
361 PowerLibrary* power_lib = CrosLibrary::Get()->GetPowerLibrary(); | 362 battery_is_present_ = power_status_.battery_is_present; |
362 | 363 line_power_on_ = power_status_.line_power_on; |
363 battery_is_present_ = power_lib->IsBatteryPresent(); | |
364 line_power_on_ = power_lib->IsLinePowerOn(); | |
365 | 364 |
366 // If fully charged, always show 100% even if internal number is a bit less. | 365 // If fully charged, always show 100% even if internal number is a bit less. |
367 if (power_lib->IsBatteryFullyCharged()) { | 366 if (power_status_.battery_is_full) |
368 // We always call power_lib->GetBatteryPercentage() for test predictability. | |
369 power_lib->GetBatteryPercentage(); | |
370 battery_percentage_ = 100.0; | 367 battery_percentage_ = 100.0; |
371 } else { | 368 else |
372 battery_percentage_ = power_lib->GetBatteryPercentage(); | 369 battery_percentage_ = power_status_.battery_percentage; |
373 } | |
374 | 370 |
375 UpdateBatteryTime(&battery_time_to_full_, power_lib->GetBatteryTimeToFull()); | 371 UpdateBatteryTime(&battery_time_to_full_, |
| 372 TimeDelta::FromSeconds( |
| 373 power_status_.battery_seconds_to_full)); |
376 UpdateBatteryTime(&battery_time_to_empty_, | 374 UpdateBatteryTime(&battery_time_to_empty_, |
377 power_lib->GetBatteryTimeToEmpty()); | 375 TimeDelta::FromSeconds( |
| 376 power_status_.battery_seconds_to_empty)); |
378 | 377 |
379 string16 tooltip_text; | 378 string16 tooltip_text; |
380 if (!battery_is_present_) { | 379 if (!battery_is_present_) { |
381 battery_index_ = -1; | 380 battery_index_ = -1; |
382 SetIcon(GetMissingImage(SMALL)); | 381 SetIcon(GetMissingImage(SMALL)); |
383 tooltip_text = l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_BATTERY); | 382 tooltip_text = l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_BATTERY); |
384 } else { | 383 } else { |
385 // Preserve the fully charged icon for 100% only. | 384 // Preserve the fully charged icon for 100% only. |
386 if (battery_percentage_ >= 100) { | 385 if (battery_percentage_ >= 100) { |
387 battery_index_ = kNumPowerImages - 1; | 386 battery_index_ = kNumPowerImages - 1; |
(...skipping 28 matching lines...) Expand all Loading... |
416 // If previous is 0, then it either was never set (initial condition) | 415 // If previous is 0, then it either was never set (initial condition) |
417 // or got down to 0. | 416 // or got down to 0. |
418 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || | 417 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || |
419 diff < kMinDiff || | 418 diff < kMinDiff || |
420 diff > kMaxDiff) { | 419 diff > kMaxDiff) { |
421 *previous = current; | 420 *previous = current; |
422 } | 421 } |
423 } | 422 } |
424 | 423 |
425 } // namespace chromeos | 424 } // namespace chromeos |
OLD | NEW |