| 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 // RemovableDeviceNotificationsLinux listens for mount point changes, notifies | 5 // RemovableDeviceNotificationsLinux listens for mount point changes, notifies |
| 6 // the SystemMonitor about the addition and deletion of media devices, and | 6 // listeners about the addition and deletion of media devices, and |
| 7 // answers queries about mounted devices. | 7 // answers queries about mounted devices. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ | 9 #ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |
| 10 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ | 10 #define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |
| 11 | 11 |
| 12 #if defined(OS_CHROMEOS) | 12 #if defined(OS_CHROMEOS) |
| 13 #error "Use the ChromeOS-specific implementation instead." | 13 #error "Use the ChromeOS-specific implementation instead." |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include <map> | 16 #include <map> |
| 17 #include <set> | 17 #include <set> |
| 18 #include <string> | 18 #include <string> |
| 19 #include <utility> | 19 #include <utility> |
| 20 | 20 |
| 21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
| 22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
| 23 #include "base/files/file_path_watcher.h" | 23 #include "base/files/file_path_watcher.h" |
| 24 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
| 25 #include "base/system_monitor/system_monitor.h" | |
| 26 #include "chrome/browser/system_monitor/removable_storage_notifications.h" | 25 #include "chrome/browser/system_monitor/removable_storage_notifications.h" |
| 27 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 28 | 27 |
| 29 class FilePath; | 28 class FilePath; |
| 30 | 29 |
| 31 // Gets device information given a |device_path|. On success, fills in | 30 // Gets device information given a |device_path|. On success, fills in |
| 32 // |unique_id|, |name|, |removable| and |partition_size_in_bytes|. | 31 // |unique_id|, |name|, |removable| and |partition_size_in_bytes|. |
| 33 typedef void (*GetDeviceInfoFunc)(const FilePath& device_path, | 32 typedef void (*GetDeviceInfoFunc)(const FilePath& device_path, |
| 34 std::string* unique_id, | 33 std::string* unique_id, |
| 35 string16* name, | 34 string16* name, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 // Should only be called by browser start up code. Use GetInstance() instead. | 45 // Should only be called by browser start up code. Use GetInstance() instead. |
| 47 explicit RemovableDeviceNotificationsLinux(const FilePath& path); | 46 explicit RemovableDeviceNotificationsLinux(const FilePath& path); |
| 48 | 47 |
| 49 // Must be called for RemovableDeviceNotificationsLinux to work. | 48 // Must be called for RemovableDeviceNotificationsLinux to work. |
| 50 void Init(); | 49 void Init(); |
| 51 | 50 |
| 52 // Finds the device that contains |path| and populates |device_info|. | 51 // Finds the device that contains |path| and populates |device_info|. |
| 53 // Returns false if unable to find the device. | 52 // Returns false if unable to find the device. |
| 54 virtual bool GetDeviceInfoForPath( | 53 virtual bool GetDeviceInfoForPath( |
| 55 const FilePath& path, | 54 const FilePath& path, |
| 56 base::SystemMonitor::RemovableStorageInfo* device_info) const OVERRIDE; | 55 StorageInfo* device_info) const OVERRIDE; |
| 57 | 56 |
| 58 // Returns the storage partition size of the device present at |location|. | 57 // Returns the storage partition size of the device present at |location|. |
| 59 // If the requested information is unavailable, returns 0. | 58 // If the requested information is unavailable, returns 0. |
| 60 virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE; | 59 virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE; |
| 61 | 60 |
| 62 protected: | 61 protected: |
| 63 // Only for use in unit tests. | 62 // Only for use in unit tests. |
| 64 RemovableDeviceNotificationsLinux(const FilePath& path, | 63 RemovableDeviceNotificationsLinux(const FilePath& path, |
| 65 GetDeviceInfoFunc getDeviceInfo); | 64 GetDeviceInfoFunc getDeviceInfo); |
| 66 | 65 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // any) we have notified system monitor about. | 101 // any) we have notified system monitor about. |
| 103 typedef std::map<FilePath, ReferencedMountPoint> MountPriorityMap; | 102 typedef std::map<FilePath, ReferencedMountPoint> MountPriorityMap; |
| 104 | 103 |
| 105 // Do initialization on the File Thread. | 104 // Do initialization on the File Thread. |
| 106 void InitOnFileThread(); | 105 void InitOnFileThread(); |
| 107 | 106 |
| 108 // Parses mtab file and find all changes. | 107 // Parses mtab file and find all changes. |
| 109 void UpdateMtab(); | 108 void UpdateMtab(); |
| 110 | 109 |
| 111 // Adds |mount_device| as mounted on |mount_point|. If the device is a new | 110 // Adds |mount_device| as mounted on |mount_point|. If the device is a new |
| 112 // device SystemMonitor is notified. | 111 // device any listeners are notified. |
| 113 void AddNewMount(const FilePath& mount_device, const FilePath& mount_point); | 112 void AddNewMount(const FilePath& mount_device, const FilePath& mount_point); |
| 114 | 113 |
| 115 // Whether Init() has been called or not. | 114 // Whether Init() has been called or not. |
| 116 bool initialized_; | 115 bool initialized_; |
| 117 | 116 |
| 118 // Mtab file that lists the mount points. | 117 // Mtab file that lists the mount points. |
| 119 const FilePath mtab_path_; | 118 const FilePath mtab_path_; |
| 120 | 119 |
| 121 // Watcher for |mtab_path_|. | 120 // Watcher for |mtab_path_|. |
| 122 base::FilePathWatcher file_watcher_; | 121 base::FilePathWatcher file_watcher_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 138 // to notify about it's departure and notify about another one of it's mount | 137 // to notify about it's departure and notify about another one of it's mount |
| 139 // points. | 138 // points. |
| 140 MountPriorityMap mount_priority_map_; | 139 MountPriorityMap mount_priority_map_; |
| 141 | 140 |
| 142 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux); | 141 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux); |
| 143 }; | 142 }; |
| 144 | 143 |
| 145 } // namespace chrome | 144 } // namespace chrome |
| 146 | 145 |
| 147 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ | 146 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |
| OLD | NEW |