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

Unified Diff: chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc

Issue 10918259: [Chrome OS]Implement MediaStorageUtil::GetDeviceInfoForPath function to support media gallery permi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 3 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: chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc
diff --git a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc
index a9d6dfeffa3ef3c1e6d12dde620760e87716dca8..f0fb5f789d239ecee4ae9572e5ca220e221564c9 100644
--- a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc
+++ b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc
@@ -4,12 +4,12 @@
#include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.h"
+#include "base/file_path.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/stringprintf.h"
-#include "base/system_monitor/system_monitor.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/mtp/media_transfer_protocol_manager.h"
#include "chrome/browser/system_monitor/removable_device_constants.h"
@@ -19,13 +19,25 @@
namespace chromeos {
namespace mtp {
+using base::SystemMonitor;
using chrome::MediaStorageUtil;
namespace {
+static MediaTransferProtocolDeviceObserverCros* g_mtp_device_observer = NULL;
+
// Device root path constant.
const char kRootPath[] = "/";
+// Constructs and returns the location of the device using the |storage_name|.
+std::string GetDeviceLocationFromStorageName(const std::string& storage_name) {
+ // Construct a dummy device path using the storage name. This is only used
+ // for registering device media file system.
+ // E.g.: /usb:2,2:12345
+ DCHECK(!storage_name.empty());
+ return kRootPath + storage_name;
+}
+
// Returns the storage identifier of the device from the given |storage_name|.
// E.g. If the |storage_name| is "usb:2,2:65537", the storage identifier is
// "65537".
@@ -73,6 +85,19 @@ string16 GetDeviceLabelFromStorageInfo(const MtpStorageInfo& storage_info) {
device_label += chrome::kSpaceDelim;
device_label += product_name;
}
+
+ // Add the data store id to the device label.
kmadhusu 2012/09/17 21:47:56 The following code appends the data store id to th
vandebo (ex-Chrome) 2012/09/17 22:29:44 The user won't understand the value anyway, so it'
kmadhusu 2012/09/17 23:32:23 Done.
+ if (!device_label.empty()) {
+ const std::string& volume_id = storage_info.volume_identifier();
+ if (volume_id.empty()) {
vandebo (ex-Chrome) 2012/09/17 22:29:44 nit: negate this: if (!volume_id.empty()) { dev
kmadhusu 2012/09/17 23:32:23 Done.
+ const std::string data_store_id =
+ GetStorageIdFromStorageName(storage_info.storage_name());
+ if (!data_store_id.empty())
+ device_label += chrome::kNonSpaceDelim + data_store_id;
+ } else {
+ device_label += chrome::kNonSpaceDelim + volume_id;
+ }
+ }
return UTF8ToUTF16(device_label);
}
@@ -98,11 +123,9 @@ void GetStorageInfo(const std::string& storage_name,
if (label)
*label = GetDeviceLabelFromStorageInfo(*storage_info);
- // Construct a dummy device path using the storage name. This is only used
- // for registering device media file system.
- // E.g.: /usb:2,2:12345
+
if (location)
- *location = kRootPath + storage_name;
+ *location = GetDeviceLocationFromStorageName(storage_name);
}
} // namespace
@@ -110,6 +133,9 @@ void GetStorageInfo(const std::string& storage_name,
MediaTransferProtocolDeviceObserverCros::
MediaTransferProtocolDeviceObserverCros()
: get_storage_info_func_(&GetStorageInfo) {
+ DCHECK(!g_mtp_device_observer);
+ g_mtp_device_observer = this;
+
MediaTransferProtocolManager* mtp_manager =
MediaTransferProtocolManager::GetInstance();
if (mtp_manager)
@@ -124,23 +150,59 @@ MediaTransferProtocolDeviceObserverCros::
: get_storage_info_func_(get_storage_info_func) {
// In unit tests, we don't have a media transfer protocol manager.
DCHECK(!MediaTransferProtocolManager::GetInstance());
+ DCHECK(!g_mtp_device_observer);
+ g_mtp_device_observer = this;
}
MediaTransferProtocolDeviceObserverCros::
~MediaTransferProtocolDeviceObserverCros() {
+ DCHECK_EQ(this, g_mtp_device_observer);
+ g_mtp_device_observer = NULL;
+
MediaTransferProtocolManager* mtp_manager =
MediaTransferProtocolManager::GetInstance();
if (mtp_manager)
mtp_manager->RemoveObserver(this);
}
+// static
+MediaTransferProtocolDeviceObserverCros*
+MediaTransferProtocolDeviceObserverCros::GetInstance() {
+ DCHECK(g_mtp_device_observer != NULL);
+ return g_mtp_device_observer;
+}
+
+bool MediaTransferProtocolDeviceObserverCros::GetStorageInfoForPath(
+ const FilePath& path,
+ SystemMonitor::RemovableStorageInfo* storage_info) const {
+ if (!path.IsAbsolute())
+ return false;
+
+ std::vector<FilePath::StringType> path_components;
+ path.GetComponents(&path_components);
+ if (path_components.size() < 2)
+ return false;
+
+ // First and second component of the path specifies the device location.
+ // E.g.: If |path| is "/usb:2,2:65537/DCIM/Folder_a", "/usb:2,2:65537" is the
+ // device location.
+ StorageLocationToInfoMap::const_iterator info_it =
+ storage_map_.find(path_components[0] + path_components[1]);
+ if (info_it == storage_map_.end())
+ return false;
+
+ if (storage_info)
+ *storage_info = info_it->second;
+ return true;
+}
+
// MediaTransferProtocolManager::Observer override.
void MediaTransferProtocolDeviceObserverCros::StorageChanged(
bool is_attached,
const std::string& storage_name) {
DCHECK(!storage_name.empty());
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
+ SystemMonitor* system_monitor = SystemMonitor::Get();
DCHECK(system_monitor);
// New storage is attached.
@@ -160,16 +222,20 @@ void MediaTransferProtocolDeviceObserverCros::StorageChanged(
if (device_id.empty() || device_name.empty())
return;
- DCHECK(!ContainsKey(storage_map_, storage_name));
- storage_map_[storage_name] = device_id;
+ DCHECK(!ContainsKey(storage_map_, location));
+
+ SystemMonitor::RemovableStorageInfo storage_info(device_id, device_name,
+ location);
+ storage_map_[location] = storage_info;
system_monitor->ProcessRemovableStorageAttached(device_id, device_name,
location);
} else {
// Existing storage is detached.
- StorageNameToIdMap::iterator it = storage_map_.find(storage_name);
+ StorageLocationToInfoMap::iterator it =
+ storage_map_.find(GetDeviceLocationFromStorageName(storage_name));
if (it == storage_map_.end())
return;
- system_monitor->ProcessRemovableStorageDetached(it->second);
+ system_monitor->ProcessRemovableStorageDetached(it->second.device_id);
storage_map_.erase(it);
}
}

Powered by Google App Engine
This is Rietveld 408576698