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

Side by Side Diff: ash/system/chromeos/power/power_status.h

Issue 18176013: chromeos: Refactor system tray code into PowerStatus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove virtual Created 7 years, 5 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
« no previous file with comments | « no previous file | ash/system/chromeos/power/power_status.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 #ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 6 #define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_
7 7
8 #include "ash/ash_export.h" 8 #include "ash/ash_export.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "base/strings/string16.h"
12 #include "base/time/time.h"
11 #include "chromeos/dbus/power_manager_client.h" 13 #include "chromeos/dbus/power_manager_client.h"
12 #include "chromeos/dbus/power_supply_status.h" 14 #include "chromeos/dbus/power_supply_status.h"
15 #include "ui/gfx/image/image_skia.h"
13 16
14 namespace ash { 17 namespace ash {
15 namespace internal { 18 namespace internal {
16 19
20 // PowerStatus is a singleton that receives updates about the system's
21 // power status from chromeos::PowerManagerClient and makes the information
22 // available to interested classes within Ash.
17 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer { 23 class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
18 public: 24 public:
25 // Different styles of battery icons.
26 enum IconSet {
27 ICON_LIGHT,
28 ICON_DARK
29 };
30
31 // Interface for classes that wish to be notified when the power status
32 // has changed.
19 class Observer { 33 class Observer {
20 public: 34 public:
21 // Called when the power status changes. 35 // Called when the power status changes.
22 virtual void OnPowerStatusChanged( 36 virtual void OnPowerStatusChanged() = 0;
23 const chromeos::PowerSupplyStatus& power_status) = 0;
24 37
25 protected: 38 protected:
26 virtual ~Observer() {} 39 virtual ~Observer() {}
27 }; 40 };
28 41
29 virtual ~PowerStatus(); 42 virtual ~PowerStatus();
30 43
31 // Sets the global instance. Must be called before any calls to Get(). 44 // Sets the global instance. Must be called before any calls to Get().
32 static void Initialize(); 45 static void Initialize();
33 46
34 // Destroys the global instance. 47 // Destroys the global instance.
35 static void Shutdown(); 48 static void Shutdown();
36 49
37 // Returns true if the global instance is initialized. 50 // Returns true if the global instance is initialized.
38 static bool IsInitialized(); 51 static bool IsInitialized();
39 52
40 // Gets the global instance. Initialize must be called first. 53 // Gets the global instance. Initialize must be called first.
41 static PowerStatus* Get(); 54 static PowerStatus* Get();
42 55
43 // Adds an observer. 56 void set_status_for_testing(const chromeos::PowerSupplyStatus& status) {
44 virtual void AddObserver(Observer* observer); 57 status_ = status;
58 }
45 59
46 // Removes an observer. 60 // Adds or removes an observer.
47 virtual void RemoveObserver(Observer* observer); 61 void AddObserver(Observer* observer);
62 void RemoveObserver(Observer* observer);
48 63
49 // Requests power status update. 64 // Requests updated status from the power manager.
50 void RequestStatusUpdate(); 65 void RequestStatusUpdate();
51 66
52 // Gets the current power supply status. 67 // Returns true if a battery is present.
53 chromeos::PowerSupplyStatus GetPowerSupplyStatus() const; 68 bool IsBatteryPresent() const;
69
70 // Returns true if the battery is full.
71 bool IsBatteryFull() const;
72
73 // Returns the battery's remaining charge as a value in the range [0.0,
74 // 100.0].
75 double GetBatteryPercent() const;
76
77 // Returns the battery's remaining charge, rounded to an integer with a
78 // maximum value of 100.
79 int GetRoundedBatteryPercent() const;
80
81 // Returns true if the battery's time-to-full and time-to-empty estimates
82 // should not be displayed because the power manager is still calculating
83 // them.
84 bool IsBatteryTimeBeingCalculated() const;
85
86 // Returns the estimated time until the battery is empty (if line power
87 // is disconnected) or full (if line power is connected). These estimates
88 // should only be used if IsBatteryTimeBeingCalculated() returns false.
89 base::TimeDelta GetBatteryTimeToEmpty() const;
90 base::TimeDelta GetBatteryTimeToFull() const;
91
92 // Returns true if line power (including a charger of any type) is connected.
93 bool IsLinePowerConnected() const;
94
95 // Returns true if an official, non-USB charger is connected.
96 bool IsMainsChargerConnected() const;
97
98 // Returns true if a USB charger (which is likely to only support a low
99 // charging rate) is connected.
100 bool IsUsbChargerConnected() const;
101
102 // Returns the image that should be shown for the battery's current state.
103 gfx::ImageSkia GetBatteryImage(IconSet icon_set) const;
104
105 // Returns an string describing the current state for accessibility.
106 base::string16 GetAccessibleNameString() const;
54 107
55 protected: 108 protected:
56 PowerStatus(); 109 PowerStatus();
57 110
58 private: 111 private:
59 // Overriden from PowerManagerClient::Observer. 112 // Overriden from PowerManagerClient::Observer.
60 virtual void PowerChanged( 113 virtual void PowerChanged(const chromeos::PowerSupplyStatus& status) OVERRIDE;
61 const chromeos::PowerSupplyStatus& power_status) OVERRIDE;
62 114
63 ObserverList<Observer> observers_; 115 ObserverList<Observer> observers_;
64 116
65 // PowerSupplyStatus state. 117 // Current state.
66 chromeos::PowerSupplyStatus power_supply_status_; 118 chromeos::PowerSupplyStatus status_;
67 119
68 DISALLOW_COPY_AND_ASSIGN(PowerStatus); 120 DISALLOW_COPY_AND_ASSIGN(PowerStatus);
69 }; 121 };
70 122
71 } // namespace internal 123 } // namespace internal
72 } // namespace ash 124 } // namespace ash
73 125
74 #endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_ 126 #endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_H_
OLDNEW
« no previous file with comments | « no previous file | ash/system/chromeos/power/power_status.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698