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

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: nits 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/files/file_path_watcher.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/system_monitor/system_monitor.h"
20 #include "content/common/content_export.h"
21
22 namespace content {
23
24 class CONTENT_EXPORT MediaDeviceNotificationsLinux
25 : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux> {
26 public:
27 explicit MediaDeviceNotificationsLinux(const FilePath& path);
28
29 // Must be called for MediaDeviceNotificationsLinux to work.
30 void InitOnFileThread();
31
32 void OnFilePathChanged(const FilePath& path);
33
34 private:
35 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>;
36
37 typedef std::string MountDevice;
38 typedef std::string MountPoint;
39 typedef std::pair<MountDevice,
40 base::SystemMonitor::DeviceIdType> MountDeviceAndId;
41 typedef std::map<MountPoint, MountDeviceAndId> MountMap;
42
43 // A simple pass-through class. MediaDeviceNotificationsLinux cannot directly
44 // inherit from FilePathWatcher::Delegate due to multiple inheritance.
45 class WatcherDelegate : public base::files::FilePathWatcher::Delegate {
46 public:
47 explicit WatcherDelegate(MediaDeviceNotificationsLinux* notifier);
48
49 // base::files::FilePathWatcher::Delegate implementation.
50 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE;
51
52 private:
53 friend class base::RefCountedThreadSafe<WatcherDelegate>;
54
55 virtual ~WatcherDelegate();
56 MediaDeviceNotificationsLinux* notifier_;
57
58 DISALLOW_COPY_AND_ASSIGN(WatcherDelegate);
59 };
60
61 virtual ~MediaDeviceNotificationsLinux();
62
63 // Parse the mtab file and find all changes.
64 void UpdateMtab();
65
66 // Read the mtab file entries into |mtab|.
67 void ReadMtab(MountMap* mtab);
68
69 // For a new device mounted at |mount_point|, see if it is a media device by
70 // checking for the existence of a DCIM directory.
71 // If it is a media device, return true, otherwise return false.
72 // Mac OS X behaves similarly, but this is not the only heuristic it uses.
73 // TODO(vandebo) Try to figure out how Mac OS X decides this.
74 bool IsMediaDevice(const MountPoint& mount_point);
75
76 // Add a media device with a given device and mount device. Assign it a device
77 // id as well.
78 void AddNewDevice(const MountDevice& mount_device,
79 const MountPoint& mount_point,
80 base::SystemMonitor::DeviceIdType* device_id);
81
82 // Remove a media device with a given device id.
83 void RemoveOldDevice(const base::SystemMonitor::DeviceIdType& device_id);
84
85 // Whether Init() has been called or not.
86 bool initialized_;
87
88 // Mtab file that lists the mount points.
89 const FilePath mtab_path_;
90 // Watcher for |mtab_path_|.
91 base::files::FilePathWatcher file_watcher_;
92 // Delegate to receive watcher notifications.
93 scoped_refptr<WatcherDelegate> watcher_delegate_;
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 // The lowest available device id number.
101 base::SystemMonitor::DeviceIdType current_device_id_;
102
103 // Set of known file systems that we care about.
104 std::set<std::string> known_file_systems_;
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