Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / volume_manager.h
blob3471652ef45bea106ed28e103fa6eeb686f52ebf
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/prefs/pref_change_registrar.h"
16 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
17 #include "chrome/browser/chromeos/file_system_provider/observer.h"
18 #include "chrome/browser/chromeos/file_system_provider/service.h"
19 #include "chrome/browser/local_discovery/storage/privet_volume_lister.h"
20 #include "chromeos/dbus/cros_disks_client.h"
21 #include "chromeos/disks/disk_mount_manager.h"
22 #include "components/keyed_service/core/keyed_service.h"
24 class Profile;
26 namespace chromeos {
27 class PowerManagerClient;
28 } // namespace chromeos
30 namespace content {
31 class BrowserContext;
32 } // namespace content
34 namespace drive {
35 class DriveIntegrationService;
36 } // namespace drive
38 namespace file_manager {
40 class MountedDiskMonitor;
41 class VolumeManagerObserver;
43 // This manager manages "Drive" and "Downloads" in addition to disks managed
44 // by DiskMountManager.
45 enum VolumeType {
46 VOLUME_TYPE_GOOGLE_DRIVE,
47 VOLUME_TYPE_DOWNLOADS_DIRECTORY,
48 VOLUME_TYPE_REMOVABLE_DISK_PARTITION,
49 VOLUME_TYPE_MOUNTED_ARCHIVE_FILE,
50 VOLUME_TYPE_CLOUD_DEVICE,
51 VOLUME_TYPE_PROVIDED, // File system provided by the FileSystemProvider API.
52 VOLUME_TYPE_TESTING
55 struct VolumeInfo {
56 VolumeInfo();
57 ~VolumeInfo();
59 // The ID of the volume.
60 std::string volume_id;
62 // The type of mounted volume.
63 VolumeType type;
65 // The type of device. (e.g. USB, SD card, DVD etc.)
66 chromeos::DeviceType device_type;
68 // The source path of the volume.
69 // E.g.:
70 // - /home/chronos/user/Downloads/zipfile_path.zip
71 base::FilePath source_path;
73 // The mount path of the volume.
74 // E.g.:
75 // - /home/chronos/user/Downloads
76 // - /media/removable/usb1
77 // - /media/archive/zip1
78 base::FilePath mount_path;
80 // The mounting condition. See the enum for the details.
81 chromeos::disks::MountCondition mount_condition;
83 // Path of the system device this device's block is a part of.
84 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/)
85 base::FilePath system_path_prefix;
87 // If disk is a parent, then its label, else parents label.
88 // (e.g. "TransMemory")
89 std::string drive_label;
91 // Is the device is a parent device (i.e. sdb rather than sdb1).
92 bool is_parent;
94 // True if the volume is read only.
95 bool is_read_only;
98 // Manages "Volume"s for file manager. Here are "Volume"s.
99 // - Drive File System (not yet supported).
100 // - Downloads directory.
101 // - Removable disks (volume will be created for each partition, not only one
102 // for a device).
103 // - Mounted zip archives.
104 class VolumeManager : public KeyedService,
105 public drive::DriveIntegrationServiceObserver,
106 public chromeos::disks::DiskMountManager::Observer,
107 public chromeos::file_system_provider::Observer {
108 public:
109 VolumeManager(
110 Profile* profile,
111 drive::DriveIntegrationService* drive_integration_service,
112 chromeos::PowerManagerClient* power_manager_client,
113 chromeos::disks::DiskMountManager* disk_mount_manager,
114 chromeos::file_system_provider::Service* file_system_provider_service);
115 virtual ~VolumeManager();
117 // Returns the instance corresponding to the |context|.
118 static VolumeManager* Get(content::BrowserContext* context);
120 // Intializes this instance.
121 void Initialize();
123 // Disposes this instance.
124 virtual void Shutdown() OVERRIDE;
126 // Adds an observer.
127 void AddObserver(VolumeManagerObserver* observer);
129 // Removes the observer.
130 void RemoveObserver(VolumeManagerObserver* observer);
132 // Returns the information about all volumes currently mounted.
133 std::vector<VolumeInfo> GetVolumeInfoList() const;
135 // Finds VolumeInfo for the given volume ID. If found, returns true and the
136 // result is written into |result|. Returns false otherwise.
137 bool FindVolumeInfoById(const std::string& volume_id,
138 VolumeInfo* result) const;
140 // For testing purpose, registers a native local file system poniting to
141 // |path| with DOWNLOADS type, and adds its volume info.
142 bool RegisterDownloadsDirectoryForTesting(const base::FilePath& path);
144 // For testing purpose, adds a volume info pointing to |path|, with TESTING
145 // type. Assumes that the mount point is already registered.
146 void AddVolumeInfoForTesting(const base::FilePath& path,
147 VolumeType volume_type,
148 chromeos::DeviceType device_type);
150 // drive::DriveIntegrationServiceObserver overrides.
151 virtual void OnFileSystemMounted() OVERRIDE;
152 virtual void OnFileSystemBeingUnmounted() OVERRIDE;
154 // chromeos::disks::DiskMountManager::Observer overrides.
155 virtual void OnDiskEvent(
156 chromeos::disks::DiskMountManager::DiskEvent event,
157 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE;
158 virtual void OnDeviceEvent(
159 chromeos::disks::DiskMountManager::DeviceEvent event,
160 const std::string& device_path) OVERRIDE;
161 virtual void OnMountEvent(
162 chromeos::disks::DiskMountManager::MountEvent event,
163 chromeos::MountError error_code,
164 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info)
165 OVERRIDE;
166 virtual void OnFormatEvent(
167 chromeos::disks::DiskMountManager::FormatEvent event,
168 chromeos::FormatError error_code,
169 const std::string& device_path) OVERRIDE;
171 // chromeos::file_system_provider::Observer overrides.
172 virtual void OnProvidedFileSystemRegistered(
173 const chromeos::file_system_provider::ProvidedFileSystem& file_system)
174 OVERRIDE;
175 virtual void OnProvidedFileSystemUnregistered(
176 const chromeos::file_system_provider::ProvidedFileSystem& file_system)
177 OVERRIDE;
179 // Called on change to kExternalStorageDisabled pref.
180 void OnExternalStorageDisabledChanged();
182 private:
183 void OnPrivetVolumesAvailable(
184 const local_discovery::PrivetVolumeLister::VolumeList& volumes);
185 void DoMountEvent(chromeos::MountError error_code,
186 const VolumeInfo& volume_info,
187 bool is_remounting);
188 void DoUnmountEvent(chromeos::MountError error_code,
189 const VolumeInfo& volume_info);
191 Profile* profile_;
192 drive::DriveIntegrationService* drive_integration_service_; // Not owned.
193 chromeos::disks::DiskMountManager* disk_mount_manager_; // Not owned.
194 scoped_ptr<MountedDiskMonitor> mounted_disk_monitor_;
195 PrefChangeRegistrar pref_change_registrar_;
196 ObserverList<VolumeManagerObserver> observers_;
197 scoped_ptr<local_discovery::PrivetVolumeLister> privet_volume_lister_;
198 chromeos::file_system_provider::Service*
199 file_system_provider_service_; // Not owned by this class.
200 std::map<std::string, VolumeInfo> mounted_volumes_;
202 DISALLOW_COPY_AND_ASSIGN(VolumeManager);
205 } // namespace file_manager
207 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_