blob: b069284fef22f0e9f49b1d410c6a71736df14c71 [file] [log] [blame]
[email protected]df6c4192012-03-02 23:13:401// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]e41d7dd2011-05-18 07:29:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Sebastien Marchand0f56c3cd2018-10-05 15:29:275#ifndef BASE_SYSTEM_SYSTEM_MONITOR_H_
6#define BASE_SYSTEM_SYSTEM_MONITOR_H_
[email protected]e41d7dd2011-05-18 07:29:567
[email protected]0bea7252011-08-05 15:34:008#include "base/base_export.h"
[email protected]e41d7dd2011-05-18 07:29:569#include "base/observer_list_threadsafe.h"
[email protected]6c5905b72013-04-03 19:06:5110#include "build/build_config.h"
[email protected]e41d7dd2011-05-18 07:29:5611
12namespace 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]0bea7252011-08-05 15:34:0017class BASE_EXPORT SystemMonitor {
[email protected]e41d7dd2011-05-18 07:29:5618 public:
[email protected]515be832012-07-31 01:16:3519 // Type of devices whose change need to be monitored, such as add/remove.
20 enum DeviceType {
guidoud6789a32016-09-16 09:29:2121 DEVTYPE_AUDIO, // Audio device, e.g., microphone.
[email protected]515be832012-07-31 01:16:3522 DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam.
guidoud6789a32016-09-16 09:29:2123 DEVTYPE_UNKNOWN, // Other devices.
[email protected]515be832012-07-31 01:16:3524 };
25
[email protected]e41d7dd2011-05-18 07:29:5626 // Create SystemMonitor. Only one SystemMonitor instance per application
27 // is allowed.
28 SystemMonitor();
Peter Boström7319bbd2021-09-15 22:59:3829
30 SystemMonitor(const SystemMonitor&) = delete;
31 SystemMonitor& operator=(const SystemMonitor&) = delete;
32
[email protected]e41d7dd2011-05-18 07:29:5633 ~SystemMonitor();
34
35 // Get the application-wide SystemMonitor (if not present, returns NULL).
36 static SystemMonitor* Get();
37
[email protected]cd1cd4c02011-11-15 01:59:4938 class BASE_EXPORT DevicesChangedObserver {
39 public:
40 // Notification that the devices connected to the system have changed.
[email protected]df6c4192012-03-02 23:13:4041 // This is only implemented on Windows currently.
[email protected]515be832012-07-31 01:16:3542 virtual void OnDevicesChanged(DeviceType device_type) {}
[email protected]cd1cd4c02011-11-15 01:59:4943
44 protected:
Chris Watkins091d6292017-12-13 04:25:5845 virtual ~DevicesChangedObserver() = default;
[email protected]cd1cd4c02011-11-15 01:59:4946 };
47
[email protected]e41d7dd2011-05-18 07:29:5648 // Add a new observer.
49 // Can be called from any thread.
50 // Must not be called from within a notification callback.
[email protected]cd1cd4c02011-11-15 01:59:4951 void AddDevicesChangedObserver(DevicesChangedObserver* obs);
[email protected]e41d7dd2011-05-18 07:29:5652
53 // Remove an existing observer.
54 // Can be called from any thread.
55 // Must not be called from within a notification callback.
[email protected]cd1cd4c02011-11-15 01:59:4956 void RemoveDevicesChangedObserver(DevicesChangedObserver* obs);
[email protected]e41d7dd2011-05-18 07:29:5657
[email protected]348599312012-09-13 21:24:0358 // 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]cd1cd4c02011-11-15 01:59:4962 // Cross-platform handling of a device change event.
[email protected]515be832012-07-31 01:16:3563 void ProcessDevicesChanged(DeviceType device_type);
[email protected]04b4c672012-05-21 22:24:1464
[email protected]e41d7dd2011-05-18 07:29:5665 private:
[email protected]e41d7dd2011-05-18 07:29:5666 // Functions to trigger notifications.
[email protected]515be832012-07-31 01:16:3567 void NotifyDevicesChanged(DeviceType device_type);
[email protected]e41d7dd2011-05-18 07:29:5668
Sebastien Marchand0f56c3cd2018-10-05 15:29:2769 scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver>>
[email protected]cd1cd4c02011-11-15 01:59:4970 devices_changed_observer_list_;
[email protected]e41d7dd2011-05-18 07:29:5671};
72
73} // namespace base
74
Sebastien Marchand0f56c3cd2018-10-05 15:29:2775#endif // BASE_SYSTEM_SYSTEM_MONITOR_H_