Commit b9a1cd10 authored by vandebo@chromium.org's avatar vandebo@chromium.org

Move TransientDeviceId from MediFileSystemRegistry to RemovableStorageNotifications.

BUG=NONE


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182086 0039d316-1c4b-4281-b951-d872f2087c98
parent 945cdc83
......@@ -11,11 +11,9 @@
#include "base/strings/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/media_gallery/media_file_system_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/system_monitor/removable_storage_notifications.h"
#include "chrome/common/extensions/api/media_galleries_private.h"
......@@ -26,9 +24,10 @@ namespace extensions {
namespace {
std::string GetTransientIdForDeviceId(const std::string& device_id) {
chrome::MediaFileSystemRegistry* registry =
g_browser_process->media_file_system_registry();
return base::Uint64ToString(registry->GetTransientIdForDeviceId(device_id));
chrome::RemovableStorageNotifications* storage_notifications =
chrome::RemovableStorageNotifications::GetInstance();
return base::Uint64ToString(
storage_notifications->GetTransientIdForDeviceId(device_id));
}
} // namespace
......
......@@ -402,9 +402,9 @@ class ExtensionGalleriesHost
uint64 GetTransientIdForRemovableDeviceId(const std::string& device_id) {
if (!MediaStorageUtil::IsRemovableDevice(device_id))
return 0;
MediaFileSystemRegistry* registry =
file_system_context_->GetMediaFileSystemRegistry();
return registry->GetTransientIdForDeviceId(device_id);
RemovableStorageNotifications* storage_notifications =
RemovableStorageNotifications::GetInstance();
return storage_notifications->GetTransientIdForDeviceId(device_id);
}
// This code is deprecated and should be removed. See http://crbug.com/170138
......@@ -629,11 +629,6 @@ size_t MediaFileSystemRegistry::GetExtensionHostCountForTests() const {
return extension_hosts_map_.size();
}
uint64 MediaFileSystemRegistry::GetTransientIdForDeviceId(
const std::string& device_id) {
return transient_device_ids_.GetTransientIdForDeviceId(device_id);
}
/******************
* Private methods
******************/
......
......@@ -18,7 +18,6 @@
#include "base/memory/ref_counted.h"
#include "base/prefs/public/pref_change_registrar.h"
#include "chrome/browser/media_gallery/media_galleries_preferences.h"
#include "chrome/browser/media_gallery/transient_device_ids.h"
#include "chrome/browser/system_monitor/removable_storage_observer.h"
#include "webkit/fileapi/media/mtp_device_file_system_config.h"
......@@ -153,8 +152,6 @@ class MediaFileSystemRegistry : public RemovableStorageObserver {
scoped_ptr<MediaFileSystemContext> file_system_context_;
TransientDeviceIds transient_device_ids_;
DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistry);
};
......
......@@ -7,6 +7,7 @@
#include "base/stl_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/system_monitor/removable_storage_observer.h"
#include "chrome/browser/system_monitor/transient_device_ids.h"
namespace chrome {
......@@ -59,9 +60,40 @@ void RemovableStorageNotifications::ReceiverImpl::ProcessDetach(
notifications_->ProcessDetach(id);
}
RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() {
return g_removable_storage_notifications;
}
std::vector<RemovableStorageNotifications::StorageInfo>
RemovableStorageNotifications::GetAttachedStorage() const {
std::vector<StorageInfo> results;
base::AutoLock lock(storage_lock_);
for (RemovableStorageMap::const_iterator it = storage_map_.begin();
it != storage_map_.end();
++it) {
results.push_back(it->second);
}
return results;
}
void RemovableStorageNotifications::AddObserver(RemovableStorageObserver* obs) {
observer_list_->AddObserver(obs);
}
void RemovableStorageNotifications::RemoveObserver(
RemovableStorageObserver* obs) {
observer_list_->RemoveObserver(obs);
}
uint64 RemovableStorageNotifications::GetTransientIdForDeviceId(
const std::string& device_id) {
return transient_device_ids_->GetTransientIdForDeviceId(device_id);
}
RemovableStorageNotifications::RemovableStorageNotifications()
: observer_list_(
new ObserverListThreadSafe<RemovableStorageObserver>()) {
: observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()),
transient_device_ids_(new TransientDeviceIds) {
receiver_.reset(new ReceiverImpl(this));
DCHECK(!g_removable_storage_notifications);
......@@ -112,30 +144,4 @@ void RemovableStorageNotifications::ProcessDetach(const std::string& id) {
&RemovableStorageObserver::OnRemovableStorageDetached, info);
}
std::vector<RemovableStorageNotifications::StorageInfo>
RemovableStorageNotifications::GetAttachedStorage() const {
std::vector<StorageInfo> results;
base::AutoLock lock(storage_lock_);
for (RemovableStorageMap::const_iterator it = storage_map_.begin();
it != storage_map_.end();
++it) {
results.push_back(it->second);
}
return results;
}
void RemovableStorageNotifications::AddObserver(RemovableStorageObserver* obs) {
observer_list_->AddObserver(obs);
}
void RemovableStorageNotifications::RemoveObserver(
RemovableStorageObserver* obs) {
observer_list_->RemoveObserver(obs);
}
RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() {
return g_removable_storage_notifications;
}
} // namespace chrome
......@@ -18,6 +18,7 @@ namespace chrome {
class MediaFileSystemRegistryTest;
class RemovableStorageObserver;
class TransientDeviceIds;
// Base class for platform-specific instances watching for removable storage
// attachments/detachments.
......@@ -83,6 +84,8 @@ class RemovableStorageNotifications {
void AddObserver(RemovableStorageObserver* obs);
void RemoveObserver(RemovableStorageObserver* obs);
uint64 GetTransientIdForDeviceId(const std::string& device_id);
protected:
RemovableStorageNotifications();
virtual ~RemovableStorageNotifications();
......@@ -114,6 +117,8 @@ class RemovableStorageNotifications {
// Map of all the attached removable storage devices.
RemovableStorageMap storage_map_;
scoped_ptr<TransientDeviceIds> transient_device_ids_;
};
} // namespace chrome
......
......@@ -4,7 +4,7 @@
// TransientDeviceIds implementation.
#include "chrome/browser/media_gallery/transient_device_ids.h"
#include "chrome/browser/system_monitor/transient_device_ids.h"
#include "base/logging.h"
#include "chrome/browser/system_monitor/media_storage_util.h"
......
......@@ -7,8 +7,8 @@
// gets mapped to a transient ID, the mapping remains valid for the duration of
// TransientDeviceIds' lifetime.
#ifndef CHROME_BROWSER_MEDIA_GALLERY_TRANSIENT_DEVICE_IDS_H_
#define CHROME_BROWSER_MEDIA_GALLERY_TRANSIENT_DEVICE_IDS_H_
#ifndef CHROME_BROWSER_SYSTEM_MONITOR_TRANSIENT_DEVICE_IDS_H_
#define CHROME_BROWSER_SYSTEM_MONITOR_TRANSIENT_DEVICE_IDS_H_
#include <map>
#include <string>
......@@ -42,4 +42,4 @@ class TransientDeviceIds {
} // namespace chrome
#endif // CHROME_BROWSER_MEDIA_GALLERY_TRANSIENT_DEVICE_IDS_H_
#endif // CHROME_BROWSER_SYSTEM_MONITOR_TRANSIENT_DEVICE_IDS_H_
......@@ -1052,8 +1052,6 @@
'browser/media_gallery/mtp_device_delegate_impl.h',
'browser/media_gallery/scoped_mtp_device_map_entry.cc',
'browser/media_gallery/scoped_mtp_device_map_entry.h',
'browser/media_gallery/transient_device_ids.cc',
'browser/media_gallery/transient_device_ids.h',
'browser/media_gallery/win/mtp_device_delegate_impl_win.cc',
'browser/media_gallery/win/mtp_device_delegate_impl_win.h',
'browser/media_gallery/win/mtp_device_object_entry.cc',
......@@ -2077,6 +2075,8 @@
'browser/system_monitor/removable_storage_notifications.cc',
'browser/system_monitor/removable_storage_notifications.h',
'browser/system_monitor/removable_storage_observer.h',
'browser/system_monitor/transient_device_ids.cc',
'browser/system_monitor/transient_device_ids.h',
'browser/system_monitor/udev_util_linux.cc',
'browser/system_monitor/udev_util_linux.h',
'browser/system_monitor/volume_mount_watcher_win.cc',
......
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