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

Side by Side Diff: content/browser/media_device_notifications_linux.h

Issue 9622020: C++ Readability Review for thestig. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: blank line Created 8 years, 8 months 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
« no previous file with comments | « no previous file | content/browser/media_device_notifications_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // MediaDeviceNotificationsLinux listens for mount point changes and notifies
6 // the SystemMonitor about the addition and deletion of media devices.
7
5 #ifndef CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ 8 #ifndef CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
6 #define CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ 9 #define CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
7 #pragma once 10 #pragma once
8 11
9 #include <map> 12 #include <map>
10 #include <set> 13 #include <set>
11 #include <string> 14 #include <string>
12 #include <utility> 15 #include <utility>
13 16
14 #include "base/basictypes.h" 17 #include "base/basictypes.h"
15 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
16 #include "base/file_path.h"
17 #include "base/files/file_path_watcher.h" 19 #include "base/files/file_path_watcher.h"
18 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
19 #include "base/system_monitor/system_monitor.h" 21 #include "base/system_monitor/system_monitor.h"
20 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
21 23
24 class FilePath;
25
22 namespace content { 26 namespace content {
23 27
24 class CONTENT_EXPORT MediaDeviceNotificationsLinux 28 class CONTENT_EXPORT MediaDeviceNotificationsLinux
25 : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux> { 29 : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux> {
26 public: 30 public:
27 explicit MediaDeviceNotificationsLinux(const FilePath& path); 31 explicit MediaDeviceNotificationsLinux(const FilePath& path);
28 32
29 // Must be called for MediaDeviceNotificationsLinux to work. 33 // Must be called for MediaDeviceNotificationsLinux to work.
30 void Init(); 34 void Init();
31 35
32 protected: 36 protected:
37 // Avoids code deleting the object while there are references to it.
38 // Aside from the base::RefCountedThreadSafe friend class, and derived
vandebo (ex-Chrome) 2012/04/11 21:45:16 nit: I don't think derived classes can safely call
Lei Zhang 2012/04/12 00:15:10 MediaDeviceNotificationsLinuxTestWrapper needs to
39 // classes, any attempts to call this dtor will result in a compile-time
40 // error.
33 virtual ~MediaDeviceNotificationsLinux(); 41 virtual ~MediaDeviceNotificationsLinux();
34 42
35 virtual void OnFilePathChanged(const FilePath& path); 43 virtual void OnFilePathChanged(const FilePath& path);
36 44
37 private: 45 private:
38 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>; 46 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>;
39 47
40 typedef std::string MountDevice; 48 class WatcherDelegate;
41 typedef std::string MountPoint; 49
42 typedef std::pair<MountDevice, 50 // (mount device, device id)
51 typedef std::pair<std::string,
43 base::SystemMonitor::DeviceIdType> MountDeviceAndId; 52 base::SystemMonitor::DeviceIdType> MountDeviceAndId;
44 typedef std::map<MountPoint, MountDeviceAndId> MountMap; 53 // Mapping of mount points to MountDeviceAndId.
45 54 typedef std::map<std::string, MountDeviceAndId> MountMap;
46 // A simple pass-through class. MediaDeviceNotificationsLinux cannot directly
47 // inherit from FilePathWatcher::Delegate due to multiple inheritance.
48 class WatcherDelegate : public base::files::FilePathWatcher::Delegate {
49 public:
50 explicit WatcherDelegate(MediaDeviceNotificationsLinux* notifier);
51
52 // base::files::FilePathWatcher::Delegate implementation.
53 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE;
54
55 private:
56 friend class base::RefCountedThreadSafe<WatcherDelegate>;
57
58 virtual ~WatcherDelegate();
59 MediaDeviceNotificationsLinux* notifier_;
60
61 DISALLOW_COPY_AND_ASSIGN(WatcherDelegate);
62 };
63 55
64 void InitOnFileThread(); 56 void InitOnFileThread();
65 57
66 // Parse the mtab file and find all changes. 58 // Parse the mtab file and find all changes.
67 void UpdateMtab(); 59 void UpdateMtab();
68 60
69 // Read the mtab file entries into |mtab|. 61 // Read the mtab file entries into |mtab|.
70 void ReadMtab(MountMap* mtab); 62 void ReadMtab(MountMap* mtab);
71 63
72 // For a new device mounted at |mount_point|, see if it is a media device by 64 // For a new device mounted at |mount_point|, see if it is a media device by
73 // checking for the existence of a DCIM directory. 65 // checking for the existence of a DCIM directory.
74 // If it is a media device, return true, otherwise return false. 66 // If it is a media device, return true, otherwise return false.
75 // Mac OS X behaves similarly, but this is not the only heuristic it uses. 67 // Mac OS X behaves similarly, but this is not the only heuristic it uses.
76 // TODO(vandebo) Try to figure out how Mac OS X decides this. 68 // TODO(vandebo) Try to figure out how Mac OS X decides this.
77 bool IsMediaDevice(const MountPoint& mount_point); 69 bool IsMediaDevice(const std::string& mount_point);
78 70
79 // Add a media device with a given device and mount device. Assign it a device 71 // Add a media device with a given device and mount device. Assign it a device
80 // id as well. 72 // id as well.
81 void AddNewDevice(const MountDevice& mount_device, 73 void AddNewDevice(const std::string& mount_device,
82 const MountPoint& mount_point, 74 const std::string& mount_point,
83 base::SystemMonitor::DeviceIdType* device_id); 75 base::SystemMonitor::DeviceIdType* device_id);
84 76
85 // Remove a media device with a given device id. 77 // Remove a media device with a given device id.
86 void RemoveOldDevice(const base::SystemMonitor::DeviceIdType& device_id); 78 void RemoveOldDevice(const base::SystemMonitor::DeviceIdType& device_id);
87 79
88 // Whether Init() has been called or not. 80 // Whether Init() has been called or not.
89 bool initialized_; 81 bool initialized_;
90 82
91 // Mtab file that lists the mount points. 83 // Mtab file that lists the mount points.
92 const FilePath mtab_path_; 84 const FilePath mtab_path_;
(...skipping 12 matching lines...) Expand all
105 97
106 // Set of known file systems that we care about. 98 // Set of known file systems that we care about.
107 std::set<std::string> known_file_systems_; 99 std::set<std::string> known_file_systems_;
108 100
109 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); 101 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux);
110 }; 102 };
111 103
112 } // namespace content 104 } // namespace content
113 105
114 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ 106 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/media_device_notifications_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698