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

Unified Diff: device/media_transfer_protocol/media_transfer_protocol_manager.cc

Issue 982283002: Implement DeleteFile and DeleteDirectory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit_tests. 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 side-by-side diff with in-line comments
Download patch
Index: device/media_transfer_protocol/media_transfer_protocol_manager.cc
diff --git a/device/media_transfer_protocol/media_transfer_protocol_manager.cc b/device/media_transfer_protocol/media_transfer_protocol_manager.cc
index fb59588be516b54c95a9bdcce21fa83f481cdb71..832688e3fb925695e172e9d7e21d4425eea2c7fd 100644
--- a/device/media_transfer_protocol/media_transfer_protocol_manager.cc
+++ b/device/media_transfer_protocol/media_transfer_protocol_manager.cc
@@ -172,15 +172,33 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
}
read_directory_callbacks_.push(callback);
mtp_client_->ReadDirectoryEntryIds(
- storage_handle,
- file_id,
- base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryEntryIds,
- weak_ptr_factory_.GetWeakPtr(),
- storage_handle),
+ storage_handle, file_id,
+ base::Bind(&MediaTransferProtocolManagerImpl::
+ OnReadDirectoryEntryIdsToReadDirectory,
+ weak_ptr_factory_.GetWeakPtr(), storage_handle),
base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError,
weak_ptr_factory_.GetWeakPtr()));
}
+ void ReadDirectoryEntryIds(
+ const std::string& storage_handle,
+ const uint32 file_id,
+ const ReadDirectoryEntryIdsCallback& callback) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
+ callback.Run(std::vector<uint32>(), true /* error */);
+ return;
+ }
+ read_directory_entry_ids_callbacks_.push(callback);
+ mtp_client_->ReadDirectoryEntryIds(
+ storage_handle, file_id,
+ base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryEntryIds,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(
+ &MediaTransferProtocolManagerImpl::OnReadDirectoryEntryIdsError,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+
// MediaTransferProtocolManager override.
void ReadFileChunk(const std::string& storage_handle,
uint32 file_id,
@@ -242,6 +260,23 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
weak_ptr_factory_.GetWeakPtr()));
}
+ void DeleteObject(const std::string& storage_handle,
+ const uint32 object_id,
+ const DeleteObjectCallback& callback) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
+ callback.Run(true /* error */);
+ return;
+ }
+ delete_object_callbacks_.push(callback);
+ mtp_client_->DeleteObject(
+ storage_handle, object_id,
+ base::Bind(&MediaTransferProtocolManagerImpl::OnDeleteObject,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&MediaTransferProtocolManagerImpl::OnDeleteObjectError,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+
private:
// Map of storage names to storage info.
typedef std::map<std::string, MtpStorageInfo> StorageInfoMap;
@@ -252,9 +287,12 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
typedef std::queue<std::pair<CloseStorageCallback, std::string>
> CloseStorageCallbackQueue;
typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue;
+ typedef std::queue<ReadDirectoryEntryIdsCallback>
+ ReadDirectoryEntryIdsCallbackQueue;
typedef std::queue<ReadFileCallback> ReadFileCallbackQueue;
typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue;
typedef std::queue<CopyFileFromLocalCallback> CopyFileFromLocalCallbackQueue;
+ typedef std::queue<DeleteObjectCallback> DeleteObjectCallbackQueue;
void OnStorageAttached(const std::string& storage_name) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -357,8 +395,9 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
close_storage_callbacks_.pop();
}
- void OnReadDirectoryEntryIds(const std::string& storage_handle,
- const std::vector<uint32>& file_ids) {
+ void OnReadDirectoryEntryIdsToReadDirectory(
+ const std::string& storage_handle,
+ const std::vector<uint32>& file_ids) {
DCHECK(thread_checker_.CalledOnValidThread());
if (file_ids.empty()) {
@@ -443,6 +482,20 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
read_directory_callbacks_.pop();
}
+ void OnReadDirectoryEntryIds(const std::vector<uint32>& file_ids) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ read_directory_entry_ids_callbacks_.front().Run(file_ids,
+ false /* no error */);
+ read_directory_entry_ids_callbacks_.pop();
+ }
+
+ void OnReadDirectoryEntryIdsError() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ read_directory_entry_ids_callbacks_.front().Run(std::vector<uint32>(),
+ true /* error */);
+ read_directory_entry_ids_callbacks_.pop();
+ }
+
void OnReadFile(const std::string& data) {
DCHECK(thread_checker_.CalledOnValidThread());
read_file_callbacks_.front().Run(data, false);
@@ -483,6 +536,18 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
copy_file_from_local_callbacks_.pop();
}
+ void OnDeleteObject() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ delete_object_callbacks_.front().Run(false /* no error */);
+ delete_object_callbacks_.pop();
+ }
+
+ void OnDeleteObjectError() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ delete_object_callbacks_.front().Run(true /* error */);
+ delete_object_callbacks_.pop();
+ }
+
// Get the Bus object used to communicate with mtpd.
dbus::Bus* GetBus() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -562,9 +627,11 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
OpenStorageCallbackQueue open_storage_callbacks_;
CloseStorageCallbackQueue close_storage_callbacks_;
ReadDirectoryCallbackQueue read_directory_callbacks_;
+ ReadDirectoryEntryIdsCallbackQueue read_directory_entry_ids_callbacks_;
ReadFileCallbackQueue read_file_callbacks_;
GetFileInfoCallbackQueue get_file_info_callbacks_;
CopyFileFromLocalCallbackQueue copy_file_from_local_callbacks_;
+ DeleteObjectCallbackQueue delete_object_callbacks_;
base::ThreadChecker thread_checker_;

Powered by Google App Engine
This is Rietveld 408576698