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

Unified 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: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media_device_notifications_linux.h
===================================================================
--- content/browser/media_device_notifications_linux.h (revision 0)
+++ content/browser/media_device_notifications_linux.h (revision 0)
@@ -0,0 +1,105 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
+#define CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+#include <utility>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
+#include "base/system_monitor/system_monitor.h"
+#include "content/common/content_export.h"
+
+struct inotify_event;
+
+namespace content {
+
+class CONTENT_EXPORT MediaDeviceNotificationsLinux
+ : public base::MessagePumpLibevent::Watcher,
+ public base::RefCounted<MediaDeviceNotificationsLinux> {
jam 2012/03/05 23:31:54 i think you want RefCountedThreadSafe?
Lei Zhang 2012/03/05 23:44:35 Done.
+ public:
+ explicit MediaDeviceNotificationsLinux(const FilePath& path);
+
+ // Must be called for MediaDeviceNotificationsLinux to work.
+ void InitOnFileThread();
+
+ // base::MessagePump:Libevent::Watcher implementation
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
+ virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
+
+ private:
+ friend class base::RefCounted<MediaDeviceNotificationsLinux>;
+
+ typedef std::string MountDevice;
+ typedef std::string MountPoint;
+ typedef std::pair<MountPoint, MountDevice> MountEntry;
+
+ typedef std::map<MountPoint, MountDevice> MountMap;
+
+ // Map with key: (mount point, mount device) value: device id.
+ typedef std::map<MountEntry, base::SystemMonitor::DeviceIdType> DeviceIdMap;
+
+ virtual ~MediaDeviceNotificationsLinux();
+
+ // Helper function to close and clear |inotify_fd_|.
+ void CleanupInotifyFD();
+
+ // Process a single event from Inotify.
+ bool ProcessInotifyEvent(inotify_event* event);
+
+ // Parse the mtab file and find all changes.
+ void UpdateMtab();
+
+ // Read the mtab file entries into |mtab|.
+ void ReadMtab(MountMap* mtab);
+
+ // Add and remove media devices with a given mount point and mount device.
+ void AddNewDevice(const MountPoint& mount_point,
+ const MountDevice& mount_device);
+ void RemoveOldDevice(const MountPoint& mount_point,
+ const MountDevice& mount_device);
+
+ // Whether Init() has been called or not.
+ bool initialized_;
+
+ // The directory to watch with Inotify.
+ const FilePath watch_dir_;
+ // The file in |watch_dir_| to watch for.
+ const FilePath watch_file_;
+
+ // Inotify file descriptor and watch descriptor.
+ int inotify_fd_;
+ int inotify_wd_;
+
+ // Watcher for |inotify_fd_|.
+ base::MessagePumpLibevent::FileDescriptorWatcher inotify_watcher_;
+
+ // Mapping of relevent mount points and their corresponding mount devices.
+ // Keep in mind on Linux, a device can be mounted at multiple mount points,
+ // and multiple devices can be mounted at a mount point.
+ MountMap mtab_;
+
+ // Mapping of mount entries to unique device ids.
+ DeviceIdMap device_id_map_;
+
+ // The lowest available device id number.
+ base::SystemMonitor::DeviceIdType current_device_id_;
+
+ // Set of known file systems that we care about.
+ std::set<std::string> known_file_systems_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinux);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_MEDIA_DEVICE_NOTIFICATIONS_LINUX_H_
Property changes on: content/browser/media_device_notifications_linux.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698