| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 storage_handle, | 216 storage_handle, |
| 217 file_ids, | 217 file_ids, |
| 218 kInitialOffset, | 218 kInitialOffset, |
| 219 file_ids.size(), | 219 file_ids.size(), |
| 220 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo, | 220 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo, |
| 221 weak_ptr_factory_.GetWeakPtr()), | 221 weak_ptr_factory_.GetWeakPtr()), |
| 222 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError, | 222 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError, |
| 223 weak_ptr_factory_.GetWeakPtr())); | 223 weak_ptr_factory_.GetWeakPtr())); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void RenameObject(const std::string& storage_handle, |
| 227 const uint32 object_id, |
| 228 const std::string& new_name, |
| 229 const RenameObjectCallback& callback) override { |
| 230 DCHECK(thread_checker_.CalledOnValidThread()); |
| 231 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { |
| 232 callback.Run(true /* error */); |
| 233 return; |
| 234 } |
| 235 rename_object_callbacks_.push(callback); |
| 236 mtp_client_->RenameObject( |
| 237 storage_handle, object_id, new_name, |
| 238 base::Bind(&MediaTransferProtocolManagerImpl::OnRenameObject, |
| 239 weak_ptr_factory_.GetWeakPtr()), |
| 240 base::Bind(&MediaTransferProtocolManagerImpl::OnRenameObjectError, |
| 241 weak_ptr_factory_.GetWeakPtr())); |
| 242 } |
| 243 |
| 226 void CopyFileFromLocal(const std::string& storage_handle, | 244 void CopyFileFromLocal(const std::string& storage_handle, |
| 227 const int source_file_descriptor, | 245 const int source_file_descriptor, |
| 228 const uint32 parent_id, | 246 const uint32 parent_id, |
| 229 const std::string& file_name, | 247 const std::string& file_name, |
| 230 const CopyFileFromLocalCallback& callback) override { | 248 const CopyFileFromLocalCallback& callback) override { |
| 231 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
| 232 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { | 250 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) { |
| 233 callback.Run(true /* error */); | 251 callback.Run(true /* error */); |
| 234 return; | 252 return; |
| 235 } | 253 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 264 typedef std::map<std::string, MtpStorageInfo> StorageInfoMap; | 282 typedef std::map<std::string, MtpStorageInfo> StorageInfoMap; |
| 265 // Callback queues - DBus communication is in-order, thus callbacks are | 283 // Callback queues - DBus communication is in-order, thus callbacks are |
| 266 // received in the same order as the requests. | 284 // received in the same order as the requests. |
| 267 typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue; | 285 typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue; |
| 268 // (callback, handle) | 286 // (callback, handle) |
| 269 typedef std::queue<std::pair<CloseStorageCallback, std::string> | 287 typedef std::queue<std::pair<CloseStorageCallback, std::string> |
| 270 > CloseStorageCallbackQueue; | 288 > CloseStorageCallbackQueue; |
| 271 typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue; | 289 typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue; |
| 272 typedef std::queue<ReadFileCallback> ReadFileCallbackQueue; | 290 typedef std::queue<ReadFileCallback> ReadFileCallbackQueue; |
| 273 typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue; | 291 typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue; |
| 292 typedef std::queue<RenameObjectCallback> RenameObjectCallbackQueue; |
| 274 typedef std::queue<CopyFileFromLocalCallback> CopyFileFromLocalCallbackQueue; | 293 typedef std::queue<CopyFileFromLocalCallback> CopyFileFromLocalCallbackQueue; |
| 275 typedef std::queue<DeleteObjectCallback> DeleteObjectCallbackQueue; | 294 typedef std::queue<DeleteObjectCallback> DeleteObjectCallbackQueue; |
| 276 | 295 |
| 277 void OnStorageAttached(const std::string& storage_name) { | 296 void OnStorageAttached(const std::string& storage_name) { |
| 278 DCHECK(thread_checker_.CalledOnValidThread()); | 297 DCHECK(thread_checker_.CalledOnValidThread()); |
| 279 mtp_client_->GetStorageInfo( | 298 mtp_client_->GetStorageInfo( |
| 280 storage_name, | 299 storage_name, |
| 281 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, | 300 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, |
| 282 weak_ptr_factory_.GetWeakPtr()), | 301 weak_ptr_factory_.GetWeakPtr()), |
| 283 base::Bind(&base::DoNothing)); | 302 base::Bind(&base::DoNothing)); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 OnGetFileInfoError(); | 499 OnGetFileInfoError(); |
| 481 } | 500 } |
| 482 } | 501 } |
| 483 | 502 |
| 484 void OnGetFileInfoError() { | 503 void OnGetFileInfoError() { |
| 485 DCHECK(thread_checker_.CalledOnValidThread()); | 504 DCHECK(thread_checker_.CalledOnValidThread()); |
| 486 get_file_info_callbacks_.front().Run(MtpFileEntry(), true); | 505 get_file_info_callbacks_.front().Run(MtpFileEntry(), true); |
| 487 get_file_info_callbacks_.pop(); | 506 get_file_info_callbacks_.pop(); |
| 488 } | 507 } |
| 489 | 508 |
| 509 void OnRenameObject() { |
| 510 DCHECK(thread_checker_.CalledOnValidThread()); |
| 511 rename_object_callbacks_.front().Run(false /* no error */); |
| 512 rename_object_callbacks_.pop(); |
| 513 } |
| 514 |
| 515 void OnRenameObjectError() { |
| 516 DCHECK(thread_checker_.CalledOnValidThread()); |
| 517 rename_object_callbacks_.front().Run(true /* error */); |
| 518 rename_object_callbacks_.pop(); |
| 519 } |
| 520 |
| 490 void OnCopyFileFromLocal() { | 521 void OnCopyFileFromLocal() { |
| 491 DCHECK(thread_checker_.CalledOnValidThread()); | 522 DCHECK(thread_checker_.CalledOnValidThread()); |
| 492 copy_file_from_local_callbacks_.front().Run(false /* no error */); | 523 copy_file_from_local_callbacks_.front().Run(false /* no error */); |
| 493 copy_file_from_local_callbacks_.pop(); | 524 copy_file_from_local_callbacks_.pop(); |
| 494 } | 525 } |
| 495 | 526 |
| 496 void OnCopyFileFromLocalError() { | 527 void OnCopyFileFromLocalError() { |
| 497 DCHECK(thread_checker_.CalledOnValidThread()); | 528 DCHECK(thread_checker_.CalledOnValidThread()); |
| 498 copy_file_from_local_callbacks_.front().Run(true /* error */); | 529 copy_file_from_local_callbacks_.front().Run(true /* error */); |
| 499 copy_file_from_local_callbacks_.pop(); | 530 copy_file_from_local_callbacks_.pop(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 dbus::Bus::GetServiceOwnerCallback mtpd_owner_changed_callback_; | 616 dbus::Bus::GetServiceOwnerCallback mtpd_owner_changed_callback_; |
| 586 | 617 |
| 587 std::string current_mtpd_owner_; | 618 std::string current_mtpd_owner_; |
| 588 | 619 |
| 589 // Queued callbacks. | 620 // Queued callbacks. |
| 590 OpenStorageCallbackQueue open_storage_callbacks_; | 621 OpenStorageCallbackQueue open_storage_callbacks_; |
| 591 CloseStorageCallbackQueue close_storage_callbacks_; | 622 CloseStorageCallbackQueue close_storage_callbacks_; |
| 592 ReadDirectoryCallbackQueue read_directory_callbacks_; | 623 ReadDirectoryCallbackQueue read_directory_callbacks_; |
| 593 ReadFileCallbackQueue read_file_callbacks_; | 624 ReadFileCallbackQueue read_file_callbacks_; |
| 594 GetFileInfoCallbackQueue get_file_info_callbacks_; | 625 GetFileInfoCallbackQueue get_file_info_callbacks_; |
| 626 RenameObjectCallbackQueue rename_object_callbacks_; |
| 595 CopyFileFromLocalCallbackQueue copy_file_from_local_callbacks_; | 627 CopyFileFromLocalCallbackQueue copy_file_from_local_callbacks_; |
| 596 DeleteObjectCallbackQueue delete_object_callbacks_; | 628 DeleteObjectCallbackQueue delete_object_callbacks_; |
| 597 | 629 |
| 598 base::ThreadChecker thread_checker_; | 630 base::ThreadChecker thread_checker_; |
| 599 | 631 |
| 600 base::WeakPtrFactory<MediaTransferProtocolManagerImpl> weak_ptr_factory_; | 632 base::WeakPtrFactory<MediaTransferProtocolManagerImpl> weak_ptr_factory_; |
| 601 | 633 |
| 602 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl); | 634 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl); |
| 603 }; | 635 }; |
| 604 | 636 |
| 605 } // namespace | 637 } // namespace |
| 606 | 638 |
| 607 // static | 639 // static |
| 608 MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize( | 640 MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize( |
| 609 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 641 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 610 DCHECK(!g_media_transfer_protocol_manager); | 642 DCHECK(!g_media_transfer_protocol_manager); |
| 611 | 643 |
| 612 g_media_transfer_protocol_manager = | 644 g_media_transfer_protocol_manager = |
| 613 new MediaTransferProtocolManagerImpl(task_runner); | 645 new MediaTransferProtocolManagerImpl(task_runner); |
| 614 VLOG(1) << "MediaTransferProtocolManager initialized"; | 646 VLOG(1) << "MediaTransferProtocolManager initialized"; |
| 615 | 647 |
| 616 return g_media_transfer_protocol_manager; | 648 return g_media_transfer_protocol_manager; |
| 617 } | 649 } |
| 618 | 650 |
| 619 } // namespace device | 651 } // namespace device |
| OLD | NEW |