blob: 99152ab8a85d5a61c297f94e37f93f006dcb1f6d [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
5#include "base/system_monitor/system_monitor.h"
6
[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]495cad92013-07-18 08:12:4010#include "base/message_loop/message_loop.h"
[email protected]8f9a3a52013-06-28 15:14:1811#include "base/time/time.h"
[email protected]e41d7dd2011-05-18 07:29:5612
13namespace base {
14
15static SystemMonitor* g_system_monitor = NULL;
16
[email protected]e41d7dd2011-05-18 07:29:5617SystemMonitor::SystemMonitor()
[email protected]6c5905b72013-04-03 19:06:5118 : devices_changed_observer_list_(
19 new ObserverListThreadSafe<DevicesChangedObserver>()) {
[email protected]e41d7dd2011-05-18 07:29:5620 DCHECK(!g_system_monitor);
21 g_system_monitor = this;
[email protected]e41d7dd2011-05-18 07:29:5622}
23
24SystemMonitor::~SystemMonitor() {
[email protected]e41d7dd2011-05-18 07:29:5625 DCHECK_EQ(this, g_system_monitor);
26 g_system_monitor = NULL;
27}
28
29// static
30SystemMonitor* SystemMonitor::Get() {
31 return g_system_monitor;
32}
33
[email protected]515be832012-07-31 01:16:3534void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) {
35 NotifyDevicesChanged(device_type);
[email protected]e41d7dd2011-05-18 07:29:5636}
37
[email protected]cd1cd4c02011-11-15 01:59:4938void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) {
39 devices_changed_observer_list_->AddObserver(obs);
40}
41
42void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
43 devices_changed_observer_list_->RemoveObserver(obs);
44}
45
[email protected]515be832012-07-31 01:16:3546void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) {
47 DVLOG(1) << "DevicesChanged with device type " << device_type;
[email protected]cd1cd4c02011-11-15 01:59:4948 devices_changed_observer_list_->Notify(
reillyg9a77a722015-02-09 20:18:3349 FROM_HERE, &DevicesChangedObserver::OnDevicesChanged, device_type);
[email protected]e41d7dd2011-05-18 07:29:5650}
51
[email protected]e41d7dd2011-05-18 07:29:5652} // namespace base