| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/common/system/chromeos/power/power_status.h" | 5 #include "ash/common/system/chromeos/power/power_status.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "ash/common/dbus_thread_manager_ash.h" |
| 10 #include "ash/common/material_design/material_design_controller.h" | 11 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/resources/vector_icons/vector_icons.h" | 12 #include "ash/resources/vector_icons/vector_icons.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" | 16 // #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "chromeos/dbus/power_manager_client.h" | 17 #include "chromeos/dbus/power_manager_client.h" |
| 17 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
| 18 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/l10n/time_format.h" | 21 #include "ui/base/l10n/time_format.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/display/display.h" | 23 #include "ui/display/display.h" |
| 23 #include "ui/display/screen.h" | 24 #include "ui/display/screen.h" |
| 24 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 DCHECK(observer); | 220 DCHECK(observer); |
| 220 observers_.AddObserver(observer); | 221 observers_.AddObserver(observer); |
| 221 } | 222 } |
| 222 | 223 |
| 223 void PowerStatus::RemoveObserver(Observer* observer) { | 224 void PowerStatus::RemoveObserver(Observer* observer) { |
| 224 DCHECK(observer); | 225 DCHECK(observer); |
| 225 observers_.RemoveObserver(observer); | 226 observers_.RemoveObserver(observer); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void PowerStatus::RequestStatusUpdate() { | 229 void PowerStatus::RequestStatusUpdate() { |
| 229 chromeos::DBusThreadManager::Get() | 230 DBusThreadManagerAsh::Get() |
| 230 ->GetPowerManagerClient() | 231 ->GetPowerManagerClient() |
| 231 ->RequestStatusUpdate(); | 232 ->RequestStatusUpdate(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void PowerStatus::SetPowerSource(const std::string& id) { | 235 void PowerStatus::SetPowerSource(const std::string& id) { |
| 235 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->SetPowerSource( | 236 DBusThreadManagerAsh::Get()->GetPowerManagerClient()->SetPowerSource( |
| 236 id); | 237 id); |
| 237 } | 238 } |
| 238 | 239 |
| 239 bool PowerStatus::IsBatteryPresent() const { | 240 bool PowerStatus::IsBatteryPresent() const { |
| 240 return proto_.battery_state() != | 241 return proto_.battery_state() != |
| 241 power_manager::PowerSupplyProperties_BatteryState_NOT_PRESENT; | 242 power_manager::PowerSupplyProperties_BatteryState_NOT_PRESENT; |
| 242 } | 243 } |
| 243 | 244 |
| 244 bool PowerStatus::IsBatteryFull() const { | 245 bool PowerStatus::IsBatteryFull() const { |
| 245 return proto_.battery_state() == | 246 return proto_.battery_state() == |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 : IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_ACCESSIBLE, | 483 : IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_ACCESSIBLE, |
| 483 GetBatteryTimeAccessibilityString(hour, min)); | 484 GetBatteryTimeAccessibilityString(hour, min)); |
| 484 } | 485 } |
| 485 return battery_time_accessible.empty() | 486 return battery_time_accessible.empty() |
| 486 ? battery_percentage_accessible | 487 ? battery_percentage_accessible |
| 487 : battery_percentage_accessible + base::ASCIIToUTF16(". ") + | 488 : battery_percentage_accessible + base::ASCIIToUTF16(". ") + |
| 488 battery_time_accessible; | 489 battery_time_accessible; |
| 489 } | 490 } |
| 490 | 491 |
| 491 PowerStatus::PowerStatus() { | 492 PowerStatus::PowerStatus() { |
| 492 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 493 DBusThreadManagerAsh::Get()->GetPowerManagerClient()->AddObserver( |
| 493 this); | 494 this); |
| 494 chromeos::DBusThreadManager::Get() | 495 DBusThreadManagerAsh::Get() |
| 495 ->GetPowerManagerClient() | 496 ->GetPowerManagerClient() |
| 496 ->RequestStatusUpdate(); | 497 ->RequestStatusUpdate(); |
| 497 } | 498 } |
| 498 | 499 |
| 499 PowerStatus::~PowerStatus() { | 500 PowerStatus::~PowerStatus() { |
| 500 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 501 DBusThreadManagerAsh::Get()->GetPowerManagerClient()->RemoveObserver( |
| 501 this); | 502 this); |
| 502 } | 503 } |
| 503 | 504 |
| 504 void PowerStatus::SetProtoForTesting( | 505 void PowerStatus::SetProtoForTesting( |
| 505 const power_manager::PowerSupplyProperties& proto) { | 506 const power_manager::PowerSupplyProperties& proto) { |
| 506 proto_ = proto; | 507 proto_ = proto; |
| 507 SanitizeProto(&proto_); | 508 SanitizeProto(&proto_); |
| 508 } | 509 } |
| 509 | 510 |
| 510 void PowerStatus::PowerChanged( | 511 void PowerStatus::PowerChanged( |
| 511 const power_manager::PowerSupplyProperties& proto) { | 512 const power_manager::PowerSupplyProperties& proto) { |
| 512 proto_ = proto; | 513 proto_ = proto; |
| 513 SanitizeProto(&proto_); | 514 SanitizeProto(&proto_); |
| 514 FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged()); | 515 FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged()); |
| 515 } | 516 } |
| 516 | 517 |
| 517 } // namespace ash | 518 } // namespace ash |
| OLD | NEW |