| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 20 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 20 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 21 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 21 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 22 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 22 #include "chrome/browser/chromeos/file_system_provider/service.h" | 23 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 23 #include "chromeos/dbus/cros_disks_client.h" | 24 #include "chromeos/dbus/cros_disks_client.h" |
| 24 #include "chromeos/disks/disk_mount_manager.h" | 25 #include "chromeos/disks/disk_mount_manager.h" |
| 25 #include "components/keyed_service/core/keyed_service.h" | 26 #include "components/keyed_service/core/keyed_service.h" |
| 26 #include "components/prefs/pref_change_registrar.h" | 27 #include "components/prefs/pref_change_registrar.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 enum Source { SOURCE_FILE, SOURCE_DEVICE, SOURCE_NETWORK, SOURCE_SYSTEM }; | 73 enum Source { SOURCE_FILE, SOURCE_DEVICE, SOURCE_NETWORK, SOURCE_SYSTEM }; |
| 73 | 74 |
| 74 // Represents a volume (mount point) in the volume manager. Validity of the data | 75 // Represents a volume (mount point) in the volume manager. Validity of the data |
| 75 // is guaranteed by the weak pointer. Simply saying, the weak pointer should be | 76 // is guaranteed by the weak pointer. Simply saying, the weak pointer should be |
| 76 // valid as long as the volume is mounted. | 77 // valid as long as the volume is mounted. |
| 77 class Volume : public base::SupportsWeakPtr<Volume> { | 78 class Volume : public base::SupportsWeakPtr<Volume> { |
| 78 public: | 79 public: |
| 79 ~Volume(); | 80 ~Volume(); |
| 80 | 81 |
| 81 // Factory static methods for different volume types. | 82 // Factory static methods for different volume types. |
| 82 static std::unique_ptr<Volume> CreateForDrive(Profile* profile); | 83 static Volume* CreateForDrive(Profile* profile); |
| 83 static std::unique_ptr<Volume> CreateForDownloads( | 84 static Volume* CreateForDownloads(const base::FilePath& downloads_path); |
| 84 const base::FilePath& downloads_path); | 85 static Volume* CreateForRemovable( |
| 85 static std::unique_ptr<Volume> CreateForRemovable( | |
| 86 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, | 86 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, |
| 87 const chromeos::disks::DiskMountManager::Disk* disk); | 87 const chromeos::disks::DiskMountManager::Disk* disk); |
| 88 static std::unique_ptr<Volume> CreateForProvidedFileSystem( | 88 static Volume* CreateForProvidedFileSystem( |
| 89 const chromeos::file_system_provider::ProvidedFileSystemInfo& | 89 const chromeos::file_system_provider::ProvidedFileSystemInfo& |
| 90 file_system_info, | 90 file_system_info, |
| 91 MountContext mount_context); | 91 MountContext mount_context); |
| 92 static std::unique_ptr<Volume> CreateForMTP(const base::FilePath& mount_path, | 92 static Volume* CreateForMTP(const base::FilePath& mount_path, |
| 93 const std::string& label, | 93 const std::string& label, |
| 94 bool read_only); | 94 bool read_only); |
| 95 static std::unique_ptr<Volume> CreateForMediaView( | 95 static Volume* CreateForMediaView(const std::string& root_document_id); |
| 96 const std::string& root_document_id); | 96 static Volume* CreateForTesting(const base::FilePath& path, |
| 97 static std::unique_ptr<Volume> CreateForTesting( | 97 VolumeType volume_type, |
| 98 const base::FilePath& path, | 98 chromeos::DeviceType device_type, |
| 99 VolumeType volume_type, | 99 bool read_only); |
| 100 chromeos::DeviceType device_type, | 100 static Volume* CreateForTesting(const base::FilePath& device_path, |
| 101 bool read_only); | 101 const base::FilePath& mount_path); |
| 102 static std::unique_ptr<Volume> CreateForTesting( | |
| 103 const base::FilePath& device_path, | |
| 104 const base::FilePath& mount_path); | |
| 105 | 102 |
| 106 // Getters for all members. See below for details. | 103 // Getters for all members. See below for details. |
| 107 const std::string& volume_id() const { return volume_id_; } | 104 const std::string& volume_id() const { return volume_id_; } |
| 108 const std::string& file_system_id() const { return file_system_id_; } | 105 const std::string& file_system_id() const { return file_system_id_; } |
| 109 const std::string& extension_id() const { return extension_id_; } | 106 const std::string& extension_id() const { return extension_id_; } |
| 110 Source source() const { return source_; } | 107 Source source() const { return source_; } |
| 111 VolumeType type() const { return type_; } | 108 VolumeType type() const { return type_; } |
| 112 chromeos::DeviceType device_type() const { return device_type_; } | 109 chromeos::DeviceType device_type() const { return device_type_; } |
| 113 const base::FilePath& source_path() const { return source_path_; } | 110 const base::FilePath& source_path() const { return source_path_; } |
| 114 const base::FilePath& mount_path() const { return mount_path_; } | 111 const base::FilePath& mount_path() const { return mount_path_; } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 bool RegisterDownloadsDirectoryForTesting(const base::FilePath& path); | 263 bool RegisterDownloadsDirectoryForTesting(const base::FilePath& path); |
| 267 | 264 |
| 268 // For testing purpose, adds a volume info pointing to |path|, with TESTING | 265 // For testing purpose, adds a volume info pointing to |path|, with TESTING |
| 269 // type. Assumes that the mount point is already registered. | 266 // type. Assumes that the mount point is already registered. |
| 270 void AddVolumeForTesting(const base::FilePath& path, | 267 void AddVolumeForTesting(const base::FilePath& path, |
| 271 VolumeType volume_type, | 268 VolumeType volume_type, |
| 272 chromeos::DeviceType device_type, | 269 chromeos::DeviceType device_type, |
| 273 bool read_only); | 270 bool read_only); |
| 274 | 271 |
| 275 // For testing purpose, adds the volume info to the volume manager. | 272 // For testing purpose, adds the volume info to the volume manager. |
| 276 void AddVolumeForTesting(std::unique_ptr<Volume> volume); | 273 void AddVolumeForTesting(const linked_ptr<Volume>& volume); |
| 277 | 274 |
| 278 // drive::DriveIntegrationServiceObserver overrides. | 275 // drive::DriveIntegrationServiceObserver overrides. |
| 279 void OnFileSystemMounted() override; | 276 void OnFileSystemMounted() override; |
| 280 void OnFileSystemBeingUnmounted() override; | 277 void OnFileSystemBeingUnmounted() override; |
| 281 | 278 |
| 282 // chromeos::disks::DiskMountManager::Observer overrides. | 279 // chromeos::disks::DiskMountManager::Observer overrides. |
| 283 void OnDiskEvent( | 280 void OnDiskEvent( |
| 284 chromeos::disks::DiskMountManager::DiskEvent event, | 281 chromeos::disks::DiskMountManager::DiskEvent event, |
| 285 const chromeos::disks::DiskMountManager::Disk* disk) override; | 282 const chromeos::disks::DiskMountManager::Disk* disk) override; |
| 286 void OnDeviceEvent(chromeos::disks::DiskMountManager::DeviceEvent event, | 283 void OnDeviceEvent(chromeos::disks::DiskMountManager::DeviceEvent event, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 const storage_monitor::StorageInfo& info) override; | 315 const storage_monitor::StorageInfo& info) override; |
| 319 void OnRemovableStorageDetached( | 316 void OnRemovableStorageDetached( |
| 320 const storage_monitor::StorageInfo& info) override; | 317 const storage_monitor::StorageInfo& info) override; |
| 321 | 318 |
| 322 SnapshotManager* snapshot_manager() { return snapshot_manager_.get(); } | 319 SnapshotManager* snapshot_manager() { return snapshot_manager_.get(); } |
| 323 | 320 |
| 324 private: | 321 private: |
| 325 void OnDiskMountManagerRefreshed(bool success); | 322 void OnDiskMountManagerRefreshed(bool success); |
| 326 void OnStorageMonitorInitialized(); | 323 void OnStorageMonitorInitialized(); |
| 327 void DoMountEvent(chromeos::MountError error_code, | 324 void DoMountEvent(chromeos::MountError error_code, |
| 328 std::unique_ptr<Volume> volume); | 325 const linked_ptr<Volume>& volume); |
| 329 void DoUnmountEvent(chromeos::MountError error_code, const Volume& volume); | 326 void DoUnmountEvent(chromeos::MountError error_code, |
| 327 const linked_ptr<Volume>& volume); |
| 330 void OnExternalStorageDisabledChangedUnmountCallback( | 328 void OnExternalStorageDisabledChangedUnmountCallback( |
| 331 chromeos::MountError error_code); | 329 chromeos::MountError error_code); |
| 332 | 330 |
| 333 Profile* profile_; | 331 Profile* profile_; |
| 334 drive::DriveIntegrationService* drive_integration_service_; // Not owned. | 332 drive::DriveIntegrationService* drive_integration_service_; // Not owned. |
| 335 chromeos::disks::DiskMountManager* disk_mount_manager_; // Not owned. | 333 chromeos::disks::DiskMountManager* disk_mount_manager_; // Not owned. |
| 336 PrefChangeRegistrar pref_change_registrar_; | 334 PrefChangeRegistrar pref_change_registrar_; |
| 337 base::ObserverList<VolumeManagerObserver> observers_; | 335 base::ObserverList<VolumeManagerObserver> observers_; |
| 338 chromeos::file_system_provider::Service* | 336 chromeos::file_system_provider::Service* |
| 339 file_system_provider_service_; // Not owned by this class. | 337 file_system_provider_service_; // Not owned by this class. |
| 340 GetMtpStorageInfoCallback get_mtp_storage_info_callback_; | 338 GetMtpStorageInfoCallback get_mtp_storage_info_callback_; |
| 341 std::map<std::string, std::unique_ptr<Volume>> mounted_volumes_; | 339 std::map<std::string, linked_ptr<Volume>> mounted_volumes_; |
| 342 std::unique_ptr<SnapshotManager> snapshot_manager_; | 340 std::unique_ptr<SnapshotManager> snapshot_manager_; |
| 343 bool arc_volumes_mounted_ = false; | 341 bool arc_volumes_mounted_ = false; |
| 344 | 342 |
| 345 // Note: This should remain the last member so it'll be destroyed and | 343 // Note: This should remain the last member so it'll be destroyed and |
| 346 // invalidate its weak pointers before any other members are destroyed. | 344 // invalidate its weak pointers before any other members are destroyed. |
| 347 base::WeakPtrFactory<VolumeManager> weak_ptr_factory_; | 345 base::WeakPtrFactory<VolumeManager> weak_ptr_factory_; |
| 348 DISALLOW_COPY_AND_ASSIGN(VolumeManager); | 346 DISALLOW_COPY_AND_ASSIGN(VolumeManager); |
| 349 }; | 347 }; |
| 350 | 348 |
| 351 } // namespace file_manager | 349 } // namespace file_manager |
| 352 | 350 |
| 353 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_ | 351 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_VOLUME_MANAGER_H_ |
| OLD | NEW |