• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // 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 
7 #include <utility>
8 
9 #include "base/logging.h"
10 #include "base/time/time.h"
11 
12 namespace base {
13 
14 static SystemMonitor* g_system_monitor = nullptr;
15 
SystemMonitor()16 SystemMonitor::SystemMonitor()
17     :  devices_changed_observer_list_(
18           new ObserverListThreadSafe<DevicesChangedObserver>()) {
19   DCHECK(!g_system_monitor);
20   g_system_monitor = this;
21 }
22 
~SystemMonitor()23 SystemMonitor::~SystemMonitor() {
24   DCHECK_EQ(this, g_system_monitor);
25   g_system_monitor = nullptr;
26 }
27 
28 // static
Get()29 SystemMonitor* SystemMonitor::Get() {
30   return g_system_monitor;
31 }
32 
ProcessDevicesChanged(DeviceType device_type)33 void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) {
34   NotifyDevicesChanged(device_type);
35 }
36 
AddDevicesChangedObserver(DevicesChangedObserver * obs)37 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) {
38   devices_changed_observer_list_->AddObserver(obs);
39 }
40 
RemoveDevicesChangedObserver(DevicesChangedObserver * obs)41 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
42   devices_changed_observer_list_->RemoveObserver(obs);
43 }
44 
NotifyDevicesChanged(DeviceType device_type)45 void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) {
46   DVLOG(1) << "DevicesChanged with device type " << device_type;
47   devices_changed_observer_list_->Notify(
48       FROM_HERE, &DevicesChangedObserver::OnDevicesChanged, device_type);
49 }
50 
51 }  // namespace base
52