| 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 // chromeos::MediaDeviceNotifications listens for mount point changes and | |
| 6 // notifies the SystemMonitor about the addition and deletion of media devices. | |
| 7 | |
| 8 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_CHROMEOS_H_ | |
| 9 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_CHROMEOS_H_ | |
| 10 | |
| 11 #if !defined(OS_CHROMEOS) | |
| 12 #error "Should only be used on ChromeOS." | |
| 13 #endif | |
| 14 | |
| 15 #include <map> | |
| 16 #include <string> | |
| 17 | |
| 18 #include "base/basictypes.h" | |
| 19 #include "base/compiler_specific.h" | |
| 20 #include "base/memory/ref_counted.h" | |
| 21 #include "base/system_monitor/system_monitor.h" | |
| 22 #include "chromeos/disks/disk_mount_manager.h" | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 class MediaDeviceNotifications | |
| 27 : public base::RefCountedThreadSafe<MediaDeviceNotifications>, | |
| 28 public disks::DiskMountManager::Observer { | |
| 29 public: | |
| 30 MediaDeviceNotifications(); | |
| 31 | |
| 32 virtual void DiskChanged(disks::DiskMountManagerEventType event, | |
| 33 const disks::DiskMountManager::Disk* disk) OVERRIDE; | |
| 34 virtual void DeviceChanged(disks::DiskMountManagerEventType event, | |
| 35 const std::string& device_path) OVERRIDE; | |
| 36 virtual void MountCompleted( | |
| 37 disks::DiskMountManager::MountEvent event_type, | |
| 38 MountError error_code, | |
| 39 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 friend class base::RefCountedThreadSafe<MediaDeviceNotifications>; | |
| 43 | |
| 44 // Mapping of mount points to mount device IDs. | |
| 45 typedef std::map<std::string, std::string> MountMap; | |
| 46 | |
| 47 // Private to avoid code deleting the object. | |
| 48 virtual ~MediaDeviceNotifications(); | |
| 49 | |
| 50 // Checks existing mount points map for media devices. For each mount point, | |
| 51 // call CheckMountedPathOnFileThread() below. | |
| 52 void CheckExistingMountPointsOnUIThread(); | |
| 53 | |
| 54 // Checks if the mount point in |mount_info| is a media device. If it is, | |
| 55 // then continue with AddMountedPathOnUIThread() below. | |
| 56 void CheckMountedPathOnFileThread( | |
| 57 const disks::DiskMountManager::MountPointInfo& mount_info); | |
| 58 | |
| 59 // Adds the mount point in |mount_info| to |mount_map_| and send a media | |
| 60 // device attach notification. | |
| 61 void AddMountedPathOnUIThread( | |
| 62 const disks::DiskMountManager::MountPointInfo& mount_info); | |
| 63 | |
| 64 // Mapping of relevant mount points and their corresponding mount devices. | |
| 65 // Only accessed on the UI thread. | |
| 66 MountMap mount_map_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotifications); | |
| 69 }; | |
| 70 | |
| 71 } // namespace chromeos | |
| 72 | |
| 73 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_DEVICE_NOTIFICATIONS_CHROMEOS_H_ | |
| OLD | NEW |