| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // MTPDeviceDelegateImplWin implementation. | 5 // MTPDeviceDelegateImplWin implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/media_galleries/win/mtp_device_delegate_impl_win.h" | 7 #include "chrome/browser/media_galleries/win/mtp_device_delegate_impl_win.h" |
| 8 | 8 |
| 9 #include <portabledevice.h> | 9 #include <portabledevice.h> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 path_components[i]); | 91 path_components[i]); |
| 92 if (file_object_id.empty()) | 92 if (file_object_id.empty()) |
| 93 break; | 93 break; |
| 94 parent_id = file_object_id; | 94 parent_id = file_object_id; |
| 95 } | 95 } |
| 96 return file_object_id; | 96 return file_object_id; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Returns a pointer to a new instance of AbstractFileEnumerator for the given | 99 // Returns a pointer to a new instance of AbstractFileEnumerator for the given |
| 100 // |root| directory. Called on a blocking pool thread. | 100 // |root| directory. Called on a blocking pool thread. |
| 101 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | 101 scoped_ptr<MTPDeviceObjectEnumerator> |
| 102 CreateFileEnumeratorOnBlockingPoolThread( | 102 CreateFileEnumeratorOnBlockingPoolThread( |
| 103 const MTPDeviceDelegateImplWin::StorageDeviceInfo& device_info, | 103 const MTPDeviceDelegateImplWin::StorageDeviceInfo& device_info, |
| 104 const base::FilePath& root) { | 104 const base::FilePath& root) { |
| 105 base::ThreadRestrictions::AssertIOAllowed(); | 105 base::ThreadRestrictions::AssertIOAllowed(); |
| 106 DCHECK(!device_info.registered_device_path.empty()); | 106 DCHECK(!device_info.registered_device_path.empty()); |
| 107 DCHECK(!root.empty()); | 107 DCHECK(!root.empty()); |
| 108 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | |
| 109 file_enumerator(new fileapi::FileSystemFileUtil::EmptyFileEnumerator()); | |
| 110 IPortableDevice* device = | 108 IPortableDevice* device = |
| 111 PortableDeviceMapService::GetInstance()->GetPortableDevice( | 109 PortableDeviceMapService::GetInstance()->GetPortableDevice( |
| 112 device_info.registered_device_path); | 110 device_info.registered_device_path); |
| 113 if (!device) | 111 if (!device) |
| 114 return file_enumerator.Pass(); | 112 return scoped_ptr<MTPDeviceObjectEnumerator>(); |
| 115 | 113 |
| 116 string16 object_id = GetFileObjectIdFromPathOnBlockingPoolThread(device_info, | 114 string16 object_id = GetFileObjectIdFromPathOnBlockingPoolThread(device_info, |
| 117 root); | 115 root); |
| 118 if (object_id.empty()) | 116 if (object_id.empty()) |
| 119 return file_enumerator.Pass(); | 117 return scoped_ptr<MTPDeviceObjectEnumerator>(); |
| 120 | 118 |
| 121 MTPDeviceObjectEntries entries; | 119 MTPDeviceObjectEntries entries; |
| 122 if (!media_transfer_protocol::GetDirectoryEntries(device, object_id, | 120 if (!media_transfer_protocol::GetDirectoryEntries(device, object_id, |
| 123 &entries) || | 121 &entries) || |
| 124 entries.empty()) | 122 entries.empty()) |
| 125 return file_enumerator.Pass(); | 123 return scoped_ptr<MTPDeviceObjectEnumerator>(); |
| 126 | 124 |
| 127 file_enumerator.reset(new MTPDeviceObjectEnumerator(entries)); | 125 return scoped_ptr<MTPDeviceObjectEnumerator>( |
| 128 return file_enumerator.Pass(); | 126 new MTPDeviceObjectEnumerator(entries)); |
| 129 } | 127 } |
| 130 | 128 |
| 131 // Opens the device for communication on a blocking pool thread. | 129 // Opens the device for communication on a blocking pool thread. |
| 132 // |pnp_device_id| specifies the PnP device id. | 130 // |pnp_device_id| specifies the PnP device id. |
| 133 // |registered_device_path| specifies the registered file system root path for | 131 // |registered_device_path| specifies the registered file system root path for |
| 134 // the given device. | 132 // the given device. |
| 135 bool OpenDeviceOnBlockingPoolThread(const string16& pnp_device_id, | 133 bool OpenDeviceOnBlockingPoolThread(const string16& pnp_device_id, |
| 136 const string16& registered_device_path) { | 134 const string16& registered_device_path) { |
| 137 base::ThreadRestrictions::AssertIOAllowed(); | 135 base::ThreadRestrictions::AssertIOAllowed(); |
| 138 DCHECK(!pnp_device_id.empty()); | 136 DCHECK(!pnp_device_id.empty()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 base::PlatformFileError error = GetFileInfoOnBlockingPoolThread(device_info, | 186 base::PlatformFileError error = GetFileInfoOnBlockingPoolThread(device_info, |
| 189 root, | 187 root, |
| 190 &file_info); | 188 &file_info); |
| 191 if (error != base::PLATFORM_FILE_OK) | 189 if (error != base::PLATFORM_FILE_OK) |
| 192 return error; | 190 return error; |
| 193 | 191 |
| 194 if (!file_info.is_directory) | 192 if (!file_info.is_directory) |
| 195 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 193 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 196 | 194 |
| 197 base::FilePath current; | 195 base::FilePath current; |
| 198 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> file_enum = | 196 scoped_ptr<MTPDeviceObjectEnumerator> file_enum = |
| 199 CreateFileEnumeratorOnBlockingPoolThread(device_info, root); | 197 CreateFileEnumeratorOnBlockingPoolThread(device_info, root); |
| 198 if (!file_enum) |
| 199 return error; |
| 200 |
| 200 while (!(current = file_enum->Next()).empty()) { | 201 while (!(current = file_enum->Next()).empty()) { |
| 201 fileapi::DirectoryEntry entry; | 202 fileapi::DirectoryEntry entry; |
| 202 entry.is_directory = file_enum->IsDirectory(); | 203 entry.is_directory = file_enum->IsDirectory(); |
| 203 entry.name = fileapi::VirtualPath::BaseName(current).value(); | 204 entry.name = fileapi::VirtualPath::BaseName(current).value(); |
| 204 entry.size = file_enum->Size(); | 205 entry.size = file_enum->Size(); |
| 205 entry.last_modified_time = file_enum->LastModifiedTime(); | 206 entry.last_modified_time = file_enum->LastModifiedTime(); |
| 206 entries->push_back(entry); | 207 entries->push_back(entry); |
| 207 } | 208 } |
| 208 return error; | 209 return error; |
| 209 } | 210 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 file_details.optimal_transfer_size()); | 285 file_details.optimal_transfer_size()); |
| 285 } | 286 } |
| 286 | 287 |
| 287 void DeletePortableDeviceOnBlockingPoolThread( | 288 void DeletePortableDeviceOnBlockingPoolThread( |
| 288 const string16& registered_device_path) { | 289 const string16& registered_device_path) { |
| 289 base::ThreadRestrictions::AssertIOAllowed(); | 290 base::ThreadRestrictions::AssertIOAllowed(); |
| 290 PortableDeviceMapService::GetInstance()->RemovePortableDevice( | 291 PortableDeviceMapService::GetInstance()->RemovePortableDevice( |
| 291 registered_device_path); | 292 registered_device_path); |
| 292 } | 293 } |
| 293 | 294 |
| 294 | |
| 295 } // namespace | 295 } // namespace |
| 296 | 296 |
| 297 // Used by CreateMTPDeviceAsyncDelegate() to create the MTP device | 297 // Used by CreateMTPDeviceAsyncDelegate() to create the MTP device |
| 298 // delegate on the IO thread. | 298 // delegate on the IO thread. |
| 299 void OnGetStorageInfoCreateDelegate( | 299 void OnGetStorageInfoCreateDelegate( |
| 300 const string16& device_location, | 300 const string16& device_location, |
| 301 const CreateMTPDeviceAsyncDelegateCallback& callback, | 301 const CreateMTPDeviceAsyncDelegateCallback& callback, |
| 302 string16* pnp_device_id, | 302 string16* pnp_device_id, |
| 303 string16* storage_object_id, | 303 string16* storage_object_id, |
| 304 bool succeeded) { | 304 bool succeeded) { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 current_snapshot_details_->file_info(), | 601 current_snapshot_details_->file_info(), |
| 602 current_snapshot_details_->request_info().snapshot_file_path); | 602 current_snapshot_details_->request_info().snapshot_file_path); |
| 603 } else { | 603 } else { |
| 604 current_snapshot_details_->request_info().error_callback.Run( | 604 current_snapshot_details_->request_info().error_callback.Run( |
| 605 base::PLATFORM_FILE_ERROR_FAILED); | 605 base::PLATFORM_FILE_ERROR_FAILED); |
| 606 } | 606 } |
| 607 task_in_progress_ = false; | 607 task_in_progress_ = false; |
| 608 current_snapshot_details_.reset(); | 608 current_snapshot_details_.reset(); |
| 609 ProcessNextPendingRequest(); | 609 ProcessNextPendingRequest(); |
| 610 } | 610 } |
| OLD | NEW |