| 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 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } // namespace | 134 } // namespace |
| 135 | 135 |
| 136 namespace chrome { | 136 namespace chrome { |
| 137 | 137 |
| 138 const int kWorkerPoolNumThreads = 3; | 138 const int kWorkerPoolNumThreads = 3; |
| 139 const char* kWorkerPoolNamePrefix = "DeviceInfoPool"; | 139 const char* kWorkerPoolNamePrefix = "DeviceInfoPool"; |
| 140 | 140 |
| 141 VolumeMountWatcherWin::VolumeMountWatcherWin() | 141 VolumeMountWatcherWin::VolumeMountWatcherWin() |
| 142 : device_info_worker_pool_(new base::SequencedWorkerPool( | 142 : device_info_worker_pool_(new base::SequencedWorkerPool( |
| 143 kWorkerPoolNumThreads, kWorkerPoolNamePrefix)), | 143 kWorkerPoolNumThreads, kWorkerPoolNamePrefix)), |
| 144 weak_factory_(this) { | 144 weak_factory_(this), |
| 145 notifications_(NULL) { |
| 145 get_attached_devices_callback_ = base::Bind(&GetAttachedDevices); | 146 get_attached_devices_callback_ = base::Bind(&GetAttachedDevices); |
| 146 get_device_details_callback_ = base::Bind(&GetDeviceDetails); | 147 get_device_details_callback_ = base::Bind(&GetDeviceDetails); |
| 147 } | 148 } |
| 148 | 149 |
| 149 // static | 150 // static |
| 150 FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) { | 151 FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) { |
| 151 if (drive_number < 0 || drive_number > 25) | 152 if (drive_number < 0 || drive_number > 25) |
| 152 return FilePath(); | 153 return FilePath(); |
| 153 string16 path(L"_:\\"); | 154 string16 path(L"_:\\"); |
| 154 path[0] = L'A' + drive_number; | 155 path[0] = L'A' + drive_number; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 if (!(unitmask & 0x01)) | 295 if (!(unitmask & 0x01)) |
| 295 continue; | 296 continue; |
| 296 HandleDeviceDetachEventOnUIThread(DriveNumberToFilePath(i).value()); | 297 HandleDeviceDetachEventOnUIThread(DriveNumberToFilePath(i).value()); |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 break; | 300 break; |
| 300 } | 301 } |
| 301 } | 302 } |
| 302 } | 303 } |
| 303 | 304 |
| 305 void VolumeMountWatcherWin::SetNotifications( |
| 306 RemovableStorageNotifications::Receiver* notifications) { |
| 307 notifications_ = notifications; |
| 308 } |
| 309 |
| 304 VolumeMountWatcherWin::~VolumeMountWatcherWin() { | 310 VolumeMountWatcherWin::~VolumeMountWatcherWin() { |
| 305 weak_factory_.InvalidateWeakPtrs(); | 311 weak_factory_.InvalidateWeakPtrs(); |
| 306 } | 312 } |
| 307 | 313 |
| 308 | 314 |
| 309 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( | 315 void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( |
| 310 const FilePath& device_path, | 316 const FilePath& device_path, |
| 311 const MountPointInfo& info) { | 317 const MountPointInfo& info) { |
| 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 313 | 319 |
| 314 device_metadata_[device_path.value()] = info; | 320 device_metadata_[device_path.value()] = info; |
| 315 | 321 |
| 316 DeviceCheckComplete(device_path); | 322 DeviceCheckComplete(device_path); |
| 317 | 323 |
| 318 // Don't call removable storage observers for fixed volumes. | 324 // Don't call removable storage observers for fixed volumes. |
| 319 if (!info.removable) | 325 if (!info.removable) |
| 320 return; | 326 return; |
| 321 | 327 |
| 322 RemovableStorageNotifications* notifications = | 328 if (notifications_) { |
| 323 RemovableStorageNotifications::GetInstance(); | 329 string16 display_name = GetDisplayNameForDevice(0, device_name); |
| 324 if (notifications) { | 330 notifications_->ProcessAttach(info.device_id, display_name, |
| 325 string16 display_name = GetDisplayNameForDevice(0, info.name); | 331 device_path.value()); |
| 326 notifications->ProcessAttach(info.device_id, display_name, | |
| 327 device_path.value()); | |
| 328 } | 332 } |
| 329 } | 333 } |
| 330 | 334 |
| 331 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( | 335 void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( |
| 332 const string16& device_location) { | 336 const string16& device_location) { |
| 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 334 | 338 |
| 335 MountPointDeviceMetadataMap::const_iterator device_info = | 339 MountPointDeviceMetadataMap::const_iterator device_info = |
| 336 device_metadata_.find(device_location); | 340 device_metadata_.find(device_location); |
| 337 // If the device isn't type removable (like a CD), it won't be there. | 341 // If the device isn't type removable (like a CD), it won't be there. |
| 338 if (device_info == device_metadata_.end()) | 342 if (device_info == device_metadata_.end()) |
| 339 return; | 343 return; |
| 340 | 344 |
| 341 RemovableStorageNotifications* notifications = | 345 if (notifications_) |
| 342 RemovableStorageNotifications::GetInstance(); | 346 notifications_->ProcessDetach(device_info->second.device_id); |
| 343 if (notifications) | |
| 344 notifications->ProcessDetach(device_info->second.device_id); | |
| 345 device_metadata_.erase(device_info); | 347 device_metadata_.erase(device_info); |
| 346 } | 348 } |
| 347 | 349 |
| 348 } // namespace chrome | 350 } // namespace chrome |
| OLD | NEW |