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

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

Issue 10909259: Share MediaStorageUtil common code among platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try a different way 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_storage_util.cc
diff --git a/chrome/browser/system_monitor/media_storage_util.cc b/chrome/browser/system_monitor/media_storage_util.cc
index 82045a1152b2b0bd2a3340c15d8048dc69f3b4a0..cd8b8a23619f03e0aa37e25997dce88328fa7fd8 100644
--- a/chrome/browser/system_monitor/media_storage_util.cc
+++ b/chrome/browser/system_monitor/media_storage_util.cc
@@ -14,6 +14,17 @@
#include "base/system_monitor/system_monitor.h"
#include "content/public/browser/browser_thread.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.h"
+#include "chrome/browser/system_monitor/removable_device_notifications_chromeos.h"
+#elif defined(OS_LINUX)
+#include "chrome/browser/system_monitor/removable_device_notifications_linux.h"
+#elif defined(OS_MACOSX)
+#include "chrome/browser/system_monitor/removable_device_notifications_mac.h"
+#elif defined(OS_WIN)
+#include "chrome/browser/system_monitor/removable_device_notifications_window_win.h"
+#endif
+
using base::SystemMonitor;
using content::BrowserThread;
@@ -150,14 +161,55 @@ bool MediaStorageUtil::GetDeviceInfoFromPath(const FilePath& path,
std::string* device_id,
string16* device_name,
FilePath* relative_path) {
+ if (!path.IsAbsolute())
+ return false;
+
if (g_test_get_device_info_from_path_function) {
return g_test_get_device_info_from_path_function(path, device_id,
device_name,
relative_path);
- } else {
- return GetDeviceInfoFromPathImpl(path, device_id, device_name,
- relative_path);
}
+
+ bool found_device = false;
+ base::SystemMonitor::RemovableStorageInfo device_info;
+#if (defined(OS_LINUX) || defined(OS_MACOSX)) && !defined(OS_CHROMEOS)
+ RemovableDeviceNotifications* notifier =
+ RemovableDeviceNotifications::GetInstance();
+ found_device = notifier->GetDeviceInfoForPath(path, &device_info);
+#endif
+
+#if 0 && defined(OS_CHROMEOS)
Lei Zhang 2012/09/17 00:25:47 Whose job is it to remove the #if 0 bit and use mt
vandebo (ex-Chrome) 2012/09/17 00:32:58 http://codereview.chromium.org/10908277/ will take
+ MediaTransferProtocolDeviceObserver* mtp_manager =
+ MediaTransferProtocolDeviceObserver::GetInstance();
+ found_device = mtp_manager->GetStorageInfoForPath(path, &device_info);
+#endif
+
+ if (found_device && IsRemovableDevice(device_info.device_id)) {
+ if (device_id)
+ *device_id = device_info.device_id;
+ if (device_name)
+ *device_name = device_info.name;
+ if (relative_path) {
+ *relative_path = FilePath();
+ FilePath mount_point(device_info.location);
+ mount_point.AppendRelativePath(path, relative_path);
+ }
+ return true;
+ }
+
+#if !defined(POSIX)
Lei Zhang 2012/09/17 00:25:47 OS_POSIX?
vandebo (ex-Chrome) 2012/09/17 00:32:58 Done.
+ if (!found_device)
+ return false;
+#endif
+
+ // On Posix systems, there's one root so any absolute path could be valid.
+ if (device_id)
+ *device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe());
+ if (device_name)
+ *device_name = path.BaseName().LossyDisplayName();
+ if (relative_path)
+ *relative_path = FilePath();
+ return true;
}
// static
@@ -186,26 +238,4 @@ void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting(
MediaStorageUtil::MediaStorageUtil() {}
-#if !defined(OS_LINUX) || defined(OS_CHROMEOS)
-// static
-bool MediaStorageUtil::GetDeviceInfoFromPathImpl(const FilePath& path,
- std::string* device_id,
- string16* device_name,
- FilePath* relative_path) {
- // TODO(vandebo) This needs to be implemented per platform. Below is no
- // worse than what the code already does.
- // * Find mount point parent (determines relative file path)
- // * Search System monitor, just in case.
- // * If it's a removable device, generate device id, else use device root
- // path as id
- if (device_id)
- *device_id = MakeDeviceId(FIXED_MASS_STORAGE, path.AsUTF8Unsafe());
- if (device_name)
- *device_name = path.BaseName().LossyDisplayName();
- if (relative_path)
- *relative_path = FilePath();
- return true;
-}
-#endif
-
} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698