| 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 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 5 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 close_storage_callbacks_.push(std::make_pair(callback, storage_handle)); | 153 close_storage_callbacks_.push(std::make_pair(callback, storage_handle)); |
| 154 mtp_client_->CloseStorage( | 154 mtp_client_->CloseStorage( |
| 155 storage_handle, | 155 storage_handle, |
| 156 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorage, | 156 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorage, |
| 157 weak_ptr_factory_.GetWeakPtr()), | 157 weak_ptr_factory_.GetWeakPtr()), |
| 158 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorageError, | 158 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorageError, |
| 159 weak_ptr_factory_.GetWeakPtr())); | 159 weak_ptr_factory_.GetWeakPtr())); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // MediaTransferProtocolManager override. | 162 // MediaTransferProtocolManager override. |
| 163 virtual void ReadDirectoryById( | 163 virtual void ReadDirectory(const std::string& storage_handle, |
| 164 const std::string& storage_handle, | 164 uint32 file_id, |
| 165 uint32 file_id, | 165 const ReadDirectoryCallback& callback) OVERRIDE { |
| 166 const ReadDirectoryCallback& callback) OVERRIDE { | |
| 167 DCHECK(thread_checker_.CalledOnValidThread()); | 166 DCHECK(thread_checker_.CalledOnValidThread()); |
| 168 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { | 167 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { |
| 169 callback.Run(std::vector<MtpFileEntry>(), | 168 callback.Run(std::vector<MtpFileEntry>(), |
| 170 false /* no more entries */, | 169 false /* no more entries */, |
| 171 true /* error */); | 170 true /* error */); |
| 172 return; | 171 return; |
| 173 } | 172 } |
| 174 read_directory_callbacks_.push(callback); | 173 read_directory_callbacks_.push(callback); |
| 175 mtp_client_->ReadDirectoryEntryIds( | 174 mtp_client_->ReadDirectoryEntryIds( |
| 176 storage_handle, | 175 storage_handle, |
| 177 file_id, | 176 file_id, |
| 178 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryEntryIds, | 177 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryEntryIds, |
| 179 weak_ptr_factory_.GetWeakPtr(), | 178 weak_ptr_factory_.GetWeakPtr(), |
| 180 storage_handle), | 179 storage_handle), |
| 181 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, | 180 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, |
| 182 weak_ptr_factory_.GetWeakPtr())); | 181 weak_ptr_factory_.GetWeakPtr())); |
| 183 } | 182 } |
| 184 | 183 |
| 185 // MediaTransferProtocolManager override. | 184 // MediaTransferProtocolManager override. |
| 186 virtual void ReadFileChunkById(const std::string& storage_handle, | 185 virtual void ReadFileChunk(const std::string& storage_handle, |
| 187 uint32 file_id, | 186 uint32 file_id, |
| 188 uint32 offset, | 187 uint32 offset, |
| 189 uint32 count, | 188 uint32 count, |
| 190 const ReadFileCallback& callback) OVERRIDE { | 189 const ReadFileCallback& callback) OVERRIDE { |
| 191 DCHECK(thread_checker_.CalledOnValidThread()); | 190 DCHECK(thread_checker_.CalledOnValidThread()); |
| 192 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { | 191 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { |
| 193 callback.Run(std::string(), true); | 192 callback.Run(std::string(), true); |
| 194 return; | 193 return; |
| 195 } | 194 } |
| 196 read_file_callbacks_.push(callback); | 195 read_file_callbacks_.push(callback); |
| 197 mtp_client_->ReadFileChunkById( | 196 mtp_client_->ReadFileChunk( |
| 198 storage_handle, file_id, offset, count, | 197 storage_handle, file_id, offset, count, |
| 199 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile, | 198 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile, |
| 200 weak_ptr_factory_.GetWeakPtr()), | 199 weak_ptr_factory_.GetWeakPtr()), |
| 201 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError, | 200 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError, |
| 202 weak_ptr_factory_.GetWeakPtr())); | 201 weak_ptr_factory_.GetWeakPtr())); |
| 203 } | 202 } |
| 204 | 203 |
| 205 virtual void GetFileInfoById(const std::string& storage_handle, | 204 virtual void GetFileInfo(const std::string& storage_handle, |
| 206 uint32 file_id, | 205 uint32 file_id, |
| 207 const GetFileInfoCallback& callback) OVERRIDE { | 206 const GetFileInfoCallback& callback) OVERRIDE { |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { | 208 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { |
| 210 callback.Run(MtpFileEntry(), true); | 209 callback.Run(MtpFileEntry(), true); |
| 211 return; | 210 return; |
| 212 } | 211 } |
| 213 std::vector<uint32> file_ids; | 212 std::vector<uint32> file_ids; |
| 214 file_ids.push_back(file_id); | 213 file_ids.push_back(file_id); |
| 215 get_file_info_callbacks_.push(callback); | 214 get_file_info_callbacks_.push(callback); |
| 216 mtp_client_->GetFileInfo( | 215 mtp_client_->GetFileInfo( |
| 217 storage_handle, | 216 storage_handle, |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 DCHECK(!g_media_transfer_protocol_manager); | 548 DCHECK(!g_media_transfer_protocol_manager); |
| 550 | 549 |
| 551 g_media_transfer_protocol_manager = | 550 g_media_transfer_protocol_manager = |
| 552 new MediaTransferProtocolManagerImpl(task_runner); | 551 new MediaTransferProtocolManagerImpl(task_runner); |
| 553 VLOG(1) << "MediaTransferProtocolManager initialized"; | 552 VLOG(1) << "MediaTransferProtocolManager initialized"; |
| 554 | 553 |
| 555 return g_media_transfer_protocol_manager; | 554 return g_media_transfer_protocol_manager; |
| 556 } | 555 } |
| 557 | 556 |
| 558 } // namespace device | 557 } // namespace device |
| OLD | NEW |