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

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

Issue 9560008: Implement Linux media notifier. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: with tests Created 8 years, 9 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
6 #define CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
7 #pragma once
8
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <utility>
13
14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h"
16 #include "base/file_path.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/message_loop.h"
19 #include "base/system_monitor/system_monitor.h"
20 #include "content/common/content_export.h"
21
22 struct inotify_event;
23
24 namespace content {
25
26 class CONTENT_EXPORT MediaDeviceNotificationsLinux
27 : public base::MessagePumpLibevent::Watcher,
28 public base::RefCounted<MediaDeviceNotificationsLinux> {
29 public:
30 explicit MediaDeviceNotificationsLinux(const FilePath& path);
31
32 // Must be called for MediaDeviceNotificationsLinux to work.
33 void InitOnFileThread();
34
35 // base::MessagePump:Libevent::Watcher implementation
36 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
37 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
38
39 private:
40 friend class base::RefCounted<MediaDeviceNotificationsLinux>;
41
42 typedef std::string MountDevice;
43 typedef std::string MountPoint;
44 typedef std::pair<MountPoint, MountDevice> MountEntry;
45
46 // Set of mount devices for a given mount point.
47 typedef std::set<MountDevice> MountDevices;
48
49 typedef std::map<MountPoint, MountDevices> MountMap;
50
51 // Map with key: (mount point, mount device) value: device id.
52 typedef std::map<MountEntry, base::SystemMonitor::DeviceIdType> DeviceIdMap;
53
54 virtual ~MediaDeviceNotificationsLinux();
55
56 // Helper function to close and clear |inotify_fd_|.
57 void CleanupInotifyFD();
58
59 // Process a single event from Inotify.
60 bool ProcessInotifyEvent(inotify_event* event);
61
62 // Parse the mtab file and find all changes.
63 void UpdateMtab();
64
65 // Read the mtab file entries into |mtab|.
66 void ReadMtab(MountMap* mtab);
67
68 // For a given mount point, check the new mount devices against existing
69 // known mount devices.
70 void CompareMountPointDevices(const MountPoint& mount_point,
71 const MountDevices& new_devices,
72 const MountDevices& old_devices);
73
74 // Add and remove media devices with a given mount point and mount device.
75 void AddNewMediaDevice(const MountPoint& mount_point,
76 const MountDevice& mount_device);
77 void RemoveOldMediaDevice(const MountPoint& mount_point,
78 const MountDevice& mount_device);
79
80 // Whether Init() has been called or not.
81 bool initialized_;
82
83 // The directory to watch with Inotify.
84 const FilePath watch_dir_;
85 // The file in |watch_dir_| to watch for.
86 const FilePath watch_file_;
87
88 // Inotify file descriptor and watch descriptor.
89 int inotify_fd_;
90 int inotify_wd_;
91
92 // Watcher for |inotify_fd_|.
93 base::MessagePumpLibevent::FileDescriptorWatcher inotify_watcher_;
94
95 // Mapping of relevent mount points and their corresponding mount devices.
96 // Keep in mind on Linux, a device can be mounted at multiple mount points,
97 // and multiple devices can be mounted at a mount point.
98 MountMap mtab_;
99
100 // Mapping of mount entries to unique device ids.
101 DeviceIdMap device_id_map_;
102
103 // The lowest available device id number.
104 base::SystemMonitor::DeviceIdType current_device_id_;
105
106 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux);
107 };
108
109 } // namespace content
110
111 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698