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 "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"
21 class PowerManagerClient;
22 } // namespace chromeos
26 } // namespace content
29 class DriveIntegrationService;
32 namespace file_manager {
34 class MountedDiskMonitor;
35 class VolumeManagerObserver;
37 // This manager manages "Drive" and "Downloads" in addition to disks managed
38 // by DiskMountManager.
40 VOLUME_TYPE_GOOGLE_DRIVE,
41 VOLUME_TYPE_DOWNLOADS_DIRECTORY,
42 VOLUME_TYPE_REMOVABLE_DISK_PARTITION,
43 VOLUME_TYPE_MOUNTED_ARCHIVE_FILE,
50 // The type of mounted volume.
53 // The type of device. (e.g. USB, SD card, DVD etc.)
54 chromeos::DeviceType device_type;
56 // The source path of the volume.
58 // - /home/chronos/user/Downloads/zipfile_path.zip
59 base::FilePath source_path;
61 // The mount path of the volume.
63 // - /home/chronos/user/Downloads
64 // - /media/removable/usb1
65 // - /media/archive/zip1
66 base::FilePath mount_path;
68 // The mounting condition. See the enum for the details.
69 chromeos::disks::MountCondition mount_condition;
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;
75 // If disk is a parent, then its label, else parents label.
76 // (e.g. "TransMemory")
77 std::string drive_label;
79 // Is the device is a parent device (i.e. sdb rather than sdb1).
82 // True if the volume is read only.
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
91 // - Mounted zip archives.
92 class VolumeManager : public BrowserContextKeyedService,
93 public drive::DriveIntegrationServiceObserver,
94 public chromeos::disks::DiskMountManager::Observer {
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();
102 // Returns the instance corresponding to the |context|.
103 static VolumeManager* Get(content::BrowserContext* context);
105 // Intializes this instance.
108 // Disposes this instance.
109 virtual void Shutdown() OVERRIDE;
112 void AddObserver(VolumeManagerObserver* observer);
114 // Removes the observer.
115 void RemoveObserver(VolumeManagerObserver* observer);
117 // Returns the information about all volumes currently mounted.
118 std::vector<VolumeInfo> GetVolumeInfoList() const;
120 // drive::DriveIntegrationServiceObserver overrides.
121 virtual void OnFileSystemMounted() OVERRIDE;
122 virtual void OnFileSystemBeingUnmounted() OVERRIDE;
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)
136 virtual void OnFormatEvent(
137 chromeos::disks::DiskMountManager::FormatEvent event,
138 chromeos::FormatError error_code,
139 const std::string& device_path) OVERRIDE;
141 // Called on change to kExternalStorageDisabled pref.
142 void OnExternalStorageDisabledChanged();
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);
154 } // namespace file_manager
156 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_