| 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 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // |registered_device_path| specifies the registered file system root path for | 134 // |registered_device_path| specifies the registered file system root path for |
| 135 // the given device. | 135 // the given device. |
| 136 bool OpenDeviceOnBlockingPoolThread( | 136 bool OpenDeviceOnBlockingPoolThread( |
| 137 const base::string16& pnp_device_id, | 137 const base::string16& pnp_device_id, |
| 138 const base::string16& registered_device_path) { | 138 const base::string16& registered_device_path) { |
| 139 base::ThreadRestrictions::AssertIOAllowed(); | 139 base::ThreadRestrictions::AssertIOAllowed(); |
| 140 DCHECK(!pnp_device_id.empty()); | 140 DCHECK(!pnp_device_id.empty()); |
| 141 DCHECK(!registered_device_path.empty()); | 141 DCHECK(!registered_device_path.empty()); |
| 142 base::win::ScopedComPtr<IPortableDevice> device = | 142 base::win::ScopedComPtr<IPortableDevice> device = |
| 143 media_transfer_protocol::OpenDevice(pnp_device_id); | 143 media_transfer_protocol::OpenDevice(pnp_device_id); |
| 144 bool init_succeeded = device.get() != NULL; | 144 bool init_succeeded = device.Get() != NULL; |
| 145 if (init_succeeded) { | 145 if (init_succeeded) { |
| 146 PortableDeviceMapService::GetInstance()->AddPortableDevice( | 146 PortableDeviceMapService::GetInstance()->AddPortableDevice( |
| 147 registered_device_path, device.get()); | 147 registered_device_path, device.Get()); |
| 148 } | 148 } |
| 149 return init_succeeded; | 149 return init_succeeded; |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Gets the |file_path| details from the MTP device specified by the | 152 // Gets the |file_path| details from the MTP device specified by the |
| 153 // |device_info.registered_device_path|. On success, |error| is set to | 153 // |device_info.registered_device_path|. On success, |error| is set to |
| 154 // base::File::FILE_OK and fills in |file_info|. On failure, |error| is set | 154 // base::File::FILE_OK and fills in |file_info|. On failure, |error| is set |
| 155 // to corresponding platform file error and |file_info| is not set. | 155 // to corresponding platform file error and |file_info| is not set. |
| 156 base::File::Error GetFileInfoOnBlockingPoolThread( | 156 base::File::Error GetFileInfoOnBlockingPoolThread( |
| 157 const MTPDeviceDelegateImplWin::StorageDeviceInfo& device_info, | 157 const MTPDeviceDelegateImplWin::StorageDeviceInfo& device_info, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // Snapshot file modification time does not match the last modified time | 259 // Snapshot file modification time does not match the last modified time |
| 260 // of the original media file. Therefore, set the last modified time to null | 260 // of the original media file. Therefore, set the last modified time to null |
| 261 // in order to avoid the verification in LocalFileStreamReader. | 261 // in order to avoid the verification in LocalFileStreamReader. |
| 262 // | 262 // |
| 263 // Users will use HTML5 FileSystem Entry getMetadata() interface to get the | 263 // Users will use HTML5 FileSystem Entry getMetadata() interface to get the |
| 264 // actual last modified time of the media file. | 264 // actual last modified time of the media file. |
| 265 file_info.last_modified = base::Time(); | 265 file_info.last_modified = base::Time(); |
| 266 | 266 |
| 267 DCHECK(file_info.size == 0 || optimal_transfer_size > 0U); | 267 DCHECK(file_info.size == 0 || optimal_transfer_size > 0U); |
| 268 file_details->set_file_info(file_info); | 268 file_details->set_file_info(file_info); |
| 269 file_details->set_device_file_stream(file_stream.get()); | 269 file_details->set_device_file_stream(file_stream.Get()); |
| 270 file_details->set_optimal_transfer_size(optimal_transfer_size); | 270 file_details->set_optimal_transfer_size(optimal_transfer_size); |
| 271 return error; | 271 return error; |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Copies the data chunk from device file to the snapshot file based on the | 274 // Copies the data chunk from device file to the snapshot file based on the |
| 275 // parameters specified by |file_details|. | 275 // parameters specified by |file_details|. |
| 276 // Returns the total number of bytes written to the snapshot file for non-empty | 276 // Returns the total number of bytes written to the snapshot file for non-empty |
| 277 // files, or 0 on failure. For empty files, just return 0. | 277 // files, or 0 on failure. For empty files, just return 0. |
| 278 DWORD WriteDataChunkIntoSnapshotFileOnBlockingPoolThread( | 278 DWORD WriteDataChunkIntoSnapshotFileOnBlockingPoolThread( |
| 279 const SnapshotFileDetails& file_details) { | 279 const SnapshotFileDetails& file_details) { |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 current_snapshot_details_->file_info(), | 695 current_snapshot_details_->file_info(), |
| 696 current_snapshot_details_->request_info().snapshot_file_path); | 696 current_snapshot_details_->request_info().snapshot_file_path); |
| 697 } else { | 697 } else { |
| 698 current_snapshot_details_->request_info().error_callback.Run( | 698 current_snapshot_details_->request_info().error_callback.Run( |
| 699 base::File::FILE_ERROR_FAILED); | 699 base::File::FILE_ERROR_FAILED); |
| 700 } | 700 } |
| 701 task_in_progress_ = false; | 701 task_in_progress_ = false; |
| 702 current_snapshot_details_.reset(); | 702 current_snapshot_details_.reset(); |
| 703 ProcessNextPendingRequest(); | 703 ProcessNextPendingRequest(); |
| 704 } | 704 } |
| OLD | NEW |