| 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 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
| 23 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
| 24 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
| 25 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" |
| 25 #include "chrome/browser/media_galleries/win/mtp_device_object_entry.h" | 26 #include "chrome/browser/media_galleries/win/mtp_device_object_entry.h" |
| 26 #include "chrome/browser/media_galleries/win/mtp_device_object_enumerator.h" | 27 #include "chrome/browser/media_galleries/win/mtp_device_object_enumerator.h" |
| 27 #include "chrome/browser/media_galleries/win/mtp_device_operations_util.h" | 28 #include "chrome/browser/media_galleries/win/mtp_device_operations_util.h" |
| 28 #include "chrome/browser/media_galleries/win/portable_device_map_service.h" | 29 #include "chrome/browser/media_galleries/win/portable_device_map_service.h" |
| 29 #include "chrome/browser/media_galleries/win/snapshot_file_details.h" | 30 #include "chrome/browser/media_galleries/win/snapshot_file_details.h" |
| 30 #include "chrome/browser/storage_monitor/storage_monitor.h" | 31 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "webkit/browser/fileapi/file_system_task_runners.h" | |
| 33 #include "webkit/common/fileapi/file_system_util.h" | 33 #include "webkit/common/fileapi/file_system_util.h" |
| 34 | 34 |
| 35 namespace chrome { | 35 namespace chrome { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // Gets the details of the MTP partition storage specified by the | 39 // Gets the details of the MTP partition storage specified by the |
| 40 // |storage_path| on the UI thread. Returns true if the storage details are | 40 // |storage_path| on the UI thread. Returns true if the storage details are |
| 41 // valid and returns false otherwise. | 41 // valid and returns false otherwise. |
| 42 bool GetStorageInfoOnUIThread(const string16& storage_path, | 42 bool GetStorageInfoOnUIThread(const string16& storage_path, |
| 43 string16* pnp_device_id, | 43 string16* pnp_device_id, |
| 44 string16* storage_object_id) { | 44 string16* storage_object_id) { |
| 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 46 DCHECK(!storage_path.empty()); | 46 DCHECK(!storage_path.empty()); |
| 47 DCHECK(pnp_device_id); | 47 DCHECK(pnp_device_id); |
| 48 DCHECK(storage_object_id); | 48 DCHECK(storage_object_id); |
| 49 string16 storage_device_id; | 49 string16 storage_device_id; |
| 50 RemoveChars(storage_path, L"\\\\", &storage_device_id); | 50 RemoveChars(storage_path, L"\\\\", &storage_device_id); |
| 51 DCHECK(!storage_device_id.empty()); | 51 DCHECK(!storage_device_id.empty()); |
| 52 // TODO(gbillock): Take the StorageMonitor as an argument. | 52 // TODO(gbillock): Take the StorageMonitor as an argument. |
| 53 StorageMonitor* monitor = StorageMonitor::GetInstance(); | 53 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
| 54 DCHECK(monitor); | 54 DCHECK(monitor); |
| 55 return monitor->GetMTPStorageInfoFromDeviceId( | 55 return monitor->GetMTPStorageInfoFromDeviceId( |
| 56 UTF16ToUTF8(storage_device_id), pnp_device_id, storage_object_id); | 56 UTF16ToUTF8(storage_device_id), pnp_device_id, storage_object_id); |
| 57 } | 57 } |
| 58 | 58 |
| 59 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() { | 59 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() { |
| 60 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 60 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 61 base::SequencedWorkerPool::SequenceToken media_sequence_token = | 61 base::SequencedWorkerPool::SequenceToken media_sequence_token = |
| 62 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); | 62 pool->GetNamedSequenceToken( |
| 63 MediaFileSystemMountPointProvider::kMediaTaskRunnerName); |
| 63 return pool->GetSequencedTaskRunner(media_sequence_token); | 64 return pool->GetSequencedTaskRunner(media_sequence_token); |
| 64 } | 65 } |
| 65 | 66 |
| 66 // Returns the object id of the file object specified by the |file_path|, | 67 // Returns the object id of the file object specified by the |file_path|, |
| 67 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM" | 68 // e.g. if the |file_path| is "\\MTP:StorageSerial:SID-{1001,,192}:125\DCIM" |
| 68 // and |device_info.registered_device_path_| is | 69 // and |device_info.registered_device_path_| is |
| 69 // "\\MTP:StorageSerial:SID-{1001,,192}:125", this function returns the | 70 // "\\MTP:StorageSerial:SID-{1001,,192}:125", this function returns the |
| 70 // identifier of the "DCIM" folder object. | 71 // identifier of the "DCIM" folder object. |
| 71 // | 72 // |
| 72 // Returns an empty string if the device is detached while the request is in | 73 // Returns an empty string if the device is detached while the request is in |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 } else { | 614 } else { |
| 614 current_snapshot_details_->request_info().error_callback.Run( | 615 current_snapshot_details_->request_info().error_callback.Run( |
| 615 base::PLATFORM_FILE_ERROR_FAILED); | 616 base::PLATFORM_FILE_ERROR_FAILED); |
| 616 } | 617 } |
| 617 task_in_progress_ = false; | 618 task_in_progress_ = false; |
| 618 current_snapshot_details_.reset(); | 619 current_snapshot_details_.reset(); |
| 619 ProcessNextPendingRequest(); | 620 ProcessNextPendingRequest(); |
| 620 } | 621 } |
| 621 | 622 |
| 622 } // namespace chrome | 623 } // namespace chrome |
| OLD | NEW |