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

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_linux.h

Issue 11363153: [Media Gallery][Linux] Improve device media gallery names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
Lei Zhang 2012/11/13 20:35:04 nit: const
kmadhusu 2012/11/13 21:57:27 Done.
Lei Zhang 2012/11/13 22:17:49 No, I mean mark the method as const.
kmadhusu 2012/11/13 23:05:32 Done.
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 {
81 FilePath mount_device; 87 FilePath mount_device;
82 std::string device_id; 88 std::string device_id;
83 string16 device_name; 89 string16 device_name;
90 uint64 partition_size_in_bytes;
84 }; 91 };
85 92
86 // Mapping of mount points to MountPointInfo. 93 // Mapping of mount points to MountPointInfo.
87 typedef std::map<FilePath, MountPointInfo> MountMap; 94 typedef std::map<FilePath, MountPointInfo> MountMap;
88 95
89 // (mount point, priority) 96 // (mount point, priority)
90 // For devices that are mounted to multiple mount points, this helps us track 97 // For devices that are mounted to multiple mount points, this helps us track
91 // which one we've notified system monitor about. 98 // which one we've notified system monitor about.
92 typedef std::map<FilePath, bool> ReferencedMountPoint; 99 typedef std::map<FilePath, bool> ReferencedMountPoint;
93 100
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // to notify about it's departure and notify about another one of it's mount 139 // to notify about it's departure and notify about another one of it's mount
133 // points. 140 // points.
134 MountPriorityMap mount_priority_map_; 141 MountPriorityMap mount_priority_map_;
135 142
136 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux); 143 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinux);
137 }; 144 };
138 145
139 } // namespace chrome 146 } // namespace chrome
140 147
141 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_ 148 #endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698