| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // chromeos::RemovableDeviceNotificationsCros listens for mount point changes | 5 // chromeos::StorageMonitorCros listens for mount point changes and notifies |
| 6 // and notifies listeners about the addition and deletion of media | 6 // listeners about the addition and deletion of media devices. |
| 7 // devices. | |
| 8 | 7 |
| 9 #ifndef CHROME_BROWSER_STORAGE_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H
_ | 8 #ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_ |
| 10 #define CHROME_BROWSER_STORAGE_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H
_ | 9 #define CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_ |
| 11 | 10 |
| 12 #if !defined(OS_CHROMEOS) | 11 #if !defined(OS_CHROMEOS) |
| 13 #error "Should only be used on ChromeOS." | 12 #error "Should only be used on ChromeOS." |
| 14 #endif | 13 #endif |
| 15 | 14 |
| 16 #include <map> | 15 #include <map> |
| 17 #include <string> | 16 #include <string> |
| 18 | 17 |
| 19 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 20 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 21 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 22 #include "chrome/browser/storage_monitor/storage_monitor.h" | 21 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 23 #include "chromeos/disks/disk_mount_manager.h" | 22 #include "chromeos/disks/disk_mount_manager.h" |
| 24 | 23 |
| 25 namespace chromeos { | 24 namespace chromeos { |
| 26 | 25 |
| 27 class RemovableDeviceNotificationsCros | 26 class StorageMonitorCros |
| 28 : public chrome::StorageMonitor, | 27 : public chrome::StorageMonitor, |
| 29 public base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>, | 28 public base::RefCountedThreadSafe<StorageMonitorCros>, |
| 30 public disks::DiskMountManager::Observer { | 29 public disks::DiskMountManager::Observer { |
| 31 public: | 30 public: |
| 32 // Should only be called by browser start up code. Use GetInstance() instead. | 31 // Should only be called by browser start up code. Use GetInstance() instead. |
| 33 RemovableDeviceNotificationsCros(); | 32 StorageMonitorCros(); |
| 34 | 33 |
| 35 virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event, | 34 virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event, |
| 36 const disks::DiskMountManager::Disk* disk) OVERRIDE; | 35 const disks::DiskMountManager::Disk* disk) OVERRIDE; |
| 37 virtual void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event, | 36 virtual void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event, |
| 38 const std::string& device_path) OVERRIDE; | 37 const std::string& device_path) OVERRIDE; |
| 39 virtual void OnMountEvent( | 38 virtual void OnMountEvent( |
| 40 disks::DiskMountManager::MountEvent event, | 39 disks::DiskMountManager::MountEvent event, |
| 41 MountError error_code, | 40 MountError error_code, |
| 42 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; | 41 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; |
| 43 virtual void OnFormatEvent(disks::DiskMountManager::FormatEvent event, | 42 virtual void OnFormatEvent(disks::DiskMountManager::FormatEvent event, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 struct StorageObjectInfo { | 57 struct StorageObjectInfo { |
| 59 // Basic details {storage device name, location and identifier}. | 58 // Basic details {storage device name, location and identifier}. |
| 60 StorageInfo storage_info; | 59 StorageInfo storage_info; |
| 61 | 60 |
| 62 // Device storage size. | 61 // Device storage size. |
| 63 uint64 storage_size_in_bytes; | 62 uint64 storage_size_in_bytes; |
| 64 }; | 63 }; |
| 65 | 64 |
| 66 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>; | 65 friend class base::RefCountedThreadSafe<StorageMonitorCros>; |
| 67 | 66 |
| 68 // Mapping of mount path to removable mass storage info. | 67 // Mapping of mount path to removable mass storage info. |
| 69 typedef std::map<std::string, StorageObjectInfo> MountMap; | 68 typedef std::map<std::string, StorageObjectInfo> MountMap; |
| 70 | 69 |
| 71 // Private to avoid code deleting the object. | 70 // Private to avoid code deleting the object. |
| 72 virtual ~RemovableDeviceNotificationsCros(); | 71 virtual ~StorageMonitorCros(); |
| 73 | 72 |
| 74 // Checks existing mount points map for media devices. For each mount point, | 73 // Checks existing mount points map for media devices. For each mount point, |
| 75 // call CheckMountedPathOnFileThread() below. | 74 // call CheckMountedPathOnFileThread() below. |
| 76 void CheckExistingMountPointsOnUIThread(); | 75 void CheckExistingMountPointsOnUIThread(); |
| 77 | 76 |
| 78 // Checks if the mount point in |mount_info| is a media device. If it is, | 77 // Checks if the mount point in |mount_info| is a media device. If it is, |
| 79 // then continue with AddMountedPathOnUIThread() below. | 78 // then continue with AddMountedPathOnUIThread() below. |
| 80 void CheckMountedPathOnFileThread( | 79 void CheckMountedPathOnFileThread( |
| 81 const disks::DiskMountManager::MountPointInfo& mount_info); | 80 const disks::DiskMountManager::MountPointInfo& mount_info); |
| 82 | 81 |
| 83 // Adds the mount point in |mount_info| to |mount_map_| and send a media | 82 // Adds the mount point in |mount_info| to |mount_map_| and send a media |
| 84 // device attach notification. |has_dcim| is true if the attached device has | 83 // device attach notification. |has_dcim| is true if the attached device has |
| 85 // a DCIM folder. | 84 // a DCIM folder. |
| 86 void AddMountedPathOnUIThread( | 85 void AddMountedPathOnUIThread( |
| 87 const disks::DiskMountManager::MountPointInfo& mount_info, | 86 const disks::DiskMountManager::MountPointInfo& mount_info, |
| 88 bool has_dcim); | 87 bool has_dcim); |
| 89 | 88 |
| 90 // Mapping of relevant mount points and their corresponding mount devices. | 89 // Mapping of relevant mount points and their corresponding mount devices. |
| 91 // Only accessed on the UI thread. | 90 // Only accessed on the UI thread. |
| 92 MountMap mount_map_; | 91 MountMap mount_map_; |
| 93 | 92 |
| 94 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCros); | 93 DISALLOW_COPY_AND_ASSIGN(StorageMonitorCros); |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 } // namespace chromeos | 96 } // namespace chromeos |
| 98 | 97 |
| 99 #endif // CHROME_BROWSER_STORAGE_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEO
S_H_ | 98 #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_ |
| OLD | NEW |