Index: chrome/browser/media_gallery/removable_device_notifications_linux.h |
diff --git a/chrome/browser/media_gallery/media_device_notifications_linux.h b/chrome/browser/media_gallery/removable_device_notifications_linux.h |
similarity index 43% |
rename from chrome/browser/media_gallery/media_device_notifications_linux.h |
rename to chrome/browser/media_gallery/removable_device_notifications_linux.h |
index 418c1e413c1a8f540cbccacd706cd3b417eedff0..0501d2120b95fe8deffdd5ac8e8697594ad5e111 100644 |
--- a/chrome/browser/media_gallery/media_device_notifications_linux.h |
+++ b/chrome/browser/media_gallery/removable_device_notifications_linux.h |
@@ -2,11 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// MediaDeviceNotificationsLinux listens for mount point changes and notifies |
-// the SystemMonitor about the addition and deletion of media devices. |
+// RemovableDeviceNotificationsLinux listens for mount point changes, notifies |
+// the SystemMonitor about the addition and deletion of media devices, and |
+// answers queries about mounted devices. |
-#ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
-#define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
+#ifndef CHROME_BROWSER_MEDIA_GALLERY_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |
+#define CHROME_BROWSER_MEDIA_GALLERY_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |
#if defined(OS_CHROMEOS) |
#error "Use the ChromeOS-specific implementation instead." |
@@ -26,54 +27,74 @@ |
class FilePath; |
// Gets the media device information given a |device_path|. On success, |
-// returns true and fills in |name| and |id|. |
-typedef bool (*GetDeviceInfoFunc)(const std::string& device_path, |
- std::string* id, |
- string16* name); |
+// returns true and fills in |device_name| and |unique_id|. |
+typedef bool (*GetDeviceInfoFunc)(const FilePath& device_path, |
+ std::string* unique_id, string16* name, |
+ bool* removable); |
namespace chrome { |
-class MediaDeviceNotificationsLinux |
- : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux, |
+class RemovableDeviceNotificationsLinux |
+ : public base::RefCountedThreadSafe<RemovableDeviceNotificationsLinux, |
content::BrowserThread::DeleteOnFileThread> { |
public: |
- explicit MediaDeviceNotificationsLinux(const FilePath& path); |
+ // Should only be called by browser start up code. Use GetInstance() instead. |
+ explicit RemovableDeviceNotificationsLinux(const FilePath& path); |
- // Must be called for MediaDeviceNotificationsLinux to work. |
+ static RemovableDeviceNotificationsLinux* GetInstance(); |
+ |
+ // Must be called for RemovableDeviceNotificationsLinux to work. |
void Init(); |
+ // Use |unique_id| to find and return where the device is mounted. |
+ FilePath GetDeviceMountPoint(const std::string& device_id) const; |
+ |
+ // Determines which device |path| is located on and returns the unique id |
+ // for that device. If |mount_point| is not NULL, set it to the mount point |
+ // of the device. |
+ std::string GetDeviceIdForPath(const FilePath& path, |
+ FilePath* mount_point) const; |
+ |
protected: |
// Only for use in unit tests. |
- MediaDeviceNotificationsLinux(const FilePath& path, |
- GetDeviceInfoFunc getDeviceInfo); |
+ RemovableDeviceNotificationsLinux(const FilePath& path, |
+ GetDeviceInfoFunc getDeviceInfo); |
// Avoids code deleting the object while there are references to it. |
// Aside from the base::RefCountedThreadSafe friend class, and derived |
// classes, any attempts to call this dtor will result in a compile-time |
// error. |
- virtual ~MediaDeviceNotificationsLinux(); |
+ virtual ~RemovableDeviceNotificationsLinux(); |
virtual void OnFilePathChanged(const FilePath& path, bool error); |
private: |
- friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>; |
- friend class base::DeleteHelper<MediaDeviceNotificationsLinux>; |
+ friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsLinux>; |
+ friend class base::DeleteHelper<RemovableDeviceNotificationsLinux>; |
friend struct content::BrowserThread::DeleteOnThread< |
content::BrowserThread::FILE>; |
// Structure to save mounted device information such as device path and unique |
// identifier. |
- struct MountDeviceAndId { |
- std::string mount_device; |
+ struct MountPointInfo { |
+ FilePath mount_device; |
std::string device_id; |
+ string16 device_name; |
+ bool has_dcim; |
}; |
- // Mapping of mount points to MountDeviceAndId. |
- typedef std::map<std::string, MountDeviceAndId> MountMap; |
+ // Mapping of mount points to MountPointInfo. |
+ typedef std::map<FilePath, MountPointInfo> MountMap; |
+ |
+ // (mount point, priority) |
+ // For devices that are mounted to multiple mount points, this helps us track |
+ // which one we've notified system monitor about. |
+ typedef std::map<FilePath, bool> ReferencedMountPoint; |
- // (mount point, mount device) |
- // Helper Map to get new entries from mtab file. |
- typedef std::map<std::string, std::string> MountPointDeviceMap; |
+ // (mount device, map of known mount points) |
+ // For each mount device, track the places it is mounted and which one (if |
+ // any) we have notified system monitor about. |
+ typedef std::map<FilePath, ReferencedMountPoint> MountPriorityMap; |
// Do initialization on the File Thread. |
void InitOnFileThread(); |
@@ -81,15 +102,12 @@ class MediaDeviceNotificationsLinux |
// Parses mtab file and find all changes. |
void UpdateMtab(); |
- // Reads mtab file entries into |mtab|. |
- void ReadMtab(MountPointDeviceMap* mtab); |
- |
- // Checks and adds |mount_device| as media device given the |mount_point|. |
- void CheckAndAddMediaDevice(const std::string& mount_device, |
- const std::string& mount_point); |
+ // Adds |mount_device| as mounted on |mount_point|. If the deice is a new |
+ // media // device, SystemMonitor is notified. |
+ void AddNewMount(const FilePath& mount_device, const FilePath& mount_point); |
// Removes media device with a given device id. |
- void RemoveOldDevice(const std::string& device_id); |
+ void RemoveMediaMount(const std::string& device_id); |
// Whether Init() has been called or not. |
bool initialized_; |
@@ -100,11 +118,6 @@ class MediaDeviceNotificationsLinux |
// Watcher for |mtab_path_|. |
base::files::FilePathWatcher file_watcher_; |
- // Mapping of relevant mount points and their corresponding mount devices. |
- // Keep in mind on Linux, a device can be mounted at multiple mount points, |
- // and multiple devices can be mounted at a mount point. |
- MountMap mount_info_map_; |
- |
// Set of known file systems that we care about. |
std::set<std::string> known_file_systems_; |
@@ -112,9 +125,20 @@ class MediaDeviceNotificationsLinux |
// handler for unit testing. |
GetDeviceInfoFunc get_device_info_func_; |
- DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); |
+ // Mapping of relevant mount points and their corresponding mount devices. |
+ // Keep in mind on Linux, a device can be mounted at multiple mount points, |
+ // and multiple devices can be mounted at a mount point. |
+ MountMap mount_info_map_; |
+ |
+ // Because a device can be mounted to multiple places, we only want to |
+ // notify about one of them. If (and only if) that one is unmounted, we need |
+ // to notify about it's departure and notify about another one of it's mount |
+ // points. |
+ MountPriorityMap mount_priority_map_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux); |
}; |
} // namespace chrome |
-#endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
+#endif // CHROME_BROWSER_MEDIA_GALLERY_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |