summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-07 18:57:27 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-07 18:57:27 +0000
commit85b95a20147299973f59886883a8dc44bb66f4b1 (patch)
tree840bd6227dc5600ae5bd010baf06a5331d9be564
parent7c5787734503205c56a3058044c90a662567504b (diff)
downloadchromium_src-85b95a20147299973f59886883a8dc44bb66f4b1.zip
chromium_src-85b95a20147299973f59886883a8dc44bb66f4b1.tar.gz
chromium_src-85b95a20147299973f59886883a8dc44bb66f4b1.tar.bz2
chromeos: Add dbus MTPDClient.
BUG=chromium-os:29557 TEST=none Review URL: https://chromiumcodereview.appspot.com/10825170 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150382 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chromeos/chromeos.gyp8
-rw-r--r--chromeos/dbus/cros_disks_client.cc8
-rw-r--r--chromeos/dbus/cros_disks_client.h34
-rw-r--r--chromeos/dbus/dbus_thread_manager.cc16
-rw-r--r--chromeos/dbus/dbus_thread_manager.h7
-rw-r--r--chromeos/dbus/media_transfer_protocol_daemon_client.cc572
-rw-r--r--chromeos/dbus/media_transfer_protocol_daemon_client.h283
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.cc5
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.h9
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc6
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.h2
-rw-r--r--chromeos/dbus/mock_media_transfer_protocol_daemon_client.cc13
-rw-r--r--chromeos/dbus/mock_media_transfer_protocol_daemon_client.h54
13 files changed, 997 insertions, 20 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index f174b0f..47b9587 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -95,6 +95,8 @@
'dbus/image_burner_client.h',
'dbus/introspectable_client.cc',
'dbus/introspectable_client.h',
+ 'dbus/media_transfer_protocol_daemon_client.cc',
+ 'dbus/media_transfer_protocol_daemon_client.h',
'dbus/modem_messaging_client.cc',
'dbus/modem_messaging_client.h',
'dbus/power_manager_client.cc',
@@ -142,10 +144,10 @@
'dbus/mock_bluetooth_node_client.h',
'dbus/mock_bluetooth_out_of_band_client.cc',
'dbus/mock_bluetooth_out_of_band_client.h',
- 'dbus/mock_cros_disks_client.cc',
- 'dbus/mock_cros_disks_client.h',
'dbus/mock_cashew_client.cc',
'dbus/mock_cashew_client.h',
+ 'dbus/mock_cros_disks_client.cc',
+ 'dbus/mock_cros_disks_client.h',
'dbus/mock_cryptohome_client.cc',
'dbus/mock_cryptohome_client.h',
'dbus/mock_dbus_thread_manager.cc',
@@ -170,6 +172,8 @@
'dbus/mock_image_burner_client.h',
'dbus/mock_introspectable_client.cc',
'dbus/mock_introspectable_client.h',
+ 'dbus/mock_media_transfer_protocol_daemon_client.cc',
+ 'dbus/mock_media_transfer_protocol_daemon_client.h',
'dbus/mock_modem_messaging_client.cc',
'dbus/mock_modem_messaging_client.h',
'dbus/mock_power_manager_client.cc',
diff --git a/chromeos/dbus/cros_disks_client.cc b/chromeos/dbus/cros_disks_client.cc
index 9f367c2..fafec90 100644
--- a/chromeos/dbus/cros_disks_client.cc
+++ b/chromeos/dbus/cros_disks_client.cc
@@ -4,6 +4,8 @@
#include "chromeos/dbus/cros_disks_client.h"
+#include <map>
+
#include "base/bind.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
@@ -246,7 +248,7 @@ class CrosDisksClientImpl : public CrosDisksClient {
cros_disks::kMountCompleted,
base::Bind(&CrosDisksClientImpl::OnMountCompleted,
weak_ptr_factory_.GetWeakPtr(),
- mount_completed_handler ),
+ mount_completed_handler),
base::Bind(&CrosDisksClientImpl::OnSignalConnected,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -415,7 +417,7 @@ class CrosDisksClientStubImpl : public CrosDisksClient {
DISALLOW_COPY_AND_ASSIGN(CrosDisksClientStubImpl);
};
-} // namespace
+} // namespace
////////////////////////////////////////////////////////////////////////////////
// DiskInfo
@@ -435,7 +437,7 @@ DiskInfo::DiskInfo(const std::string& device_path, dbus::Response* response)
DiskInfo::~DiskInfo() {
}
-// Initialize |this| from |response| given by the cros-disks service.
+// Initializes |this| from |response| given by the cros-disks service.
// Below is an example of |response|'s raw message (long string is ellipsized).
//
//
diff --git a/chromeos/dbus/cros_disks_client.h b/chromeos/dbus/cros_disks_client.h
index 7338111..c79e466 100644
--- a/chromeos/dbus/cros_disks_client.h
+++ b/chromeos/dbus/cros_disks_client.h
@@ -71,14 +71,14 @@ class DiskInfo {
~DiskInfo();
// Device path. (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
- std::string device_path() const { return device_path_; }
+ const std::string& device_path() const { return device_path_; }
// Disk mount path. (e.g. /media/removable/VOLUME)
- std::string mount_path() const { return mount_path_; }
+ const std::string& mount_path() const { return mount_path_; }
// Disk system path given by udev.
// (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
- std::string system_path() const { return system_path_; }
+ const std::string& system_path() const { return system_path_; }
// Is a drive or not. (i.e. true with /dev/sdb, false with /dev/sdb1)
bool is_drive() const { return is_drive_; }
@@ -90,13 +90,13 @@ class DiskInfo {
bool on_boot_device() const { return on_boot_device_; }
// Disk file path (e.g. /dev/sdb).
- std::string file_path() const { return file_path_; }
+ const std::string& file_path() const { return file_path_; }
// Disk label.
- std::string label() const { return label_; }
+ const std::string& label() const { return label_; }
// Disk model. (e.g. "TransMemory")
- std::string drive_label() const { return drive_model_; }
+ const std::string& drive_label() const { return drive_model_; }
// Device type. Not working well, yet.
DeviceType device_type() const { return device_type_; }
@@ -111,7 +111,7 @@ class DiskInfo {
bool is_hidden() const { return is_hidden_; }
// Returns file system uuid.
- std::string uuid() const { return uuid_; }
+ const std::string& uuid() const { return uuid_; }
private:
void InitializeFromResponse(dbus::Response* response);
@@ -146,34 +146,40 @@ class CHROMEOS_EXPORT CrosDisksClient {
// A callback to handle the result of Unmount.
// The argument is the device path.
- typedef base::Callback<void(const std::string&)> UnmountCallback;
+ typedef base::Callback<void(const std::string& device_path)> UnmountCallback;
// A callback to handle the result of EnumerateAutoMountableDevices.
// The argument is the enumerated device paths.
- typedef base::Callback<void(const std::vector<std::string>&)
+ typedef base::Callback<void(const std::vector<std::string>& device_paths)
> EnumerateAutoMountableDevicesCallback;
// A callback to handle the result of FormatDevice.
// The first argument is the device path.
// The second argument is true when formatting succeeded, false otherwise.
- typedef base::Callback<void(const std::string&, bool)> FormatDeviceCallback;
+ typedef base::Callback<void(const std::string& device_path,
+ bool format_succeeded)> FormatDeviceCallback;
// A callback to handle the result of GetDeviceProperties.
// The argument is the information about the specified device.
- typedef base::Callback<void(const DiskInfo&)> GetDevicePropertiesCallback;
+ typedef base::Callback<void(const DiskInfo& disk_info)
+ > GetDevicePropertiesCallback;
// A callback to handle MountCompleted signal.
// The first argument is the error code.
// The second argument is the source path.
// The third argument is the mount type.
// The fourth argument is the mount path.
- typedef base::Callback<void(MountError, const std::string&, MountType,
- const std::string&)> MountCompletedHandler;
+ typedef base::Callback<void(MountError error_code,
+ const std::string& source_path,
+ MountType mount_type,
+ const std::string& mount_path)
+ > MountCompletedHandler;
// A callback to handle mount events.
// The first argument is the event type.
// The second argument is the device path.
- typedef base::Callback<void(MountEventType, const std::string&)
+ typedef base::Callback<void(MountEventType event_type,
+ const std::string& device_path)
> MountEventHandler;
virtual ~CrosDisksClient();
diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc
index 955493a..d7459e5 100644
--- a/chromeos/dbus/dbus_thread_manager.cc
+++ b/chromeos/dbus/dbus_thread_manager.cc
@@ -4,6 +4,8 @@
#include "chromeos/dbus/dbus_thread_manager.h"
+#include <map>
+
#include "base/chromeos/chromeos_version.h"
#include "base/command_line.h"
#include "base/threading/thread.h"
@@ -32,6 +34,7 @@
#include "chromeos/dbus/ibus/ibus_input_context_client.h"
#include "chromeos/dbus/image_burner_client.h"
#include "chromeos/dbus/introspectable_client.h"
+#include "chromeos/dbus/media_transfer_protocol_daemon_client.h"
#include "chromeos/dbus/modem_messaging_client.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/dbus/session_manager_client.h"
@@ -120,6 +123,10 @@ class DBusThreadManagerImpl : public DBusThreadManager {
// Create the introspectable object client.
introspectable_client_.reset(
IntrospectableClient::Create(client_type, system_bus_.get()));
+ // Create the media transfer protocol daemon client.
+ media_transfer_protocol_daemon_client_.reset(
+ MediaTransferProtocolDaemonClient::Create(client_type,
+ system_bus_.get()));
// Create the ModemMessaging client.
modem_messaging_client_.reset(
ModemMessagingClient::Create(client_type, system_bus_.get()));
@@ -296,6 +303,12 @@ class DBusThreadManagerImpl : public DBusThreadManager {
}
// DBusThreadManager override.
+ virtual MediaTransferProtocolDaemonClient*
+ GetMediaTransferProtocolDaemonClient() OVERRIDE {
+ return media_transfer_protocol_daemon_client_.get();
+ }
+
+ // DBusThreadManager override.
virtual ModemMessagingClient* GetModemMessagingClient() OVERRIDE {
return modem_messaging_client_.get();
}
@@ -343,7 +356,6 @@ class DBusThreadManagerImpl : public DBusThreadManager {
// DBusThreadManager override.
virtual IBusEngineService* GetIBusEngineService(
const dbus::ObjectPath& object_path) OVERRIDE {
-
const DBusClientImplementationType client_type =
base::chromeos::IsRunningOnChromeOS() ? REAL_DBUS_CLIENT_IMPLEMENTATION
: STUB_DBUS_CLIENT_IMPLEMENTATION;
@@ -389,6 +401,8 @@ class DBusThreadManagerImpl : public DBusThreadManager {
scoped_ptr<GsmSMSClient> gsm_sms_client_;
scoped_ptr<ImageBurnerClient> image_burner_client_;
scoped_ptr<IntrospectableClient> introspectable_client_;
+ scoped_ptr<MediaTransferProtocolDaemonClient>
+ media_transfer_protocol_daemon_client_;
scoped_ptr<ModemMessagingClient> modem_messaging_client_;
scoped_ptr<PowerManagerClient> power_manager_client_;
scoped_ptr<SessionManagerClient> session_manager_client_;
diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h
index 6a325e2..53c44cf 100644
--- a/chromeos/dbus/dbus_thread_manager.h
+++ b/chromeos/dbus/dbus_thread_manager.h
@@ -46,6 +46,7 @@ class IBusEngineFactoryService;
class IBusInputContextClient;
class ImageBurnerClient;
class IntrospectableClient;
+class MediaTransferProtocolDaemonClient;
class ModemMessagingClient;
class PowerManagerClient;
class SessionManagerClient;
@@ -199,6 +200,12 @@ class CHROMEOS_EXPORT DBusThreadManager {
// down.
virtual IntrospectableClient* GetIntrospectableClient() = 0;
+ // Returns the media transfer protocol client, owned by DBusThreadManager.
+ // Do not cache this pointer and use it after DBusThreadManager is shut
+ // down.
+ virtual MediaTransferProtocolDaemonClient*
+ GetMediaTransferProtocolDaemonClient() = 0;
+
// Returns the Modem Messaging client, owned by DBusThreadManager.
// Do not cache this pointer and use it after DBusThreadManager is shut
// down.
diff --git a/chromeos/dbus/media_transfer_protocol_daemon_client.cc b/chromeos/dbus/media_transfer_protocol_daemon_client.cc
new file mode 100644
index 0000000..2e4b9d8
--- /dev/null
+++ b/chromeos/dbus/media_transfer_protocol_daemon_client.cc
@@ -0,0 +1,572 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/media_transfer_protocol_daemon_client.h"
+
+#include <map>
+
+#include "base/bind.h"
+#include "base/stl_util.h"
+#include "base/stringprintf.h"
+#include "dbus/bus.h"
+#include "dbus/message.h"
+#include "dbus/object_path.h"
+#include "dbus/object_proxy.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+namespace chromeos {
+
+namespace {
+
+// Pops a string value when |reader| is not NULL.
+// Returns true when a value is popped, false otherwise.
+bool MaybePopString(dbus::MessageReader* reader, std::string* value) {
+ if (!reader)
+ return false;
+ return reader->PopString(value);
+}
+
+// Pops a uint16 value when |reader| is not NULL.
+// Returns true when a value is popped, false otherwise.
+bool MaybePopUint16(dbus::MessageReader* reader, uint16* value) {
+ if (!reader)
+ return false;
+ return reader->PopUint16(value);
+}
+
+// Pops a uint32 value when |reader| is not NULL.
+// Returns true when a value is popped, false otherwise.
+bool MaybePopUint32(dbus::MessageReader* reader, uint32* value) {
+ if (!reader)
+ return false;
+ return reader->PopUint32(value);
+}
+
+// Pops a uint64 value when |reader| is not NULL.
+// Returns true when a value is popped, false otherwise.
+bool MaybePopUint64(dbus::MessageReader* reader, uint64* value) {
+ if (!reader)
+ return false;
+ return reader->PopUint64(value);
+}
+
+// Pops a int64 value when |reader| is not NULL.
+// Returns true when a value is popped, false otherwise.
+bool MaybePopInt64(dbus::MessageReader* reader, int64* value) {
+ if (!reader)
+ return false;
+ return reader->PopInt64(value);
+}
+
+// The MediaTransferProtocolDaemonClient implementation.
+class MediaTransferProtocolDaemonClientImpl
+ : public MediaTransferProtocolDaemonClient {
+ public:
+ explicit MediaTransferProtocolDaemonClientImpl(dbus::Bus* bus)
+ : proxy_(bus->GetObjectProxy(
+ mtpd::kMtpdServiceName,
+ dbus::ObjectPath(mtpd::kMtpdServicePath))),
+ weak_ptr_factory_(this) {
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void EnumerateStorage(const EnumerateStorageCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kEnumerateStorage);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnEnumerateStorage,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void GetStorageInfo(const std::string& storage_name,
+ const GetStorageInfoCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kGetStorageInfo);
+ 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.
+ virtual void OpenStorage(const std::string& storage_name,
+ OpenStorageMode mode,
+ const OpenStorageCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kOpenStorage);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(storage_name);
+ DCHECK_EQ(OPEN_STORAGE_MODE_READ_ONLY, mode);
+ writer.AppendString(mtpd::kReadOnlyMode);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnOpenStorage,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void CloseStorage(const std::string& handle,
+ const CloseStorageCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kCloseStorage);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(handle);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnCloseStorage,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void ReadDirectoryByPath(
+ const std::string& handle,
+ const std::string& path,
+ const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface,
+ mtpd::kReadDirectoryByPath);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(handle);
+ writer.AppendString(path);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadDirectory,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void ReadDirectoryById(
+ const std::string& handle,
+ uint32 file_id,
+ const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface,
+ mtpd::kReadDirectoryById);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(handle);
+ writer.AppendUint32(file_id);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadDirectory,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void ReadFileByPath(const std::string& handle,
+ const std::string& path,
+ const ReadFileCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kReadFileByPath);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(handle);
+ writer.AppendString(path);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void ReadFileById(const std::string& handle,
+ uint32 file_id,
+ const ReadFileCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kReadFileById);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(handle);
+ writer.AppendUint32(file_id);
+ proxy_->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ error_callback));
+ }
+
+ // MediaTransferProtocolDaemonClient override.
+ virtual void SetUpConnections(
+ const MTPStorageEventHandler& handler) OVERRIDE {
+ static const SignalEventTuple kSignalEventTuples[] = {
+ { mtpd::kMTPStorageAttached, true },
+ { mtpd::kMTPStorageDetached, false },
+ };
+ const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples);
+
+ for (size_t i = 0; i < kNumSignalEventTuples; ++i) {
+ proxy_->ConnectToSignal(
+ mtpd::kMtpdInterface,
+ kSignalEventTuples[i].signal_name,
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnMTPStorageSignal,
+ weak_ptr_factory_.GetWeakPtr(),
+ handler,
+ kSignalEventTuples[i].is_attach),
+ base::Bind(&MediaTransferProtocolDaemonClientImpl::OnSignalConnected,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+ }
+
+ private:
+ // A struct to contain a pair of signal name and attachment event type.
+ // Used by SetUpConnections.
+ struct SignalEventTuple {
+ const char *signal_name;
+ bool is_attach;
+ };
+
+ // Handles the result of EnumerateStorage and calls |callback| or
+ // |error_callback|.
+ void OnEnumerateStorage(const EnumerateStorageCallback& callback,
+ const ErrorCallback& error_callback,
+ dbus::Response* response) {
+ if (!response) {
+ error_callback.Run();
+ return;
+ }
+ dbus::MessageReader reader(response);
+ std::vector<std::string> storage_names;
+ if (!reader.PopArrayOfStrings(&storage_names)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ error_callback.Run();
+ return;
+ }
+ callback.Run(storage_names);
+ }
+
+ // Handles the result of GetStorageInfo and calls |callback| or
+ // |error_callback|.
+ void OnGetStorageInfo(const std::string& storage_name,
+ const GetStorageInfoCallback& callback,
+ const ErrorCallback& error_callback,
+ dbus::Response* response) {
+ if (!response) {
+ error_callback.Run();
+ return;
+ }
+ StorageInfo storage_info(storage_name, response);
+ callback.Run(storage_info);
+ }
+
+ // Handles the result of OpenStorage and calls |callback| or |error_callback|.
+ void OnOpenStorage(const OpenStorageCallback& callback,
+ const ErrorCallback& error_callback,
+ dbus::Response* response) {
+ if (!response) {
+ error_callback.Run();
+ return;
+ }
+ dbus::MessageReader reader(response);
+ std::string handle;
+ if (!reader.PopString(&handle)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ error_callback.Run();
+ return;
+ }
+ callback.Run(handle);
+ }
+
+ // Handles the result of CloseStorage and calls |callback| or
+ // |error_callback|.
+ void OnCloseStorage(const CloseStorageCallback& callback,
+ const ErrorCallback& error_callback,
+ dbus::Response* response) {
+ if (!response) {
+ error_callback.Run();
+ return;
+ }
+ callback.Run();
+ }
+
+ // Handles the result of ReadDirectoryByPath/Id and calls |callback| or
+ // |error_callback|.
+ void OnReadDirectory(const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback,
+ dbus::Response* response) {
+ if (!response) {
+ error_callback.Run();
+ return;
+ }
+
+ std::vector<FileEntry> file_entries;
+ dbus::MessageReader response_reader(response);
+ dbus::MessageReader array_reader(response);
+ if (!response_reader.PopArray(&array_reader)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ error_callback.Run();
+ return;
+ }
+ while (array_reader.HasMoreData()) {
+ FileEntry entry(response);
+ file_entries.push_back(entry);
+ }
+ callback.Run(file_entries);
+ }
+
+ // Handles the result of ReadFileByPath/Id and calls |callback| or
+ // |error_callback|.
+ void OnReadFile(const ReadFileCallback& callback,
+ const ErrorCallback& error_callback,
+ dbus::Response* response) {
+ if (!response) {
+ error_callback.Run();
+ return;
+ }
+
+ uint8* data_bytes = NULL;
+ size_t data_length = 0;
+ dbus::MessageReader reader(response);
+ if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) {
+ error_callback.Run();
+ return;
+ }
+ std::string data(reinterpret_cast<const char*>(data_bytes), data_length);
+ callback.Run(data);
+ }
+
+ // Handles MTPStorageAttached/Dettached signals and calls |handler|.
+ void OnMTPStorageSignal(MTPStorageEventHandler handler,
+ bool is_attach,
+ dbus::Signal* signal) {
+ dbus::MessageReader reader(signal);
+ std::string storage_name;
+ if (!reader.PopString(&storage_name)) {
+ LOG(ERROR) << "Invalid signal: " << signal->ToString();
+ return;
+ }
+ DCHECK(!storage_name.empty());
+ handler.Run(is_attach, storage_name);
+ }
+
+
+ // Handles the result of signal connection setup.
+ void OnSignalConnected(const std::string& interface,
+ const std::string& signal,
+ bool successed) {
+ LOG_IF(ERROR, !successed) << "Connect to " << interface << " "
+ << signal << " failed.";
+ }
+
+ dbus::ObjectProxy* proxy_;
+ base::WeakPtrFactory<MediaTransferProtocolDaemonClientImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClientImpl);
+};
+
+// A stub implementaion of MediaTransferProtocolDaemonClient.
+class MediaTransferProtocolDaemonClientStubImpl
+ : public MediaTransferProtocolDaemonClient {
+ public:
+ MediaTransferProtocolDaemonClientStubImpl() {}
+ virtual ~MediaTransferProtocolDaemonClientStubImpl() {}
+
+ virtual void EnumerateStorage(
+ const EnumerateStorageCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void GetStorageInfo(
+ const std::string& storage_name,
+ const GetStorageInfoCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void OpenStorage(const std::string& storage_name,
+ OpenStorageMode mode,
+ const OpenStorageCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void CloseStorage(const std::string& handle,
+ const CloseStorageCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void ReadDirectoryByPath(
+ const std::string& handle,
+ const std::string& path,
+ const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void ReadDirectoryById(
+ const std::string& handle,
+ uint32 file_id,
+ const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void ReadFileByPath(const std::string& handle,
+ const std::string& path,
+ const ReadFileCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void ReadFileById(const std::string& handle,
+ uint32 file_id,
+ const ReadFileCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {}
+ virtual void SetUpConnections(
+ const MTPStorageEventHandler& handler) OVERRIDE {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClientStubImpl);
+};
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// StorageInfo
+
+StorageInfo::StorageInfo(const std::string& storage_name,
+ dbus::Response* response)
+ : vendor_id_(0),
+ product_id_(0),
+ device_flags_(0),
+ storage_name_(storage_name),
+ storage_type_(0),
+ filesystem_type_(0),
+ access_capability_(0),
+ max_capacity_(0),
+ free_space_in_bytes_(0),
+ free_space_in_objects_(0) {
+ InitializeFromResponse(response);
+}
+
+StorageInfo::~StorageInfo() {
+}
+
+// Initializes |this| from |response| given by the mtpd service.
+void StorageInfo::InitializeFromResponse(dbus::Response* response) {
+ dbus::MessageReader response_reader(response);
+ dbus::MessageReader array_reader(response);
+ if (!response_reader.PopArray(&array_reader)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ return;
+ }
+ // TODO(thestig): Rework this code using Protocol Buffers. crosbug.com/22626
+ typedef std::map<std::string, dbus::MessageReader*> PropertiesMap;
+ PropertiesMap properties;
+ STLValueDeleter<PropertiesMap> properties_value_deleter(&properties);
+ while (array_reader.HasMoreData()) {
+ dbus::MessageReader* value_reader = new dbus::MessageReader(response);
+ dbus::MessageReader dict_entry_reader(response);
+ std::string key;
+ if (!array_reader.PopDictEntry(&dict_entry_reader) ||
+ !dict_entry_reader.PopString(&key) ||
+ !dict_entry_reader.PopVariant(value_reader)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ return;
+ }
+ properties[key] = value_reader;
+ }
+ // TODO(thestig) Add enums for fields below as appropriate.
+ MaybePopString(properties[mtpd::kVendor], &vendor_);
+ MaybePopString(properties[mtpd::kProduct], &product_);
+ MaybePopString(properties[mtpd::kStorageDescription], &storage_description_);
+ MaybePopString(properties[mtpd::kVolumeIdentifier], &volume_identifier_);
+ MaybePopUint16(properties[mtpd::kVendorId], &vendor_id_);
+ MaybePopUint16(properties[mtpd::kProductId], &product_id_);
+ MaybePopUint16(properties[mtpd::kStorageType], &storage_type_);
+ MaybePopUint16(properties[mtpd::kFilesystemType], &filesystem_type_);
+ MaybePopUint16(properties[mtpd::kAccessCapability], &access_capability_);
+ MaybePopUint32(properties[mtpd::kDeviceFlags], &device_flags_);
+ MaybePopUint64(properties[mtpd::kMaxCapacity], &max_capacity_);
+ MaybePopUint64(properties[mtpd::kFreeSpaceInBytes], &free_space_in_bytes_);
+ MaybePopUint64(properties[mtpd::kFreeSpaceInObjects],
+ &free_space_in_objects_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// FileEntry
+
+FileEntry::FileEntry(dbus::Response* response)
+ : item_id_(0),
+ parent_id_(0),
+ file_size_(0),
+ file_type_(FILE_TYPE_UNKNOWN) {
+ InitializeFromResponse(response);
+}
+
+FileEntry::~FileEntry() {
+}
+
+// Initializes |this| from |response| given by the mtpd service.
+void FileEntry::InitializeFromResponse(dbus::Response* response) {
+ dbus::MessageReader response_reader(response);
+ dbus::MessageReader array_reader(response);
+ if (!response_reader.PopArray(&array_reader)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ return;
+ }
+ // TODO(thestig): Rework this code using Protocol Buffers. crosbug.com/22626
+ typedef std::map<std::string, dbus::MessageReader*> PropertiesMap;
+ PropertiesMap properties;
+ STLValueDeleter<PropertiesMap> properties_value_deleter(&properties);
+ while (array_reader.HasMoreData()) {
+ dbus::MessageReader* value_reader = new dbus::MessageReader(response);
+ dbus::MessageReader dict_entry_reader(response);
+ std::string key;
+ if (!array_reader.PopDictEntry(&dict_entry_reader) ||
+ !dict_entry_reader.PopString(&key) ||
+ !dict_entry_reader.PopVariant(value_reader)) {
+ LOG(ERROR) << "Invalid response: " << response->ToString();
+ return;
+ }
+ properties[key] = value_reader;
+ }
+
+ MaybePopString(properties[mtpd::kFileName], &file_name_);
+ MaybePopUint32(properties[mtpd::kItemId], &item_id_);
+ MaybePopUint32(properties[mtpd::kParentId], &parent_id_);
+ MaybePopUint64(properties[mtpd::kFileSize], &file_size_);
+
+ int64 modification_date = -1;
+ if (MaybePopInt64(properties[mtpd::kModificationDate], &modification_date))
+ modification_date_ = base::Time::FromTimeT(modification_date);
+
+ uint16 file_type = FILE_TYPE_OTHER;
+ if (MaybePopUint16(properties[mtpd::kFileType], &file_type)) {
+ switch (file_type) {
+ case FILE_TYPE_FOLDER:
+ case FILE_TYPE_JPEG:
+ case FILE_TYPE_JFIF:
+ case FILE_TYPE_TIFF:
+ case FILE_TYPE_BMP:
+ case FILE_TYPE_GIF:
+ case FILE_TYPE_PICT:
+ case FILE_TYPE_PNG:
+ case FILE_TYPE_WINDOWSIMAGEFORMAT:
+ case FILE_TYPE_JP2:
+ case FILE_TYPE_JPX:
+ case FILE_TYPE_UNKNOWN:
+ file_type_ = static_cast<FileType>(file_type);
+ default:
+ file_type_ = FILE_TYPE_OTHER;
+ break;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// MediaTransferProtocolDaemonClient
+
+MediaTransferProtocolDaemonClient::MediaTransferProtocolDaemonClient() {}
+
+MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {}
+
+// static
+MediaTransferProtocolDaemonClient*
+MediaTransferProtocolDaemonClient::Create(DBusClientImplementationType type,
+ dbus::Bus* bus) {
+ if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
+ return new MediaTransferProtocolDaemonClientImpl(bus);
+ DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
+ return new MediaTransferProtocolDaemonClientStubImpl();
+}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/media_transfer_protocol_daemon_client.h b/chromeos/dbus/media_transfer_protocol_daemon_client.h
new file mode 100644
index 0000000..510dda2
--- /dev/null
+++ b/chromeos/dbus/media_transfer_protocol_daemon_client.h
@@ -0,0 +1,283 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Client code to talk to the Media Transfer Protocol daemon. The MTP daemon is
+// responsible for communicating with PTP / MTP capable devices like cameras
+// and smartphones.
+
+#ifndef CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
+#define CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/time.h"
+#include "chromeos/chromeos_export.h"
+#include "chromeos/dbus/dbus_client_implementation_type.h"
+
+namespace dbus {
+class Bus;
+class Response;
+}
+
+namespace chromeos {
+
+// Mode to open a storage in.
+enum OpenStorageMode {
+ OPEN_STORAGE_MODE_READ_ONLY,
+};
+
+// Values match libmtp values unless noted below.
+// TODO(thestig) See if we can do better than this.
+enum FileType {
+ FILE_TYPE_FOLDER = 0,
+ FILE_TYPE_JPEG = 14,
+ FILE_TYPE_JFIF = 15,
+ FILE_TYPE_TIFF = 16,
+ FILE_TYPE_BMP = 17,
+ FILE_TYPE_GIF = 18,
+ FILE_TYPE_PICT = 19,
+ FILE_TYPE_PNG = 20,
+ FILE_TYPE_WINDOWSIMAGEFORMAT = 25,
+ FILE_TYPE_JP2 = 40,
+ FILE_TYPE_JPX = 41,
+ // Truly unknown file type.
+ FILE_TYPE_UNKNOWN = 44,
+ // There's more file types to map to, but right now they are not interesting.
+ // Just assign a dummy value for now.
+ FILE_TYPE_OTHER = 9999
+};
+
+// A class to represent information about a storage sent from mtpd.
+class StorageInfo {
+ public:
+ StorageInfo(const std::string& storage_name, dbus::Response* response);
+ ~StorageInfo();
+
+ // Storage name. (e.g. usb:1,5:65537)
+ const std::string& storage_name() const { return storage_name_; }
+
+ // Vendor. (e.g. Kodak)
+ const std::string& vendor() const { return vendor_; }
+
+ // Vendor ID. (e.g. 0x040a)
+ uint16 vendor_id() const { return vendor_id_; }
+
+ // Product. (e.g. DC4800)
+ const std::string& product() const { return product_; }
+
+ // Vendor ID. (e.g. 0x0160)
+ uint16 product_id() const { return product_id_; }
+
+ // Device flags as defined by libmtp.
+ uint32 device_flags() const { return device_flags_; }
+
+ // Storage type as defined in libmtp. (e.g. PTP_ST_FixedROM)
+ uint16 storage_type() const { return storage_type_; }
+
+ // File system type as defined in libmtp. (e.g. PTP_FST_DCF)
+ uint16 filesystem_type() const { return filesystem_type_; }
+
+ // Access capability as defined in libmtp. (e.g. PTP_AC_ReadWrite)
+ uint16 access_capability() const { return access_capability_; }
+
+ // Max capacity in bytes.
+ uint64 max_capacity() const { return max_capacity_; }
+
+ // Free space in byte.
+ uint64 free_space_in_bytes() const { return free_space_in_bytes_; }
+
+ // Free space in number of objects.
+ uint64 free_space_in_objects() const { return free_space_in_objects_; }
+
+ // Storage description. (e.g. internal memory)
+ const std::string& storage_description() const {
+ return storage_description_;
+ }
+
+ // Volume identifier. (e.g. the serial number, should be unique)
+ const std::string& volume_identifier() const { return volume_identifier_; }
+
+ private:
+ void InitializeFromResponse(dbus::Response* response);
+
+ // Device info. (A device can have multiple storages)
+ std::string vendor_;
+ uint16 vendor_id_;
+ std::string product_;
+ uint16 product_id_;
+ uint32 device_flags_;
+
+ // Storage info.
+ std::string storage_name_;
+ uint16 storage_type_;
+ uint16 filesystem_type_;
+ uint16 access_capability_;
+ uint64 max_capacity_;
+ uint64 free_space_in_bytes_;
+ uint64 free_space_in_objects_;
+ std::string storage_description_;
+ std::string volume_identifier_;
+};
+
+// A class to represent information about a file entry sent from mtpd.
+class FileEntry {
+ public:
+ explicit FileEntry(dbus::Response* response);
+ ~FileEntry();
+
+ // ID for the file.
+ uint32 item_id() const { return item_id_; }
+
+ // ID for the file's parent.
+ uint32 parent_id() const { return parent_id_; }
+
+ // Name of the file.
+ const std::string& file_name() const { return file_name_; }
+
+ // Size of the file.
+ uint64 file_size() const { return file_size_; }
+
+ // Modification time of the file.
+ base::Time modification_date() const { return modification_date_; }
+
+ // File type.
+ FileType file_type() const { return file_type_; }
+
+ private:
+ void InitializeFromResponse(dbus::Response* response);
+
+ // Storage info.
+ uint32 item_id_;
+ uint32 parent_id_;
+ std::string file_name_;
+ uint64 file_size_;
+ base::Time modification_date_;
+ FileType file_type_;
+};
+
+// A class to make the actual DBus calls for mtpd service.
+// This class only makes calls, result/error handling should be done
+// by callbacks.
+class CHROMEOS_EXPORT MediaTransferProtocolDaemonClient {
+ public:
+ // A callback to be called when DBus method call fails.
+ typedef base::Callback<void()> ErrorCallback;
+
+ // A callback to handle the result of EnumerateAutoMountableDevices.
+ // The argument is the enumerated storage names.
+ typedef base::Callback<void(const std::vector<std::string>& storage_names)
+ > EnumerateStorageCallback;
+
+ // A callback to handle the result of GetStorageInfo.
+ // The argument is the information about the specified storage.
+ typedef base::Callback<void(const StorageInfo& storage_info)
+ > GetStorageInfoCallback;
+
+ // A callback to handle the result of OpenStorage.
+ // The argument is the returned handle.
+ typedef base::Callback<void(const std::string& handle)> OpenStorageCallback;
+
+ // A callback to handle the result of CloseStorage.
+ typedef base::Callback<void()> CloseStorageCallback;
+
+ // A callback to handle the result of ReadDirectoryByPath/Id.
+ // The argument is a vector of file entries.
+ typedef base::Callback<void(const std::vector<FileEntry>& file_entries)
+ > ReadDirectoryCallback;
+
+ // A callback to handle the result of ReadFileByPath/Id.
+ // The argument is a string containing the file data.
+ // TODO(thestig) Consider using a file descriptor instead of the data.
+ typedef base::Callback<void(const std::string& data)> ReadFileCallback;
+
+ // A callback to handle storage attach/detach events.
+ // The first argument is true for attach, false for detach.
+ // The second argument is the storage name.
+ typedef base::Callback<void(bool is_attach,
+ const std::string& storage_name)
+ > MTPStorageEventHandler;
+
+ virtual ~MediaTransferProtocolDaemonClient();
+
+ // Calls EnumerateStorage method. |callback| is called after the
+ // method call succeeds, otherwise, |error_callback| is called.
+ virtual void EnumerateStorage(
+ const EnumerateStorageCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls GetStorageInfo method. |callback| is called after the method call
+ // succeeds, otherwise, |error_callback| is called.
+ virtual void GetStorageInfo(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|.
+ virtual void OpenStorage(const std::string& storage_name,
+ OpenStorageMode mode,
+ const OpenStorageCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls CloseStorage method. |callback| is called after the method call
+ // succeeds, otherwise, |error_callback| is called.
+ // |handle| comes from a OpenStorageCallback.
+ virtual void CloseStorage(const std::string& handle,
+ const CloseStorageCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls ReadDirectoryByPath method. |callback| is called after the method
+ // call succeeds, otherwise, |error_callback| is called.
+ virtual void ReadDirectoryByPath(const std::string& handle,
+ const std::string& path,
+ const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls ReadDirectoryById method. |callback| is called after the method
+ // call succeeds, otherwise, |error_callback| is called.
+ // |file_id| is a MTP-device specific id for a file.
+ virtual void ReadDirectoryById(const std::string& handle,
+ uint32 file_id,
+ const ReadDirectoryCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls ReadFileByPath method. |callback| is called after the method call
+ // succeeds, otherwise, |error_callback| is called.
+ virtual void ReadFileByPath(const std::string& handle,
+ const std::string& path,
+ const ReadFileCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Calls ReadFileById method. |callback| is called after the method call
+ // succeeds, otherwise, |error_callback| is called.
+ // |file_id| is a MTP-device specific id for a file.
+ virtual void ReadFileById(const std::string& handle,
+ uint32 file_id,
+ const ReadFileCallback& callback,
+ const ErrorCallback& error_callback) = 0;
+
+ // Registers given callback for events.
+ // |storage_event_handler| is called when a mtp storage attach or detach
+ // signal is received.
+ virtual void SetUpConnections(const MTPStorageEventHandler& handler) = 0;
+
+ // Factory function, creates a new instance and returns ownership.
+ // For normal usage, access the singleton via DBusThreadManager::Get().
+ static MediaTransferProtocolDaemonClient*
+ Create(DBusClientImplementationType type, dbus::Bus* bus);
+
+ protected:
+ // Create() should be used instead.
+ MediaTransferProtocolDaemonClient();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
diff --git a/chromeos/dbus/mock_dbus_thread_manager.cc b/chromeos/dbus/mock_dbus_thread_manager.cc
index d6d9402..c78be52 100644
--- a/chromeos/dbus/mock_dbus_thread_manager.cc
+++ b/chromeos/dbus/mock_dbus_thread_manager.cc
@@ -23,6 +23,7 @@
#include "chromeos/dbus/mock_gsm_sms_client.h"
#include "chromeos/dbus/mock_image_burner_client.h"
#include "chromeos/dbus/mock_introspectable_client.h"
+#include "chromeos/dbus/mock_media_transfer_protocol_daemon_client.h"
#include "chromeos/dbus/mock_modem_messaging_client.h"
#include "chromeos/dbus/mock_power_manager_client.h"
#include "chromeos/dbus/mock_session_manager_client.h"
@@ -57,6 +58,8 @@ MockDBusThreadManager::MockDBusThreadManager()
mock_gsm_sms_client_(new MockGsmSMSClient),
mock_image_burner_client_(new MockImageBurnerClient),
mock_introspectable_client_(new MockIntrospectableClient),
+ mock_media_transfer_protocol_daemon_client_(
+ new MockMediaTransferProtocolDaemonClient),
mock_modem_messaging_client_(new MockModemMessagingClient),
mock_power_manager_client_(new MockPowerManagerClient),
mock_session_manager_client_(new MockSessionManagerClient),
@@ -101,6 +104,8 @@ MockDBusThreadManager::MockDBusThreadManager()
.WillRepeatedly(Return(mock_image_burner_client()));
EXPECT_CALL(*this, GetIntrospectableClient())
.WillRepeatedly(Return(mock_introspectable_client()));
+ EXPECT_CALL(*this, GetMediaTransferProtocolDaemonClient())
+ .WillRepeatedly(Return(mock_media_transfer_protocol_daemon_client()));
EXPECT_CALL(*this, GetModemMessagingClient())
.WillRepeatedly(Return(mock_modem_messaging_client()));
EXPECT_CALL(*this, GetPowerManagerClient())
diff --git a/chromeos/dbus/mock_dbus_thread_manager.h b/chromeos/dbus/mock_dbus_thread_manager.h
index f3e976a..dfdac24 100644
--- a/chromeos/dbus/mock_dbus_thread_manager.h
+++ b/chromeos/dbus/mock_dbus_thread_manager.h
@@ -37,6 +37,7 @@ class MockFlimflamServiceClient;
class MockGsmSMSClient;
class MockImageBurnerClient;
class MockIntrospectableClient;
+class MockMediaTransferProtocolDaemonClient;
class MockModemMessagingClient;
class MockPowerManagerClient;
class MockSessionManagerClient;
@@ -74,6 +75,8 @@ class MockDBusThreadManager : public DBusThreadManager {
MOCK_METHOD0(GetGsmSMSClient, GsmSMSClient*(void));
MOCK_METHOD0(GetImageBurnerClient, ImageBurnerClient*(void));
MOCK_METHOD0(GetIntrospectableClient, IntrospectableClient*(void));
+ MOCK_METHOD0(GetMediaTransferProtocolDaemonClient,
+ MediaTransferProtocolDaemonClient*(void));
MOCK_METHOD0(GetModemMessagingClient, ModemMessagingClient*(void));
MOCK_METHOD0(GetPowerManagerClient, PowerManagerClient*(void));
MOCK_METHOD0(GetSessionManagerClient, SessionManagerClient*(void));
@@ -145,6 +148,10 @@ class MockDBusThreadManager : public DBusThreadManager {
MockIntrospectableClient* mock_introspectable_client() {
return mock_introspectable_client_.get();
}
+ MockMediaTransferProtocolDaemonClient*
+ mock_media_transfer_protocol_daemon_client() {
+ return mock_media_transfer_protocol_daemon_client_.get();
+ }
MockModemMessagingClient* mock_modem_messaging_client() {
return mock_modem_messaging_client_.get();
}
@@ -184,6 +191,8 @@ class MockDBusThreadManager : public DBusThreadManager {
scoped_ptr<MockGsmSMSClient> mock_gsm_sms_client_;
scoped_ptr<MockImageBurnerClient> mock_image_burner_client_;
scoped_ptr<MockIntrospectableClient> mock_introspectable_client_;
+ scoped_ptr<MockMediaTransferProtocolDaemonClient>
+ mock_media_transfer_protocol_daemon_client_;
scoped_ptr<MockModemMessagingClient> mock_modem_messaging_client_;
scoped_ptr<MockPowerManagerClient> mock_power_manager_client_;
scoped_ptr<MockSessionManagerClient> mock_session_manager_client_;
diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
index 46b6f41..625590c 100644
--- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
+++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
@@ -135,6 +135,12 @@ IntrospectableClient*
return NULL;
}
+MediaTransferProtocolDaemonClient*
+ MockDBusThreadManagerWithoutGMock::GetMediaTransferProtocolDaemonClient() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
ModemMessagingClient*
MockDBusThreadManagerWithoutGMock::GetModemMessagingClient() {
NOTIMPLEMENTED();
diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
index b6ab1d3..65df874 100644
--- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
+++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
@@ -52,6 +52,8 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager {
virtual GsmSMSClient* GetGsmSMSClient() OVERRIDE;
virtual ImageBurnerClient* GetImageBurnerClient() OVERRIDE;
virtual IntrospectableClient* GetIntrospectableClient() OVERRIDE;
+ virtual MediaTransferProtocolDaemonClient*
+ GetMediaTransferProtocolDaemonClient() OVERRIDE;
virtual ModemMessagingClient* GetModemMessagingClient() OVERRIDE;
virtual PowerManagerClient* GetPowerManagerClient() OVERRIDE;
virtual SessionManagerClient* GetSessionManagerClient() OVERRIDE;
diff --git a/chromeos/dbus/mock_media_transfer_protocol_daemon_client.cc b/chromeos/dbus/mock_media_transfer_protocol_daemon_client.cc
new file mode 100644
index 0000000..144d318
--- /dev/null
+++ b/chromeos/dbus/mock_media_transfer_protocol_daemon_client.cc
@@ -0,0 +1,13 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/mock_media_transfer_protocol_daemon_client.h"
+
+namespace chromeos {
+
+MockMediaTransferProtocolDaemonClient::MockMediaTransferProtocolDaemonClient() {} // NOLINT
+
+MockMediaTransferProtocolDaemonClient::~MockMediaTransferProtocolDaemonClient() {} // NOLINT
+
+} // namespace chromeos
diff --git a/chromeos/dbus/mock_media_transfer_protocol_daemon_client.h b/chromeos/dbus/mock_media_transfer_protocol_daemon_client.h
new file mode 100644
index 0000000..cdb8897
--- /dev/null
+++ b/chromeos/dbus/mock_media_transfer_protocol_daemon_client.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_DBUS_MOCK_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
+#define CHROMEOS_DBUS_MOCK_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_
+
+#include <string>
+
+#include "chromeos/dbus/media_transfer_protocol_daemon_client.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockMediaTransferProtocolDaemonClient
+ : public MediaTransferProtocolDaemonClient {
+ public:
+ MockMediaTransferProtocolDaemonClient();
+ virtual ~MockMediaTransferProtocolDaemonClient();
+
+ MOCK_METHOD2(EnumerateStorage, void(const EnumerateStorageCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD3(GetStorageInfo, void(const std::string&,
+ const GetStorageInfoCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD4(OpenStorage, void(const std::string&,
+ OpenStorageMode mode,
+ const OpenStorageCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD3(CloseStorage, void(const std::string&,
+ const CloseStorageCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD4(ReadDirectoryByPath, void(const std::string&,
+ const std::string&,
+ const ReadDirectoryCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD4(ReadDirectoryById, void(const std::string&,
+ uint32,
+ const ReadDirectoryCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD4(ReadFileByPath, void(const std::string&,
+ const std::string&,
+ const ReadFileCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD4(ReadFileById, void(const std::string&,
+ uint32,
+ const ReadFileCallback&,
+ const ErrorCallback&));
+ MOCK_METHOD1(SetUpConnections, void(const MTPStorageEventHandler&));
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_MOCK_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_