diff options
author | yawano <yawano@chromium.org> | 2015-06-02 12:18:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-02 19:19:01 +0000 |
commit | 355d47a1e6e433bf580ce110e57b5930b924c7d8 (patch) | |
tree | 1343fe965df026d93d2712a78d15448c2bf24a5c /device/media_transfer_protocol | |
parent | db0866191ff62557caf8e3e9c9a356f80675c34a (diff) | |
download | chromium_src-355d47a1e6e433bf580ce110e57b5930b924c7d8.zip chromium_src-355d47a1e6e433bf580ce110e57b5930b924c7d8.tar.gz chromium_src-355d47a1e6e433bf580ce110e57b5930b924c7d8.tar.bz2 |
Get latest available space by calling GetStorageInfoFromDevice of mtpd.
BUG=486396
TEST=manually tested; Open file manager, do some file operations on it. Confirm that available space of mtp volume is updated.
Review URL: https://codereview.chromium.org/1148733002
Cr-Commit-Position: refs/heads/master@{#332444}
Diffstat (limited to 'device/media_transfer_protocol')
4 files changed, 70 insertions, 1 deletions
diff --git a/device/media_transfer_protocol/media_transfer_protocol_daemon_client.cc b/device/media_transfer_protocol/media_transfer_protocol_daemon_client.cc index deecea6..1d2ca8c 100644 --- a/device/media_transfer_protocol/media_transfer_protocol_daemon_client.cc +++ b/device/media_transfer_protocol/media_transfer_protocol_daemon_client.cc @@ -64,6 +64,20 @@ class MediaTransferProtocolDaemonClientImpl error_callback)); } + void GetStorageInfoFromDevice(const std::string& storage_name, + const GetStorageInfoCallback& callback, + const ErrorCallback& error_callback) override { + dbus::MethodCall method_call(mtpd::kMtpdInterface, + mtpd::kGetStorageInfoFromDevice); + dbus::MessageWriter writer(&method_call); + writer.AppendString(storage_name); + proxy_->CallMethod( + &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetStorageInfo, + weak_ptr_factory_.GetWeakPtr(), storage_name, callback, + error_callback)); + } + // MediaTransferProtocolDaemonClient override. void OpenStorage(const std::string& storage_name, const std::string& mode, diff --git a/device/media_transfer_protocol/media_transfer_protocol_daemon_client.h b/device/media_transfer_protocol/media_transfer_protocol_daemon_client.h index c4c32c6..ad059bb 100644 --- a/device/media_transfer_protocol/media_transfer_protocol_daemon_client.h +++ b/device/media_transfer_protocol/media_transfer_protocol_daemon_client.h @@ -101,6 +101,13 @@ class MediaTransferProtocolDaemonClient { const GetStorageInfoCallback& callback, const ErrorCallback& error_callback) = 0; + // Calls GetStorageInfoFromDevice method. |callback| is called after the + // method call succeeds, otherwise, |error_callback| is called. + virtual void GetStorageInfoFromDevice( + const std::string& storage_name, + const GetStorageInfoCallback& callback, + const ErrorCallback& error_callback) = 0; + // Calls OpenStorage method. |callback| is called after the method call // succeeds, otherwise, |error_callback| is called. // OpenStorage returns a handle in |callback|. diff --git a/device/media_transfer_protocol/media_transfer_protocol_manager.cc b/device/media_transfer_protocol/media_transfer_protocol_manager.cc index 314c2b8..7e55cd9 100644 --- a/device/media_transfer_protocol/media_transfer_protocol_manager.cc +++ b/device/media_transfer_protocol/media_transfer_protocol_manager.cc @@ -124,6 +124,27 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { } // MediaTransferProtocolManager override. + void GetStorageInfoFromDevice( + const std::string& storage_name, + const GetStorageInfoFromDeviceCallback& callback) override { + DCHECK(thread_checker_.CalledOnValidThread()); + if (!ContainsKey(storage_info_map_, storage_name) || !mtp_client_) { + MtpStorageInfo info; + callback.Run(info, true /* error */); + return; + } + get_storage_info_from_device_callbacks_.push(callback); + mtp_client_->GetStorageInfoFromDevice( + storage_name, + base::Bind( + &MediaTransferProtocolManagerImpl::OnGetStorageInfoFromDevice, + weak_ptr_factory_.GetWeakPtr()), + base::Bind( + &MediaTransferProtocolManagerImpl::OnGetStorageInfoFromDeviceError, + weak_ptr_factory_.GetWeakPtr())); + } + + // MediaTransferProtocolManager override. void OpenStorage(const std::string& storage_name, const std::string& mode, const OpenStorageCallback& callback) override { @@ -298,6 +319,8 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { private: // Map of storage names to storage info. typedef std::map<std::string, MtpStorageInfo> StorageInfoMap; + typedef std::queue<GetStorageInfoFromDeviceCallback> + GetStorageInfoFromDeviceCallbackQueue; // Callback queues - DBus communication is in-order, thus callbacks are // received in the same order as the requests. typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue; @@ -377,6 +400,18 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { StorageChanged(true /* is attach */, storage_name)); } + void OnGetStorageInfoFromDevice(const MtpStorageInfo& storage_info) { + get_storage_info_from_device_callbacks_.front().Run(storage_info, + false /* no error */); + get_storage_info_from_device_callbacks_.pop(); + } + + void OnGetStorageInfoFromDeviceError() { + MtpStorageInfo info; + get_storage_info_from_device_callbacks_.front().Run(info, true /* error */); + get_storage_info_from_device_callbacks_.pop(); + } + void OnOpenStorage(const std::string& handle) { DCHECK(thread_checker_.CalledOnValidThread()); if (!ContainsKey(handles_, handle)) { @@ -649,6 +684,7 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { std::string current_mtpd_owner_; // Queued callbacks. + GetStorageInfoFromDeviceCallbackQueue get_storage_info_from_device_callbacks_; OpenStorageCallbackQueue open_storage_callbacks_; CloseStorageCallbackQueue close_storage_callbacks_; CreateDirectoryCallbackQueue create_directory_callbacks_; diff --git a/device/media_transfer_protocol/media_transfer_protocol_manager.h b/device/media_transfer_protocol/media_transfer_protocol_manager.h index 90acd5e..048e75b 100644 --- a/device/media_transfer_protocol/media_transfer_protocol_manager.h +++ b/device/media_transfer_protocol/media_transfer_protocol_manager.h @@ -29,6 +29,13 @@ namespace device { // Other classes can add themselves as observers. class MediaTransferProtocolManager { public: + // A callback to handle the result of GetStorageInfoFromDevice. + // The first argument is the returned storage info. + // The second argument is true if there was an error. + typedef base::Callback<void(const MtpStorageInfo& storage_info, + const bool error)> + GetStorageInfoFromDeviceCallback; + // A callback to handle the result of OpenStorage. // The first argument is the returned handle. // The second argument is true if there was an error. @@ -97,11 +104,16 @@ class MediaTransferProtocolManager { // Returns a vector of available MTP storages. virtual const std::vector<std::string> GetStorages() const = 0; - // On success, returns the the metadata for |storage_name|. + // On success, returns the metadata for |storage_name|. // Otherwise returns NULL. virtual const MtpStorageInfo* GetStorageInfo( const std::string& storage_name) const = 0; + // Read the metadata of |storage_name| from device and runs |callback|. + virtual void GetStorageInfoFromDevice( + const std::string& storage_name, + const GetStorageInfoFromDeviceCallback& callback) = 0; + // Opens |storage_name| in |mode| and runs |callback|. virtual void OpenStorage(const std::string& storage_name, const std::string& mode, |