vandebo@chromium.org | fab003a | 2012-03-03 08:13:40 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
| 6 | #define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 7 | |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 8 | #include "base/base_export.h" |
avi | a6a6a68 | 2015-12-27 07:15:14 +0900 | [diff] [blame] | 9 | #include "base/macros.h" |
hongbo.min@intel.com | 076c6c6 | 2013-04-04 04:06:51 +0900 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 11 | #include "base/observer_list_threadsafe.h" |
hongbo.min@intel.com | 076c6c6 | 2013-04-04 04:06:51 +0900 | [diff] [blame] | 12 | #include "build/build_config.h" |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 13 | |
| 14 | namespace base { |
| 15 | |
| 16 | // Class for monitoring various system-related subsystems |
| 17 | // such as power management, network status, etc. |
| 18 | // TODO(mbelshe): Add support beyond just power management. |
darin@chromium.org | e585bed | 2011-08-06 00:34:00 +0900 | [diff] [blame] | 19 | class BASE_EXPORT SystemMonitor { |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 20 | public: |
wjia@chromium.org | bd5efd8 | 2012-07-31 10:16:35 +0900 | [diff] [blame] | 21 | // Type of devices whose change need to be monitored, such as add/remove. |
| 22 | enum DeviceType { |
guidou | ca69b87 | 2016-09-16 18:29:21 +0900 | [diff] [blame] | 23 | DEVTYPE_AUDIO, // Audio device, e.g., microphone. |
wjia@chromium.org | bd5efd8 | 2012-07-31 10:16:35 +0900 | [diff] [blame] | 24 | DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. |
guidou | ca69b87 | 2016-09-16 18:29:21 +0900 | [diff] [blame] | 25 | DEVTYPE_UNKNOWN, // Other devices. |
wjia@chromium.org | bd5efd8 | 2012-07-31 10:16:35 +0900 | [diff] [blame] | 26 | }; |
| 27 | |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 28 | // Create SystemMonitor. Only one SystemMonitor instance per application |
| 29 | // is allowed. |
| 30 | SystemMonitor(); |
| 31 | ~SystemMonitor(); |
| 32 | |
| 33 | // Get the application-wide SystemMonitor (if not present, returns NULL). |
| 34 | static SystemMonitor* Get(); |
| 35 | |
scottmg@chromium.org | 3190a59 | 2011-11-15 10:59:49 +0900 | [diff] [blame] | 36 | class BASE_EXPORT DevicesChangedObserver { |
| 37 | public: |
| 38 | // Notification that the devices connected to the system have changed. |
vandebo@chromium.org | fab003a | 2012-03-03 08:13:40 +0900 | [diff] [blame] | 39 | // This is only implemented on Windows currently. |
wjia@chromium.org | bd5efd8 | 2012-07-31 10:16:35 +0900 | [diff] [blame] | 40 | virtual void OnDevicesChanged(DeviceType device_type) {} |
scottmg@chromium.org | 3190a59 | 2011-11-15 10:59:49 +0900 | [diff] [blame] | 41 | |
| 42 | protected: |
| 43 | virtual ~DevicesChangedObserver() {} |
| 44 | }; |
| 45 | |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 46 | // Add a new observer. |
| 47 | // Can be called from any thread. |
| 48 | // Must not be called from within a notification callback. |
scottmg@chromium.org | 3190a59 | 2011-11-15 10:59:49 +0900 | [diff] [blame] | 49 | void AddDevicesChangedObserver(DevicesChangedObserver* obs); |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 50 | |
| 51 | // Remove an existing observer. |
| 52 | // Can be called from any thread. |
| 53 | // Must not be called from within a notification callback. |
scottmg@chromium.org | 3190a59 | 2011-11-15 10:59:49 +0900 | [diff] [blame] | 54 | void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 55 | |
vandebo@chromium.org | 090cf18 | 2012-09-14 06:24:03 +0900 | [diff] [blame] | 56 | // The ProcessFoo() style methods are a broken pattern and should not |
| 57 | // be copied. Any significant addition to this class is blocked on |
| 58 | // refactoring to improve the state of affairs. See http://crbug.com/149059 |
| 59 | |
scottmg@chromium.org | 3190a59 | 2011-11-15 10:59:49 +0900 | [diff] [blame] | 60 | // Cross-platform handling of a device change event. |
wjia@chromium.org | bd5efd8 | 2012-07-31 10:16:35 +0900 | [diff] [blame] | 61 | void ProcessDevicesChanged(DeviceType device_type); |
thestig@chromium.org | d18525b | 2012-05-22 07:24:14 +0900 | [diff] [blame] | 62 | |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 63 | private: |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 64 | // Functions to trigger notifications. |
wjia@chromium.org | bd5efd8 | 2012-07-31 10:16:35 +0900 | [diff] [blame] | 65 | void NotifyDevicesChanged(DeviceType device_type); |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 66 | |
scottmg@chromium.org | 3190a59 | 2011-11-15 10:59:49 +0900 | [diff] [blame] | 67 | scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> > |
| 68 | devices_changed_observer_list_; |
hongbo.min@intel.com | f922ef3 | 2013-03-01 12:20:30 +0900 | [diff] [blame] | 69 | |
willchan@chromium.org | 0fbb868 | 2011-05-18 16:29:56 +0900 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(SystemMonitor); |
| 71 | }; |
| 72 | |
| 73 | } // namespace base |
| 74 | |
| 75 | #endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_ |