| 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 // Any tasks that communicates with the portable device may take >100ms to | 5 // Any tasks that communicates with the portable device may take >100ms to |
| 6 // complete. Those tasks should be run on an blocking thread instead of the | 6 // complete. Those tasks should be run on an blocking thread instead of the |
| 7 // UI thread. | 7 // UI thread. |
| 8 | 8 |
| 9 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" | 9 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
| 10 | 10 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 hr = storage_ids->GetAt(index, &object_id); | 287 hr = storage_ids->GetAt(index, &object_id); |
| 288 if (SUCCEEDED(hr) && (object_id.pwszVal != NULL) && | 288 if (SUCCEEDED(hr) && (object_id.pwszVal != NULL) && |
| 289 (object_id.vt == VT_LPWSTR)) { | 289 (object_id.vt == VT_LPWSTR)) { |
| 290 storage_object_ids->push_back(object_id.pwszVal); | 290 storage_object_ids->push_back(object_id.pwszVal); |
| 291 } | 291 } |
| 292 PropVariantClear(&object_id); | 292 PropVariantClear(&object_id); |
| 293 } | 293 } |
| 294 return true; | 294 return true; |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Returns true if the portable device is mounted on a volume. |device_name| | 297 // Returns true if the portable device belongs to a mass storage class. |
| 298 // specifies the name of the device. | 298 // |pnp_device_id| specifies the plug and play device id. |
| 299 bool IsVolumeMountedPortableDevice(const string16& device_name) { | 299 // |device_name| specifies the name of the device. |
| 300 bool IsMassStoragePortableDevice(const string16& pnp_device_id, |
| 301 const string16& device_name) { |
| 302 // Based on testing, if the pnp device id starts with "\\?\wpdbusenumroot#", |
| 303 // then the attached device belongs to a mass storage class. |
| 304 if (StartsWith(pnp_device_id, L"\\\\?\\wpdbusenumroot#", false)) |
| 305 return true; |
| 306 |
| 300 // If the device is a volume mounted device, |device_name| will be | 307 // If the device is a volume mounted device, |device_name| will be |
| 301 // the volume name. | 308 // the volume name. |
| 302 return ((device_name.length() >= 2) && (device_name[1] == L':') && | 309 return ((device_name.length() >= 2) && (device_name[1] == L':') && |
| 303 (((device_name[0] >= L'A') && (device_name[0] <= L'Z')) || | 310 (((device_name[0] >= L'A') && (device_name[0] <= L'Z')) || |
| 304 ((device_name[0] >= L'a') && (device_name[0] <= L'z')))); | 311 ((device_name[0] >= L'a') && (device_name[0] <= L'z')))); |
| 305 } | 312 } |
| 306 | 313 |
| 307 // Returns the name of the device specified by |pnp_device_id|. | 314 // Returns the name of the device specified by |pnp_device_id|. |
| 308 string16 GetDeviceNameOnBlockingThread( | 315 string16 GetDeviceNameOnBlockingThread( |
| 309 IPortableDeviceManager* portable_device_manager, | 316 IPortableDeviceManager* portable_device_manager, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 bool GetDeviceInfoOnBlockingThread( | 366 bool GetDeviceInfoOnBlockingThread( |
| 360 IPortableDeviceManager* portable_device_manager, | 367 IPortableDeviceManager* portable_device_manager, |
| 361 const string16& pnp_device_id, | 368 const string16& pnp_device_id, |
| 362 PortableDeviceWatcherWin::DeviceDetails* device_details) { | 369 PortableDeviceWatcherWin::DeviceDetails* device_details) { |
| 363 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 370 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 364 DCHECK(portable_device_manager); | 371 DCHECK(portable_device_manager); |
| 365 DCHECK(device_details); | 372 DCHECK(device_details); |
| 366 DCHECK(!pnp_device_id.empty()); | 373 DCHECK(!pnp_device_id.empty()); |
| 367 device_details->name = GetDeviceNameOnBlockingThread(portable_device_manager, | 374 device_details->name = GetDeviceNameOnBlockingThread(portable_device_manager, |
| 368 pnp_device_id); | 375 pnp_device_id); |
| 369 if (IsVolumeMountedPortableDevice(device_details->name)) | 376 if (IsMassStoragePortableDevice(pnp_device_id, device_details->name)) |
| 370 return false; | 377 return false; |
| 371 | 378 |
| 372 device_details->location = pnp_device_id; | 379 device_details->location = pnp_device_id; |
| 373 PortableDeviceWatcherWin::StorageObjects storage_objects; | 380 PortableDeviceWatcherWin::StorageObjects storage_objects; |
| 374 return GetDeviceStorageObjectsOnBlockingThread( | 381 return GetDeviceStorageObjectsOnBlockingThread( |
| 375 pnp_device_id, &device_details->storage_objects); | 382 pnp_device_id, &device_details->storage_objects); |
| 376 } | 383 } |
| 377 | 384 |
| 378 // Wrapper function to get an instance of portable device manager. On success, | 385 // Wrapper function to get an instance of portable device manager. On success, |
| 379 // returns true and fills in |portable_device_mgr|. On failure, returns false. | 386 // returns true and fills in |portable_device_mgr|. On failure, returns false. |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 609 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 603 DCHECK(storage_map_iter != storage_map_.end()); | 610 DCHECK(storage_map_iter != storage_map_.end()); |
| 604 system_monitor->ProcessRemovableStorageDetached( | 611 system_monitor->ProcessRemovableStorageDetached( |
| 605 storage_map_iter->second.device_id); | 612 storage_map_iter->second.device_id); |
| 606 storage_map_.erase(storage_map_iter); | 613 storage_map_.erase(storage_map_iter); |
| 607 } | 614 } |
| 608 device_map_.erase(device_iter); | 615 device_map_.erase(device_iter); |
| 609 } | 616 } |
| 610 | 617 |
| 611 } // namespace chrome | 618 } // namespace chrome |
| OLD | NEW |