Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: device/media_transfer_protocol/media_transfer_protocol_manager.cc

Issue 947943002: Implement CopyFileFromLocal of MTPDeviceAsyncDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/media_transfer_protocol/media_transfer_protocol_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 CopyFileFromLocal(const std::string& storage_handle,
227 const int source_file_descriptor,
228 const uint32 parent_id,
229 const std::string& file_name,
230 const CopyFileFromLocalCallback& callback) override {
231 DCHECK(thread_checker_.CalledOnValidThread());
232 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
233 callback.Run(true /* error */);
234 return;
235 }
236 copy_file_from_local_callbacks_.push(callback);
237 mtp_client_->CopyFileFromLocal(
238 storage_handle, source_file_descriptor, parent_id, file_name,
239 base::Bind(&MediaTransferProtocolManagerImpl::OnCopyFileFromLocal,
240 weak_ptr_factory_.GetWeakPtr()),
241 base::Bind(&MediaTransferProtocolManagerImpl::OnCopyFileFromLocalError,
242 weak_ptr_factory_.GetWeakPtr()));
243 }
244
226 private: 245 private:
227 // Map of storage names to storage info. 246 // Map of storage names to storage info.
228 typedef std::map<std::string, MtpStorageInfo> StorageInfoMap; 247 typedef std::map<std::string, MtpStorageInfo> StorageInfoMap;
229 // Callback queues - DBus communication is in-order, thus callbacks are 248 // Callback queues - DBus communication is in-order, thus callbacks are
230 // received in the same order as the requests. 249 // received in the same order as the requests.
231 typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue; 250 typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue;
232 // (callback, handle) 251 // (callback, handle)
233 typedef std::queue<std::pair<CloseStorageCallback, std::string> 252 typedef std::queue<std::pair<CloseStorageCallback, std::string>
234 > CloseStorageCallbackQueue; 253 > CloseStorageCallbackQueue;
235 typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue; 254 typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue;
236 typedef std::queue<ReadFileCallback> ReadFileCallbackQueue; 255 typedef std::queue<ReadFileCallback> ReadFileCallbackQueue;
237 typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue; 256 typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue;
257 typedef std::queue<CopyFileFromLocalCallback> CopyFileFromLocalCallbackQueue;
238 258
239 void OnStorageAttached(const std::string& storage_name) { 259 void OnStorageAttached(const std::string& storage_name) {
240 DCHECK(thread_checker_.CalledOnValidThread()); 260 DCHECK(thread_checker_.CalledOnValidThread());
241 mtp_client_->GetStorageInfo( 261 mtp_client_->GetStorageInfo(
242 storage_name, 262 storage_name,
243 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, 263 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo,
244 weak_ptr_factory_.GetWeakPtr()), 264 weak_ptr_factory_.GetWeakPtr()),
245 base::Bind(&base::DoNothing)); 265 base::Bind(&base::DoNothing));
246 } 266 }
247 267
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 OnGetFileInfoError(); 464 OnGetFileInfoError();
445 } 465 }
446 } 466 }
447 467
448 void OnGetFileInfoError() { 468 void OnGetFileInfoError() {
449 DCHECK(thread_checker_.CalledOnValidThread()); 469 DCHECK(thread_checker_.CalledOnValidThread());
450 get_file_info_callbacks_.front().Run(MtpFileEntry(), true); 470 get_file_info_callbacks_.front().Run(MtpFileEntry(), true);
451 get_file_info_callbacks_.pop(); 471 get_file_info_callbacks_.pop();
452 } 472 }
453 473
474 void OnCopyFileFromLocal() {
475 DCHECK(thread_checker_.CalledOnValidThread());
476 copy_file_from_local_callbacks_.front().Run(false /* no error */);
477 copy_file_from_local_callbacks_.pop();
478 }
479
480 void OnCopyFileFromLocalError() {
481 DCHECK(thread_checker_.CalledOnValidThread());
482 copy_file_from_local_callbacks_.front().Run(true /* error */);
483 copy_file_from_local_callbacks_.pop();
484 }
485
454 // Get the Bus object used to communicate with mtpd. 486 // Get the Bus object used to communicate with mtpd.
455 dbus::Bus* GetBus() { 487 dbus::Bus* GetBus() {
456 DCHECK(thread_checker_.CalledOnValidThread()); 488 DCHECK(thread_checker_.CalledOnValidThread());
457 #if defined(OS_CHROMEOS) 489 #if defined(OS_CHROMEOS)
458 return chromeos::DBusThreadManager::Get()->GetSystemBus(); 490 return chromeos::DBusThreadManager::Get()->GetSystemBus();
459 #else 491 #else
460 return session_bus_.get(); 492 return session_bus_.get();
461 #endif 493 #endif
462 } 494 }
463 495
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 dbus::Bus::GetServiceOwnerCallback mtpd_owner_changed_callback_; 557 dbus::Bus::GetServiceOwnerCallback mtpd_owner_changed_callback_;
526 558
527 std::string current_mtpd_owner_; 559 std::string current_mtpd_owner_;
528 560
529 // Queued callbacks. 561 // Queued callbacks.
530 OpenStorageCallbackQueue open_storage_callbacks_; 562 OpenStorageCallbackQueue open_storage_callbacks_;
531 CloseStorageCallbackQueue close_storage_callbacks_; 563 CloseStorageCallbackQueue close_storage_callbacks_;
532 ReadDirectoryCallbackQueue read_directory_callbacks_; 564 ReadDirectoryCallbackQueue read_directory_callbacks_;
533 ReadFileCallbackQueue read_file_callbacks_; 565 ReadFileCallbackQueue read_file_callbacks_;
534 GetFileInfoCallbackQueue get_file_info_callbacks_; 566 GetFileInfoCallbackQueue get_file_info_callbacks_;
567 CopyFileFromLocalCallbackQueue copy_file_from_local_callbacks_;
535 568
536 base::ThreadChecker thread_checker_; 569 base::ThreadChecker thread_checker_;
537 570
538 base::WeakPtrFactory<MediaTransferProtocolManagerImpl> weak_ptr_factory_; 571 base::WeakPtrFactory<MediaTransferProtocolManagerImpl> weak_ptr_factory_;
539 572
540 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl); 573 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl);
541 }; 574 };
542 575
543 } // namespace 576 } // namespace
544 577
545 // static 578 // static
546 MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize( 579 MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize(
547 scoped_refptr<base::SequencedTaskRunner> task_runner) { 580 scoped_refptr<base::SequencedTaskRunner> task_runner) {
548 DCHECK(!g_media_transfer_protocol_manager); 581 DCHECK(!g_media_transfer_protocol_manager);
549 582
550 g_media_transfer_protocol_manager = 583 g_media_transfer_protocol_manager =
551 new MediaTransferProtocolManagerImpl(task_runner); 584 new MediaTransferProtocolManagerImpl(task_runner);
552 VLOG(1) << "MediaTransferProtocolManager initialized"; 585 VLOG(1) << "MediaTransferProtocolManager initialized";
553 586
554 return g_media_transfer_protocol_manager; 587 return g_media_transfer_protocol_manager;
555 } 588 }
556 589
557 } // namespace device 590 } // namespace device
OLDNEW
« no previous file with comments | « device/media_transfer_protocol/media_transfer_protocol_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698