[email protected] | df6c419 | 2012-03-02 23:13:40 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [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 | |
Sebastien Marchand | 0f56c3cd | 2018-10-05 15:29:27 | [diff] [blame] | 5 | #ifndef BASE_SYSTEM_SYSTEM_MONITOR_H_ |
| 6 | #define BASE_SYSTEM_SYSTEM_MONITOR_H_ |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 7 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 8 | #include "base/base_export.h" |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 9 | #include "base/observer_list_threadsafe.h" |
[email protected] | 6c5905b7 | 2013-04-03 19:06:51 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 11 | |
| 12 | namespace base { |
| 13 | |
| 14 | // Class for monitoring various system-related subsystems |
| 15 | // such as power management, network status, etc. |
| 16 | // TODO(mbelshe): Add support beyond just power management. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 17 | class BASE_EXPORT SystemMonitor { |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 18 | public: |
[email protected] | 515be83 | 2012-07-31 01:16:35 | [diff] [blame] | 19 | // Type of devices whose change need to be monitored, such as add/remove. |
| 20 | enum DeviceType { |
guidou | d6789a3 | 2016-09-16 09:29:21 | [diff] [blame] | 21 | DEVTYPE_AUDIO, // Audio device, e.g., microphone. |
[email protected] | 515be83 | 2012-07-31 01:16:35 | [diff] [blame] | 22 | DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. |
guidou | d6789a3 | 2016-09-16 09:29:21 | [diff] [blame] | 23 | DEVTYPE_UNKNOWN, // Other devices. |
[email protected] | 515be83 | 2012-07-31 01:16:35 | [diff] [blame] | 24 | }; |
| 25 | |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 26 | // Create SystemMonitor. Only one SystemMonitor instance per application |
| 27 | // is allowed. |
| 28 | SystemMonitor(); |
Peter Boström | 7319bbd | 2021-09-15 22:59:38 | [diff] [blame] | 29 | |
| 30 | SystemMonitor(const SystemMonitor&) = delete; |
| 31 | SystemMonitor& operator=(const SystemMonitor&) = delete; |
| 32 | |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 33 | ~SystemMonitor(); |
| 34 | |
| 35 | // Get the application-wide SystemMonitor (if not present, returns NULL). |
| 36 | static SystemMonitor* Get(); |
| 37 | |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 38 | class BASE_EXPORT DevicesChangedObserver { |
| 39 | public: |
| 40 | // Notification that the devices connected to the system have changed. |
[email protected] | df6c419 | 2012-03-02 23:13:40 | [diff] [blame] | 41 | // This is only implemented on Windows currently. |
[email protected] | 515be83 | 2012-07-31 01:16:35 | [diff] [blame] | 42 | virtual void OnDevicesChanged(DeviceType device_type) {} |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 43 | |
| 44 | protected: |
Chris Watkins | 091d629 | 2017-12-13 04:25:58 | [diff] [blame] | 45 | virtual ~DevicesChangedObserver() = default; |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 46 | }; |
| 47 | |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 48 | // Add a new observer. |
| 49 | // Can be called from any thread. |
| 50 | // Must not be called from within a notification callback. |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 51 | void AddDevicesChangedObserver(DevicesChangedObserver* obs); |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 52 | |
| 53 | // Remove an existing observer. |
| 54 | // Can be called from any thread. |
| 55 | // Must not be called from within a notification callback. |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 56 | void RemoveDevicesChangedObserver(DevicesChangedObserver* obs); |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 57 | |
[email protected] | 34859931 | 2012-09-13 21:24:03 | [diff] [blame] | 58 | // The ProcessFoo() style methods are a broken pattern and should not |
| 59 | // be copied. Any significant addition to this class is blocked on |
| 60 | // refactoring to improve the state of affairs. See http://crbug.com/149059 |
| 61 | |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 62 | // Cross-platform handling of a device change event. |
[email protected] | 515be83 | 2012-07-31 01:16:35 | [diff] [blame] | 63 | void ProcessDevicesChanged(DeviceType device_type); |
[email protected] | 04b4c67 | 2012-05-21 22:24:14 | [diff] [blame] | 64 | |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 65 | private: |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 66 | // Functions to trigger notifications. |
[email protected] | 515be83 | 2012-07-31 01:16:35 | [diff] [blame] | 67 | void NotifyDevicesChanged(DeviceType device_type); |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 68 | |
Sebastien Marchand | 0f56c3cd | 2018-10-05 15:29:27 | [diff] [blame] | 69 | scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver>> |
[email protected] | cd1cd4c0 | 2011-11-15 01:59:49 | [diff] [blame] | 70 | devices_changed_observer_list_; |
[email protected] | e41d7dd | 2011-05-18 07:29:56 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace base |
| 74 | |
Sebastien Marchand | 0f56c3cd | 2018-10-05 15:29:27 | [diff] [blame] | 75 | #endif // BASE_SYSTEM_SYSTEM_MONITOR_H_ |