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

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: rebase 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 Init();
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 void InitOnFileThread();
64
65 // Parse the mtab file and find all changes.
66 void UpdateMtab();
67
68 // Read the mtab file entries into |mtab|.
69 void ReadMtab(MountMap* mtab);
70
71 // For a new device mounted at |mount_point|, see if it is a media device by
72 // checking for the existence of a DCIM directory.
73 // If it is a media device, return true, otherwise return false.
74 // Mac OS X behaves similarly, but this is not the only heuristic it uses.
75 // TODO(vandebo) Try to figure out how Mac OS X decides this.
76 bool IsMediaDevice(const MountPoint& mount_point);
77
78 // Add a media device with a given device and mount device. Assign it a device
79 // id as well.
80 void AddNewDevice(const MountDevice& mount_device,
81 const MountPoint& mount_point,
82 base::SystemMonitor::DeviceIdType* device_id);
83
84 // Remove a media device with a given device id.
85 void RemoveOldDevice(const base::SystemMonitor::DeviceIdType& device_id);
86
87 // Whether Init() has been called or not.
88 bool initialized_;
89
90 // Mtab file that lists the mount points.
91 const FilePath mtab_path_;
92 // Watcher for |mtab_path_|.
93 base::files::FilePathWatcher file_watcher_;
94 // Delegate to receive watcher notifications.
95 scoped_refptr<WatcherDelegate> watcher_delegate_;
96
97 // Mapping of relevent mount points and their corresponding mount devices.
98 // Keep in mind on Linux, a device can be mounted at multiple mount points,
99 // and multiple devices can be mounted at a mount point.
100 MountMap mtab_;
101
102 // The lowest available device id number.
103 base::SystemMonitor::DeviceIdType current_device_id_;
104
105 // Set of known file systems that we care about.
106 std::set<std::string> known_file_systems_;
107
108 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux);
109 };
110
111 } // namespace content
112
113 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/browser/media_device_notifications_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698