| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/core/device_monitor_win.h" | 5 #include "device/core/device_monitor_win.h" |
| 6 | 6 |
| 7 #include <dbt.h> | 7 #include <dbt.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // This singleton class manages a shared message window for all registered | 35 // This singleton class manages a shared message window for all registered |
| 36 // device notification observers. It vends one instance of DeviceManagerWin for | 36 // device notification observers. It vends one instance of DeviceManagerWin for |
| 37 // each unique GUID it sees. | 37 // each unique GUID it sees. |
| 38 class DeviceMonitorMessageWindow { | 38 class DeviceMonitorMessageWindow { |
| 39 public: | 39 public: |
| 40 static DeviceMonitorMessageWindow* GetInstance() { | 40 static DeviceMonitorMessageWindow* GetInstance() { |
| 41 if (!g_message_window) { | 41 if (!g_message_window) { |
| 42 g_message_window = new DeviceMonitorMessageWindow(); | 42 g_message_window = new DeviceMonitorMessageWindow(); |
| 43 if (g_message_window->Init()) { | 43 if (g_message_window->Init()) { |
| 44 base::AtExitManager::RegisterTask( | 44 base::AtExitManager::RegisterTask( |
| 45 base::Bind(&base::DeletePointer<DeviceMonitorMessageWindow>, | 45 base::Bind(&DeviceMonitorMessageWindow::Delete)); |
| 46 base::Unretained(g_message_window))); | |
| 47 } else { | 46 } else { |
| 48 delete g_message_window; | 47 delete g_message_window; |
| 49 g_message_window = nullptr; | 48 g_message_window = nullptr; |
| 50 } | 49 } |
| 51 } | 50 } |
| 52 return g_message_window; | 51 return g_message_window; |
| 53 } | 52 } |
| 54 | 53 |
| 55 DeviceMonitorWin* GetForDeviceInterface(const GUID& device_interface) { | 54 DeviceMonitorWin* GetForDeviceInterface(const GUID& device_interface) { |
| 56 scoped_ptr<DeviceMonitorWin>& device_monitor = | 55 scoped_ptr<DeviceMonitorWin>& device_monitor = |
| 57 device_monitors_[device_interface]; | 56 device_monitors_[device_interface]; |
| 58 if (!device_monitor) { | 57 if (!device_monitor) { |
| 59 device_monitor.reset(new DeviceMonitorWin()); | 58 device_monitor.reset(new DeviceMonitorWin()); |
| 60 } | 59 } |
| 61 return device_monitor.get(); | 60 return device_monitor.get(); |
| 62 } | 61 } |
| 63 | 62 |
| 64 DeviceMonitorWin* GetForAllInterfaces() { return &all_device_monitor_; } | 63 DeviceMonitorWin* GetForAllInterfaces() { return &all_device_monitor_; } |
| 65 | 64 |
| 66 private: | 65 private: |
| 67 friend void base::DeletePointer<DeviceMonitorMessageWindow>( | 66 static void Delete() { |
| 68 DeviceMonitorMessageWindow* message_window); | 67 delete g_message_window; |
| 69 | 68 g_message_window = nullptr; |
| 69 } |
| 70 DeviceMonitorMessageWindow() { | 70 DeviceMonitorMessageWindow() { |
| 71 } | 71 } |
| 72 | 72 |
| 73 ~DeviceMonitorMessageWindow() { | 73 ~DeviceMonitorMessageWindow() { |
| 74 if (notify_handle_) { | 74 if (notify_handle_) { |
| 75 UnregisterDeviceNotification(notify_handle_); | 75 UnregisterDeviceNotification(notify_handle_); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool Init() { | 79 bool Init() { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 OnDeviceAdded(class_guid, device_path)); | 194 OnDeviceAdded(class_guid, device_path)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void DeviceMonitorWin::NotifyDeviceRemoved(const GUID& class_guid, | 197 void DeviceMonitorWin::NotifyDeviceRemoved(const GUID& class_guid, |
| 198 const std::string& device_path) { | 198 const std::string& device_path) { |
| 199 FOR_EACH_OBSERVER(Observer, observer_list_, | 199 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 200 OnDeviceRemoved(class_guid, device_path)); | 200 OnDeviceRemoved(class_guid, device_path)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace device | 203 } // namespace device |
| OLD | NEW |