OLD | NEW |
(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 typedef std::map<MountPoint, MountDevice> MountMap; |
| 47 |
| 48 // Map with key: (mount point, mount device) value: device id. |
| 49 typedef std::map<MountEntry, base::SystemMonitor::DeviceIdType> DeviceIdMap; |
| 50 |
| 51 virtual ~MediaDeviceNotificationsLinux(); |
| 52 |
| 53 // Helper function to close and clear |inotify_fd_|. |
| 54 void CleanupInotifyFD(); |
| 55 |
| 56 // Process a single event from Inotify. |
| 57 bool ProcessInotifyEvent(inotify_event* event); |
| 58 |
| 59 // Parse the mtab file and find all changes. |
| 60 void UpdateMtab(); |
| 61 |
| 62 // Read the mtab file entries into |mtab|. |
| 63 void ReadMtab(MountMap* mtab); |
| 64 |
| 65 // Add and remove media devices with a given mount point and mount device. |
| 66 void AddNewDevice(const MountPoint& mount_point, |
| 67 const MountDevice& mount_device); |
| 68 void RemoveOldDevice(const MountPoint& mount_point, |
| 69 const MountDevice& mount_device); |
| 70 |
| 71 // Whether Init() has been called or not. |
| 72 bool initialized_; |
| 73 |
| 74 // The directory to watch with Inotify. |
| 75 const FilePath watch_dir_; |
| 76 // The file in |watch_dir_| to watch for. |
| 77 const FilePath watch_file_; |
| 78 |
| 79 // Inotify file descriptor and watch descriptor. |
| 80 int inotify_fd_; |
| 81 int inotify_wd_; |
| 82 |
| 83 // Watcher for |inotify_fd_|. |
| 84 base::MessagePumpLibevent::FileDescriptorWatcher inotify_watcher_; |
| 85 |
| 86 // Mapping of relevent mount points and their corresponding mount devices. |
| 87 // Keep in mind on Linux, a device can be mounted at multiple mount points, |
| 88 // and multiple devices can be mounted at a mount point. |
| 89 MountMap mtab_; |
| 90 |
| 91 // Mapping of mount entries to unique device ids. |
| 92 DeviceIdMap device_id_map_; |
| 93 |
| 94 // The lowest available device id number. |
| 95 base::SystemMonitor::DeviceIdType current_device_id_; |
| 96 |
| 97 // Set of known file systems that we care about. |
| 98 std::set<std::string> known_file_systems_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); |
| 101 }; |
| 102 |
| 103 } // namespace content |
| 104 |
| 105 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ |
OLD | NEW |