- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / storage_monitor / storage_monitor_chromeos.h
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::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.
8
9 #ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_
10 #define CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_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/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"
25
26 class MediaTransferProtocolDeviceObserverLinux;
27
28 namespace chromeos {
29
30 class StorageMonitorCros : public StorageMonitor,
31                            public disks::DiskMountManager::Observer {
32  public:
33   // Should only be called by browser start up code.
34   // Use StorageMonitor::GetInstance() instead.
35   StorageMonitorCros();
36   virtual ~StorageMonitorCros();
37
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;
41
42  protected:
43   void SetMediaTransferProtocolManagerForTest(
44       device::MediaTransferProtocolManager* test_manager);
45
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;
58
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;
67
68  private:
69   // Mapping of mount path to removable mass storage info.
70   typedef std::map<std::string, StorageInfo> MountMap;
71
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();
75
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
78   // a DCIM folder.
79   void AddMountedPath(const disks::DiskMountManager::MountPointInfo& mount_info,
80                       bool has_dcim);
81
82   // Mapping of relevant mount points and their corresponding mount devices.
83   MountMap mount_map_;
84
85   scoped_ptr<device::MediaTransferProtocolManager>
86       media_transfer_protocol_manager_;
87   scoped_ptr<MediaTransferProtocolDeviceObserverLinux>
88       media_transfer_protocol_device_observer_;
89
90   base::WeakPtrFactory<StorageMonitorCros> weak_ptr_factory_;
91
92   DISALLOW_COPY_AND_ASSIGN(StorageMonitorCros);
93 };
94
95 }  // namespace chromeos
96
97 #endif  // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_CHROMEOS_H_