Commit bd9cc50d authored by thestig@chromium.org's avatar thestig@chromium.org

Storage Monitor: Make StorageMonitorLinux own the MediaTransferProtocolManager.

Review URL: https://chromiumcodereview.appspot.com/14016002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194994 0039d316-1c4b-4281-b951-d872f2087c98
parent cb22f2e4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h" #include "chrome/browser/media_galleries/linux/mtp_device_object_enumerator.h"
#include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h" #include "chrome/browser/media_galleries/linux/mtp_read_file_worker.h"
#include "chrome/browser/media_galleries/linux/snapshot_file_details.h" #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
#include "chrome/browser/storage_monitor/storage_monitor.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -25,10 +26,7 @@ void DoNothing(bool error) { ...@@ -25,10 +26,7 @@ void DoNothing(bool error) {
} }
device::MediaTransferProtocolManager* GetMediaTransferProtocolManager() { device::MediaTransferProtocolManager* GetMediaTransferProtocolManager() {
device::MediaTransferProtocolManager* mtp_device_mgr = return StorageMonitor::GetInstance()->media_transfer_protocol_manager();
device::MediaTransferProtocolManager::GetInstance();
DCHECK(mtp_device_mgr);
return mtp_device_mgr;
} }
} // namespace } // namespace
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/safe_numerics.h" #include "base/safe_numerics.h"
#include "chrome/browser/media_galleries/linux/snapshot_file_details.h" #include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
#include "chrome/browser/storage_monitor/storage_monitor.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -64,9 +65,9 @@ void MTPReadFileWorker::ReadDataChunkFromDeviceFile( ...@@ -64,9 +65,9 @@ void MTPReadFileWorker::ReadDataChunkFromDeviceFile(
// |snapshot_file_details| in the same_line. // |snapshot_file_details| in the same_line.
SnapshotFileDetails* snapshot_file_details_ptr = snapshot_file_details.get(); SnapshotFileDetails* snapshot_file_details_ptr = snapshot_file_details.get();
device::MediaTransferProtocolManager* mtp_device_mgr = device::MediaTransferProtocolManager* mtp_device_manager =
device::MediaTransferProtocolManager::GetInstance(); StorageMonitor::GetInstance()->media_transfer_protocol_manager();
mtp_device_mgr->ReadFileChunkByPath( mtp_device_manager->ReadFileChunkByPath(
device_handle_, device_handle_,
snapshot_file_details_ptr->device_file_path(), snapshot_file_details_ptr->device_file_path(),
snapshot_file_details_ptr->bytes_written(), snapshot_file_details_ptr->bytes_written(),
......
...@@ -24,6 +24,13 @@ static MediaTransferProtocolDeviceObserverLinux* g_mtp_device_observer = NULL; ...@@ -24,6 +24,13 @@ static MediaTransferProtocolDeviceObserverLinux* g_mtp_device_observer = NULL;
// Device root path constant. // Device root path constant.
const char kRootPath[] = "/"; const char kRootPath[] = "/";
device::MediaTransferProtocolManager* GetMediaTransferProtocolManager() {
StorageMonitor* monitor = StorageMonitor::GetInstance();
if (!monitor)
return NULL;
return monitor->media_transfer_protocol_manager();
}
// Constructs and returns the location of the device using the |storage_name|. // Constructs and returns the location of the device using the |storage_name|.
std::string GetDeviceLocationFromStorageName(const std::string& storage_name) { std::string GetDeviceLocationFromStorageName(const std::string& storage_name) {
// Construct a dummy device path using the storage name. This is only used // Construct a dummy device path using the storage name. This is only used
...@@ -101,10 +108,8 @@ void GetStorageInfo(const std::string& storage_name, ...@@ -101,10 +108,8 @@ void GetStorageInfo(const std::string& storage_name,
string16* label, string16* label,
std::string* location) { std::string* location) {
DCHECK(!storage_name.empty()); DCHECK(!storage_name.empty());
device::MediaTransferProtocolManager* mtp_manager =
device::MediaTransferProtocolManager::GetInstance();
const MtpStorageInfo* storage_info = const MtpStorageInfo* storage_info =
mtp_manager->GetStorageInfo(storage_name); GetMediaTransferProtocolManager()->GetStorageInfo(storage_name);
if (!storage_info) if (!storage_info)
return; return;
...@@ -128,10 +133,7 @@ MediaTransferProtocolDeviceObserverLinux(StorageMonitor::Receiver* receiver) ...@@ -128,10 +133,7 @@ MediaTransferProtocolDeviceObserverLinux(StorageMonitor::Receiver* receiver)
DCHECK(!g_mtp_device_observer); DCHECK(!g_mtp_device_observer);
g_mtp_device_observer = this; g_mtp_device_observer = this;
device::MediaTransferProtocolManager* mtp_manager = GetMediaTransferProtocolManager()->AddObserver(this);
device::MediaTransferProtocolManager::GetInstance();
DCHECK(mtp_manager);
mtp_manager->AddObserver(this);
EnumerateStorages(); EnumerateStorages();
} }
...@@ -152,7 +154,7 @@ MediaTransferProtocolDeviceObserverLinux:: ...@@ -152,7 +154,7 @@ MediaTransferProtocolDeviceObserverLinux::
g_mtp_device_observer = NULL; g_mtp_device_observer = NULL;
device::MediaTransferProtocolManager* mtp_manager = device::MediaTransferProtocolManager* mtp_manager =
device::MediaTransferProtocolManager::GetInstance(); GetMediaTransferProtocolManager();
if (mtp_manager) if (mtp_manager)
mtp_manager->RemoveObserver(this); mtp_manager->RemoveObserver(this);
} }
...@@ -219,9 +221,7 @@ void MediaTransferProtocolDeviceObserverLinux::StorageChanged( ...@@ -219,9 +221,7 @@ void MediaTransferProtocolDeviceObserverLinux::StorageChanged(
void MediaTransferProtocolDeviceObserverLinux::EnumerateStorages() { void MediaTransferProtocolDeviceObserverLinux::EnumerateStorages() {
typedef std::vector<std::string> StorageList; typedef std::vector<std::string> StorageList;
device::MediaTransferProtocolManager* mtp_manager = StorageList storages = GetMediaTransferProtocolManager()->GetStorages();
device::MediaTransferProtocolManager::GetInstance();
StorageList storages = mtp_manager->GetStorages();
for (StorageList::const_iterator storage_iter = storages.begin(); for (StorageList::const_iterator storage_iter = storages.begin();
storage_iter != storages.end(); ++storage_iter) { storage_iter != storages.end(); ++storage_iter) {
StorageChanged(true, *storage_iter); StorageChanged(true, *storage_iter);
......
...@@ -23,6 +23,10 @@ class MediaGalleriesPrivateEjectApiTest; ...@@ -23,6 +23,10 @@ class MediaGalleriesPrivateEjectApiTest;
class PlatformAppMediaGalleriesBrowserTest; class PlatformAppMediaGalleriesBrowserTest;
class SystemInfoStorageApiTest; class SystemInfoStorageApiTest;
namespace device {
class MediaTransferProtocolManager;
}
namespace chrome { namespace chrome {
class MediaFileSystemRegistryTest; class MediaFileSystemRegistryTest;
...@@ -80,6 +84,11 @@ class StorageMonitor { ...@@ -80,6 +84,11 @@ class StorageMonitor {
string16* storage_object_id) const = 0; string16* storage_object_id) const = 0;
#endif #endif
#if defined(OS_LINUX)
virtual device::MediaTransferProtocolManager*
media_transfer_protocol_manager() = 0;
#endif
// Returns information for attached removable storage. // Returns information for attached removable storage.
std::vector<StorageInfo> GetAttachedStorage() const; std::vector<StorageInfo> GetAttachedStorage() const;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/storage_monitor/media_storage_util.h" #include "chrome/browser/storage_monitor/media_storage_util.h"
#include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux.h" #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux.h"
#include "chrome/browser/storage_monitor/removable_device_constants.h" #include "chrome/browser/storage_monitor/removable_device_constants.h"
#include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_linux.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
...@@ -117,13 +118,15 @@ using chrome::StorageInfo; ...@@ -117,13 +118,15 @@ using chrome::StorageInfo;
StorageMonitorCros::StorageMonitorCros() StorageMonitorCros::StorageMonitorCros()
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
// TODO(thestig) Do not do this here. Do it in TestingBrowserProcess when
// BrowserProcess owns StorageMonitor.
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
SetMediaTransferProtocolManagerForTest(
new chrome::TestMediaTransferProtocolManagerLinux());
}
} }
StorageMonitorCros::~StorageMonitorCros() { StorageMonitorCros::~StorageMonitorCros() {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
device::MediaTransferProtocolManager::Shutdown();
}
disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
if (manager) { if (manager) {
manager->RemoveObserver(this); manager->RemoveObserver(this);
...@@ -135,13 +138,14 @@ void StorageMonitorCros::Init() { ...@@ -135,13 +138,14 @@ void StorageMonitorCros::Init() {
disks::DiskMountManager::GetInstance()->AddObserver(this); disks::DiskMountManager::GetInstance()->AddObserver(this);
CheckExistingMountPoints(); CheckExistingMountPoints();
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { if (!media_transfer_protocol_manager_) {
scoped_refptr<base::MessageLoopProxy> loop_proxy; scoped_refptr<base::MessageLoopProxy> loop_proxy;
device::MediaTransferProtocolManager::Initialize(loop_proxy); media_transfer_protocol_manager_.reset(
device::MediaTransferProtocolManager::Initialize(loop_proxy));
media_transfer_protocol_device_observer_.reset(
new chrome::MediaTransferProtocolDeviceObserverLinux(receiver()));
} }
media_transfer_protocol_device_observer_.reset(
new chrome::MediaTransferProtocolDeviceObserverLinux(receiver()));
} }
void StorageMonitorCros::CheckExistingMountPoints() { void StorageMonitorCros::CheckExistingMountPoints() {
...@@ -214,13 +218,17 @@ void StorageMonitorCros::OnFormatEvent( ...@@ -214,13 +218,17 @@ void StorageMonitorCros::OnFormatEvent(
const std::string& device_path) { const std::string& device_path) {
} }
void StorageMonitorCros::SetMediaTransferProtocolManagerForTest(
device::MediaTransferProtocolManager* test_manager) {
DCHECK(!media_transfer_protocol_manager_);
media_transfer_protocol_manager_.reset(test_manager);
}
bool StorageMonitorCros::GetStorageInfoForPath( bool StorageMonitorCros::GetStorageInfoForPath(
const base::FilePath& path, const base::FilePath& path,
StorageInfo* device_info) const { StorageInfo* device_info) const {
// TODO(thestig) |media_transfer_protocol_device_observer_| should always be if (media_transfer_protocol_device_observer_->GetStorageInfoForPath(
// valid.
if (media_transfer_protocol_device_observer_ &&
media_transfer_protocol_device_observer_->GetStorageInfoForPath(
path, device_info)) { path, device_info)) {
return true; return true;
} }
...@@ -279,6 +287,11 @@ void StorageMonitorCros::EjectDevice( ...@@ -279,6 +287,11 @@ void StorageMonitorCros::EjectDevice(
base::Bind(NotifyUnmountResult, callback)); base::Bind(NotifyUnmountResult, callback));
} }
device::MediaTransferProtocolManager*
StorageMonitorCros::media_transfer_protocol_manager() {
return media_transfer_protocol_manager_.get();
}
void StorageMonitorCros::AddMountedPath( void StorageMonitorCros::AddMountedPath(
const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -42,6 +42,9 @@ class StorageMonitorCros : public chrome::StorageMonitor, ...@@ -42,6 +42,9 @@ class StorageMonitorCros : public chrome::StorageMonitor,
void Init(); void Init();
protected: protected:
void SetMediaTransferProtocolManagerForTest(
device::MediaTransferProtocolManager* test_manager);
// disks::DiskMountManager::Observer implementation. // disks::DiskMountManager::Observer implementation.
virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event, virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event,
const disks::DiskMountManager::Disk* disk) OVERRIDE; const disks::DiskMountManager::Disk* disk) OVERRIDE;
...@@ -62,6 +65,8 @@ class StorageMonitorCros : public chrome::StorageMonitor, ...@@ -62,6 +65,8 @@ class StorageMonitorCros : public chrome::StorageMonitor,
virtual void EjectDevice( virtual void EjectDevice(
const std::string& device_id, const std::string& device_id,
base::Callback<void(EjectStatus)> callback) OVERRIDE; base::Callback<void(EjectStatus)> callback) OVERRIDE;
virtual device::MediaTransferProtocolManager*
media_transfer_protocol_manager() OVERRIDE;
private: private:
// Mapping of mount path to removable mass storage info. // Mapping of mount path to removable mass storage info.
...@@ -80,6 +85,8 @@ class StorageMonitorCros : public chrome::StorageMonitor, ...@@ -80,6 +85,8 @@ class StorageMonitorCros : public chrome::StorageMonitor,
// Mapping of relevant mount points and their corresponding mount devices. // Mapping of relevant mount points and their corresponding mount devices.
MountMap mount_map_; MountMap mount_map_;
scoped_ptr<device::MediaTransferProtocolManager>
media_transfer_protocol_manager_;
scoped_ptr<chrome::MediaTransferProtocolDeviceObserverLinux> scoped_ptr<chrome::MediaTransferProtocolDeviceObserverLinux>
media_transfer_protocol_device_observer_; media_transfer_protocol_device_observer_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
#include "chrome/browser/storage_monitor/removable_device_constants.h" #include "chrome/browser/storage_monitor/removable_device_constants.h"
#include "chrome/browser/storage_monitor/storage_info.h" #include "chrome/browser/storage_monitor/storage_info.h"
#include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_linux.h"
#include "chromeos/disks/mock_disk_mount_manager.h" #include "chromeos/disks/mock_disk_mount_manager.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -64,6 +65,12 @@ class TestStorageMonitorCros : public StorageMonitorCros { ...@@ -64,6 +65,12 @@ class TestStorageMonitorCros : public StorageMonitorCros {
virtual ~TestStorageMonitorCros() {} virtual ~TestStorageMonitorCros() {}
void Init() {
SetMediaTransferProtocolManagerForTest(
new chrome::TestMediaTransferProtocolManagerLinux());
StorageMonitorCros::Init();
}
virtual void OnMountEvent( virtual void OnMountEvent(
disks::DiskMountManager::MountEvent event, disks::DiskMountManager::MountEvent event,
MountError error_code, MountError error_code,
...@@ -171,6 +178,7 @@ void StorageMonitorCrosTest::SetUp() { ...@@ -171,6 +178,7 @@ void StorageMonitorCrosTest::SetUp() {
// Initialize the test subject. // Initialize the test subject.
monitor_.reset(new TestStorageMonitorCros()); monitor_.reset(new TestStorageMonitorCros());
monitor_->Init();
monitor_->AddObserver(mock_storage_observer_.get()); monitor_->AddObserver(mock_storage_observer_.get());
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/storage_monitor/media_storage_util.h" #include "chrome/browser/storage_monitor/media_storage_util.h"
#include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux.h" #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux.h"
#include "chrome/browser/storage_monitor/removable_device_constants.h" #include "chrome/browser/storage_monitor/removable_device_constants.h"
#include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_linux.h"
#include "chrome/browser/storage_monitor/udev_util_linux.h" #include "chrome/browser/storage_monitor/udev_util_linux.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "device/media_transfer_protocol/media_transfer_protocol_manager.h" #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
...@@ -232,12 +233,17 @@ StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path) ...@@ -232,12 +233,17 @@ StorageMonitorLinux::StorageMonitorLinux(const base::FilePath& path)
get_device_info_callback_(base::Bind(&GetDeviceInfo)), get_device_info_callback_(base::Bind(&GetDeviceInfo)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// TODO(thestig) Do not do this here. Do it in TestingBrowserProcess when
// BrowserProcess owns StorageMonitor.
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
SetMediaTransferProtocolManagerForTest(
new TestMediaTransferProtocolManagerLinux());
}
} }
StorageMonitorLinux::~StorageMonitorLinux() { StorageMonitorLinux::~StorageMonitorLinux() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
device::MediaTransferProtocolManager::Shutdown();
} }
void StorageMonitorLinux::Init() { void StorageMonitorLinux::Init() {
...@@ -251,15 +257,15 @@ void StorageMonitorLinux::Init() { ...@@ -251,15 +257,15 @@ void StorageMonitorLinux::Init() {
base::Bind(&StorageMonitorLinux::OnMtabWatcherCreated, base::Bind(&StorageMonitorLinux::OnMtabWatcherCreated,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { if (!media_transfer_protocol_manager_) {
scoped_refptr<base::MessageLoopProxy> loop_proxy; scoped_refptr<base::MessageLoopProxy> loop_proxy =
loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
content::BrowserThread::FILE); media_transfer_protocol_manager_.reset(
device::MediaTransferProtocolManager::Initialize(loop_proxy); device::MediaTransferProtocolManager::Initialize(loop_proxy));
media_transfer_protocol_device_observer_.reset(
new MediaTransferProtocolDeviceObserverLinux(receiver()));
} }
media_transfer_protocol_device_observer_.reset(
new MediaTransferProtocolDeviceObserverLinux(receiver()));
} }
bool StorageMonitorLinux::GetStorageInfoForPath( bool StorageMonitorLinux::GetStorageInfoForPath(
...@@ -290,11 +296,22 @@ bool StorageMonitorLinux::GetStorageInfoForPath( ...@@ -290,11 +296,22 @@ bool StorageMonitorLinux::GetStorageInfoForPath(
return true; return true;
} }
device::MediaTransferProtocolManager*
StorageMonitorLinux::media_transfer_protocol_manager() {
return media_transfer_protocol_manager_.get();
}
void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest( void StorageMonitorLinux::SetGetDeviceInfoCallbackForTest(
const GetDeviceInfoCallback& get_device_info_callback) { const GetDeviceInfoCallback& get_device_info_callback) {
get_device_info_callback_ = get_device_info_callback; get_device_info_callback_ = get_device_info_callback;
} }
void StorageMonitorLinux::SetMediaTransferProtocolManagerForTest(
device::MediaTransferProtocolManager* test_manager) {
DCHECK(!media_transfer_protocol_manager_);
media_transfer_protocol_manager_.reset(test_manager);
}
void StorageMonitorLinux::OnMtabWatcherCreated(MtabWatcherLinux* watcher) { void StorageMonitorLinux::OnMtabWatcherCreated(MtabWatcherLinux* watcher) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
mtab_watcher_.reset(watcher); mtab_watcher_.reset(watcher);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_path_watcher.h" #include "base/files/file_path_watcher.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/storage_monitor/mtab_watcher_linux.h" #include "chrome/browser/storage_monitor/mtab_watcher_linux.h"
#include "chrome/browser/storage_monitor/storage_monitor.h" #include "chrome/browser/storage_monitor/storage_monitor.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -34,19 +35,15 @@ class MediaTransferProtocolDeviceObserverLinux; ...@@ -34,19 +35,15 @@ class MediaTransferProtocolDeviceObserverLinux;
class StorageMonitorLinux : public StorageMonitor, class StorageMonitorLinux : public StorageMonitor,
public MtabWatcherLinux::Delegate { public MtabWatcherLinux::Delegate {
public: public:
// Should only be called by browser start up code. Use GetInstance() instead. // Should only be called by browser start up code.
explicit StorageMonitorLinux(const base::FilePath& path); // Use StorageMonitor::GetInstance() instead.
// |mtab_file_path| is the path to a mtab file to watch for mount points.
explicit StorageMonitorLinux(const base::FilePath& mtab_file_path);
virtual ~StorageMonitorLinux(); virtual ~StorageMonitorLinux();
// Must be called for StorageMonitorLinux to work. // Must be called for StorageMonitorLinux to work.
void Init(); void Init();
// Finds the device that contains |path| and populates |device_info|.
// Returns false if unable to find the device.
virtual bool GetStorageInfoForPath(
const base::FilePath& path,
StorageInfo* device_info) const OVERRIDE;
protected: protected:
// Gets device information given a |device_path| and |mount_point|. // Gets device information given a |device_path| and |mount_point|.
typedef base::Callback<scoped_ptr<StorageInfo>( typedef base::Callback<scoped_ptr<StorageInfo>(
...@@ -56,6 +53,9 @@ class StorageMonitorLinux : public StorageMonitor, ...@@ -56,6 +53,9 @@ class StorageMonitorLinux : public StorageMonitor,
void SetGetDeviceInfoCallbackForTest( void SetGetDeviceInfoCallbackForTest(
const GetDeviceInfoCallback& get_device_info_callback); const GetDeviceInfoCallback& get_device_info_callback);
void SetMediaTransferProtocolManagerForTest(
device::MediaTransferProtocolManager* test_manager);
// MtabWatcherLinux::Delegate implementation. // MtabWatcherLinux::Delegate implementation.
virtual void UpdateMtab( virtual void UpdateMtab(
const MtabWatcherLinux::MountPointDeviceMap& new_mtab) OVERRIDE; const MtabWatcherLinux::MountPointDeviceMap& new_mtab) OVERRIDE;
...@@ -89,6 +89,12 @@ class StorageMonitorLinux : public StorageMonitor, ...@@ -89,6 +89,12 @@ class StorageMonitorLinux : public StorageMonitor,
// any) we have notified system monitor about. // any) we have notified system monitor about.
typedef std::map<base::FilePath, ReferencedMountPoint> MountPriorityMap; typedef std::map<base::FilePath, ReferencedMountPoint> MountPriorityMap;
// StorageMonitor implementation.
virtual bool GetStorageInfoForPath(const base::FilePath& path,
StorageInfo* device_info) const OVERRIDE;
virtual device::MediaTransferProtocolManager*
media_transfer_protocol_manager() OVERRIDE;
// Called when the MtabWatcher has been created. // Called when the MtabWatcher has been created.
void OnMtabWatcherCreated(MtabWatcherLinux* watcher); void OnMtabWatcherCreated(MtabWatcherLinux* watcher);
...@@ -121,6 +127,8 @@ class StorageMonitorLinux : public StorageMonitor, ...@@ -121,6 +127,8 @@ class StorageMonitorLinux : public StorageMonitor,
// points. // points.
MountPriorityMap mount_priority_map_; MountPriorityMap mount_priority_map_;
scoped_ptr<device::MediaTransferProtocolManager>
media_transfer_protocol_manager_;
scoped_ptr<MediaTransferProtocolDeviceObserverLinux> scoped_ptr<MediaTransferProtocolDeviceObserverLinux>
media_transfer_protocol_device_observer_; media_transfer_protocol_device_observer_;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
#include "chrome/browser/storage_monitor/removable_device_constants.h" #include "chrome/browser/storage_monitor/removable_device_constants.h"
#include "chrome/browser/storage_monitor/storage_monitor.h" #include "chrome/browser/storage_monitor/storage_monitor.h"
#include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_linux.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -143,6 +144,8 @@ class TestStorageMonitorLinux : public StorageMonitorLinux { ...@@ -143,6 +144,8 @@ class TestStorageMonitorLinux : public StorageMonitorLinux {
TestStorageMonitorLinux(const base::FilePath& path, MessageLoop* message_loop) TestStorageMonitorLinux(const base::FilePath& path, MessageLoop* message_loop)
: StorageMonitorLinux(path), : StorageMonitorLinux(path),
message_loop_(message_loop) { message_loop_(message_loop) {
SetMediaTransferProtocolManagerForTest(
new TestMediaTransferProtocolManagerLinux());
SetGetDeviceInfoCallbackForTest(base::Bind(&GetDeviceInfo)); SetGetDeviceInfoCallbackForTest(base::Bind(&GetDeviceInfo));
} }
virtual ~TestStorageMonitorLinux() {} virtual ~TestStorageMonitorLinux() {}
...@@ -257,7 +260,7 @@ class StorageMonitorLinuxTest : public testing::Test { ...@@ -257,7 +260,7 @@ class StorageMonitorLinuxTest : public testing::Test {
return *mock_storage_observer_; return *mock_storage_observer_;
} }
StorageMonitorLinux* notifier() { StorageMonitor* notifier() {
return monitor_.get(); return monitor_.get();
} }
......
// Copyright (c) 2013 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/storage_monitor/test_media_transfer_protocol_manager_linux.h"
#include "device/media_transfer_protocol/mtp_file_entry.pb.h"
namespace chrome {
TestMediaTransferProtocolManagerLinux::
TestMediaTransferProtocolManagerLinux() {}
TestMediaTransferProtocolManagerLinux::
~TestMediaTransferProtocolManagerLinux() {}
void TestMediaTransferProtocolManagerLinux::AddObserver(Observer* observer) {}
void TestMediaTransferProtocolManagerLinux::RemoveObserver(
Observer* observer) {}
const std::vector<std::string>
TestMediaTransferProtocolManagerLinux::GetStorages() const {
return std::vector<std::string>();
}
const MtpStorageInfo* TestMediaTransferProtocolManagerLinux::GetStorageInfo(
const std::string& storage_name) const {
return NULL;
}
void TestMediaTransferProtocolManagerLinux::OpenStorage(
const std::string& storage_name,
const std::string& mode,
const OpenStorageCallback& callback) {
callback.Run("", true);
}
void TestMediaTransferProtocolManagerLinux::CloseStorage(
const std::string& storage_handle,
const CloseStorageCallback& callback) {
callback.Run(true);
}
void TestMediaTransferProtocolManagerLinux::ReadDirectoryByPath(
const std::string& storage_handle,
const std::string& path,
const ReadDirectoryCallback& callback) {
callback.Run(std::vector<MtpFileEntry>(), true);
}
void TestMediaTransferProtocolManagerLinux::ReadDirectoryById(
const std::string& storage_handle,
uint32 file_id,
const ReadDirectoryCallback& callback) {
callback.Run(std::vector<MtpFileEntry>(), true);
}
void TestMediaTransferProtocolManagerLinux::ReadFileChunkByPath(
const std::string& storage_handle,
const std::string& path,
uint32 offset,
uint32 count,
const ReadFileCallback& callback) {
callback.Run(std::string(), true);
}
void TestMediaTransferProtocolManagerLinux::ReadFileChunkById(
const std::string& storage_handle,
uint32 file_id,
uint32 offset,
uint32 count,
const ReadFileCallback& callback) {
callback.Run(std::string(), true);
}
void TestMediaTransferProtocolManagerLinux::GetFileInfoByPath(
const std::string& storage_handle,
const std::string& path,
const GetFileInfoCallback& callback) {
callback.Run(MtpFileEntry(), true);
}
void TestMediaTransferProtocolManagerLinux::GetFileInfoById(
const std::string& storage_handle,
uint32 file_id,
const GetFileInfoCallback& callback) {
callback.Run(MtpFileEntry(), true);
}
} // namespace chrome
// Copyright (c) 2013 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_STORAGE_MONITOR_TEST_MEDIA_TRANSFER_PROTOCOL_MANAGER_LINUX_H_
#define CHROME_BROWSER_STORAGE_MONITOR_TEST_MEDIA_TRANSFER_PROTOCOL_MANAGER_LINUX_H_
#include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
namespace chrome {
// A dummy MediaTransferProtocolManager implementation.
class TestMediaTransferProtocolManagerLinux
: public device::MediaTransferProtocolManager {
public:
TestMediaTransferProtocolManagerLinux();
virtual ~TestMediaTransferProtocolManagerLinux();
private:
// device::MediaTransferProtocolManager implementation.
virtual void AddObserver(Observer* observer) OVERRIDE;
virtual void RemoveObserver(Observer* observer) OVERRIDE;
virtual const std::vector<std::string> GetStorages() const OVERRIDE;
virtual const MtpStorageInfo* GetStorageInfo(
const std::string& storage_name) const OVERRIDE;
virtual void OpenStorage(const std::string& storage_name,
const std::string& mode,
const OpenStorageCallback& callback) OVERRIDE;
virtual void CloseStorage(const std::string& storage_handle,
const CloseStorageCallback& callback) OVERRIDE;
virtual void ReadDirectoryByPath(
const std::string& storage_handle,
const std::string& path,
const ReadDirectoryCallback& callback) OVERRIDE;
virtual void ReadDirectoryById(
const std::string& storage_handle,
uint32 file_id,
const ReadDirectoryCallback& callback) OVERRIDE;
virtual void ReadFileChunkByPath(const std::string& storage_handle,
const std::string& path,
uint32 offset,
uint32 count,
const ReadFileCallback& callback) OVERRIDE;
virtual void ReadFileChunkById(const std::string& storage_handle,
uint32 file_id,
uint32 offset,
uint32 count,
const ReadFileCallback& callback) OVERRIDE;
virtual void GetFileInfoByPath(const std::string& storage_handle,
const std::string& path,
const GetFileInfoCallback& callback) OVERRIDE;
virtual void GetFileInfoById(const std::string& storage_handle,
uint32 file_id,
const GetFileInfoCallback& callback) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(TestMediaTransferProtocolManagerLinux);
};
} // namespace chrome
#endif // CHROME_BROWSER_STORAGE_MONITOR_TEST_MEDIA_TRANSFER_PROTOCOL_MANAGER_LINUX_H_
...@@ -6,11 +6,21 @@ ...@@ -6,11 +6,21 @@
#include "chrome/browser/storage_monitor/media_storage_util.h" #include "chrome/browser/storage_monitor/media_storage_util.h"
#if defined(OS_LINUX)
#include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_linux.h"
#include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
#endif
namespace chrome { namespace chrome {
namespace test { namespace test {
TestStorageMonitor::TestStorageMonitor() TestStorageMonitor::TestStorageMonitor()
: StorageMonitor() {} : StorageMonitor() {
#if defined(OS_LINUX)
media_transfer_protocol_manager_.reset(
new TestMediaTransferProtocolManagerLinux());
#endif
}
TestStorageMonitor::~TestStorageMonitor() {} TestStorageMonitor::~TestStorageMonitor() {}
...@@ -45,6 +55,13 @@ bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId( ...@@ -45,6 +55,13 @@ bool TestStorageMonitor::GetMTPStorageInfoFromDeviceId(
} }
#endif #endif
#if defined(OS_LINUX)
device::MediaTransferProtocolManager*
TestStorageMonitor::media_transfer_protocol_manager() {
return media_transfer_protocol_manager_.get();
}
#endif
StorageMonitor::Receiver* TestStorageMonitor::receiver() const { StorageMonitor::Receiver* TestStorageMonitor::receiver() const {
return StorageMonitor::receiver(); return StorageMonitor::receiver();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_ #ifndef CHROME_BROWSER_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
#define CHROME_BROWSER_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_ #define CHROME_BROWSER_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
#include <string>
#include "chrome/browser/storage_monitor/storage_monitor.h" #include "chrome/browser/storage_monitor/storage_monitor.h"
namespace chrome { namespace chrome {
...@@ -30,6 +32,11 @@ class TestStorageMonitor : public chrome::StorageMonitor { ...@@ -30,6 +32,11 @@ class TestStorageMonitor : public chrome::StorageMonitor {
string16* storage_object_id) const OVERRIDE; string16* storage_object_id) const OVERRIDE;
#endif #endif
#if defined(OS_LINUX)
virtual device::MediaTransferProtocolManager*
media_transfer_protocol_manager() OVERRIDE;
#endif
virtual Receiver* receiver() const OVERRIDE; virtual Receiver* receiver() const OVERRIDE;
virtual void EjectDevice( virtual void EjectDevice(
...@@ -41,6 +48,11 @@ class TestStorageMonitor : public chrome::StorageMonitor { ...@@ -41,6 +48,11 @@ class TestStorageMonitor : public chrome::StorageMonitor {
private: private:
std::string ejected_device_; std::string ejected_device_;
#if defined(OS_LINUX)
scoped_ptr<device::MediaTransferProtocolManager>
media_transfer_protocol_manager_;
#endif
}; };
} // namespace test } // namespace test
......
...@@ -1827,6 +1827,7 @@ ...@@ -1827,6 +1827,7 @@
'browser/storage_monitor/portable_device_watcher_win.h', 'browser/storage_monitor/portable_device_watcher_win.h',
'browser/storage_monitor/removable_device_constants.cc', 'browser/storage_monitor/removable_device_constants.cc',
'browser/storage_monitor/removable_device_constants.h', 'browser/storage_monitor/removable_device_constants.h',
'browser/storage_monitor/removable_storage_observer.h',
'browser/storage_monitor/storage_info.cc', 'browser/storage_monitor/storage_info.cc',
'browser/storage_monitor/storage_info.h', 'browser/storage_monitor/storage_info.h',
'browser/storage_monitor/storage_monitor_chromeos.cc', 'browser/storage_monitor/storage_monitor_chromeos.cc',
...@@ -1837,9 +1838,11 @@ ...@@ -1837,9 +1838,11 @@
'browser/storage_monitor/storage_monitor_mac.mm', 'browser/storage_monitor/storage_monitor_mac.mm',
'browser/storage_monitor/storage_monitor_win.cc', 'browser/storage_monitor/storage_monitor_win.cc',
'browser/storage_monitor/storage_monitor_win.h', 'browser/storage_monitor/storage_monitor_win.h',
'browser/storage_monitor/removable_storage_observer.h',
'browser/storage_monitor/storage_monitor.cc', 'browser/storage_monitor/storage_monitor.cc',
'browser/storage_monitor/storage_monitor.h', 'browser/storage_monitor/storage_monitor.h',
# TODO(thestig) Refactor StorageMonitor so these are test-only.
'browser/storage_monitor/test_media_transfer_protocol_manager_linux.cc',
'browser/storage_monitor/test_media_transfer_protocol_manager_linux.h',
'browser/storage_monitor/transient_device_ids.cc', 'browser/storage_monitor/transient_device_ids.cc',
'browser/storage_monitor/transient_device_ids.h', 'browser/storage_monitor/transient_device_ids.h',
'browser/storage_monitor/udev_util_linux.cc', 'browser/storage_monitor/udev_util_linux.cc',
......
...@@ -35,7 +35,7 @@ MediaTransferProtocolManager* g_media_transfer_protocol_manager = NULL; ...@@ -35,7 +35,7 @@ MediaTransferProtocolManager* g_media_transfer_protocol_manager = NULL;
// The MediaTransferProtocolManager implementation. // The MediaTransferProtocolManager implementation.
class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
public: public:
MediaTransferProtocolManagerImpl( explicit MediaTransferProtocolManagerImpl(
scoped_refptr<base::MessageLoopProxy> loop_proxy) scoped_refptr<base::MessageLoopProxy> loop_proxy)
: weak_ptr_factory_(this) { : weak_ptr_factory_(this) {
dbus::Bus* bus = NULL; dbus::Bus* bus = NULL;
...@@ -71,6 +71,9 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -71,6 +71,9 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
} }
virtual ~MediaTransferProtocolManagerImpl() { virtual ~MediaTransferProtocolManagerImpl() {
DCHECK(g_media_transfer_protocol_manager);
g_media_transfer_protocol_manager = NULL;
VLOG(1) << "MediaTransferProtocolManager Shutdown completed";
} }
// MediaTransferProtocolManager override. // MediaTransferProtocolManager override.
...@@ -434,31 +437,14 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager { ...@@ -434,31 +437,14 @@ class MediaTransferProtocolManagerImpl : public MediaTransferProtocolManager {
} // namespace } // namespace
// static // static
void MediaTransferProtocolManager::Initialize( MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize(
scoped_refptr<base::MessageLoopProxy> loop_proxy) { scoped_refptr<base::MessageLoopProxy> loop_proxy) {
if (g_media_transfer_protocol_manager) { DCHECK(!g_media_transfer_protocol_manager);
LOG(WARNING) << "MediaTransferProtocolManager was already initialized";
return;
}
g_media_transfer_protocol_manager = g_media_transfer_protocol_manager =
new MediaTransferProtocolManagerImpl(loop_proxy); new MediaTransferProtocolManagerImpl(loop_proxy);
VLOG(1) << "MediaTransferProtocolManager initialized"; 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; return g_media_transfer_protocol_manager;
} }
......
...@@ -132,19 +132,13 @@ class MediaTransferProtocolManager { ...@@ -132,19 +132,13 @@ class MediaTransferProtocolManager {
uint32 file_id, uint32 file_id,
const GetFileInfoCallback& callback) = 0; const GetFileInfoCallback& callback) = 0;
// Creates the global MediaTransferProtocolManager instance. // Creates and returns the global MediaTransferProtocolManager instance.
// On Linux, |loop_proxy| specifies the message loop proxy to process // On Linux, |loop_proxy| specifies the message loop proxy to process
// asynchronous operations. // asynchronous operations.
// On ChromeOS, |loop_proxy| is set to NULL because ChromeOS already has a // On ChromeOS, |loop_proxy| is set to NULL because ChromeOS already has a
// dedicated message loop proxy. // dedicated message loop proxy.
static void Initialize(scoped_refptr<base::MessageLoopProxy> loop_proxy); static MediaTransferProtocolManager* Initialize(
scoped_refptr<base::MessageLoopProxy> loop_proxy);
// 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 device } // namespace device
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment