| Index: device/media_transfer_protocol/media_transfer_protocol_manager.cc
|
| ===================================================================
|
| --- device/media_transfer_protocol/media_transfer_protocol_manager.cc (revision 193280)
|
| +++ device/media_transfer_protocol/media_transfer_protocol_manager.cc (working copy)
|
| @@ -32,10 +32,17 @@
|
|
|
| MediaTransferProtocolManager* g_media_transfer_protocol_manager = NULL;
|
|
|
| +// static
|
| +void Shutdown() {
|
| + DCHECK(g_media_transfer_protocol_manager);
|
| + g_media_transfer_protocol_manager = NULL;
|
| + VLOG(1) << "MediaTransferProtocolManager Shutdown completed";
|
| +}
|
| +
|
| // The MediaTransferProtocolManager implementation.
|
| class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
|
| public:
|
| - MediaTransferProtocolManagerImpl(
|
| + explicit MediaTransferProtocolManagerImpl(
|
| scoped_refptr<base::MessageLoopProxy> loop_proxy)
|
| : weak_ptr_factory_(this) {
|
| dbus::Bus* bus = NULL;
|
| @@ -71,6 +78,7 @@
|
| }
|
|
|
| virtual ~MediaTransferProtocolManagerImpl() {
|
| + Shutdown();
|
| }
|
|
|
| // MediaTransferProtocolManager override.
|
| @@ -431,34 +439,93 @@
|
| DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl);
|
| };
|
|
|
| +// Dummy MediaTransferProtocolManager implementation for testing.
|
| +class MediaTransferProtocolManagerDummyImpl
|
| + : public MediaTransferProtocolManager {
|
| + public:
|
| + MediaTransferProtocolManagerDummyImpl() {}
|
| +
|
| + virtual ~MediaTransferProtocolManagerDummyImpl() {
|
| + Shutdown();
|
| + }
|
| +
|
| + // MediaTransferProtocolManager overrides.
|
| + virtual void AddObserver(Observer* observer) OVERRIDE {}
|
| + virtual void RemoveObserver(Observer* observer) OVERRIDE {}
|
| + virtual const std::vector<std::string> GetStorages() const OVERRIDE {
|
| + std::vector<std::string> storages;
|
| + return storages;
|
| + }
|
| + virtual const MtpStorageInfo* GetStorageInfo(
|
| + const std::string& storage_name) const OVERRIDE {
|
| + return NULL;
|
| + }
|
| + virtual void OpenStorage(const std::string& storage_name,
|
| + const std::string& mode,
|
| + const OpenStorageCallback& callback) OVERRIDE {
|
| + callback.Run("", true);
|
| + }
|
| + virtual void CloseStorage(const std::string& storage_handle,
|
| + const CloseStorageCallback& callback) OVERRIDE {
|
| + callback.Run(true);
|
| + }
|
| + virtual void ReadDirectoryByPath(
|
| + const std::string& storage_handle,
|
| + const std::string& path,
|
| + const ReadDirectoryCallback& callback) OVERRIDE {
|
| + callback.Run(std::vector<MtpFileEntry>(), true);
|
| + }
|
| + virtual void ReadDirectoryById(
|
| + const std::string& storage_handle,
|
| + uint32 file_id,
|
| + const ReadDirectoryCallback& callback) OVERRIDE {
|
| + callback.Run(std::vector<MtpFileEntry>(), true);
|
| + }
|
| + virtual void ReadFileChunkByPath(const std::string& storage_handle,
|
| + const std::string& path,
|
| + uint32 offset,
|
| + uint32 count,
|
| + const ReadFileCallback& callback) OVERRIDE {
|
| + callback.Run(std::string(), true);
|
| + }
|
| + virtual void ReadFileChunkById(const std::string& storage_handle,
|
| + uint32 file_id,
|
| + uint32 offset,
|
| + uint32 count,
|
| + const ReadFileCallback& callback) OVERRIDE {
|
| + callback.Run(std::string(), true);
|
| + }
|
| + virtual void GetFileInfoByPath(const std::string& storage_handle,
|
| + const std::string& path,
|
| + const GetFileInfoCallback& callback) OVERRIDE {
|
| + callback.Run(MtpFileEntry(), true);
|
| + }
|
| + virtual void GetFileInfoById(const std::string& storage_handle,
|
| + uint32 file_id,
|
| + const GetFileInfoCallback& callback) OVERRIDE {
|
| + callback.Run(MtpFileEntry(), true);
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerDummyImpl);
|
| +};
|
| +
|
| } // namespace
|
|
|
| // static
|
| -void MediaTransferProtocolManager::Initialize(
|
| - scoped_refptr<base::MessageLoopProxy> loop_proxy) {
|
| - if (g_media_transfer_protocol_manager) {
|
| - LOG(WARNING) << "MediaTransferProtocolManager was already initialized";
|
| - return;
|
| +MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize(
|
| + scoped_refptr<base::MessageLoopProxy> loop_proxy, bool is_dummy) {
|
| + DCHECK(!g_media_transfer_protocol_manager);
|
| +
|
| + if (is_dummy) {
|
| + g_media_transfer_protocol_manager =
|
| + new MediaTransferProtocolManagerDummyImpl();
|
| + } else {
|
| + g_media_transfer_protocol_manager =
|
| + new MediaTransferProtocolManagerImpl(loop_proxy);
|
| }
|
| - g_media_transfer_protocol_manager =
|
| - new MediaTransferProtocolManagerImpl(loop_proxy);
|
| 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;
|
| }
|
|
|
|
|