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

Side by Side Diff: base/system_monitor/system_monitor.h

Issue 9363008: Add Media device notification to SystemMonitor and Mac impl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 10 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 #ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 5 #ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
6 #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 6 #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/base_export.h" 9 #include "base/base_export.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_path.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 13
13 // Windows HiRes timers drain the battery faster so we need to know the battery 14 // Windows HiRes timers drain the battery faster so we need to know the battery
14 // status. This isn't true for other platforms. 15 // status. This isn't true for other platforms.
15 #if defined(OS_WIN) 16 #if defined(OS_WIN)
16 #define ENABLE_BATTERY_MONITORING 1 17 #define ENABLE_BATTERY_MONITORING 1
17 #else 18 #else
18 #undef ENABLE_BATTERY_MONITORING 19 #undef ENABLE_BATTERY_MONITORING
19 #endif // !OS_WIN 20 #endif // !OS_WIN
20 21
(...skipping 14 matching lines...) Expand all
35 // TODO(mbelshe): Add support beyond just power management. 36 // TODO(mbelshe): Add support beyond just power management.
36 class BASE_EXPORT SystemMonitor { 37 class BASE_EXPORT SystemMonitor {
37 public: 38 public:
38 // Normalized list of power events. 39 // Normalized list of power events.
39 enum PowerEvent { 40 enum PowerEvent {
40 POWER_STATE_EVENT, // The Power status of the system has changed. 41 POWER_STATE_EVENT, // The Power status of the system has changed.
41 SUSPEND_EVENT, // The system is being suspended. 42 SUSPEND_EVENT, // The system is being suspended.
42 RESUME_EVENT // The system is being resumed. 43 RESUME_EVENT // The system is being resumed.
43 }; 44 };
44 45
46 typedef unsigned long DeviceIdType;
47
45 // Create SystemMonitor. Only one SystemMonitor instance per application 48 // Create SystemMonitor. Only one SystemMonitor instance per application
46 // is allowed. 49 // is allowed.
47 SystemMonitor(); 50 SystemMonitor();
48 ~SystemMonitor(); 51 ~SystemMonitor();
49 52
50 // Get the application-wide SystemMonitor (if not present, returns NULL). 53 // Get the application-wide SystemMonitor (if not present, returns NULL).
51 static SystemMonitor* Get(); 54 static SystemMonitor* Get();
52 55
53 #if defined(OS_MACOSX) 56 #if defined(OS_MACOSX)
54 // Allocate system resources needed by the SystemMonitor class. 57 // Allocate system resources needed by the SystemMonitor class.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Notification that the system is resuming. 89 // Notification that the system is resuming.
87 virtual void OnResume() {} 90 virtual void OnResume() {}
88 91
89 protected: 92 protected:
90 virtual ~PowerObserver() {} 93 virtual ~PowerObserver() {}
91 }; 94 };
92 95
93 class BASE_EXPORT DevicesChangedObserver { 96 class BASE_EXPORT DevicesChangedObserver {
94 public: 97 public:
95 // Notification that the devices connected to the system have changed. 98 // Notification that the devices connected to the system have changed.
99 // This is only implemented on Windows currently.
96 virtual void OnDevicesChanged() {} 100 virtual void OnDevicesChanged() {}
97 101
102 // When a media device is attached or detached, one of these two events
103 // if triggered.
104 // TODO(vandebo) Pass an appropriate device identifier or way to interact
105 // with the devices instead of FilePath.
106 virtual void OnMediaDeviceAttached(const DeviceIdType& id,
107 const std::string& name,
108 const FilePath& path) {}
109
110 virtual void OnMediaDeviceDetached(const DeviceIdType& id) {}
111
98 protected: 112 protected:
99 virtual ~DevicesChangedObserver() {} 113 virtual ~DevicesChangedObserver() {}
100 }; 114 };
101 115
102 // Add a new observer. 116 // Add a new observer.
103 // Can be called from any thread. 117 // Can be called from any thread.
104 // Must not be called from within a notification callback. 118 // Must not be called from within a notification callback.
105 void AddPowerObserver(PowerObserver* obs); 119 void AddPowerObserver(PowerObserver* obs);
106 void AddDevicesChangedObserver(DevicesChangedObserver* obs); 120 void AddDevicesChangedObserver(DevicesChangedObserver* obs);
107 121
108 // Remove an existing observer. 122 // Remove an existing observer.
109 // Can be called from any thread. 123 // Can be called from any thread.
110 // Must not be called from within a notification callback. 124 // Must not be called from within a notification callback.
111 void RemovePowerObserver(PowerObserver* obs); 125 void RemovePowerObserver(PowerObserver* obs);
112 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); 126 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs);
113 127
114 #if defined(OS_WIN) 128 #if defined(OS_WIN)
115 // Windows-specific handling of a WM_POWERBROADCAST message. 129 // Windows-specific handling of a WM_POWERBROADCAST message.
116 // Embedders of this API should hook their top-level window 130 // Embedders of this API should hook their top-level window
117 // message loop and forward WM_POWERBROADCAST through this call. 131 // message loop and forward WM_POWERBROADCAST through this call.
118 void ProcessWmPowerBroadcastMessage(int event_id); 132 void ProcessWmPowerBroadcastMessage(int event_id);
119 #endif 133 #endif
120 134
121 // Cross-platform handling of a power event. 135 // Cross-platform handling of a power event.
122 void ProcessPowerMessage(PowerEvent event_id); 136 void ProcessPowerMessage(PowerEvent event_id);
123 137
124 // Cross-platform handling of a device change event. 138 // Cross-platform handling of a device change event.
125 void ProcessDevicesChanged(); 139 void ProcessDevicesChanged();
140 void ProcessMediaDeviceAttached(const DeviceIdType& id,
141 const std::string& name,
142 const FilePath& path);
143 void ProcessMediaDeviceDetached(const DeviceIdType& id);
126 144
127 private: 145 private:
128 #if defined(OS_MACOSX) 146 #if defined(OS_MACOSX)
129 void PlatformInit(); 147 void PlatformInit();
130 void PlatformDestroy(); 148 void PlatformDestroy();
131 #endif 149 #endif
132 150
133 // Platform-specific method to check whether the system is currently 151 // Platform-specific method to check whether the system is currently
134 // running on battery power. Returns true if running on batteries, 152 // running on battery power. Returns true if running on batteries,
135 // false otherwise. 153 // false otherwise.
136 bool IsBatteryPower(); 154 bool IsBatteryPower();
137 155
138 // Checks the battery status and notifies observers if the battery 156 // Checks the battery status and notifies observers if the battery
139 // status has changed. 157 // status has changed.
140 void BatteryCheck(); 158 void BatteryCheck();
141 159
142 // Functions to trigger notifications. 160 // Functions to trigger notifications.
143 void NotifyDevicesChanged(); 161 void NotifyDevicesChanged();
162 void NotifyMediaDeviceAttached(const DeviceIdType& id,
163 const std::string& name,
164 const FilePath& path);
165 void NotifyMediaDeviceDetached(const DeviceIdType& id);
144 void NotifyPowerStateChange(); 166 void NotifyPowerStateChange();
145 void NotifySuspend(); 167 void NotifySuspend();
146 void NotifyResume(); 168 void NotifyResume();
147 169
148 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_; 170 scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
149 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > 171 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
150 devices_changed_observer_list_; 172 devices_changed_observer_list_;
151 bool battery_in_use_; 173 bool battery_in_use_;
152 bool suspended_; 174 bool suspended_;
153 175
154 #if defined(ENABLE_BATTERY_MONITORING) 176 #if defined(ENABLE_BATTERY_MONITORING)
155 base::OneShotTimer<SystemMonitor> delayed_battery_check_; 177 base::OneShotTimer<SystemMonitor> delayed_battery_check_;
156 #endif 178 #endif
157 179
158 DISALLOW_COPY_AND_ASSIGN(SystemMonitor); 180 DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
159 }; 181 };
160 182
161 } // namespace base 183 } // namespace base
162 184
163 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ 185 #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/system_monitor/system_monitor.cc » ('j') | base/system_monitor/system_monitor_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698