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