| 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 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: | 103 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: |
| 104 return "removable"; | 104 return "removable"; |
| 105 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: | 105 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: |
| 106 return "archive"; | 106 return "archive"; |
| 107 case VOLUME_TYPE_PROVIDED: | 107 case VOLUME_TYPE_PROVIDED: |
| 108 return "provided"; | 108 return "provided"; |
| 109 case VOLUME_TYPE_MTP: | 109 case VOLUME_TYPE_MTP: |
| 110 return "mtp"; | 110 return "mtp"; |
| 111 case VOLUME_TYPE_TESTING: | 111 case VOLUME_TYPE_TESTING: |
| 112 return "testing"; | 112 return "testing"; |
| 113 case VOLUME_TYPE_PLUGIN_PROVIDED: |
| 114 return "plugin_provided"; |
| 113 case NUM_VOLUME_TYPE: | 115 case NUM_VOLUME_TYPE: |
| 114 break; | 116 break; |
| 115 } | 117 } |
| 116 NOTREACHED(); | 118 NOTREACHED(); |
| 117 return ""; | 119 return ""; |
| 118 } | 120 } |
| 119 | 121 |
| 120 // Generates a unique volume ID for the given volume info. | 122 // Generates a unique volume ID for the given volume info. |
| 121 std::string GenerateVolumeId(const Volume& volume) { | 123 std::string GenerateVolumeId(const Volume& volume) { |
| 122 // For the same volume type, base names are unique, as mount points are | 124 // For the same volume type, base names are unique, as mount points are |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 case extensions::SOURCE_FILE: | 219 case extensions::SOURCE_FILE: |
| 218 volume->source_ = SOURCE_FILE; | 220 volume->source_ = SOURCE_FILE; |
| 219 break; | 221 break; |
| 220 case extensions::SOURCE_DEVICE: | 222 case extensions::SOURCE_DEVICE: |
| 221 volume->source_ = SOURCE_DEVICE; | 223 volume->source_ = SOURCE_DEVICE; |
| 222 break; | 224 break; |
| 223 case extensions::SOURCE_NETWORK: | 225 case extensions::SOURCE_NETWORK: |
| 224 volume->source_ = SOURCE_NETWORK; | 226 volume->source_ = SOURCE_NETWORK; |
| 225 break; | 227 break; |
| 226 } | 228 } |
| 229 using chromeos::file_system_provider::Source_Type; |
| 227 volume->volume_label_ = file_system_info.display_name(); | 230 volume->volume_label_ = file_system_info.display_name(); |
| 228 volume->type_ = VOLUME_TYPE_PROVIDED; | 231 volume->type_ = file_system_info.source_type() == Source_Type::plugin ? |
| 232 VOLUME_TYPE_PLUGIN_PROVIDED : VOLUME_TYPE_PROVIDED; |
| 229 volume->mount_path_ = file_system_info.mount_path(); | 233 volume->mount_path_ = file_system_info.mount_path(); |
| 230 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | 234 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; |
| 231 volume->mount_context_ = mount_context; | 235 volume->mount_context_ = mount_context; |
| 232 volume->is_parent_ = true; | 236 volume->is_parent_ = true; |
| 233 volume->is_read_only_ = !file_system_info.writable(); | 237 volume->is_read_only_ = !file_system_info.writable(); |
| 234 volume->configurable_ = file_system_info.configurable(); | 238 volume->configurable_ = file_system_info.configurable(); |
| 235 volume->volume_id_ = GenerateVolumeId(*volume); | 239 volume->volume_id_ = GenerateVolumeId(*volume); |
| 236 return volume; | 240 return volume; |
| 237 } | 241 } |
| 238 | 242 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 277 |
| 274 // static | 278 // static |
| 275 Volume* Volume::CreateForTesting(const base::FilePath& device_path, | 279 Volume* Volume::CreateForTesting(const base::FilePath& device_path, |
| 276 const base::FilePath& mount_path) { | 280 const base::FilePath& mount_path) { |
| 277 Volume* const volume = new Volume; | 281 Volume* const volume = new Volume; |
| 278 volume->system_path_prefix_ = device_path; | 282 volume->system_path_prefix_ = device_path; |
| 279 volume->mount_path_ = mount_path; | 283 volume->mount_path_ = mount_path; |
| 280 return volume; | 284 return volume; |
| 281 } | 285 } |
| 282 | 286 |
| 283 VolumeManager::VolumeManager( | 287 VolumeManager::VolumeManager(Profile* profile, |
| 284 Profile* profile, | |
| 285 drive::DriveIntegrationService* drive_integration_service, | 288 drive::DriveIntegrationService* drive_integration_service, |
| 286 chromeos::PowerManagerClient* power_manager_client, | 289 chromeos::PowerManagerClient* power_manager_client, |
| 287 chromeos::disks::DiskMountManager* disk_mount_manager, | 290 chromeos::disks::DiskMountManager* disk_mount_manager, |
| 288 chromeos::file_system_provider::Service* file_system_provider_service, | 291 chromeos::file_system_provider::Service* file_system_provider_service, |
| 292 chromeos::file_system_provider::PluginService* |
| 293 file_system_plugin_provided_service, |
| 289 GetMtpStorageInfoCallback get_mtp_storage_info_callback) | 294 GetMtpStorageInfoCallback get_mtp_storage_info_callback) |
| 290 : profile_(profile), | 295 : profile_(profile), |
| 291 drive_integration_service_(drive_integration_service), | 296 drive_integration_service_(drive_integration_service), |
| 292 disk_mount_manager_(disk_mount_manager), | 297 disk_mount_manager_(disk_mount_manager), |
| 293 file_system_provider_service_(file_system_provider_service), | 298 file_system_provider_service_(file_system_provider_service), |
| 299 file_system_plugin_provided_service_(file_system_plugin_provided_service), |
| 294 get_mtp_storage_info_callback_(get_mtp_storage_info_callback), | 300 get_mtp_storage_info_callback_(get_mtp_storage_info_callback), |
| 295 snapshot_manager_(new SnapshotManager(profile_)), | 301 snapshot_manager_(new SnapshotManager(profile_)), |
| 296 weak_ptr_factory_(this) { | 302 weak_ptr_factory_(this) { |
| 297 DCHECK(disk_mount_manager); | 303 DCHECK(disk_mount_manager); |
| 298 } | 304 } |
| 299 | 305 |
| 300 VolumeManager::~VolumeManager() { | 306 VolumeManager::~VolumeManager() { |
| 301 } | 307 } |
| 302 | 308 |
| 303 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { | 309 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 file_system_provider_service_->AddObserver(this); | 346 file_system_provider_service_->AddObserver(this); |
| 341 | 347 |
| 342 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 348 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
| 343 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 349 file_system_provider_service_->GetProvidedFileSystemInfoList(); |
| 344 for (size_t i = 0; i < file_system_info_list.size(); ++i) { | 350 for (size_t i = 0; i < file_system_info_list.size(); ++i) { |
| 345 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem( | 351 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem( |
| 346 file_system_info_list[i], MOUNT_CONTEXT_AUTO)); | 352 file_system_info_list[i], MOUNT_CONTEXT_AUTO)); |
| 347 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); | 353 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); |
| 348 } | 354 } |
| 349 } | 355 } |
| 350 | 356 // Subscribe to PluginService |
| 357 if (file_system_plugin_provided_service_) |
| 358 file_system_plugin_provided_service_->AddObserver(this); |
| 351 // Subscribe to Profile Preference change. | 359 // Subscribe to Profile Preference change. |
| 352 pref_change_registrar_.Init(profile_->GetPrefs()); | 360 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 353 pref_change_registrar_.Add( | 361 pref_change_registrar_.Add( |
| 354 prefs::kExternalStorageDisabled, | 362 prefs::kExternalStorageDisabled, |
| 355 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, | 363 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, |
| 356 weak_ptr_factory_.GetWeakPtr())); | 364 weak_ptr_factory_.GetWeakPtr())); |
| 357 | 365 |
| 358 // Subscribe to storage monitor for MTP notifications. | 366 // Subscribe to storage monitor for MTP notifications. |
| 359 if (storage_monitor::StorageMonitor::GetInstance()) { | 367 if (storage_monitor::StorageMonitor::GetInstance()) { |
| 360 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( | 368 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( |
| 361 base::Bind(&VolumeManager::OnStorageMonitorInitialized, | 369 base::Bind(&VolumeManager::OnStorageMonitorInitialized, |
| 362 weak_ptr_factory_.GetWeakPtr())); | 370 weak_ptr_factory_.GetWeakPtr())); |
| 363 } | 371 } |
| 364 } | 372 } |
| 365 | 373 |
| 366 void VolumeManager::Shutdown() { | 374 void VolumeManager::Shutdown() { |
| 367 weak_ptr_factory_.InvalidateWeakPtrs(); | 375 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 368 | 376 |
| 369 snapshot_manager_.reset(); | 377 snapshot_manager_.reset(); |
| 370 pref_change_registrar_.RemoveAll(); | 378 pref_change_registrar_.RemoveAll(); |
| 371 disk_mount_manager_->RemoveObserver(this); | 379 disk_mount_manager_->RemoveObserver(this); |
| 372 if (storage_monitor::StorageMonitor::GetInstance()) | 380 if (storage_monitor::StorageMonitor::GetInstance()) |
| 373 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); | 381 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); |
| 374 | 382 |
| 375 if (drive_integration_service_) | 383 if (drive_integration_service_) |
| 376 drive_integration_service_->RemoveObserver(this); | 384 drive_integration_service_->RemoveObserver(this); |
| 377 | 385 |
| 378 if (file_system_provider_service_) | 386 if (file_system_provider_service_) |
| 379 file_system_provider_service_->RemoveObserver(this); | 387 file_system_provider_service_->RemoveObserver(this); |
| 388 if (file_system_plugin_provided_service_) |
| 389 file_system_plugin_provided_service_->RemoveObserver(this); |
| 380 } | 390 } |
| 381 | 391 |
| 382 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { | 392 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { |
| 383 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 393 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 384 DCHECK(observer); | 394 DCHECK(observer); |
| 385 observers_.AddObserver(observer); | 395 observers_.AddObserver(observer); |
| 386 } | 396 } |
| 387 | 397 |
| 388 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { | 398 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { |
| 389 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 399 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 876 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
| 867 return; | 877 return; |
| 868 if (error_code == chromeos::MOUNT_ERROR_NONE) | 878 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 869 mounted_volumes_.erase(volume->volume_id()); | 879 mounted_volumes_.erase(volume->volume_id()); |
| 870 | 880 |
| 871 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 881 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 872 OnVolumeUnmounted(error_code, *volume.get())); | 882 OnVolumeUnmounted(error_code, *volume.get())); |
| 873 } | 883 } |
| 874 | 884 |
| 875 } // namespace file_manager | 885 } // namespace file_manager |
| OLD | NEW |