Chromium Code Reviews| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 base::win::ScopedComPtr<IPortableDeviceManager> portable_device_mgr; | 401 base::win::ScopedComPtr<IPortableDeviceManager> portable_device_mgr; |
| 402 if (!GetPortableDeviceManager(&portable_device_mgr)) | 402 if (!GetPortableDeviceManager(&portable_device_mgr)) |
| 403 return false; | 403 return false; |
| 404 | 404 |
| 405 // Get the total number of devices found on the system. | 405 // Get the total number of devices found on the system. |
| 406 DWORD pnp_device_count = 0; | 406 DWORD pnp_device_count = 0; |
| 407 HRESULT hr = portable_device_mgr->GetDevices(NULL, &pnp_device_count); | 407 HRESULT hr = portable_device_mgr->GetDevices(NULL, &pnp_device_count); |
| 408 if (FAILED(hr)) | 408 if (FAILED(hr)) |
| 409 return false; | 409 return false; |
| 410 | 410 |
| 411 scoped_array<char16*> pnp_device_ids(new char16*[pnp_device_count]); | 411 scoped_ptr<char16*[]> pnp_device_ids(new char16*[pnp_device_count]); |
| 412 ZeroMemory(pnp_device_ids.get(), pnp_device_count); | |
| 413 hr = portable_device_mgr->GetDevices(pnp_device_ids.get(), &pnp_device_count); | 412 hr = portable_device_mgr->GetDevices(pnp_device_ids.get(), &pnp_device_count); |
| 414 if (FAILED(hr)) | 413 if (FAILED(hr)) |
| 415 return false; | 414 return false; |
| 416 | 415 |
| 417 for (DWORD index = 0; index < pnp_device_count; ++index) { | 416 for (DWORD index = 0; index < pnp_device_count; ++index) { |
| 418 PortableDeviceWatcherWin::DeviceDetails device_details; | 417 PortableDeviceWatcherWin::DeviceDetails device_details; |
| 419 if (GetDeviceInfoOnBlockingThread( | 418 if (GetDeviceInfoOnBlockingThread( |
| 420 portable_device_mgr, pnp_device_ids[index], &device_details)) | 419 portable_device_mgr, pnp_device_ids[index], &device_details)) |
| 421 devices->push_back(device_details); | 420 devices->push_back(device_details); |
| 422 } | 421 } |
| 422 for (DWORD index = 0; index < pnp_device_count; ++index) | |
| 423 CoTaskMemFree(pnp_device_ids[index]); | |
|
kmadhusu
2013/01/03 00:25:52
As per http://msdn.microsoft.com/en-us/library/win
Lei Zhang
2013/01/03 21:15:26
Why not just do this at the end of the loop right
kmadhusu
2013/01/03 21:36:21
Done.
| |
| 423 return !devices->empty(); | 424 return !devices->empty(); |
| 424 } | 425 } |
| 425 | 426 |
| 426 // Handles the device attach event message on a media task runner. | 427 // Handles the device attach event message on a media task runner. |
| 427 // |pnp_device_id| specifies the attached plug and play device ID string. On | 428 // |pnp_device_id| specifies the attached plug and play device ID string. On |
| 428 // success, returns true and populates |device_details| with device information. | 429 // success, returns true and populates |device_details| with device information. |
| 429 // On failure, returns false. | 430 // On failure, returns false. |
| 430 bool HandleDeviceAttachedEventOnBlockingThread( | 431 bool HandleDeviceAttachedEventOnBlockingThread( |
| 431 const string16& pnp_device_id, | 432 const string16& pnp_device_id, |
| 432 PortableDeviceWatcherWin::DeviceDetails* device_details) { | 433 PortableDeviceWatcherWin::DeviceDetails* device_details) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); | 603 MTPStorageMap::iterator storage_map_iter = storage_map_.find(storage_id); |
| 603 DCHECK(storage_map_iter != storage_map_.end()); | 604 DCHECK(storage_map_iter != storage_map_.end()); |
| 604 system_monitor->ProcessRemovableStorageDetached( | 605 system_monitor->ProcessRemovableStorageDetached( |
| 605 storage_map_iter->second.device_id); | 606 storage_map_iter->second.device_id); |
| 606 storage_map_.erase(storage_map_iter); | 607 storage_map_.erase(storage_map_iter); |
| 607 } | 608 } |
| 608 device_map_.erase(device_iter); | 609 device_map_.erase(device_iter); |
| 609 } | 610 } |
| 610 | 611 |
| 611 } // namespace chrome | 612 } // namespace chrome |
| OLD | NEW |