- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / file_manager / volume_manager.h
1 // Copyright 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_
7
8 #include "base/basictypes.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/prefs/pref_change_registrar.h"
13 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
14 #include "chromeos/disks/disk_mount_manager.h"
15 #include "chromeos/dbus/cros_disks_client.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
17
18 class Profile;
19
20 namespace chromeos {
21 class PowerManagerClient;
22 }  // namespace chromeos
23
24 namespace content {
25 class BrowserContext;
26 }  // namespace content
27
28 namespace drive {
29 class DriveIntegrationService;
30 }  // namespace drive
31
32 namespace file_manager {
33
34 class MountedDiskMonitor;
35 class VolumeManagerObserver;
36
37 // This manager manages "Drive" and "Downloads" in addition to disks managed
38 // by DiskMountManager.
39 enum VolumeType {
40   VOLUME_TYPE_GOOGLE_DRIVE,
41   VOLUME_TYPE_DOWNLOADS_DIRECTORY,
42   VOLUME_TYPE_REMOVABLE_DISK_PARTITION,
43   VOLUME_TYPE_MOUNTED_ARCHIVE_FILE,
44 };
45
46 struct VolumeInfo {
47   VolumeInfo();
48   ~VolumeInfo();
49
50   // The type of mounted volume.
51   VolumeType type;
52
53   // The type of device. (e.g. USB, SD card, DVD etc.)
54   chromeos::DeviceType device_type;
55
56   // The source path of the volume.
57   // E.g.:
58   // - /home/chronos/user/Downloads/zipfile_path.zip
59   base::FilePath source_path;
60
61   // The mount path of the volume.
62   // E.g.:
63   // - /home/chronos/user/Downloads
64   // - /media/removable/usb1
65   // - /media/archive/zip1
66   base::FilePath mount_path;
67
68   // The mounting condition. See the enum for the details.
69   chromeos::disks::MountCondition mount_condition;
70
71   // Path of the system device this device's block is a part of.
72   // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/)
73   base::FilePath system_path_prefix;
74
75   // If disk is a parent, then its label, else parents label.
76   // (e.g. "TransMemory")
77   std::string drive_label;
78
79   // Is the device is a parent device (i.e. sdb rather than sdb1).
80   bool is_parent;
81
82   // True if the volume is read only.
83   bool is_read_only;
84 };
85
86 // Manages "Volume"s for file manager. Here are "Volume"s.
87 // - Drive File System (not yet supported).
88 // - Downloads directory.
89 // - Removable disks (volume will be created for each partition, not only one
90 //   for a device).
91 // - Mounted zip archives.
92 class VolumeManager : public BrowserContextKeyedService,
93                       public drive::DriveIntegrationServiceObserver,
94                       public chromeos::disks::DiskMountManager::Observer {
95  public:
96   VolumeManager(Profile* profile,
97                 drive::DriveIntegrationService* drive_integration_service,
98                 chromeos::PowerManagerClient* power_manager_client,
99                 chromeos::disks::DiskMountManager* disk_mount_manager);
100   virtual ~VolumeManager();
101
102   // Returns the instance corresponding to the |context|.
103   static VolumeManager* Get(content::BrowserContext* context);
104
105   // Intializes this instance.
106   void Initialize();
107
108   // Disposes this instance.
109   virtual void Shutdown() OVERRIDE;
110
111   // Adds an observer.
112   void AddObserver(VolumeManagerObserver* observer);
113
114   // Removes the observer.
115   void RemoveObserver(VolumeManagerObserver* observer);
116
117   // Returns the information about all volumes currently mounted.
118   std::vector<VolumeInfo> GetVolumeInfoList() const;
119
120   // drive::DriveIntegrationServiceObserver overrides.
121   virtual void OnFileSystemMounted() OVERRIDE;
122   virtual void OnFileSystemBeingUnmounted() OVERRIDE;
123
124   // chromeos::disks::DiskMountManager::Observer overrides.
125   virtual void OnDiskEvent(
126       chromeos::disks::DiskMountManager::DiskEvent event,
127       const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE;
128   virtual void OnDeviceEvent(
129       chromeos::disks::DiskMountManager::DeviceEvent event,
130       const std::string& device_path) OVERRIDE;
131   virtual void OnMountEvent(
132       chromeos::disks::DiskMountManager::MountEvent event,
133       chromeos::MountError error_code,
134       const chromeos::disks::DiskMountManager::MountPointInfo& mount_info)
135       OVERRIDE;
136   virtual void OnFormatEvent(
137       chromeos::disks::DiskMountManager::FormatEvent event,
138       chromeos::FormatError error_code,
139       const std::string& device_path) OVERRIDE;
140
141   // Called on change to kExternalStorageDisabled pref.
142   void OnExternalStorageDisabledChanged();
143
144  private:
145   Profile* profile_;
146   drive::DriveIntegrationService* drive_integration_service_;
147   chromeos::disks::DiskMountManager* disk_mount_manager_;
148   scoped_ptr<MountedDiskMonitor> mounted_disk_monitor_;
149   PrefChangeRegistrar pref_change_registrar_;
150   ObserverList<VolumeManagerObserver> observers_;
151   DISALLOW_COPY_AND_ASSIGN(VolumeManager);
152 };
153
154 }  // namespace file_manager
155
156 #endif  // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_