1 // Copyright 2014 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.
5 // StorageMonitorCros listens for mount point changes and notifies listeners
6 // about the addition and deletion of media devices. This class lives on the
9 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_
10 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_
12 #if !defined(OS_CHROMEOS)
13 #error "Should only be used on ChromeOS."
19 #include "base/basictypes.h"
20 #include "base/compiler_specific.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h"
23 #include "chromeos/disks/disk_mount_manager.h"
24 #include "components/storage_monitor/storage_monitor.h"
26 namespace storage_monitor
{
28 class MediaTransferProtocolDeviceObserverLinux
;
30 class StorageMonitorCros
: public StorageMonitor
,
31 public chromeos::disks::DiskMountManager::Observer
{
33 // Should only be called by browser start up code.
34 // Use StorageMonitor::GetInstance() instead.
36 ~StorageMonitorCros() override
;
38 // Sets up disk listeners and issues notifications for any discovered
39 // mount points. Sets up MTP manager and listeners.
43 void SetMediaTransferProtocolManagerForTest(
44 device::MediaTransferProtocolManager
* test_manager
);
46 // chromeos::disks::DiskMountManager::Observer implementation.
48 chromeos::disks::DiskMountManager::DiskEvent event
,
49 const chromeos::disks::DiskMountManager::Disk
* disk
) override
;
50 void OnDeviceEvent(chromeos::disks::DiskMountManager::DeviceEvent event
,
51 const std::string
& device_path
) override
;
52 void OnMountEvent(chromeos::disks::DiskMountManager::MountEvent event
,
53 chromeos::MountError error_code
,
54 const chromeos::disks::DiskMountManager::MountPointInfo
&
56 void OnFormatEvent(chromeos::disks::DiskMountManager::FormatEvent event
,
57 chromeos::FormatError error_code
,
58 const std::string
& device_path
) override
;
60 // StorageMonitor implementation.
61 bool GetStorageInfoForPath(const base::FilePath
& path
,
62 StorageInfo
* device_info
) const override
;
63 void EjectDevice(const std::string
& device_id
,
64 base::Callback
<void(EjectStatus
)> callback
) override
;
65 device::MediaTransferProtocolManager
* media_transfer_protocol_manager()
69 // Mapping of mount path to removable mass storage info.
70 typedef std::map
<std::string
, StorageInfo
> MountMap
;
72 // Helper method that checks existing mount points to see if they are media
73 // devices. Eventually calls AddMountedPath for all mount points.
74 void CheckExistingMountPoints();
76 // Adds the mount point in |mount_info| to |mount_map_| and send a media
77 // device attach notification. |has_dcim| is true if the attached device has
80 const chromeos::disks::DiskMountManager::MountPointInfo
& mount_info
,
83 // Mapping of relevant mount points and their corresponding mount devices.
86 scoped_ptr
<device::MediaTransferProtocolManager
>
87 media_transfer_protocol_manager_
;
88 scoped_ptr
<MediaTransferProtocolDeviceObserverLinux
>
89 media_transfer_protocol_device_observer_
;
91 base::WeakPtrFactory
<StorageMonitorCros
> weak_ptr_factory_
;
93 DISALLOW_COPY_AND_ASSIGN(StorageMonitorCros
);
96 } // namespace storage_monitor
98 #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_