| 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 "chrome/browser/system_monitor/volume_mount_watcher_win.h" | 5 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <dbt.h> | 8 #include <dbt.h> |
| 9 #include <fileapi.h> | 9 #include <fileapi.h> |
| 10 | 10 |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" | 14 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
| 15 #include "chrome/browser/system_monitor/media_storage_util.h" | 15 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 | 17 |
| 18 using base::SystemMonitor; | |
| 19 using content::BrowserThread; | 18 using content::BrowserThread; |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const DWORD kMaxPathBufLen = MAX_PATH + 1; | 22 const DWORD kMaxPathBufLen = MAX_PATH + 1; |
| 24 | 23 |
| 25 bool IsRemovable(const string16& mount_point) { | 24 bool IsRemovable(const string16& mount_point) { |
| 26 if (GetDriveType(mount_point.c_str()) != DRIVE_REMOVABLE) | 25 if (GetDriveType(mount_point.c_str()) != DRIVE_REMOVABLE) |
| 27 return false; | 26 return false; |
| 28 | 27 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( | 232 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( |
| 234 const std::string& device_id, const string16& device_name, | 233 const std::string& device_id, const string16& device_name, |
| 235 const FilePath& device_path) { | 234 const FilePath& device_path) { |
| 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 | 236 |
| 238 // Remember metadata for this device. | 237 // Remember metadata for this device. |
| 239 MountPointInfo info; | 238 MountPointInfo info; |
| 240 info.device_id = device_id; | 239 info.device_id = device_id; |
| 241 device_metadata_[device_path.value()] = info; | 240 device_metadata_[device_path.value()] = info; |
| 242 | 241 |
| 243 SystemMonitor* monitor = SystemMonitor::Get(); | 242 device_ids_[device_location] = device_id; |
| 244 if (monitor) { | 243 RemovableStoragNotifications* notifications = |
| 244 RemovableStorageNotifications::Get(); |
| 245 if (notifications) { |
| 245 string16 display_name = GetDisplayNameForDevice(0, device_name); | 246 string16 display_name = GetDisplayNameForDevice(0, device_name); |
| 246 monitor->ProcessRemovableStorageAttached(device_id, display_name, | 247 notifications->ProcessRemovableStorageAttached(device_id, display_name, |
| 247 device_path.value()); | 248 device_path.value()); |
| 248 } | 249 } |
| 249 } | 250 } |
| 250 | 251 |
| 251 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( | 252 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( |
| 252 const string16& device_location) { | 253 const string16& device_location) { |
| 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 254 MountPointDeviceMetadataMap::const_iterator device_info = | 255 MountPointDeviceMetadataMap::const_iterator device_info = |
| 255 device_metadata_.find(device_location); | 256 device_metadata_.find(device_location); |
| 256 // If the devices isn't type removable (like a CD), it won't be there. | 257 // If the devices isn't type removable (like a CD), it won't be there. |
| 257 if (device_info == device_metadata_.end()) | 258 if (device_info == device_metadata_.end()) |
| 258 return; | 259 return; |
| 259 | 260 |
| 260 SystemMonitor* monitor = SystemMonitor::Get(); | 261 RemovableStoragNotifications* notifications = |
| 261 if (monitor) | 262 RemovableStorageNotifications::Get(); |
| 263 if (notifications) |
| 262 monitor->ProcessRemovableStorageDetached(device_info->second.device_id); | 264 monitor->ProcessRemovableStorageDetached(device_info->second.device_id); |
| 263 device_metadata_.erase(device_info); | 265 device_metadata_.erase(device_info); |
| 264 } | 266 } |
| 265 | 267 |
| 266 } // namespace chrome | 268 } // namespace chrome |
| OLD | NEW |