From 4b6de89b8a0fedf9e6a379f317f19a04c84967ce Mon Sep 17 00:00:00 2001 From: "kmadhusu@chromium.org" Date: Fri, 4 Jan 2013 18:06:06 +0000 Subject: Try 2 [Media Gallery] Move chrome/browser/media_transfer_protocol code to src/device. BUG=156929 TEST=none Original CL: https://chromiumcodereview.appspot.com/11744014 Review URL: https://chromiumcodereview.appspot.com/11744030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175150 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/DEPS | 1 + chrome/browser/chrome_browser_main_linux.cc | 6 +- .../linux/mtp_device_delegate_impl_linux.cc | 2 +- .../linux/mtp_device_object_enumerator.h | 2 +- .../linux/mtp_device_operations_utils.cc | 8 +- .../linux/mtp_device_operations_utils.h | 8 +- .../linux/mtp_get_file_info_worker.cc | 2 +- .../media_gallery/linux/mtp_get_file_info_worker.h | 2 +- .../media_gallery/linux/mtp_open_storage_worker.cc | 2 +- .../linux/mtp_read_directory_worker.cc | 2 +- .../linux/mtp_read_directory_worker.h | 2 +- .../media_gallery/linux/mtp_read_file_worker.cc | 4 +- .../linux/mtp_recursive_device_object_enumerator.h | 2 +- chrome/browser/media_transfer_protocol/DEPS | 4 - chrome/browser/media_transfer_protocol/OWNERS | 2 - .../media_transfer_protocol_daemon_client.cc | 489 --------------------- .../media_transfer_protocol_daemon_client.h | 180 -------- .../media_transfer_protocol_manager.cc | 453 ------------------- .../media_transfer_protocol_manager.h | 143 ------ ...edia_transfer_protocol_device_observer_linux.cc | 22 +- ...media_transfer_protocol_device_observer_linux.h | 6 +- chrome/chrome_browser.gypi | 44 +- chrome/common/DEPS | 1 + 23 files changed, 41 insertions(+), 1346 deletions(-) delete mode 100644 chrome/browser/media_transfer_protocol/DEPS delete mode 100644 chrome/browser/media_transfer_protocol/OWNERS delete mode 100644 chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.cc delete mode 100644 chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h delete mode 100644 chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.cc delete mode 100644 chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h (limited to 'chrome') diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 219cd51..6b17612 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -7,6 +7,7 @@ include_rules = [ "+content/components", "+content/public/browser", "+device/bluetooth", + "+device/media_transfer_protocol", "+extensions/common", "+google/cacheinvalidation", # Sync invalidation API protobuf files. "+google_apis", diff --git a/chrome/browser/chrome_browser_main_linux.cc b/chrome/browser/chrome_browser_main_linux.cc index db40bec..2bf9e3a 100644 --- a/chrome/browser/chrome_browser_main_linux.cc +++ b/chrome/browser/chrome_browser_main_linux.cc @@ -4,8 +4,8 @@ #include "chrome/browser/chrome_browser_main_linux.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" #if !defined(OS_CHROMEOS) #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" @@ -82,7 +82,7 @@ ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() { if (did_pre_profile_init_) - chrome::MediaTransferProtocolManager::Shutdown(); + device::MediaTransferProtocolManager::Shutdown(); } void ChromeBrowserMainPartsLinux::PreProfileInit() { @@ -106,7 +106,7 @@ void ChromeBrowserMainPartsLinux::PreProfileInit() { removable_device_notifications_linux_->Init(); #endif - chrome::MediaTransferProtocolManager::Initialize(); + device::MediaTransferProtocolManager::Initialize(); did_pre_profile_init_ = true; diff --git a/chrome/browser/media_gallery/linux/mtp_device_delegate_impl_linux.cc b/chrome/browser/media_gallery/linux/mtp_device_delegate_impl_linux.cc index 38b6dff..6a5e2c1 100644 --- a/chrome/browser/media_gallery/linux/mtp_device_delegate_impl_linux.cc +++ b/chrome/browser/media_gallery/linux/mtp_device_delegate_impl_linux.cc @@ -16,8 +16,8 @@ #include "chrome/browser/media_gallery/linux/mtp_read_directory_worker.h" #include "chrome/browser/media_gallery/linux/mtp_read_file_worker.h" #include "chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" #include "content/public/browser/browser_thread.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" using base::Bind; using base::PlatformFileError; diff --git a/chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h b/chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h index d7ea79a..340298ad 100644 --- a/chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h +++ b/chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h @@ -9,7 +9,7 @@ #include "base/file_path.h" #include "base/time.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" +#include "device/media_transfer_protocol/mtp_file_entry.pb.h" #include "webkit/fileapi/file_system_file_util.h" namespace chrome { diff --git a/chrome/browser/media_gallery/linux/mtp_device_operations_utils.cc b/chrome/browser/media_gallery/linux/mtp_device_operations_utils.cc index c92dda0..2a412bc 100644 --- a/chrome/browser/media_gallery/linux/mtp_device_operations_utils.cc +++ b/chrome/browser/media_gallery/linux/mtp_device_operations_utils.cc @@ -4,14 +4,14 @@ #include "chrome/browser/media_gallery/linux/mtp_device_operations_utils.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" namespace chrome { // Returns MediaTransferProtocolManager instance on success or NULL on failure. -MediaTransferProtocolManager* GetMediaTransferProtocolManager() { - MediaTransferProtocolManager* mtp_device_mgr = - MediaTransferProtocolManager::GetInstance(); +device::MediaTransferProtocolManager* GetMediaTransferProtocolManager() { + device::MediaTransferProtocolManager* mtp_device_mgr = + device::MediaTransferProtocolManager::GetInstance(); DCHECK(mtp_device_mgr); return mtp_device_mgr; } diff --git a/chrome/browser/media_gallery/linux/mtp_device_operations_utils.h b/chrome/browser/media_gallery/linux/mtp_device_operations_utils.h index 2ba22cc..f257dd1 100644 --- a/chrome/browser/media_gallery/linux/mtp_device_operations_utils.h +++ b/chrome/browser/media_gallery/linux/mtp_device_operations_utils.h @@ -14,9 +14,11 @@ #include "base/sequenced_task_runner_helpers.h" #include "base/threading/sequenced_worker_pool.h" -namespace chrome { - +namespace device { class MediaTransferProtocolManager; +} + +namespace chrome { // Helper struct to delete worker objects on |media_task_runner_| thread. template struct WorkerDeleter { @@ -30,7 +32,7 @@ template struct WorkerDeleter { }; // Returns MediaTransferProtocolManager instance on success or NULL on failure. -MediaTransferProtocolManager* GetMediaTransferProtocolManager(); +device::MediaTransferProtocolManager* GetMediaTransferProtocolManager(); } // namespace chrome diff --git a/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.cc b/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.cc index 7115595..0b1cd80 100644 --- a/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.cc +++ b/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.cc @@ -7,8 +7,8 @@ #include "base/bind.h" #include "base/sequenced_task_runner.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" #include "content/public/browser/browser_thread.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" namespace chrome { diff --git a/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.h b/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.h index 7bafca7..b6303e70 100644 --- a/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.h +++ b/chrome/browser/media_gallery/linux/mtp_get_file_info_worker.h @@ -10,7 +10,7 @@ #include "base/sequenced_task_runner_helpers.h" #include "base/synchronization/cancellation_flag.h" #include "chrome/browser/media_gallery/linux/mtp_device_operations_utils.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" +#include "device/media_transfer_protocol/mtp_file_entry.pb.h" namespace base { class SequencedTaskRunner; diff --git a/chrome/browser/media_gallery/linux/mtp_open_storage_worker.cc b/chrome/browser/media_gallery/linux/mtp_open_storage_worker.cc index 8dd0513..0d248b8 100644 --- a/chrome/browser/media_gallery/linux/mtp_open_storage_worker.cc +++ b/chrome/browser/media_gallery/linux/mtp_open_storage_worker.cc @@ -10,8 +10,8 @@ #include "base/logging.h" #include "base/sequenced_task_runner.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" #include "content/public/browser/browser_thread.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chrome { diff --git a/chrome/browser/media_gallery/linux/mtp_read_directory_worker.cc b/chrome/browser/media_gallery/linux/mtp_read_directory_worker.cc index 4e6e74b..44a3294 100644 --- a/chrome/browser/media_gallery/linux/mtp_read_directory_worker.cc +++ b/chrome/browser/media_gallery/linux/mtp_read_directory_worker.cc @@ -7,8 +7,8 @@ #include "base/bind.h" #include "base/sequenced_task_runner.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" #include "content/public/browser/browser_thread.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" namespace chrome { diff --git a/chrome/browser/media_gallery/linux/mtp_read_directory_worker.h b/chrome/browser/media_gallery/linux/mtp_read_directory_worker.h index 9ae84da..9b1f2ee 100644 --- a/chrome/browser/media_gallery/linux/mtp_read_directory_worker.h +++ b/chrome/browser/media_gallery/linux/mtp_read_directory_worker.h @@ -12,7 +12,7 @@ #include "base/sequenced_task_runner_helpers.h" #include "base/synchronization/cancellation_flag.h" #include "chrome/browser/media_gallery/linux/mtp_device_operations_utils.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" +#include "device/media_transfer_protocol/mtp_file_entry.pb.h" namespace base { class SequencedTaskRunner; diff --git a/chrome/browser/media_gallery/linux/mtp_read_file_worker.cc b/chrome/browser/media_gallery/linux/mtp_read_file_worker.cc index 7b1e9f0..bcefa33 100644 --- a/chrome/browser/media_gallery/linux/mtp_read_file_worker.cc +++ b/chrome/browser/media_gallery/linux/mtp_read_file_worker.cc @@ -12,9 +12,9 @@ #include "base/file_util.h" #include "base/sequenced_task_runner.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" #include "content/public/browser/browser_thread.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" +#include "device/media_transfer_protocol/mtp_file_entry.pb.h" #include "third_party/cros_system_api/dbus/service_constants.h" using content::BrowserThread; diff --git a/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h b/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h index 9701d4d..13b5910 100644 --- a/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h +++ b/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h @@ -11,7 +11,7 @@ #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/time.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" +#include "device/media_transfer_protocol/mtp_file_entry.pb.h" #include "webkit/fileapi/file_system_file_util.h" namespace base { diff --git a/chrome/browser/media_transfer_protocol/DEPS b/chrome/browser/media_transfer_protocol/DEPS deleted file mode 100644 index 4e249e0..0000000 --- a/chrome/browser/media_transfer_protocol/DEPS +++ /dev/null @@ -1,4 +0,0 @@ -include_rules = [ - # The media transfer protocol daemon uses D-Bus. - "+dbus", -] diff --git a/chrome/browser/media_transfer_protocol/OWNERS b/chrome/browser/media_transfer_protocol/OWNERS deleted file mode 100644 index 8cada85..0000000 --- a/chrome/browser/media_transfer_protocol/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -satorux@chromium.org -thestig@chromium.org diff --git a/chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.cc b/chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.cc deleted file mode 100644 index c88df8a..0000000 --- a/chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.cc +++ /dev/null @@ -1,489 +0,0 @@ -// 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 "chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h" - -#include "base/bind.h" -#include "base/memory/weak_ptr.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" -#include "chrome/browser/media_transfer_protocol/mtp_storage_info.pb.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 chrome { - -namespace { - -const char kInvalidResponseMsg[] = "Invalid Response: "; - -// 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 EnumerateStorages(const EnumerateStoragesCallback& callback, - const ErrorCallback& error_callback) OVERRIDE { - dbus::MethodCall method_call(mtpd::kMtpdInterface, - mtpd::kEnumerateStorages); - proxy_->CallMethod( - &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&MediaTransferProtocolDaemonClientImpl::OnEnumerateStorages, - 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, - const std::string& 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(mtpd::kReadOnlyMode, 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 ReadFileChunkByPath( - const std::string& handle, - const std::string& path, - uint32 offset, - uint32 bytes_to_read, - const ReadFileCallback& callback, - const ErrorCallback& error_callback) OVERRIDE { - dbus::MethodCall method_call(mtpd::kMtpdInterface, - mtpd::kReadFileChunkByPath); - dbus::MessageWriter writer(&method_call); - writer.AppendString(handle); - writer.AppendString(path); - writer.AppendUint32(offset); - writer.AppendUint32(bytes_to_read); - proxy_->CallMethod( - &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, - weak_ptr_factory_.GetWeakPtr(), - callback, - error_callback)); - } - - // MediaTransferProtocolDaemonClient override. - virtual void ReadFileChunkById(const std::string& handle, - uint32 file_id, - uint32 offset, - uint32 bytes_to_read, - const ReadFileCallback& callback, - const ErrorCallback& error_callback) OVERRIDE { - dbus::MethodCall method_call(mtpd::kMtpdInterface, - mtpd::kReadFileChunkById); - dbus::MessageWriter writer(&method_call); - writer.AppendString(handle); - writer.AppendUint32(file_id); - writer.AppendUint32(offset); - writer.AppendUint32(bytes_to_read); - proxy_->CallMethod( - &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&MediaTransferProtocolDaemonClientImpl::OnReadFile, - weak_ptr_factory_.GetWeakPtr(), - callback, - error_callback)); - } - - // MediaTransferProtocolDaemonClient override. - virtual void GetFileInfoByPath(const std::string& handle, - const std::string& path, - const GetFileInfoCallback& callback, - const ErrorCallback& error_callback) OVERRIDE { - dbus::MethodCall method_call(mtpd::kMtpdInterface, - mtpd::kGetFileInfoByPath); - dbus::MessageWriter writer(&method_call); - writer.AppendString(handle); - writer.AppendString(path); - proxy_->CallMethod( - &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetFileInfo, - weak_ptr_factory_.GetWeakPtr(), - callback, - error_callback)); - } - - // MediaTransferProtocolDaemonClient override. - virtual void GetFileInfoById(const std::string& handle, - uint32 file_id, - const GetFileInfoCallback& callback, - const ErrorCallback& error_callback) OVERRIDE { - dbus::MethodCall method_call(mtpd::kMtpdInterface, mtpd::kGetFileInfoById); - dbus::MessageWriter writer(&method_call); - writer.AppendString(handle); - writer.AppendUint32(file_id); - proxy_->CallMethod( - &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&MediaTransferProtocolDaemonClientImpl::OnGetFileInfo, - 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 EnumerateStorages and calls |callback| or - // |error_callback|. - void OnEnumerateStorages(const EnumerateStoragesCallback& callback, - const ErrorCallback& error_callback, - dbus::Response* response) { - if (!response) { - error_callback.Run(); - return; - } - dbus::MessageReader reader(response); - std::vector storage_names; - if (!reader.PopArrayOfStrings(&storage_names)) { - LOG(ERROR) << kInvalidResponseMsg << 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; - } - - dbus::MessageReader reader(response); - MtpStorageInfo protobuf; - if (!reader.PopArrayOfBytesAsProto(&protobuf)) { - LOG(ERROR) << kInvalidResponseMsg << response->ToString(); - error_callback.Run(); - return; - } - callback.Run(protobuf); - } - - // 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) << kInvalidResponseMsg << 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 file_entries; - dbus::MessageReader reader(response); - MtpFileEntries entries_protobuf; - if (!reader.PopArrayOfBytesAsProto(&entries_protobuf)) { - LOG(ERROR) << kInvalidResponseMsg << response->ToString(); - error_callback.Run(); - return; - } - - for (int i = 0; i < entries_protobuf.file_entries_size(); ++i) - file_entries.push_back(entries_protobuf.file_entries(i)); - callback.Run(file_entries); - } - - // Handles the result of ReadFileChunkByPath/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(data_bytes), data_length); - callback.Run(data); - } - - // Handles the result of GetFileInfoByPath/Id and calls |callback| or - // |error_callback|. - void OnGetFileInfo(const GetFileInfoCallback& callback, - const ErrorCallback& error_callback, - dbus::Response* response) { - if (!response) { - error_callback.Run(); - return; - } - - dbus::MessageReader reader(response); - MtpFileEntry protobuf; - if (!reader.PopArrayOfBytesAsProto(&protobuf)) { - LOG(ERROR) << kInvalidResponseMsg << response->ToString(); - error_callback.Run(); - return; - } - callback.Run(protobuf); - } - - // 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 succeeded) { - LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " - << signal << " failed."; - } - - dbus::ObjectProxy* proxy_; - - // Note: This should remain the last member so it'll be destroyed and - // invalidate its weak pointers before any other members are destroyed. - base::WeakPtrFactory weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClientImpl); -}; - -// A stub implementaion of MediaTransferProtocolDaemonClient. -class MediaTransferProtocolDaemonClientStubImpl - : public MediaTransferProtocolDaemonClient { - public: - MediaTransferProtocolDaemonClientStubImpl() {} - virtual ~MediaTransferProtocolDaemonClientStubImpl() {} - - virtual void EnumerateStorages( - const EnumerateStoragesCallback& 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, - const std::string& 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 ReadFileChunkByPath( - const std::string& handle, - const std::string& path, - uint32 offset, - uint32 length, - const ReadFileCallback& callback, - const ErrorCallback& error_callback) OVERRIDE {} - virtual void ReadFileChunkById( - const std::string& handle, - uint32 file_id, - uint32 offset, - uint32 length, - const ReadFileCallback& callback, - const ErrorCallback& error_callback) OVERRIDE {} - virtual void GetFileInfoByPath( - const std::string& handle, - const std::string& path, - const GetFileInfoCallback& callback, - const ErrorCallback& error_callback) OVERRIDE {} - virtual void GetFileInfoById(const std::string& handle, - uint32 file_id, - const GetFileInfoCallback& callback, - const ErrorCallback& error_callback) OVERRIDE {} - virtual void SetUpConnections( - const MTPStorageEventHandler& handler) OVERRIDE {} - - private: - DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClientStubImpl); -}; - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// MediaTransferProtocolDaemonClient - -MediaTransferProtocolDaemonClient::MediaTransferProtocolDaemonClient() {} - -MediaTransferProtocolDaemonClient::~MediaTransferProtocolDaemonClient() {} - -// static -MediaTransferProtocolDaemonClient* -MediaTransferProtocolDaemonClient::Create(dbus::Bus* bus, bool is_stub) { - if (is_stub) - return new MediaTransferProtocolDaemonClientStubImpl(); - return new MediaTransferProtocolDaemonClientImpl(bus); -} - -} // namespace chrome diff --git a/chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h b/chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h deleted file mode 100644 index 6b27fdd..0000000 --- a/chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h +++ /dev/null @@ -1,180 +0,0 @@ -// 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 CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ -#define CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ - -#include -#include - -#include "base/basictypes.h" -#include "base/callback.h" -#include "build/build_config.h" - -#if !defined(OS_LINUX) -#error "Only used on Linux and ChromeOS" -#endif - -class MtpFileEntry; -class MtpStorageInfo; - -namespace dbus { -class Bus; -} - -namespace chrome { - -// 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 MediaTransferProtocolDaemonClient { - public: - // A callback to be called when DBus method call fails. - typedef base::Callback ErrorCallback; - - // A callback to handle the result of EnumerateAutoMountableDevices. - // The argument is the enumerated storage names. - typedef base::Callback& storage_names) - > EnumerateStoragesCallback; - - // A callback to handle the result of GetStorageInfo. - // The argument is the information about the specified storage. - typedef base::Callback GetStorageInfoCallback; - - // A callback to handle the result of OpenStorage. - // The argument is the returned handle. - typedef base::Callback OpenStorageCallback; - - // A callback to handle the result of CloseStorage. - typedef base::Callback CloseStorageCallback; - - // A callback to handle the result of ReadDirectoryByPath/Id. - // The argument is a vector of file entries. - typedef base::Callback& file_entries) - > ReadDirectoryCallback; - - // A callback to handle the result of ReadFileChunkByPath/Id. - // The argument is a string containing the file data. - typedef base::Callback ReadFileCallback; - - // A callback to handle the result of GetFileInfoByPath/Id. - // The argument is a file entry. - typedef base::Callback GetFileInfoCallback; - - // 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 MTPStorageEventHandler; - - virtual ~MediaTransferProtocolDaemonClient(); - - // Calls EnumerateStorages method. |callback| is called after the - // method call succeeds, otherwise, |error_callback| is called. - virtual void EnumerateStorages( - const EnumerateStoragesCallback& 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, - const std::string& 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 ReadFileChunkByPath method. |callback| is called after the method - // call succeeds, otherwise, |error_callback| is called. - // |bytes_to_read| cannot exceed 1 MiB. - virtual void ReadFileChunkByPath(const std::string& handle, - const std::string& path, - uint32 offset, - uint32 bytes_to_read, - const ReadFileCallback& callback, - const ErrorCallback& error_callback) = 0; - - // TODO(thestig) Remove this in the near future if we don't see anyone using - // it. - // Calls ReadFilePathById 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. - // |bytes_to_read| cannot exceed 1 MiB. - virtual void ReadFileChunkById(const std::string& handle, - uint32 file_id, - uint32 offset, - uint32 bytes_to_read, - const ReadFileCallback& callback, - const ErrorCallback& error_callback) = 0; - - // Calls GetFileInfoByPath method. |callback| is called after the method - // call succeeds, otherwise, |error_callback| is called. - virtual void GetFileInfoByPath(const std::string& handle, - const std::string& path, - const GetFileInfoCallback& callback, - const ErrorCallback& error_callback) = 0; - - // Calls GetFileInfoById 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 GetFileInfoById(const std::string& handle, - uint32 file_id, - const GetFileInfoCallback& 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, set |is_stub| to false. - static MediaTransferProtocolDaemonClient* Create(dbus::Bus* bus, - bool is_stub); - - protected: - // Create() should be used instead. - MediaTransferProtocolDaemonClient(); - - private: - DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDaemonClient); -}; - -} // namespace chrome - -#endif // CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_DAEMON_CLIENT_H_ diff --git a/chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.cc b/chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.cc deleted file mode 100644 index dbb246f..0000000 --- a/chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.cc +++ /dev/null @@ -1,453 +0,0 @@ -// 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 "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" - -#include -#include -#include -#include - -#include "base/bind.h" -#include "base/command_line.h" -#include "base/memory/weak_ptr.h" -#include "base/observer_list.h" -#include "base/stl_util.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h" -#include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" -#include "chrome/browser/media_transfer_protocol/mtp_storage_info.pb.h" -#include "chrome/common/chrome_switches.h" -#include "content/public/browser/browser_thread.h" - -#if defined(OS_CHROMEOS) -#include "chromeos/dbus/dbus_thread_manager.h" -#else -#include "dbus/bus.h" -#endif - -using content::BrowserThread; - -namespace chrome { - -namespace { - -MediaTransferProtocolManager* g_media_transfer_protocol_manager = NULL; - -// The MediaTransferProtocolManager implementation. -class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { - public: - MediaTransferProtocolManagerImpl() : weak_ptr_factory_(this) { - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) - return; - - dbus::Bus* bus = NULL; -#if defined(OS_CHROMEOS) - chromeos::DBusThreadManager* dbus_thread_manager = - chromeos::DBusThreadManager::Get(); - bus = dbus_thread_manager->GetSystemBus(); - if (!bus) - return; -#else - dbus::Bus::Options options; - options.bus_type = dbus::Bus::SYSTEM; - options.connection_type = dbus::Bus::PRIVATE; - options.dbus_thread_message_loop_proxy = - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); - session_bus_ = new dbus::Bus(options); - bus = session_bus_.get(); -#endif - - DCHECK(bus); - mtp_client_.reset( - MediaTransferProtocolDaemonClient::Create(bus, false /* not stub */)); - - // Set up signals and start initializing |storage_info_map_|. - mtp_client_->SetUpConnections( - base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged, - weak_ptr_factory_.GetWeakPtr())); - mtp_client_->EnumerateStorages( - base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&base::DoNothing)); - } - - virtual ~MediaTransferProtocolManagerImpl() { - } - - // MediaTransferProtocolManager override. - virtual void AddObserver(Observer* observer) OVERRIDE { - observers_.AddObserver(observer); - } - - // MediaTransferProtocolManager override. - virtual void RemoveObserver(Observer* observer) OVERRIDE { - observers_.RemoveObserver(observer); - } - - // MediaTransferProtocolManager override. - const std::vector GetStorages() const OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::vector storages; - for (StorageInfoMap::const_iterator it = storage_info_map_.begin(); - it != storage_info_map_.end(); - ++it) { - storages.push_back(it->first); - } - return storages; - } - - // MediaTransferProtocolManager override. - virtual const MtpStorageInfo* GetStorageInfo( - const std::string& storage_name) const OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - StorageInfoMap::const_iterator it = storage_info_map_.find(storage_name); - if (it == storage_info_map_.end()) - return NULL; - return &it->second; - } - - // MediaTransferProtocolManager override. - virtual void OpenStorage(const std::string& storage_name, - const std::string& mode, - const OpenStorageCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(storage_info_map_, storage_name)) { - callback.Run("", true); - return; - } - open_storage_callbacks_.push(callback); - mtp_client_->OpenStorage( - storage_name, - mode, - base::Bind(&MediaTransferProtocolManagerImpl::OnOpenStorage, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnOpenStorageError, - weak_ptr_factory_.GetWeakPtr())); - } - - // MediaTransferProtocolManager override. - virtual void CloseStorage(const std::string& storage_handle, - const CloseStorageCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(true); - return; - } - close_storage_callbacks_.push(std::make_pair(callback, storage_handle)); - mtp_client_->CloseStorage( - storage_handle, - base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorage, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorageError, - weak_ptr_factory_.GetWeakPtr())); - } - - // MediaTransferProtocolManager override. - virtual void ReadDirectoryByPath( - const std::string& storage_handle, - const std::string& path, - const ReadDirectoryCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(std::vector(), true); - return; - } - read_directory_callbacks_.push(callback); - mtp_client_->ReadDirectoryByPath( - storage_handle, - path, - base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectory, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, - weak_ptr_factory_.GetWeakPtr())); - } - - // MediaTransferProtocolManager override. - virtual void ReadDirectoryById( - const std::string& storage_handle, - uint32 file_id, - const ReadDirectoryCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(std::vector(), true); - return; - } - read_directory_callbacks_.push(callback); - mtp_client_->ReadDirectoryById( - storage_handle, - file_id, - base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectory, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, - weak_ptr_factory_.GetWeakPtr())); - } - - // MediaTransferProtocolManager override. - virtual void ReadFileChunkByPath(const std::string& storage_handle, - const std::string& path, - uint32 offset, - uint32 count, - const ReadFileCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(std::string(), true); - return; - } - read_file_callbacks_.push(callback); - mtp_client_->ReadFileChunkByPath( - storage_handle, path, offset, count, - base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError, - weak_ptr_factory_.GetWeakPtr())); - } - - // MediaTransferProtocolManager override. - virtual void ReadFileChunkById(const std::string& storage_handle, - uint32 file_id, - uint32 offset, - uint32 count, - const ReadFileCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(std::string(), true); - return; - } - read_file_callbacks_.push(callback); - mtp_client_->ReadFileChunkById( - storage_handle, file_id, offset, count, - base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError, - weak_ptr_factory_.GetWeakPtr())); - } - - virtual void GetFileInfoByPath(const std::string& storage_handle, - const std::string& path, - const GetFileInfoCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(MtpFileEntry(), true); - return; - } - get_file_info_callbacks_.push(callback); - mtp_client_->GetFileInfoByPath( - storage_handle, - path, - base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError, - weak_ptr_factory_.GetWeakPtr())); - } - - virtual void GetFileInfoById(const std::string& storage_handle, - uint32 file_id, - const GetFileInfoCallback& callback) OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!ContainsKey(handles_, storage_handle)) { - callback.Run(MtpFileEntry(), true); - return; - } - get_file_info_callbacks_.push(callback); - mtp_client_->GetFileInfoById( - storage_handle, - file_id, - base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError, - weak_ptr_factory_.GetWeakPtr())); - } - - private: - // Map of storage names to storage info. - typedef std::map StorageInfoMap; - // Callback queues - DBus communication is in-order, thus callbacks are - // received in the same order as the requests. - typedef std::queue OpenStorageCallbackQueue; - // (callback, handle) - typedef std::queue - > CloseStorageCallbackQueue; - typedef std::queue ReadDirectoryCallbackQueue; - typedef std::queue ReadFileCallbackQueue; - typedef std::queue GetFileInfoCallbackQueue; - - void OnStorageChanged(bool is_attach, const std::string& storage_name) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (is_attach) { - mtp_client_->GetStorageInfo( - storage_name, - base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&base::DoNothing)); - return; - } - - // Detach case. - StorageInfoMap::iterator it = storage_info_map_.find(storage_name); - if (it == storage_info_map_.end()) { - // This might happen during initialization when |storage_info_map_| has - // not been fully populated yet? - return; - } - storage_info_map_.erase(it); - FOR_EACH_OBSERVER(Observer, - observers_, - StorageChanged(false /* detach */, storage_name)); - } - - void OnEnumerateStorages(const std::vector& storage_names) { - for (size_t i = 0; i < storage_names.size(); ++i) { - mtp_client_->GetStorageInfo( - storage_names[i], - base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&base::DoNothing)); - } - } - - void OnGetStorageInfo(const MtpStorageInfo& storage_info) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - const std::string& storage_name = storage_info.storage_name(); - if (ContainsKey(storage_info_map_, storage_name)) { - // This should not happen, since MediaTransferProtocolManagerImpl should - // only call EnumerateStorages() once, which populates |storage_info_map_| - // with the already-attached devices. - // After that, all incoming signals are either for new storage - // attachments, which should not be in |storage_info_map_|, or for - // storage detachements, which do not add to |storage_info_map_|. - NOTREACHED(); - return; - } - - // New storage. Add it and let the observers know. - storage_info_map_.insert(std::make_pair(storage_name, storage_info)); - FOR_EACH_OBSERVER(Observer, - observers_, - StorageChanged(true /* is attach */, storage_name)); - } - - void OnOpenStorage(const std::string& handle) { - if (!ContainsKey(handles_, handle)) { - handles_.insert(handle); - open_storage_callbacks_.front().Run(handle, false); - } else { - NOTREACHED(); - open_storage_callbacks_.front().Run("", true); - } - open_storage_callbacks_.pop(); - } - - void OnOpenStorageError() { - open_storage_callbacks_.front().Run("", true); - open_storage_callbacks_.pop(); - } - - void OnCloseStorage() { - const std::string& handle = close_storage_callbacks_.front().second; - if (ContainsKey(handles_, handle)) { - handles_.erase(handle); - close_storage_callbacks_.front().first.Run(false); - } else { - NOTREACHED(); - close_storage_callbacks_.front().first.Run(true); - } - close_storage_callbacks_.pop(); - } - - void OnCloseStorageError() { - close_storage_callbacks_.front().first.Run(true); - close_storage_callbacks_.pop(); - } - - void OnReadDirectory(const std::vector& file_entries) { - read_directory_callbacks_.front().Run(file_entries, false); - read_directory_callbacks_.pop(); - } - - void OnReadDirectoryError() { - read_directory_callbacks_.front().Run(std::vector(), true); - read_directory_callbacks_.pop(); - } - - void OnReadFile(const std::string& data) { - read_file_callbacks_.front().Run(data, false); - read_file_callbacks_.pop(); - } - - void OnReadFileError() { - read_file_callbacks_.front().Run(std::string(), true); - read_file_callbacks_.pop(); - } - - void OnGetFileInfo(const MtpFileEntry& entry) { - get_file_info_callbacks_.front().Run(entry, false); - get_file_info_callbacks_.pop(); - } - - void OnGetFileInfoError() { - get_file_info_callbacks_.front().Run(MtpFileEntry(), true); - get_file_info_callbacks_.pop(); - } - - // Mtpd DBus client. - scoped_ptr mtp_client_; - -#if !defined(OS_CHROMEOS) - // And a D-Bus session for talking to mtpd. - scoped_refptr session_bus_; -#endif - - // Device attachment / detachment observers. - ObserverList observers_; - - base::WeakPtrFactory weak_ptr_factory_; - - // Everything below is only accessed on the UI thread. - - // Map to keep track of attached storages by name. - StorageInfoMap storage_info_map_; - - // Set of open storage handles. - std::set handles_; - - // Queued callbacks. - OpenStorageCallbackQueue open_storage_callbacks_; - CloseStorageCallbackQueue close_storage_callbacks_; - ReadDirectoryCallbackQueue read_directory_callbacks_; - ReadFileCallbackQueue read_file_callbacks_; - GetFileInfoCallbackQueue get_file_info_callbacks_; - - DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl); -}; - -} // namespace - -// static -void MediaTransferProtocolManager::Initialize() { - if (g_media_transfer_protocol_manager) { - LOG(WARNING) << "MediaTransferProtocolManager was already initialized"; - return; - } - g_media_transfer_protocol_manager = new MediaTransferProtocolManagerImpl(); - VLOG(1) << "MediaTransferProtocolManager initialized"; -} - -// static -void MediaTransferProtocolManager::Shutdown() { - if (!g_media_transfer_protocol_manager) { - LOG(WARNING) << "MediaTransferProtocolManager::Shutdown() called with " - << "NULL manager"; - return; - } - delete g_media_transfer_protocol_manager; - g_media_transfer_protocol_manager = NULL; - VLOG(1) << "MediaTransferProtocolManager Shutdown completed"; -} - -// static -MediaTransferProtocolManager* MediaTransferProtocolManager::GetInstance() { - return g_media_transfer_protocol_manager; -} - -} // namespace chrome diff --git a/chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h b/chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h deleted file mode 100644 index 19247f4..0000000 --- a/chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h +++ /dev/null @@ -1,143 +0,0 @@ -// 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 CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ -#define CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ - -#include -#include - -#include "base/callback.h" -#include "build/build_config.h" - -#if !defined(OS_LINUX) -#error "Only used on Linux and ChromeOS" -#endif - -class MtpFileEntry; -class MtpStorageInfo; - -namespace chrome { - -// This class handles the interaction with mtpd. -// Other classes can add themselves as observers. -class MediaTransferProtocolManager { - public: - // 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. - typedef base::Callback OpenStorageCallback; - - // A callback to handle the result of CloseStorage. - // The argument is true if there was an error. - typedef base::Callback CloseStorageCallback; - - // A callback to handle the result of ReadDirectoryByPath/Id. - // The first argument is a vector of file entries. - // The second argument is true if there was an error. - typedef base::Callback& file_entries, - bool error)> ReadDirectoryCallback; - - // A callback to handle the result of ReadFileChunkByPath/Id. - // The first argument is a string containing the file data. - // The second argument is true if there was an error. - typedef base::Callback ReadFileCallback; - - // A callback to handle the result of GetFileInfoByPath/Id. - // The first argument is a file entry. - // The second argument is true if there was an error. - typedef base::Callback GetFileInfoCallback; - - // Implement this interface to be notified about MTP storage - // attachment / detachment events. - class Observer { - public: - virtual ~Observer() {} - - // A function called after a MTP storage has been attached / detached. - virtual void StorageChanged(bool is_attached, - const std::string& storage_name) = 0; - }; - - virtual ~MediaTransferProtocolManager() {} - - // Adds an observer. - virtual void AddObserver(Observer* observer) = 0; - - // Removes an observer. - virtual void RemoveObserver(Observer* observer) = 0; - - // Returns a vector of available MTP storages. - virtual const std::vector GetStorages() const = 0; - - // On success, returns the the metadata for |storage_name|. - // Otherwise returns NULL. - virtual const MtpStorageInfo* GetStorageInfo( - const std::string& storage_name) const = 0; - - // Opens |storage_name| in |mode| and runs |callback|. - virtual void OpenStorage(const std::string& storage_name, - const std::string& mode, - const OpenStorageCallback& callback) = 0; - - // Close |storage_handle| and runs |callback|. - virtual void CloseStorage(const std::string& storage_handle, - const CloseStorageCallback& callback) = 0; - - // Reads directory entries from |path| on |storage_handle| and runs - // |callback|. - virtual void ReadDirectoryByPath(const std::string& storage_handle, - const std::string& path, - const ReadDirectoryCallback& callback) = 0; - - // Reads directory entries from |file_id| on |storage_handle| and runs - // |callback|. - virtual void ReadDirectoryById(const std::string& storage_handle, - uint32 file_id, - const ReadDirectoryCallback& callback) = 0; - - // Reads file data from |path| on |storage_handle| and runs |callback|. - // Reads |count| bytes of data starting at |offset|. - virtual void ReadFileChunkByPath(const std::string& storage_handle, - const std::string& path, - uint32 offset, - uint32 count, - const ReadFileCallback& callback) = 0; - - // Reads file data from |file_id| on |storage_handle| and runs |callback|. - // Reads |count| bytes of data starting at |offset|. - virtual void ReadFileChunkById(const std::string& storage_handle, - uint32 file_id, - uint32 offset, - uint32 count, - const ReadFileCallback& callback) = 0; - - // Gets the file metadata for |path| on |storage_handle| and runs |callback|. - virtual void GetFileInfoByPath(const std::string& storage_handle, - const std::string& path, - const GetFileInfoCallback& callback) = 0; - - // Gets the file metadata for |file_id| on |storage_handle| and runs - // |callback|. - virtual void GetFileInfoById(const std::string& storage_handle, - uint32 file_id, - const GetFileInfoCallback& callback) = 0; - - // Creates the global MediaTransferProtocolManager instance. - static void Initialize(); - - // Destroys the global MediaTransferProtocolManager instance if it exists. - static void Shutdown(); - - // Returns a pointer to the global MediaTransferProtocolManager instance. - // Initialize() should already have been called. - static MediaTransferProtocolManager* GetInstance(); -}; - -} // namespace chrome - -#endif // CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_ diff --git a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.cc b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.cc index f98455d..2c29771 100644 --- a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.cc +++ b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.cc @@ -9,9 +9,9 @@ #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/media_transfer_protocol/mtp_storage_info.pb.h" #include "chrome/browser/system_monitor/media_storage_util.h" #include "chrome/browser/system_monitor/removable_device_constants.h" +#include "device/media_transfer_protocol/mtp_storage_info.pb.h" namespace chrome { @@ -101,8 +101,8 @@ void GetStorageInfo(const std::string& storage_name, string16* label, std::string* location) { DCHECK(!storage_name.empty()); - MediaTransferProtocolManager* mtp_manager = - MediaTransferProtocolManager::GetInstance(); + device::MediaTransferProtocolManager* mtp_manager = + device::MediaTransferProtocolManager::GetInstance(); const MtpStorageInfo* storage_info = mtp_manager->GetStorageInfo(storage_name); @@ -128,8 +128,8 @@ MediaTransferProtocolDeviceObserverLinux() DCHECK(!g_mtp_device_observer); g_mtp_device_observer = this; - MediaTransferProtocolManager* mtp_manager = - MediaTransferProtocolManager::GetInstance(); + device::MediaTransferProtocolManager* mtp_manager = + device::MediaTransferProtocolManager::GetInstance(); mtp_manager->AddObserver(this); EnumerateStorages(); } @@ -140,7 +140,7 @@ MediaTransferProtocolDeviceObserverLinux( GetStorageInfoFunc get_storage_info_func) : get_storage_info_func_(get_storage_info_func) { // In unit tests, we don't have a media transfer protocol manager. - DCHECK(!MediaTransferProtocolManager::GetInstance()); + DCHECK(!device::MediaTransferProtocolManager::GetInstance()); DCHECK(!g_mtp_device_observer); g_mtp_device_observer = this; } @@ -150,8 +150,8 @@ MediaTransferProtocolDeviceObserverLinux:: DCHECK_EQ(this, g_mtp_device_observer); g_mtp_device_observer = NULL; - MediaTransferProtocolManager* mtp_manager = - MediaTransferProtocolManager::GetInstance(); + device::MediaTransferProtocolManager* mtp_manager = + device::MediaTransferProtocolManager::GetInstance(); if (mtp_manager) mtp_manager->RemoveObserver(this); } @@ -187,7 +187,7 @@ bool MediaTransferProtocolDeviceObserverLinux::GetStorageInfoForPath( return true; } -// MediaTransferProtocolManager::Observer override. +// device::MediaTransferProtocolManager::Observer override. void MediaTransferProtocolDeviceObserverLinux::StorageChanged( bool is_attached, const std::string& storage_name) { @@ -229,8 +229,8 @@ void MediaTransferProtocolDeviceObserverLinux::StorageChanged( void MediaTransferProtocolDeviceObserverLinux::EnumerateStorages() { typedef std::vector StorageList; - MediaTransferProtocolManager* mtp_manager = - MediaTransferProtocolManager::GetInstance(); + device::MediaTransferProtocolManager* mtp_manager = + device::MediaTransferProtocolManager::GetInstance(); StorageList storages = mtp_manager->GetStorages(); for (StorageList::const_iterator storage_iter = storages.begin(); storage_iter != storages.end(); ++storage_iter) { diff --git a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.h b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.h index 3602ccc..a9df128 100644 --- a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.h +++ b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux.h @@ -10,7 +10,7 @@ #include "base/string16.h" #include "base/system_monitor/system_monitor.h" -#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h" +#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" class FilePath; @@ -26,7 +26,7 @@ typedef void (*GetStorageInfoFunc)(const std::string& storage_name, // Helper class to send MTP storage attachment and detachment events to // SystemMonitor. class MediaTransferProtocolDeviceObserverLinux - : public MediaTransferProtocolManager::Observer { + : public device::MediaTransferProtocolManager::Observer { public: // Should only be called by browser start up code. Use GetInstance() instead. MediaTransferProtocolDeviceObserverLinux(); @@ -45,7 +45,7 @@ class MediaTransferProtocolDeviceObserverLinux explicit MediaTransferProtocolDeviceObserverLinux( GetStorageInfoFunc get_storage_info_func); - // MediaTransferProtocolManager::Observer implementation. + // device::MediaTransferProtocolManager::Observer implementation. // Exposed for unit tests. virtual void StorageChanged(bool is_attached, const std::string& storage_name) OVERRIDE; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index fafd32c..c0cb66e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2458,15 +2458,10 @@ }], ['OS=="linux"', { 'dependencies': [ - 'mtp_file_entry_proto', - 'mtp_storage_info_proto', '../build/linux/system.gyp:udev', - ], - 'sources': [ - 'browser/media_transfer_protocol/media_transfer_protocol_daemon_client.cc', - 'browser/media_transfer_protocol/media_transfer_protocol_daemon_client.h', - 'browser/media_transfer_protocol/media_transfer_protocol_manager.cc', - 'browser/media_transfer_protocol/media_transfer_protocol_manager.h', + '../device/device.gyp:mtp_file_entry_proto', + '../device/device.gyp:mtp_storage_info_proto', + '../device/device.gyp:device_media_transfer_protocol', ], }], ['OS=="linux" and chromeos==0', { @@ -3124,38 +3119,5 @@ ], }, ], - ['OS=="linux"', { - 'targets': [ - { - # Protobuf compiler / generator for the MtpFileEntry and - # MtpFileEntries protocol buffers. - 'target_name': 'mtp_file_entry_proto', - 'type': 'static_library', - 'sources': [ - '../third_party/cros_system_api/dbus/mtp_file_entry.proto', - ], - 'variables': { - 'proto_in_dir': '../third_party/cros_system_api/dbus', - 'proto_out_dir': 'chrome/browser/media_transfer_protocol', - }, - 'includes': ['../build/protoc.gypi'], - }, - { - # Protobuf compiler / generator for the MtpStorageInfo protocol - # buffer. - 'target_name': 'mtp_storage_info_proto', - 'type': 'static_library', - 'sources': [ - '../third_party/cros_system_api/dbus/mtp_storage_info.proto', - ], - 'variables': { - 'proto_in_dir': '../third_party/cros_system_api/dbus', - 'proto_out_dir': 'chrome/browser/media_transfer_protocol', - }, - 'includes': ['../build/protoc.gypi'], - }, - ], - }, - ], ], } diff --git a/chrome/common/DEPS b/chrome/common/DEPS index c85a982..a1d6202 100644 --- a/chrome/common/DEPS +++ b/chrome/common/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+chrome/plugin", # For checking whether we're a plugin process. "+device/bluetooth", # For BluetoothDevicePermission + "+device/media_transfer_protocol", # For MediaTransferProtocolManager "+device/usb", # For UsbDevicePermission "+extensions/common", "+grit", # For generated headers -- cgit v1.1