Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // MediaDeviceNotificationsLinux listens for mount point changes and notifies | 5 // MediaDeviceNotificationsLinux listens for mount point changes and notifies |
| 6 // the SystemMonitor about the addition and deletion of media devices. | 6 // the SystemMonitor about the addition and deletion of media devices. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ | 8 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
| 9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ | 9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 | 45 |
| 46 virtual void OnFilePathChanged(const FilePath& path, bool error); | 46 virtual void OnFilePathChanged(const FilePath& path, bool error); |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>; | 49 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>; |
| 50 friend class base::DeleteHelper<MediaDeviceNotificationsLinux>; | 50 friend class base::DeleteHelper<MediaDeviceNotificationsLinux>; |
| 51 friend struct content::BrowserThread::DeleteOnThread< | 51 friend struct content::BrowserThread::DeleteOnThread< |
| 52 content::BrowserThread::FILE>; | 52 content::BrowserThread::FILE>; |
| 53 | 53 |
| 54 // (mount device, device id) | 54 // (mount device, device id) |
| 55 typedef std::pair<std::string, std::string> MountDeviceAndId; | 55 typedef std::pair<std::string, std::string> MountDeviceAndId; |
|
vandebo (ex-Chrome)
2012/08/09 17:52:35
You don't have to fix it, but if you feel like thi
kmadhusu
2012/08/09 23:41:29
Done.
| |
| 56 // Mapping of mount points to MountDeviceAndId. | 56 // Mapping of mount points to MountDeviceAndId. |
| 57 typedef std::map<std::string, MountDeviceAndId> MountMap; | 57 typedef std::map<std::string, MountDeviceAndId> MountMap; |
| 58 | 58 |
| 59 // (mount point, mount device) | |
| 60 // Helper map to get new entries from mtab file. | |
| 61 typedef std::map<std::string, std::string> MountPointDeviceMap; | |
| 62 | |
| 63 // Get mounted device properties. This function is exposed for unit test. | |
| 64 virtual bool GetDeviceInfo(const std::string& dev_path, | |
|
kmadhusu
2012/08/09 23:41:29
Moved this function to anonymous namespace and inc
| |
| 65 std::string* device_label, | |
| 66 string16* device_name); | |
| 67 | |
| 59 void InitOnFileThread(); | 68 void InitOnFileThread(); |
| 60 | 69 |
| 61 // Parse the mtab file and find all changes. | 70 // Parse the mtab file and find all changes. |
| 62 void UpdateMtab(); | 71 void UpdateMtab(); |
| 63 | 72 |
| 64 // Read the mtab file entries into |mtab|. | 73 // Read the mtab file entries into |mtab|. |
| 65 void ReadMtab(MountMap* mtab); | 74 void ReadMtab(MountPointDeviceMap* mtab); |
| 66 | 75 |
| 67 // Add a media device with a given device and mount device. Assign it a device | 76 // Add a media device with a given device and mount device. Assign it a device |
| 68 // id as well. | 77 // id as well. |
| 69 void AddNewDevice(const std::string& mount_device, | 78 void AddNewDevice(const std::string& mount_device, |
| 70 const std::string& mount_point, | 79 const std::string& mount_point, |
| 71 std::string* device_id); | 80 std::string* device_id); |
| 72 | 81 |
| 73 // Remove a media device with a given device id. | 82 // Remove a media device with a given device id. |
| 74 void RemoveOldDevice(const std::string& device_id); | 83 void RemoveOldDevice(const std::string& device_id); |
| 75 | 84 |
| 76 // Whether Init() has been called or not. | 85 // Whether Init() has been called or not. |
| 77 bool initialized_; | 86 bool initialized_; |
| 78 | 87 |
| 79 // Mtab file that lists the mount points. | 88 // Mtab file that lists the mount points. |
| 80 const FilePath mtab_path_; | 89 const FilePath mtab_path_; |
| 81 | 90 |
| 82 // Watcher for |mtab_path_|. | 91 // Watcher for |mtab_path_|. |
| 83 base::files::FilePathWatcher file_watcher_; | 92 base::files::FilePathWatcher file_watcher_; |
| 84 | 93 |
| 85 // Mapping of relevant mount points and their corresponding mount devices. | 94 // Mapping of relevant mount points and their corresponding mount devices. |
| 86 // Keep in mind on Linux, a device can be mounted at multiple mount points, | 95 // Keep in mind on Linux, a device can be mounted at multiple mount points, |
| 87 // and multiple devices can be mounted at a mount point. | 96 // and multiple devices can be mounted at a mount point. |
| 88 MountMap mtab_; | 97 MountMap mtab_; |
|
vandebo (ex-Chrome)
2012/08/09 17:52:35
This is more than the mtab now, right? mtab_ -> m
kmadhusu
2012/08/09 23:41:29
Done.
| |
| 89 | 98 |
| 90 // The lowest available device id number. | |
| 91 // TODO(thestig) Remove this and use a real per-device unique id instead. | |
| 92 int current_device_id_; | |
| 93 | |
| 94 // Set of known file systems that we care about. | 99 // Set of known file systems that we care about. |
| 95 std::set<std::string> known_file_systems_; | 100 std::set<std::string> known_file_systems_; |
| 96 | 101 |
| 97 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); | 102 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); |
| 98 }; | 103 }; |
| 99 | 104 |
| 100 } // namespace chrome | 105 } // namespace chrome |
| 101 | 106 |
| 102 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ | 107 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
| OLD | NEW |