blob: 2fa5aec2f76371a0a1eed987bc50b9dea264aaef [file] [log] [blame]
vandebo@chromium.orgfab003a2012-03-03 08:13:40 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
willchan@chromium.org0fbb8682011-05-18 16:29:56 +09002// 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.org0fbb8682011-05-18 16:29:56 +09007
darin@chromium.orge585bed2011-08-06 00:34:00 +09008#include "base/base_export.h"
avia6a6a682015-12-27 07:15:14 +09009#include "base/macros.h"
hongbo.min@intel.com076c6c62013-04-04 04:06:51 +090010#include "base/memory/ref_counted.h"
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090011#include "base/observer_list_threadsafe.h"
hongbo.min@intel.com076c6c62013-04-04 04:06:51 +090012#include "build/build_config.h"
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090013
14namespace 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.orge585bed2011-08-06 00:34:00 +090019class BASE_EXPORT SystemMonitor {
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090020 public:
wjia@chromium.orgbd5efd82012-07-31 10:16:35 +090021 // Type of devices whose change need to be monitored, such as add/remove.
22 enum DeviceType {
guidouca69b872016-09-16 18:29:21 +090023 DEVTYPE_AUDIO, // Audio device, e.g., microphone.
wjia@chromium.orgbd5efd82012-07-31 10:16:35 +090024 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam.
guidouca69b872016-09-16 18:29:21 +090025 DEVTYPE_UNKNOWN, // Other devices.
wjia@chromium.orgbd5efd82012-07-31 10:16:35 +090026 };
27
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090028 // 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.org3190a592011-11-15 10:59:49 +090036 class BASE_EXPORT DevicesChangedObserver {
37 public:
38 // Notification that the devices connected to the system have changed.
vandebo@chromium.orgfab003a2012-03-03 08:13:40 +090039 // This is only implemented on Windows currently.
wjia@chromium.orgbd5efd82012-07-31 10:16:35 +090040 virtual void OnDevicesChanged(DeviceType device_type) {}
scottmg@chromium.org3190a592011-11-15 10:59:49 +090041
42 protected:
43 virtual ~DevicesChangedObserver() {}
44 };
45
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090046 // Add a new observer.
47 // Can be called from any thread.
48 // Must not be called from within a notification callback.
scottmg@chromium.org3190a592011-11-15 10:59:49 +090049 void AddDevicesChangedObserver(DevicesChangedObserver* obs);
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090050
51 // Remove an existing observer.
52 // Can be called from any thread.
53 // Must not be called from within a notification callback.
scottmg@chromium.org3190a592011-11-15 10:59:49 +090054 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs);
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090055
vandebo@chromium.org090cf182012-09-14 06:24:03 +090056 // 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.org3190a592011-11-15 10:59:49 +090060 // Cross-platform handling of a device change event.
wjia@chromium.orgbd5efd82012-07-31 10:16:35 +090061 void ProcessDevicesChanged(DeviceType device_type);
thestig@chromium.orgd18525b2012-05-22 07:24:14 +090062
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090063 private:
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090064 // Functions to trigger notifications.
wjia@chromium.orgbd5efd82012-07-31 10:16:35 +090065 void NotifyDevicesChanged(DeviceType device_type);
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090066
scottmg@chromium.org3190a592011-11-15 10:59:49 +090067 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
68 devices_changed_observer_list_;
hongbo.min@intel.comf922ef32013-03-01 12:20:30 +090069
willchan@chromium.org0fbb8682011-05-18 16:29:56 +090070 DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
71};
72
73} // namespace base
74
75#endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_