blob: 35367200fee0bbe3a7a9cb4143c6549b9a074be3 [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#include "base/system/system_monitor.h"
[email protected]e41d7dd2011-05-18 07:29:566
[email protected]04b4c672012-05-21 22:24:147#include <utility>
8
[email protected]e41d7dd2011-05-18 07:29:569#include "base/logging.h"
[email protected]8f9a3a52013-06-28 15:14:1810#include "base/time/time.h"
[email protected]e41d7dd2011-05-18 07:29:5611
12namespace base {
13
Ivan Kotenkova16212a52017-11-08 12:37:3314static SystemMonitor* g_system_monitor = nullptr;
[email protected]e41d7dd2011-05-18 07:29:5615
[email protected]e41d7dd2011-05-18 07:29:5616SystemMonitor::SystemMonitor()
Sebastien Marchand0f56c3cd2018-10-05 15:29:2717 : devices_changed_observer_list_(
[email protected]6c5905b72013-04-03 19:06:5118 new ObserverListThreadSafe<DevicesChangedObserver>()) {
[email protected]e41d7dd2011-05-18 07:29:5619 DCHECK(!g_system_monitor);
20 g_system_monitor = this;
[email protected]e41d7dd2011-05-18 07:29:5621}
22
23SystemMonitor::~SystemMonitor() {
[email protected]e41d7dd2011-05-18 07:29:5624 DCHECK_EQ(this, g_system_monitor);
Ivan Kotenkova16212a52017-11-08 12:37:3325 g_system_monitor = nullptr;
[email protected]e41d7dd2011-05-18 07:29:5626}
27
28// static
29SystemMonitor* SystemMonitor::Get() {
30 return g_system_monitor;
31}
32
[email protected]515be832012-07-31 01:16:3533void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) {
34 NotifyDevicesChanged(device_type);
[email protected]e41d7dd2011-05-18 07:29:5635}
36
[email protected]cd1cd4c02011-11-15 01:59:4937void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) {
38 devices_changed_observer_list_->AddObserver(obs);
39}
40
41void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
42 devices_changed_observer_list_->RemoveObserver(obs);
43}
44
[email protected]515be832012-07-31 01:16:3545void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) {
46 DVLOG(1) << "DevicesChanged with device type " << device_type;
[email protected]cd1cd4c02011-11-15 01:59:4947 devices_changed_observer_list_->Notify(
reillyg9a77a722015-02-09 20:18:3348 FROM_HERE, &DevicesChangedObserver::OnDevicesChanged, device_type);
[email protected]e41d7dd2011-05-18 07:29:5649}
50
[email protected]e41d7dd2011-05-18 07:29:5651} // namespace base