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 // the SystemMonitor 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_ |
(...skipping 10 matching lines...) Expand all Loading... |
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" | 25 #include "base/system_monitor/system_monitor.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 | 27 |
28 class FilePath; | 28 class FilePath; |
29 | 29 |
30 // Gets device information given a |device_path|. On success, fills in | 30 // Gets device information given a |device_path|. On success, fills in |
31 // |unique_id|, |name|, and |removable|. | 31 // |unique_id|, |name|, |removable| and |partition_size_in_bytes|. |
32 typedef void (*GetDeviceInfoFunc)(const FilePath& device_path, | 32 typedef void (*GetDeviceInfoFunc)(const FilePath& device_path, |
33 std::string* unique_id, string16* name, | 33 std::string* unique_id, |
34 bool* removable); | 34 string16* name, |
| 35 bool* removable, |
| 36 uint64* partition_size_in_bytes); |
35 | 37 |
36 namespace chrome { | 38 namespace chrome { |
37 | 39 |
38 class RemovableDeviceNotificationsLinux; | 40 class RemovableDeviceNotificationsLinux; |
39 typedef RemovableDeviceNotificationsLinux RemovableDeviceNotifications; | 41 typedef RemovableDeviceNotificationsLinux RemovableDeviceNotifications; |
40 | 42 |
41 class RemovableDeviceNotificationsLinux | 43 class RemovableDeviceNotificationsLinux |
42 : public base::RefCountedThreadSafe<RemovableDeviceNotificationsLinux, | 44 : public base::RefCountedThreadSafe<RemovableDeviceNotificationsLinux, |
43 content::BrowserThread::DeleteOnFileThread> { | 45 content::BrowserThread::DeleteOnFileThread> { |
44 public: | 46 public: |
45 // Should only be called by browser start up code. Use GetInstance() instead. | 47 // Should only be called by browser start up code. Use GetInstance() instead. |
46 explicit RemovableDeviceNotificationsLinux(const FilePath& path); | 48 explicit RemovableDeviceNotificationsLinux(const FilePath& path); |
47 | 49 |
48 static RemovableDeviceNotificationsLinux* GetInstance(); | 50 static RemovableDeviceNotificationsLinux* GetInstance(); |
49 | 51 |
50 // Must be called for RemovableDeviceNotificationsLinux to work. | 52 // Must be called for RemovableDeviceNotificationsLinux to work. |
51 void Init(); | 53 void Init(); |
52 | 54 |
53 // Finds the device that contains |path| and populates |device_info|. | 55 // Finds the device that contains |path| and populates |device_info|. |
54 // Returns false if unable to find the device. | 56 // Returns false if unable to find the device. |
55 bool GetDeviceInfoForPath( | 57 bool GetDeviceInfoForPath( |
56 const FilePath& path, | 58 const FilePath& path, |
57 base::SystemMonitor::RemovableStorageInfo* device_info) const; | 59 base::SystemMonitor::RemovableStorageInfo* device_info) const; |
58 | 60 |
| 61 // Returns the storage partition size of the device present at |location|. |
| 62 // If the requested information is unavailable, returns 0. |
| 63 uint64 GetStorageSize(const std::string& location) const; |
| 64 |
59 protected: | 65 protected: |
60 // Only for use in unit tests. | 66 // Only for use in unit tests. |
61 RemovableDeviceNotificationsLinux(const FilePath& path, | 67 RemovableDeviceNotificationsLinux(const FilePath& path, |
62 GetDeviceInfoFunc getDeviceInfo); | 68 GetDeviceInfoFunc getDeviceInfo); |
63 | 69 |
64 // Avoids code deleting the object while there are references to it. | 70 // Avoids code deleting the object while there are references to it. |
65 // Aside from the base::RefCountedThreadSafe friend class, and derived | 71 // Aside from the base::RefCountedThreadSafe friend class, and derived |
66 // classes, any attempts to call this dtor will result in a compile-time | 72 // classes, any attempts to call this dtor will result in a compile-time |
67 // error. | 73 // error. |
68 virtual ~RemovableDeviceNotificationsLinux(); | 74 virtual ~RemovableDeviceNotificationsLinux(); |
69 | 75 |
70 virtual void OnFilePathChanged(const FilePath& path, bool error); | 76 virtual void OnFilePathChanged(const FilePath& path, bool error); |
71 | 77 |
72 private: | 78 private: |
73 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsLinux>; | 79 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsLinux>; |
74 friend class base::DeleteHelper<RemovableDeviceNotificationsLinux>; | 80 friend class base::DeleteHelper<RemovableDeviceNotificationsLinux>; |
75 friend struct content::BrowserThread::DeleteOnThread< | 81 friend struct content::BrowserThread::DeleteOnThread< |
76 content::BrowserThread::FILE>; | 82 content::BrowserThread::FILE>; |
77 | 83 |
78 // Structure to save mounted device information such as device path and unique | 84 // Structure to save mounted device information such as device path, unique |
79 // identifier. | 85 // identifier, device name and partition size. |
80 struct MountPointInfo { | 86 struct MountPointInfo { |
| 87 MountPointInfo(); |
| 88 |
81 FilePath mount_device; | 89 FilePath mount_device; |
82 std::string device_id; | 90 std::string device_id; |
83 string16 device_name; | 91 string16 device_name; |
| 92 uint64 partition_size_in_bytes; |
84 }; | 93 }; |
85 | 94 |
86 // Mapping of mount points to MountPointInfo. | 95 // Mapping of mount points to MountPointInfo. |
87 typedef std::map<FilePath, MountPointInfo> MountMap; | 96 typedef std::map<FilePath, MountPointInfo> MountMap; |
88 | 97 |
89 // (mount point, priority) | 98 // (mount point, priority) |
90 // For devices that are mounted to multiple mount points, this helps us track | 99 // For devices that are mounted to multiple mount points, this helps us track |
91 // which one we've notified system monitor about. | 100 // which one we've notified system monitor about. |
92 typedef std::map<FilePath, bool> ReferencedMountPoint; | 101 typedef std::map<FilePath, bool> ReferencedMountPoint; |
93 | 102 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // to notify about it's departure and notify about another one of it's mount | 141 // to notify about it's departure and notify about another one of it's mount |
133 // points. | 142 // points. |
134 MountPriorityMap mount_priority_map_; | 143 MountPriorityMap mount_priority_map_; |
135 | 144 |
136 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux); | 145 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux); |
137 }; | 146 }; |
138 | 147 |
139 } // namespace chrome | 148 } // namespace chrome |
140 | 149 |
141 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ | 150 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ |
OLD | NEW |