| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/system_message_window_win.h" | 5 #include "content/browser/system_message_window_win.h" |
| 6 | 6 |
| 7 #include <dbt.h> | 7 #include <dbt.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/system_monitor/system_monitor.h" | 10 #include "base/system_monitor/system_monitor.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 void Register(HWND hwnd) { | 40 void Register(HWND hwnd) { |
| 41 // Request to receive device notifications. All applications receive basic | 41 // Request to receive device notifications. All applications receive basic |
| 42 // notifications via WM_DEVICECHANGE but in order to receive detailed device | 42 // notifications via WM_DEVICECHANGE but in order to receive detailed device |
| 43 // arrival and removal messages, we need to register. | 43 // arrival and removal messages, we need to register. |
| 44 DEV_BROADCAST_DEVICEINTERFACE filter = {0}; | 44 DEV_BROADCAST_DEVICEINTERFACE filter = {0}; |
| 45 filter.dbcc_size = sizeof(filter); | 45 filter.dbcc_size = sizeof(filter); |
| 46 filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; | 46 filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; |
| 47 bool core_audio_support = media::CoreAudioUtil::IsSupported(); | 47 bool core_audio_support = media::CoreAudioUtil::IsSupported(); |
| 48 for (int i = 0; i < arraysize(kDeviceCategoryMap); ++i) { | 48 for (size_t i = 0; i < arraysize(kDeviceCategoryMap); ++i) { |
| 49 // If CoreAudio is supported, AudioDeviceListenerWin will | 49 // If CoreAudio is supported, AudioDeviceListenerWin will |
| 50 // take care of monitoring audio devices. | 50 // take care of monitoring audio devices. |
| 51 if (core_audio_support && | 51 if (core_audio_support && |
| 52 KSCATEGORY_AUDIO == kDeviceCategoryMap[i].device_category) { | 52 KSCATEGORY_AUDIO == kDeviceCategoryMap[i].device_category) { |
| 53 continue; | 53 continue; |
| 54 } | 54 } |
| 55 | 55 |
| 56 filter.dbcc_classguid = kDeviceCategoryMap[i].device_category; | 56 filter.dbcc_classguid = kDeviceCategoryMap[i].device_category; |
| 57 DCHECK_EQ(notifications_[i], static_cast<HDEVNOTIFY>(NULL)); | 57 DCHECK_EQ(notifications_[i], static_cast<HDEVNOTIFY>(NULL)); |
| 58 notifications_[i] = RegisterDeviceNotification( | 58 notifications_[i] = RegisterDeviceNotification( |
| 59 hwnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE); | 59 hwnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE); |
| 60 DPLOG_IF(ERROR, !notifications_[i]) | 60 DPLOG_IF(ERROR, !notifications_[i]) |
| 61 << "RegisterDeviceNotification failed"; | 61 << "RegisterDeviceNotification failed"; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Unregister() { | 65 void Unregister() { |
| 66 for (int i = 0; i < arraysize(notifications_); ++i) { | 66 for (size_t i = 0; i < arraysize(notifications_); ++i) { |
| 67 if (notifications_[i]) { | 67 if (notifications_[i]) { |
| 68 UnregisterDeviceNotification(notifications_[i]); | 68 UnregisterDeviceNotification(notifications_[i]); |
| 69 notifications_[i] = NULL; | 69 notifications_[i] = NULL; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 HDEVNOTIFY notifications_[arraysize(kDeviceCategoryMap)]; | 75 HDEVNOTIFY notifications_[arraysize(kDeviceCategoryMap)]; |
| 76 | 76 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 case DBT_DEVICEARRIVAL: { | 115 case DBT_DEVICEARRIVAL: { |
| 116 // This notification has more details about the specific device that | 116 // This notification has more details about the specific device that |
| 117 // was added or removed. See if this is a category we're interested | 117 // was added or removed. See if this is a category we're interested |
| 118 // in monitoring and if so report the specific device type. If we don't | 118 // in monitoring and if so report the specific device type. If we don't |
| 119 // find the category in our map, ignore the notification and do not | 119 // find the category in our map, ignore the notification and do not |
| 120 // notify the system monitor. | 120 // notify the system monitor. |
| 121 DEV_BROADCAST_DEVICEINTERFACE* device_interface = | 121 DEV_BROADCAST_DEVICEINTERFACE* device_interface = |
| 122 reinterpret_cast<DEV_BROADCAST_DEVICEINTERFACE*>(data); | 122 reinterpret_cast<DEV_BROADCAST_DEVICEINTERFACE*>(data); |
| 123 if (device_interface->dbcc_devicetype != DBT_DEVTYP_DEVICEINTERFACE) | 123 if (device_interface->dbcc_devicetype != DBT_DEVTYP_DEVICEINTERFACE) |
| 124 return TRUE; | 124 return TRUE; |
| 125 for (int i = 0; i < arraysize(kDeviceCategoryMap); ++i) { | 125 for (size_t i = 0; i < arraysize(kDeviceCategoryMap); ++i) { |
| 126 if (kDeviceCategoryMap[i].device_category == | 126 if (kDeviceCategoryMap[i].device_category == |
| 127 device_interface->dbcc_classguid) { | 127 device_interface->dbcc_classguid) { |
| 128 device_type = kDeviceCategoryMap[i].device_type; | 128 device_type = kDeviceCategoryMap[i].device_type; |
| 129 break; | 129 break; |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Devices that we do not have a DEVTYPE_ for, get detected via | 133 // Devices that we do not have a DEVTYPE_ for, get detected via |
| 134 // DBT_DEVNODES_CHANGED, so we avoid sending additional notifications | 134 // DBT_DEVNODES_CHANGED, so we avoid sending additional notifications |
| 135 // for those here. | 135 // for those here. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 153 case WM_DEVICECHANGE: | 153 case WM_DEVICECHANGE: |
| 154 return OnDeviceChange(static_cast<UINT>(wparam), lparam); | 154 return OnDeviceChange(static_cast<UINT>(wparam), lparam); |
| 155 default: | 155 default: |
| 156 break; | 156 break; |
| 157 } | 157 } |
| 158 | 158 |
| 159 return ::DefWindowProc(hwnd, message, wparam, lparam); | 159 return ::DefWindowProc(hwnd, message, wparam, lparam); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace content | 162 } // namespace content |
| OLD | NEW |