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 11 matching lines...) Expand all Loading... |
22 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 24 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
25 #include "chrome/browser/media_galleries/win/mtp_device_object_entry.h" | 25 #include "chrome/browser/media_galleries/win/mtp_device_object_entry.h" |
26 #include "chrome/browser/media_galleries/win/mtp_device_object_enumerator.h" | 26 #include "chrome/browser/media_galleries/win/mtp_device_object_enumerator.h" |
27 #include "chrome/browser/media_galleries/win/mtp_device_operations_util.h" | 27 #include "chrome/browser/media_galleries/win/mtp_device_operations_util.h" |
28 #include "chrome/browser/media_galleries/win/portable_device_map_service.h" | 28 #include "chrome/browser/media_galleries/win/portable_device_map_service.h" |
29 #include "chrome/browser/media_galleries/win/snapshot_file_details.h" | 29 #include "chrome/browser/media_galleries/win/snapshot_file_details.h" |
30 #include "components/storage_monitor/storage_monitor.h" | 30 #include "components/storage_monitor/storage_monitor.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "webkit/common/fileapi/file_system_util.h" | 32 #include "storage/common/fileapi/file_system_util.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Gets the details of the MTP partition storage specified by the | 36 // Gets the details of the MTP partition storage specified by the |
37 // |storage_path| on the UI thread. Returns true if the storage details are | 37 // |storage_path| on the UI thread. Returns true if the storage details are |
38 // valid and returns false otherwise. | 38 // valid and returns false otherwise. |
39 bool GetStorageInfoOnUIThread(const base::string16& storage_path, | 39 bool GetStorageInfoOnUIThread(const base::string16& storage_path, |
40 base::string16* pnp_device_id, | 40 base::string16* pnp_device_id, |
41 base::string16* storage_object_id) { | 41 base::string16* storage_object_id) { |
42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 file_info); | 173 file_info); |
174 } | 174 } |
175 | 175 |
176 // Reads the |root| directory file entries on a blocking pool thread. On | 176 // Reads the |root| directory file entries on a blocking pool thread. On |
177 // success, |error| is set to base::File::FILE_OK and |entries| contains the | 177 // success, |error| is set to base::File::FILE_OK and |entries| contains the |
178 // directory file entries. On failure, |error| is set to platform file error | 178 // directory file entries. On failure, |error| is set to platform file error |
179 // and |entries| is not set. | 179 // and |entries| is not set. |
180 base::File::Error ReadDirectoryOnBlockingPoolThread( | 180 base::File::Error ReadDirectoryOnBlockingPoolThread( |
181 const MTPDeviceDelegateImplWin::StorageDeviceInfo& device_info, | 181 const MTPDeviceDelegateImplWin::StorageDeviceInfo& device_info, |
182 const base::FilePath& root, | 182 const base::FilePath& root, |
183 fileapi::AsyncFileUtil::EntryList* entries) { | 183 storage::AsyncFileUtil::EntryList* entries) { |
184 base::ThreadRestrictions::AssertIOAllowed(); | 184 base::ThreadRestrictions::AssertIOAllowed(); |
185 DCHECK(!root.empty()); | 185 DCHECK(!root.empty()); |
186 DCHECK(entries); | 186 DCHECK(entries); |
187 base::File::Info file_info; | 187 base::File::Info file_info; |
188 base::File::Error error = GetFileInfoOnBlockingPoolThread(device_info, root, | 188 base::File::Error error = GetFileInfoOnBlockingPoolThread(device_info, root, |
189 &file_info); | 189 &file_info); |
190 if (error != base::File::FILE_OK) | 190 if (error != base::File::FILE_OK) |
191 return error; | 191 return error; |
192 | 192 |
193 if (!file_info.is_directory) | 193 if (!file_info.is_directory) |
194 return base::File::FILE_ERROR_NOT_A_DIRECTORY; | 194 return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
195 | 195 |
196 base::FilePath current; | 196 base::FilePath current; |
197 scoped_ptr<MTPDeviceObjectEnumerator> file_enum = | 197 scoped_ptr<MTPDeviceObjectEnumerator> file_enum = |
198 CreateFileEnumeratorOnBlockingPoolThread(device_info, root); | 198 CreateFileEnumeratorOnBlockingPoolThread(device_info, root); |
199 if (!file_enum) | 199 if (!file_enum) |
200 return error; | 200 return error; |
201 | 201 |
202 while (!(current = file_enum->Next()).empty()) { | 202 while (!(current = file_enum->Next()).empty()) { |
203 fileapi::DirectoryEntry entry; | 203 storage::DirectoryEntry entry; |
204 entry.is_directory = file_enum->IsDirectory(); | 204 entry.is_directory = file_enum->IsDirectory(); |
205 entry.name = fileapi::VirtualPath::BaseName(current).value(); | 205 entry.name = storage::VirtualPath::BaseName(current).value(); |
206 entry.size = file_enum->Size(); | 206 entry.size = file_enum->Size(); |
207 entry.last_modified_time = file_enum->LastModifiedTime(); | 207 entry.last_modified_time = file_enum->LastModifiedTime(); |
208 entries->push_back(entry); | 208 entries->push_back(entry); |
209 } | 209 } |
210 return error; | 210 return error; |
211 } | 211 } |
212 | 212 |
213 // Gets the device file stream object on a blocking pool thread. | 213 // Gets the device file stream object on a blocking pool thread. |
214 // |device_info| contains the device storage partition details. | 214 // |device_info| contains the device storage partition details. |
215 // On success, returns base::File::FILE_OK and file stream details are set in | 215 // On success, returns base::File::FILE_OK and file stream details are set in |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 error_callback, | 395 error_callback, |
396 base::Owned(file_info)))); | 396 base::Owned(file_info)))); |
397 } | 397 } |
398 | 398 |
399 void MTPDeviceDelegateImplWin::ReadDirectory( | 399 void MTPDeviceDelegateImplWin::ReadDirectory( |
400 const base::FilePath& root, | 400 const base::FilePath& root, |
401 const ReadDirectorySuccessCallback& success_callback, | 401 const ReadDirectorySuccessCallback& success_callback, |
402 const ErrorCallback& error_callback) { | 402 const ErrorCallback& error_callback) { |
403 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 403 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
404 DCHECK(!root.empty()); | 404 DCHECK(!root.empty()); |
405 fileapi::AsyncFileUtil::EntryList* entries = | 405 storage::AsyncFileUtil::EntryList* entries = |
406 new fileapi::AsyncFileUtil::EntryList; | 406 new storage::AsyncFileUtil::EntryList; |
407 EnsureInitAndRunTask( | 407 EnsureInitAndRunTask( |
408 PendingTaskInfo(FROM_HERE, | 408 PendingTaskInfo(FROM_HERE, |
409 base::Bind(&ReadDirectoryOnBlockingPoolThread, | 409 base::Bind(&ReadDirectoryOnBlockingPoolThread, |
410 storage_device_info_, | 410 storage_device_info_, |
411 root, | 411 root, |
412 base::Unretained(entries)), | 412 base::Unretained(entries)), |
413 base::Bind(&MTPDeviceDelegateImplWin::OnDidReadDirectory, | 413 base::Bind(&MTPDeviceDelegateImplWin::OnDidReadDirectory, |
414 weak_ptr_factory_.GetWeakPtr(), | 414 weak_ptr_factory_.GetWeakPtr(), |
415 success_callback, | 415 success_callback, |
416 error_callback, | 416 error_callback, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 success_callback.Run(*file_info); | 539 success_callback.Run(*file_info); |
540 else | 540 else |
541 error_callback.Run(error); | 541 error_callback.Run(error); |
542 task_in_progress_ = false; | 542 task_in_progress_ = false; |
543 ProcessNextPendingRequest(); | 543 ProcessNextPendingRequest(); |
544 } | 544 } |
545 | 545 |
546 void MTPDeviceDelegateImplWin::OnDidReadDirectory( | 546 void MTPDeviceDelegateImplWin::OnDidReadDirectory( |
547 const ReadDirectorySuccessCallback& success_callback, | 547 const ReadDirectorySuccessCallback& success_callback, |
548 const ErrorCallback& error_callback, | 548 const ErrorCallback& error_callback, |
549 fileapi::AsyncFileUtil::EntryList* file_list, | 549 storage::AsyncFileUtil::EntryList* file_list, |
550 base::File::Error error) { | 550 base::File::Error error) { |
551 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 551 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
552 DCHECK(file_list); | 552 DCHECK(file_list); |
553 if (error == base::File::FILE_OK) | 553 if (error == base::File::FILE_OK) |
554 success_callback.Run(*file_list, false /*no more entries*/); | 554 success_callback.Run(*file_list, false /*no more entries*/); |
555 else | 555 else |
556 error_callback.Run(error); | 556 error_callback.Run(error); |
557 task_in_progress_ = false; | 557 task_in_progress_ = false; |
558 ProcessNextPendingRequest(); | 558 ProcessNextPendingRequest(); |
559 } | 559 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 current_snapshot_details_->file_info(), | 614 current_snapshot_details_->file_info(), |
615 current_snapshot_details_->request_info().snapshot_file_path); | 615 current_snapshot_details_->request_info().snapshot_file_path); |
616 } else { | 616 } else { |
617 current_snapshot_details_->request_info().error_callback.Run( | 617 current_snapshot_details_->request_info().error_callback.Run( |
618 base::File::FILE_ERROR_FAILED); | 618 base::File::FILE_ERROR_FAILED); |
619 } | 619 } |
620 task_in_progress_ = false; | 620 task_in_progress_ = false; |
621 current_snapshot_details_.reset(); | 621 current_snapshot_details_.reset(); |
622 ProcessNextPendingRequest(); | 622 ProcessNextPendingRequest(); |
623 } | 623 } |
OLD | NEW |