| 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 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/win/message_window.h" | 15 #include "base/win/message_window.h" |
| 16 | 16 |
| 17 namespace device { | 17 namespace device { |
| 18 | 18 |
| 19 class DeviceMonitorMessageWindow; | 19 class DeviceMonitorMessageWindow; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const wchar_t kWindowClassName[] = L"DeviceMonitorMessageWindow"; | 23 const wchar_t kWindowClassName[] = L"DeviceMonitorMessageWindow"; |
| 24 DeviceMonitorMessageWindow* g_message_window; | 24 DeviceMonitorMessageWindow* g_message_window; |
| 25 | 25 |
| 26 // Provides basic comparability for GUIDs so that they can be used as keys to an | 26 // Provides basic comparability for GUIDs so that they can be used as keys to an |
| 27 // STL map. | 27 // STL map. |
| 28 struct CompareGUID { | 28 struct CompareGUID { |
| 29 bool operator()(const GUID& a, const GUID& b) { | 29 bool operator()(const GUID& a, const GUID& b) const { |
| 30 return memcmp(&a, &b, sizeof a) < 0; | 30 return memcmp(&a, &b, sizeof a) < 0; |
| 31 } | 31 } |
| 32 }; | 32 }; |
| 33 } | 33 } |
| 34 | 34 |
| 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: |
| (...skipping 154 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 |