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

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

Issue 7891021: Use stub impl when libcros fails to load (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix power manager stub impl Created 9 years, 3 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 | Annotate | Revision Log
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"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 PreferredSizeChanged(); 154 PreferredSizeChanged();
155 // Force a paint even if the size didn't change. 155 // Force a paint even if the size didn't change.
156 SchedulePaint(); 156 SchedulePaint();
157 } 157 }
158 158
159 protected: 159 protected:
160 void OnPaint(gfx::Canvas* canvas) { 160 void OnPaint(gfx::Canvas* canvas) {
161 SkBitmap image; 161 SkBitmap image;
162 162
163 bool draw_percentage_text = false; 163 bool draw_percentage_text = false;
164 if (!CrosLibrary::Get()->EnsureLoaded()) { 164 if (!menu_button_->battery_is_present_) {
165 image = GetUnknownImage(LARGE);
166 } else if (!menu_button_->battery_is_present_) {
167 image = GetMissingImage(LARGE); 165 image = GetMissingImage(LARGE);
168 } else { 166 } else {
169 image = GetImage( 167 image = GetImage(
170 LARGE, 168 LARGE,
171 menu_button_->line_power_on_ ? CHARGING : DISCHARGING, 169 menu_button_->line_power_on_ ? CHARGING : DISCHARGING,
172 menu_button_->battery_index_); 170 menu_button_->battery_index_);
173 if (menu_button_->battery_percentage_ < 100 || 171 if (menu_button_->battery_percentage_ < 100 ||
174 !menu_button_->line_power_on_) { 172 !menu_button_->line_power_on_) {
175 draw_percentage_text = true; 173 draw_percentage_text = true;
176 } 174 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 //////////////////////////////////////////////////////////////////////////////// 307 ////////////////////////////////////////////////////////////////////////////////
310 // PowerMenuButton, views::View implementation: 308 // PowerMenuButton, views::View implementation:
311 void PowerMenuButton::OnLocaleChanged() { 309 void PowerMenuButton::OnLocaleChanged() {
312 UpdateIconAndLabelInfo(); 310 UpdateIconAndLabelInfo();
313 } 311 }
314 312
315 //////////////////////////////////////////////////////////////////////////////// 313 ////////////////////////////////////////////////////////////////////////////////
316 // PowerMenuButton, views::ViewMenuDelegate implementation: 314 // PowerMenuButton, views::ViewMenuDelegate implementation:
317 315
318 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { 316 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
317 // Explicitly query the power status.
318 CrosLibrary::Get()->GetPowerLibrary()->RequestStatusUpdate();
319
319 views::MenuItemView* menu = new views::MenuItemView(this); 320 views::MenuItemView* menu = new views::MenuItemView(this);
320 // MenuRunner takes ownership of |menu|. 321 // MenuRunner takes ownership of |menu|.
321 menu_runner_.reset(new views::MenuRunner(menu)); 322 menu_runner_.reset(new views::MenuRunner(menu));
322 views::MenuItemView* submenu = menu->AppendMenuItem( 323 views::MenuItemView* submenu = menu->AppendMenuItem(
323 POWER_BATTERY_PERCENTAGE_ITEM, 324 POWER_BATTERY_PERCENTAGE_ITEM,
324 std::wstring(), 325 std::wstring(),
325 views::MenuItemView::NORMAL); 326 views::MenuItemView::NORMAL);
326 status_ = new StatusView(this); 327 status_ = new StatusView(this);
327 submenu->AddChildView(status_); 328 submenu->AddChildView(status_);
328 menu->CreateSubmenu()->set_resize_open_menu(true); 329 menu->CreateSubmenu()->set_resize_open_menu(true);
(...skipping 18 matching lines...) Expand all
347 348
348 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { 349 void PowerMenuButton::PowerChanged(PowerLibrary* obj) {
349 UpdateIconAndLabelInfo(); 350 UpdateIconAndLabelInfo();
350 } 351 }
351 352
352 //////////////////////////////////////////////////////////////////////////////// 353 ////////////////////////////////////////////////////////////////////////////////
353 // PowerMenuButton, StatusAreaButton implementation: 354 // PowerMenuButton, StatusAreaButton implementation:
354 355
355 void PowerMenuButton::UpdateIconAndLabelInfo() { 356 void PowerMenuButton::UpdateIconAndLabelInfo() {
356 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary(); 357 PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary();
357 if (!cros)
358 return;
359 358
360 bool cros_loaded = CrosLibrary::Get()->EnsureLoaded(); 359 battery_is_present_ = cros->battery_is_present();
361 if (cros_loaded) { 360 line_power_on_ = cros->line_power_on();
362 battery_is_present_ = cros->battery_is_present();
363 line_power_on_ = cros->line_power_on();
364 361
365 // If fully charged, always show 100% even if internal number is a bit less. 362 // If fully charged, always show 100% even if internal number is a bit less.
366 if (cros->battery_fully_charged()) { 363 if (cros->battery_fully_charged()) {
367 // We always call cros->battery_percentage() for test predictability. 364 // We always call cros->battery_percentage() for test predictability.
368 cros->battery_percentage(); 365 cros->battery_percentage();
369 battery_percentage_ = 100.0; 366 battery_percentage_ = 100.0;
370 } else { 367 } else {
371 battery_percentage_ = cros->battery_percentage(); 368 battery_percentage_ = cros->battery_percentage();
372 }
373
374 UpdateBatteryTime(&battery_time_to_full_, cros->battery_time_to_full());
375 UpdateBatteryTime(&battery_time_to_empty_, cros->battery_time_to_empty());
376 } 369 }
377 370
378 if (!cros_loaded) { 371 UpdateBatteryTime(&battery_time_to_full_, cros->battery_time_to_full());
379 battery_index_ = -1; 372 UpdateBatteryTime(&battery_time_to_empty_, cros->battery_time_to_empty());
380 SetIcon(GetUnknownImage(SMALL)); 373
381 } else if (!battery_is_present_) { 374 if (!battery_is_present_) {
382 battery_index_ = -1; 375 battery_index_ = -1;
383 SetIcon(GetMissingImage(SMALL)); 376 SetIcon(GetMissingImage(SMALL));
384 } else { 377 } else {
385 // Preserve the fully charged icon for 100% only. 378 // Preserve the fully charged icon for 100% only.
386 if (battery_percentage_ >= 100) { 379 if (battery_percentage_ >= 100) {
387 battery_index_ = kNumPowerImages - 1; 380 battery_index_ = kNumPowerImages - 1;
388 } else { 381 } else {
389 battery_index_ = 382 battery_index_ =
390 static_cast<int>(battery_percentage_ / 100.0 * 383 static_cast<int>(battery_percentage_ / 100.0 *
391 nextafter(static_cast<float>(kNumPowerImages - 1), 0)); 384 nextafter(static_cast<float>(kNumPowerImages - 1), 0));
(...skipping 22 matching lines...) Expand all
414 // If previous is 0, then it either was never set (initial condition) 407 // If previous is 0, then it either was never set (initial condition)
415 // or got down to 0. 408 // or got down to 0.
416 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || 409 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) ||
417 diff < kMinDiff || 410 diff < kMinDiff ||
418 diff > kMaxDiff) { 411 diff > kMaxDiff) {
419 *previous = current; 412 *previous = current;
420 } 413 }
421 } 414 }
422 415
423 } // namespace chromeos 416 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698