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::RemovableDeviceNotificationsCros listens for mount point changes | |
6 // and notifies listeners about the addition and deletion of media | |
7 // devices. | |
8 | |
9 #ifndef CHROME_BROWSER_STORAGE_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H
_ | |
10 #define CHROME_BROWSER_STORAGE_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEOS_H
_ | |
11 | |
12 #if !defined(OS_CHROMEOS) | |
13 #error "Should only be used on ChromeOS." | |
14 #endif | |
15 | |
16 #include <map> | |
17 #include <string> | |
18 | |
19 #include "base/basictypes.h" | |
20 #include "base/compiler_specific.h" | |
21 #include "base/memory/ref_counted.h" | |
22 #include "chrome/browser/storage_monitor/storage_monitor.h" | |
23 #include "chromeos/disks/disk_mount_manager.h" | |
24 | |
25 namespace chromeos { | |
26 | |
27 class RemovableDeviceNotificationsCros | |
28 : public chrome::StorageMonitor, | |
29 public base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>, | |
30 public disks::DiskMountManager::Observer { | |
31 public: | |
32 // Should only be called by browser start up code. Use GetInstance() instead. | |
33 RemovableDeviceNotificationsCros(); | |
34 | |
35 virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event, | |
36 const disks::DiskMountManager::Disk* disk) OVERRIDE; | |
37 virtual void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event, | |
38 const std::string& device_path) OVERRIDE; | |
39 virtual void OnMountEvent( | |
40 disks::DiskMountManager::MountEvent event, | |
41 MountError error_code, | |
42 const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE; | |
43 virtual void OnFormatEvent(disks::DiskMountManager::FormatEvent event, | |
44 FormatError error_code, | |
45 const std::string& device_path) OVERRIDE; | |
46 | |
47 // Finds the device that contains |path| and populates |device_info|. | |
48 // Returns false if unable to find the device. | |
49 virtual bool GetStorageInfoForPath( | |
50 const base::FilePath& path, | |
51 StorageInfo* device_info) const OVERRIDE; | |
52 | |
53 // Returns the storage size of the device present at |location|. If the | |
54 // device information is unavailable, returns zero. | |
55 virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE; | |
56 | |
57 private: | |
58 struct StorageObjectInfo { | |
59 // Basic details {storage device name, location and identifier}. | |
60 StorageInfo storage_info; | |
61 | |
62 // Device storage size. | |
63 uint64 storage_size_in_bytes; | |
64 }; | |
65 | |
66 friend class base::RefCountedThreadSafe<RemovableDeviceNotificationsCros>; | |
67 | |
68 // Mapping of mount path to removable mass storage info. | |
69 typedef std::map<std::string, StorageObjectInfo> MountMap; | |
70 | |
71 // Private to avoid code deleting the object. | |
72 virtual ~RemovableDeviceNotificationsCros(); | |
73 | |
74 // Checks existing mount points map for media devices. For each mount point, | |
75 // call CheckMountedPathOnFileThread() below. | |
76 void CheckExistingMountPointsOnUIThread(); | |
77 | |
78 // Checks if the mount point in |mount_info| is a media device. If it is, | |
79 // then continue with AddMountedPathOnUIThread() below. | |
80 void CheckMountedPathOnFileThread( | |
81 const disks::DiskMountManager::MountPointInfo& mount_info); | |
82 | |
83 // 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 | |
85 // a DCIM folder. | |
86 void AddMountedPathOnUIThread( | |
87 const disks::DiskMountManager::MountPointInfo& mount_info, | |
88 bool has_dcim); | |
89 | |
90 // Mapping of relevant mount points and their corresponding mount devices. | |
91 // Only accessed on the UI thread. | |
92 MountMap mount_map_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCros); | |
95 }; | |
96 | |
97 } // namespace chromeos | |
98 | |
99 #endif // CHROME_BROWSER_STORAGE_MONITOR_REMOVABLE_DEVICE_NOTIFICATIONS_CHROMEO
S_H_ | |
OLD | NEW |