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.
5 // chromeos::StorageMonitorCros listens for mount point changes and notifies
6 // listeners about the addition and deletion of media devices.
7 // This class lives on the UI thread.
9 #ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_
10 #define CHROME_BROWSER_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 "chrome/browser/storage_monitor/storage_monitor.h"
24 #include "chromeos/disks/disk_mount_manager.h"
26 class MediaTransferProtocolDeviceObserverLinux
;
30 class StorageMonitorCros
: public StorageMonitor
,
31 public disks::DiskMountManager::Observer
{
33 // Should only be called by browser start up code.
34 // Use StorageMonitor::GetInstance() instead.
36 virtual ~StorageMonitorCros();
38 // Sets up disk listeners and issues notifications for any discovered
39 // mount points. Sets up MTP manager and listeners.
40 virtual void Init() OVERRIDE
;
43 void SetMediaTransferProtocolManagerForTest(
44 device::MediaTransferProtocolManager
* test_manager
);
46 // disks::DiskMountManager::Observer implementation.
47 virtual void OnDiskEvent(disks::DiskMountManager::DiskEvent event
,
48 const disks::DiskMountManager::Disk
* disk
) OVERRIDE
;
49 virtual void OnDeviceEvent(disks::DiskMountManager::DeviceEvent event
,
50 const std::string
& device_path
) OVERRIDE
;
51 virtual void OnMountEvent(
52 disks::DiskMountManager::MountEvent event
,
53 MountError error_code
,
54 const disks::DiskMountManager::MountPointInfo
& mount_info
) OVERRIDE
;
55 virtual void OnFormatEvent(disks::DiskMountManager::FormatEvent event
,
56 FormatError error_code
,
57 const std::string
& device_path
) OVERRIDE
;
59 // StorageMonitor implementation.
60 virtual bool GetStorageInfoForPath(const base::FilePath
& path
,
61 StorageInfo
* device_info
) const OVERRIDE
;
62 virtual void EjectDevice(
63 const std::string
& device_id
,
64 base::Callback
<void(EjectStatus
)> callback
) OVERRIDE
;
65 virtual device::MediaTransferProtocolManager
*
66 media_transfer_protocol_manager() OVERRIDE
;
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
79 void AddMountedPath(const disks::DiskMountManager::MountPointInfo
& mount_info
,
82 // Mapping of relevant mount points and their corresponding mount devices.
85 scoped_ptr
<device::MediaTransferProtocolManager
>
86 media_transfer_protocol_manager_
;
87 scoped_ptr
<MediaTransferProtocolDeviceObserverLinux
>
88 media_transfer_protocol_device_observer_
;
90 base::WeakPtrFactory
<StorageMonitorCros
> weak_ptr_factory_
;
92 DISALLOW_COPY_AND_ASSIGN(StorageMonitorCros
);
95 } // namespace chromeos
97 #endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_