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

Unified Diff: device/media_transfer_protocol/media_transfer_protocol_manager.cc

Issue 14016002: Storage Monitor: Make StorageMonitorLinux own the MediaTransferProtocolManager. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Rebase to ToT, still need to fix CrOS Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/media_transfer_protocol/media_transfer_protocol_manager.cc
===================================================================
--- device/media_transfer_protocol/media_transfer_protocol_manager.cc (revision 193326)
+++ 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
Greg Billock 2013/04/10 18:27:25 If we have this, can we stick it in a test-util so
Lei Zhang 2013/04/11 06:54:04 Done.
+ : 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;
}

Powered by Google App Engine
This is Rietveld 408576698