| 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 // MediaDeviceNotificationsLinux listens for mount point changes and notifies | |
| 6 // the SystemMonitor about the addition and deletion of media devices. | |
| 7 | |
| 8 #ifndef CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ | |
| 9 #define CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ | |
| 10 #pragma once | |
| 11 | |
| 12 #include <map> | |
| 13 #include <set> | |
| 14 #include <string> | |
| 15 #include <utility> | |
| 16 | |
| 17 #include "base/basictypes.h" | |
| 18 #include "base/compiler_specific.h" | |
| 19 #include "base/files/file_path_watcher.h" | |
| 20 #include "base/memory/ref_counted.h" | |
| 21 #include "base/system_monitor/system_monitor.h" | |
| 22 #include "content/common/content_export.h" | |
| 23 | |
| 24 class FilePath; | |
| 25 | |
| 26 namespace content { | |
| 27 | |
| 28 class CONTENT_EXPORT MediaDeviceNotificationsLinux | |
| 29 : public base::RefCountedThreadSafe<MediaDeviceNotificationsLinux> { | |
| 30 public: | |
| 31 explicit MediaDeviceNotificationsLinux(const FilePath& path); | |
| 32 | |
| 33 // Must be called for MediaDeviceNotificationsLinux to work. | |
| 34 void Init(); | |
| 35 | |
| 36 protected: | |
| 37 // Avoids code deleting the object while there are references to it. | |
| 38 // Aside from the base::RefCountedThreadSafe friend class, and derived | |
| 39 // classes, any attempts to call this dtor will result in a compile-time | |
| 40 // error. | |
| 41 virtual ~MediaDeviceNotificationsLinux(); | |
| 42 | |
| 43 virtual void OnFilePathChanged(const FilePath& path); | |
| 44 | |
| 45 private: | |
| 46 friend class base::RefCountedThreadSafe<MediaDeviceNotificationsLinux>; | |
| 47 | |
| 48 class WatcherDelegate; | |
| 49 | |
| 50 // (mount device, device id) | |
| 51 typedef std::pair<std::string, | |
| 52 base::SystemMonitor::DeviceIdType> MountDeviceAndId; | |
| 53 // Mapping of mount points to MountDeviceAndId. | |
| 54 typedef std::map<std::string, MountDeviceAndId> MountMap; | |
| 55 | |
| 56 void InitOnFileThread(); | |
| 57 | |
| 58 // Parse the mtab file and find all changes. | |
| 59 void UpdateMtab(); | |
| 60 | |
| 61 // Read the mtab file entries into |mtab|. | |
| 62 void ReadMtab(MountMap* mtab); | |
| 63 | |
| 64 // For a new device mounted at |mount_point|, see if it is a media device by | |
| 65 // checking for the existence of a DCIM directory. | |
| 66 // If it is a media device, return true, otherwise return false. | |
| 67 // Mac OS X behaves similarly, but this is not the only heuristic it uses. | |
| 68 // TODO(vandebo) Try to figure out how Mac OS X decides this. | |
| 69 bool IsMediaDevice(const std::string& mount_point); | |
| 70 | |
| 71 // Add a media device with a given device and mount device. Assign it a device | |
| 72 // id as well. | |
| 73 void AddNewDevice(const std::string& mount_device, | |
| 74 const std::string& mount_point, | |
| 75 base::SystemMonitor::DeviceIdType* device_id); | |
| 76 | |
| 77 // Remove a media device with a given device id. | |
| 78 void RemoveOldDevice(const base::SystemMonitor::DeviceIdType& device_id); | |
| 79 | |
| 80 // Whether Init() has been called or not. | |
| 81 bool initialized_; | |
| 82 | |
| 83 // Mtab file that lists the mount points. | |
| 84 const FilePath mtab_path_; | |
| 85 // Watcher for |mtab_path_|. | |
| 86 base::files::FilePathWatcher file_watcher_; | |
| 87 // Delegate to receive watcher notifications. | |
| 88 scoped_refptr<WatcherDelegate> watcher_delegate_; | |
| 89 | |
| 90 // Mapping of relevent mount points and their corresponding mount devices. | |
| 91 // Keep in mind on Linux, a device can be mounted at multiple mount points, | |
| 92 // and multiple devices can be mounted at a mount point. | |
| 93 MountMap mtab_; | |
| 94 | |
| 95 // The lowest available device id number. | |
| 96 base::SystemMonitor::DeviceIdType current_device_id_; | |
| 97 | |
| 98 // Set of known file systems that we care about. | |
| 99 std::set<std::string> known_file_systems_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux); | |
| 102 }; | |
| 103 | |
| 104 } // namespace content | |
| 105 | |
| 106 #endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_ | |
| OLD | NEW |