| Index: chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
|
| diff --git a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
|
| index 4a9a49f26ecdee9989f6620e7af17d7adc0b56e2..94d43a0a534243445649a40e8c3a52b1a0aa397b 100644
|
| --- a/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
|
| +++ b/chrome/browser/system_monitor/removable_device_notifications_chromeos.cc
|
| @@ -20,6 +20,8 @@
|
|
|
| namespace chromeos {
|
|
|
| +using base::SystemMonitor;
|
| +
|
| namespace {
|
|
|
| // Construct a device name using label or manufacturer (vendor and product) name
|
| @@ -60,6 +62,9 @@ std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) {
|
| product.c_str(), chrome::kNonSpaceDelim);
|
| }
|
|
|
| +static RemovableDeviceNotificationsCros*
|
| + g_removable_device_notifications_chromeos = NULL;
|
| +
|
| // Returns true if the requested device is valid, else false. On success, fills
|
| // in |unique_id| and |device_label|
|
| bool GetDeviceInfo(const std::string& source_path, std::string* unique_id,
|
| @@ -84,17 +89,27 @@ using content::BrowserThread;
|
|
|
| RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() {
|
| DCHECK(disks::DiskMountManager::GetInstance());
|
| + DCHECK(!g_removable_device_notifications_chromeos);
|
| + g_removable_device_notifications_chromeos = this;
|
| disks::DiskMountManager::GetInstance()->AddObserver(this);
|
| CheckExistingMountPointsOnUIThread();
|
| }
|
|
|
| RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() {
|
| + DCHECK_EQ(this, g_removable_device_notifications_chromeos);
|
| + g_removable_device_notifications_chromeos = NULL;
|
| disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
|
| if (manager) {
|
| manager->RemoveObserver(this);
|
| }
|
| }
|
|
|
| +// static
|
| +RemovableDeviceNotificationsCros*
|
| +RemovableDeviceNotificationsCros::GetInstance() {
|
| + return g_removable_device_notifications_chromeos;
|
| +}
|
| +
|
| void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| const disks::DiskMountManager::MountPointMap& mount_point_map =
|
| @@ -152,13 +167,35 @@ void RemovableDeviceNotificationsCros::MountCompleted(
|
| MountMap::iterator it = mount_map_.find(mount_info.mount_path);
|
| if (it == mount_map_.end())
|
| return;
|
| - base::SystemMonitor::Get()->ProcessRemovableStorageDetached(it->second);
|
| + SystemMonitor::Get()->ProcessRemovableStorageDetached(
|
| + it->second.device_id);
|
| mount_map_.erase(it);
|
| break;
|
| }
|
| }
|
| }
|
|
|
| +bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath(
|
| + const FilePath& path,
|
| + SystemMonitor::RemovableStorageInfo* device_info) const {
|
| + if (!path.IsAbsolute())
|
| + return false;
|
| +
|
| + FilePath current = path;
|
| + while (!ContainsKey(mount_map_, current.value()) &&
|
| + current != current.DirName()) {
|
| + current = current.DirName();
|
| + }
|
| +
|
| + MountMap::const_iterator info_it = mount_map_.find(current.value());
|
| + if (info_it == mount_map_.end())
|
| + return false;
|
| +
|
| + if (device_info)
|
| + *device_info = info_it->second;
|
| + return true;
|
| +}
|
| +
|
| void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread(
|
| const disks::DiskMountManager::MountPointInfo& mount_info) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| @@ -175,10 +212,8 @@ void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread(
|
| const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| - if (ContainsKey(mount_map_, mount_info.mount_path)) {
|
| - NOTREACHED();
|
| + if (ContainsKey(mount_map_, mount_info.mount_path))
|
| return;
|
| - }
|
|
|
| // Get the media device uuid and label if exists.
|
| std::string unique_id;
|
| @@ -200,8 +235,10 @@ void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread(
|
|
|
| std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
|
| unique_id);
|
| - mount_map_.insert(std::make_pair(mount_info.mount_path, device_id));
|
| - base::SystemMonitor::Get()->ProcessRemovableStorageAttached(
|
| + SystemMonitor::RemovableStorageInfo info(device_id, device_label,
|
| + mount_info.mount_path);
|
| + mount_map_.insert(std::make_pair(mount_info.mount_path, info));
|
| + SystemMonitor::Get()->ProcessRemovableStorageAttached(
|
| device_id,
|
| device_label,
|
| mount_info.mount_path);
|
|
|