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

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: call init method from ctor 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 void OnFilePathChanged(const FilePath& path);
30
31 private:
32 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>;
33
34 typedef std::string MountDevice;
35 typedef std::string MountPoint;
36 typedef std::pair<MountDevice,
37 base::SystemMonitor::DeviceIdType> MountDeviceAndId;
38 typedef std::map<MountPoint, MountDeviceAndId> MountMap;
39
40 // A simple pass-through class. MediaDeviceNotificationsLinux cannot directly
41 // inherit from FilePathWatcher::Delegate due to multiple inheritance.
42 class WatcherDelegate : public base::files::FilePathWatcher::Delegate {
43 public:
44 explicit WatcherDelegate(MediaDeviceNotificationsLinux* notifier);
45
46 // base::files::FilePathWatcher::Delegate implementation.
47 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE;
48
49 private:
50 friend class base::RefCountedThreadSafe<WatcherDelegate>;
51
52 virtual ~WatcherDelegate();
53 MediaDeviceNotificationsLinux* notifier_;
54
55 DISALLOW_COPY_AND_ASSIGN(WatcherDelegate);
56 };
57
58 virtual ~MediaDeviceNotificationsLinux();
59
60 void InitOnFileThread();
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 new device mounted at |mount_point|, see if it is a media device by
69 // checking for the existence of a DCIM directory.
70 // If it is a media device, return true, otherwise return false.
71 // Mac OS X behaves similarly, but this is not the only heuristic it uses.
72 // TODO(vandebo) Try to figure out how Mac OS X decides this.
73 bool IsMediaDevice(const MountPoint& mount_point);
74
75 // Add a media device with a given device and mount device. Assign it a device
76 // id as well.
77 void AddNewDevice(const MountDevice& mount_device,
78 const MountPoint& mount_point,
79 base::SystemMonitor::DeviceIdType* device_id);
80
81 // Remove a media device with a given device id.
82 void RemoveOldDevice(const base::SystemMonitor::DeviceIdType& device_id);
83
84 // Whether Init() has been called or not.
85 bool initialized_;
86
87 // Mtab file that lists the mount points.
88 const FilePath mtab_path_;
89 // Watcher for |mtab_path_|.
90 base::files::FilePathWatcher file_watcher_;
91 // Delegate to receive watcher notifications.
92 scoped_refptr<WatcherDelegate> watcher_delegate_;
93
94 // Mapping of relevent mount points and their corresponding mount devices.
95 // Keep in mind on Linux, a device can be mounted at multiple mount points,
96 // and multiple devices can be mounted at a mount point.
97 MountMap mtab_;
98
99 // The lowest available device id number.
100 base::SystemMonitor::DeviceIdType current_device_id_;
101
102 // Set of known file systems that we care about.
103 std::set<std::string> known_file_systems_;
104
105 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux);
106 };
107
108 } // namespace content
109
110 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698