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

Side by Side Diff: chrome/browser/chromeos/status/power_menu_button.cc

Issue 8347016: chromeos: Simplify power supply info in PowerLibrary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed copy error Created 9 years, 2 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
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/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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/cros/cros_library.h" 14 #include "chrome/browser/chromeos/cros/cros_library.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 #include "third_party/cros/chromeos_power.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/canvas_skia.h" 21 #include "ui/gfx/canvas_skia.h"
21 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
22 #include "views/controls/menu/menu_item_view.h" 23 #include "views/controls/menu/menu_item_view.h"
23 #include "views/controls/menu/menu_runner.h" 24 #include "views/controls/menu/menu_runner.h"
24 #include "views/controls/menu/submenu_view.h" 25 #include "views/controls/menu/submenu_view.h"
25 #include "views/widget/widget.h" 26 #include "views/widget/widget.h"
26 27
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == 344 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) ==
344 views::MenuRunner::MENU_DELETED) 345 views::MenuRunner::MENU_DELETED)
345 return; 346 return;
346 status_ = NULL; 347 status_ = NULL;
347 menu_runner_.reset(NULL); 348 menu_runner_.reset(NULL);
348 } 349 }
349 350
350 //////////////////////////////////////////////////////////////////////////////// 351 ////////////////////////////////////////////////////////////////////////////////
351 // PowerMenuButton, PowerLibrary::Observer implementation: 352 // PowerMenuButton, PowerLibrary::Observer implementation:
352 353
353 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { 354 void PowerMenuButton::PowerChanged(const PowerStatus& power_status) {
355 power_status_ = power_status;
354 UpdateIconAndLabelInfo(); 356 UpdateIconAndLabelInfo();
355 } 357 }
356 358
357 //////////////////////////////////////////////////////////////////////////////// 359 ////////////////////////////////////////////////////////////////////////////////
358 // PowerMenuButton, StatusAreaButton implementation: 360 // PowerMenuButton, StatusAreaButton implementation:
359 361
360 void PowerMenuButton::UpdateIconAndLabelInfo() { 362 void PowerMenuButton::UpdateIconAndLabelInfo() {
361 PowerLibrary* power_lib = CrosLibrary::Get()->GetPowerLibrary(); 363 battery_is_present_ = power_status_.battery_is_present;
362 364 line_power_on_ = power_status_.line_power_on;
363 battery_is_present_ = power_lib->IsBatteryPresent();
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 (power_lib->IsBatteryFullyCharged()) { 367 if (power_status_.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED)
368 // We always call power_lib->GetBatteryPercentage() for test predictability.
369 power_lib->GetBatteryPercentage();
370 battery_percentage_ = 100.0; 368 battery_percentage_ = 100.0;
371 } else { 369 else
372 battery_percentage_ = power_lib->GetBatteryPercentage(); 370 battery_percentage_ = power_status_.battery_percentage;
373 }
374 371
375 UpdateBatteryTime(&battery_time_to_full_, power_lib->GetBatteryTimeToFull()); 372 UpdateBatteryTime(&battery_time_to_full_,
373 TimeDelta::FromSeconds(power_status_.battery_time_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_time_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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698