| 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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 base::FilePath new_path; | 222 base::FilePath new_path; |
| 223 if (!old_path.empty() && | 223 if (!old_path.empty() && |
| 224 file_manager::util::MigratePathFromOldFormat(profile_, | 224 file_manager::util::MigratePathFromOldFormat(profile_, |
| 225 old_path, &new_path)) { | 225 old_path, &new_path)) { |
| 226 profile_->GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, | 226 profile_->GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, |
| 227 new_path); | 227 new_path); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Register 'Downloads' folder for the profile to the file system. | 230 // Register 'Downloads' folder for the profile to the file system. |
| 231 if (!chromeos::ProfileHelper::IsSigninProfile(profile_)) { | 231 if (!chromeos::ProfileHelper::IsSigninProfile(profile_)) { |
| 232 bool success = RegisterDownloadsMountPoint( | 232 const base::FilePath downloads = |
| 233 profile_, | 233 file_manager::util::GetDownloadsFolderForProfile(profile_); |
| 234 file_manager::util::GetDownloadsFolderForProfile(profile_)); | 234 const bool success = RegisterDownloadsMountPoint(profile_, downloads); |
| 235 DCHECK(success); | 235 DCHECK(success); |
| 236 |
| 237 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
| 238 CreateDownloadsVolumeInfo(downloads), |
| 239 false /* is_remounting */); |
| 236 } | 240 } |
| 237 | 241 |
| 238 // Subscribe to DriveIntegrationService. | 242 // Subscribe to DriveIntegrationService. |
| 239 if (drive_integration_service_) | 243 if (drive_integration_service_) { |
| 240 drive_integration_service_->AddObserver(this); | 244 drive_integration_service_->AddObserver(this); |
| 245 if (drive_integration_service_->IsMounted()) { |
| 246 DoMountEvent( |
| 247 chromeos::MOUNT_ERROR_NONE, CreateDriveVolumeInfo(profile_), false); |
| 248 } |
| 249 } |
| 241 | 250 |
| 242 // Subscribe to DiskMountManager. | 251 // Subscribe to DiskMountManager. |
| 243 disk_mount_manager_->AddObserver(this); | 252 disk_mount_manager_->AddObserver(this); |
| 253 |
| 254 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = |
| 255 disk_mount_manager_->mount_points(); |
| 256 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = |
| 257 mount_points.begin(); |
| 258 it != mount_points.end(); |
| 259 ++it) { |
| 260 DoMountEvent( |
| 261 chromeos::MOUNT_ERROR_NONE, |
| 262 CreateVolumeInfoFromMountPointInfo( |
| 263 it->second, |
| 264 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)), |
| 265 false /* is_remounting */); |
| 266 } |
| 267 |
| 244 disk_mount_manager_->RequestMountInfoRefresh(); | 268 disk_mount_manager_->RequestMountInfoRefresh(); |
| 245 | 269 |
| 246 // Subscribe to Profile Preference change. | 270 // Subscribe to Profile Preference change. |
| 247 pref_change_registrar_.Init(profile_->GetPrefs()); | 271 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 248 pref_change_registrar_.Add( | 272 pref_change_registrar_.Add( |
| 249 prefs::kExternalStorageDisabled, | 273 prefs::kExternalStorageDisabled, |
| 250 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, | 274 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, |
| 251 base::Unretained(this))); | 275 base::Unretained(this))); |
| 252 | 276 |
| 253 if (CommandLine::ForCurrentProcess()->HasSwitch( | 277 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 276 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { | 300 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { |
| 277 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 278 DCHECK(observer); | 302 DCHECK(observer); |
| 279 observers_.RemoveObserver(observer); | 303 observers_.RemoveObserver(observer); |
| 280 } | 304 } |
| 281 | 305 |
| 282 std::vector<VolumeInfo> VolumeManager::GetVolumeInfoList() const { | 306 std::vector<VolumeInfo> VolumeManager::GetVolumeInfoList() const { |
| 283 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 307 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 284 | 308 |
| 285 std::vector<VolumeInfo> result; | 309 std::vector<VolumeInfo> result; |
| 286 | 310 for (std::map<std::string, VolumeInfo>::const_iterator iter = |
| 287 // Adds "Drive" volume. | 311 mounted_volumes_.begin(); |
| 288 if (drive_integration_service_ && drive_integration_service_->IsMounted()) | 312 iter != mounted_volumes_.end(); |
| 289 result.push_back(CreateDriveVolumeInfo(profile_)); | 313 ++iter) { |
| 290 | 314 result.push_back(iter->second); |
| 291 // Adds "Downloads". | |
| 292 // Usually, the path of the directory is where we registered in Initialize(), | |
| 293 // but in tests, the mount point may be overridden. To take it into account, | |
| 294 // here we explicitly retrieves the path from the file API mount points. | |
| 295 base::FilePath downloads; | |
| 296 if (FindDownloadsMountPointPath(profile_, &downloads)) | |
| 297 result.push_back(CreateDownloadsVolumeInfo(downloads)); | |
| 298 | |
| 299 // Adds disks (both removable disks and zip archives). | |
| 300 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = | |
| 301 disk_mount_manager_->mount_points(); | |
| 302 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | |
| 303 mount_points.begin(); | |
| 304 it != mount_points.end(); ++it) { | |
| 305 result.push_back(CreateVolumeInfoFromMountPointInfo( | |
| 306 it->second, | |
| 307 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path))); | |
| 308 } | 315 } |
| 309 | |
| 310 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 311 switches::kEnablePrivetStorage)) { | |
| 312 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = | |
| 313 privet_volume_lister_->volume_list().begin(); | |
| 314 i != privet_volume_lister_->volume_list().end(); i++) { | |
| 315 result.push_back(CreatePrivetVolumeInfo(*i)); | |
| 316 } | |
| 317 } | |
| 318 | |
| 319 return result; | 316 return result; |
| 320 } | 317 } |
| 321 | 318 |
| 322 bool VolumeManager::FindVolumeInfoById(const std::string& volume_id, | 319 bool VolumeManager::FindVolumeInfoById(const std::string& volume_id, |
| 323 VolumeInfo* result) const { | 320 VolumeInfo* result) const { |
| 324 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 325 DCHECK(result); | 322 DCHECK(result); |
| 326 | 323 |
| 327 std::vector<VolumeInfo> info_list = GetVolumeInfoList(); | 324 std::map<std::string, VolumeInfo>::const_iterator iter = |
| 328 for (size_t i = 0; i < info_list.size(); ++i) { | 325 mounted_volumes_.find(volume_id); |
| 329 if (info_list[i].volume_id == volume_id) { | 326 if (iter == mounted_volumes_.end()) |
| 330 *result = info_list[i]; | 327 return false; |
| 331 return true; | 328 *result = iter->second; |
| 332 } | 329 return true; |
| 333 } | |
| 334 | |
| 335 return false; | |
| 336 } | 330 } |
| 337 | 331 |
| 338 bool VolumeManager::RegisterDownloadsDirectoryForTesting( | 332 bool VolumeManager::RegisterDownloadsDirectoryForTesting( |
| 339 const base::FilePath& path) { | 333 const base::FilePath& path) { |
| 340 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 341 return RegisterDownloadsMountPoint(profile_, path); | 335 |
| 336 base::FilePath old_path; |
| 337 if (FindDownloadsMountPointPath(profile_, &old_path)) { |
| 338 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, |
| 339 CreateDownloadsVolumeInfo(old_path)); |
| 340 } |
| 341 |
| 342 bool success = RegisterDownloadsMountPoint(profile_, path); |
| 343 DoMountEvent( |
| 344 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, |
| 345 CreateDownloadsVolumeInfo(path), |
| 346 false /* is_remounting */); |
| 347 return success; |
| 342 } | 348 } |
| 343 | 349 |
| 344 void VolumeManager::OnFileSystemMounted() { | 350 void VolumeManager::OnFileSystemMounted() { |
| 345 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 351 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 346 | 352 |
| 347 // Raise mount event. | 353 // Raise mount event. |
| 348 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed | 354 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed |
| 349 // or network is unreachable. These two errors will be handled later. | 355 // or network is unreachable. These two errors will be handled later. |
| 350 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); | 356 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); |
| 351 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 357 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, |
| 352 OnVolumeMounted(chromeos::MOUNT_ERROR_NONE, | 358 false /* is_remounting */); |
| 353 volume_info, | |
| 354 false)); // Not remounting. | |
| 355 } | 359 } |
| 356 | 360 |
| 357 void VolumeManager::OnFileSystemBeingUnmounted() { | 361 void VolumeManager::OnFileSystemBeingUnmounted() { |
| 358 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 362 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 359 | 363 |
| 360 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); | 364 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); |
| 361 FOR_EACH_OBSERVER( | 365 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info); |
| 362 VolumeManagerObserver, observers_, | |
| 363 OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, volume_info)); | |
| 364 } | 366 } |
| 365 | 367 |
| 366 void VolumeManager::OnDiskEvent( | 368 void VolumeManager::OnDiskEvent( |
| 367 chromeos::disks::DiskMountManager::DiskEvent event, | 369 chromeos::disks::DiskMountManager::DiskEvent event, |
| 368 const chromeos::disks::DiskMountManager::Disk* disk) { | 370 const chromeos::disks::DiskMountManager::Disk* disk) { |
| 369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 371 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 370 | 372 |
| 371 // Disregard hidden devices. | 373 // Disregard hidden devices. |
| 372 if (disk->is_hidden()) | 374 if (disk->is_hidden()) |
| 373 return; | 375 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 472 |
| 471 // Notify a mounting/unmounting event to observers. | 473 // Notify a mounting/unmounting event to observers. |
| 472 const chromeos::disks::DiskMountManager::Disk* disk = | 474 const chromeos::disks::DiskMountManager::Disk* disk = |
| 473 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); | 475 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); |
| 474 VolumeInfo volume_info = | 476 VolumeInfo volume_info = |
| 475 CreateVolumeInfoFromMountPointInfo(mount_info, disk); | 477 CreateVolumeInfoFromMountPointInfo(mount_info, disk); |
| 476 switch (event) { | 478 switch (event) { |
| 477 case chromeos::disks::DiskMountManager::MOUNTING: { | 479 case chromeos::disks::DiskMountManager::MOUNTING: { |
| 478 bool is_remounting = | 480 bool is_remounting = |
| 479 disk && mounted_disk_monitor_->DiskIsRemounting(*disk); | 481 disk && mounted_disk_monitor_->DiskIsRemounting(*disk); |
| 480 FOR_EACH_OBSERVER( | 482 DoMountEvent(error_code, volume_info, is_remounting); |
| 481 VolumeManagerObserver, observers_, | |
| 482 OnVolumeMounted(error_code, volume_info, is_remounting)); | |
| 483 return; | 483 return; |
| 484 } | 484 } |
| 485 case chromeos::disks::DiskMountManager::UNMOUNTING: | 485 case chromeos::disks::DiskMountManager::UNMOUNTING: |
| 486 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, | 486 DoUnmountEvent(error_code, volume_info); |
| 487 OnVolumeUnmounted(error_code, volume_info)); | |
| 488 return; | 487 return; |
| 489 } | 488 } |
| 490 NOTREACHED(); | 489 NOTREACHED(); |
| 491 } | 490 } |
| 492 | 491 |
| 493 void VolumeManager::OnFormatEvent( | 492 void VolumeManager::OnFormatEvent( |
| 494 chromeos::disks::DiskMountManager::FormatEvent event, | 493 chromeos::disks::DiskMountManager::FormatEvent event, |
| 495 chromeos::FormatError error_code, | 494 chromeos::FormatError error_code, |
| 496 const std::string& device_path) { | 495 const std::string& device_path) { |
| 497 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 496 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 chromeos::disks::DiskMountManager::UnmountPathCallback()); | 542 chromeos::disks::DiskMountManager::UnmountPathCallback()); |
| 544 } | 543 } |
| 545 } | 544 } |
| 546 } | 545 } |
| 547 | 546 |
| 548 void VolumeManager::OnPrivetVolumesAvailable( | 547 void VolumeManager::OnPrivetVolumesAvailable( |
| 549 const local_discovery::PrivetVolumeLister::VolumeList& volumes) { | 548 const local_discovery::PrivetVolumeLister::VolumeList& volumes) { |
| 550 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = | 549 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = |
| 551 volumes.begin(); i != volumes.end(); i++) { | 550 volumes.begin(); i != volumes.end(); i++) { |
| 552 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); | 551 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); |
| 553 | 552 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); |
| 554 FOR_EACH_OBSERVER( | |
| 555 VolumeManagerObserver, observers_, | |
| 556 OnVolumeMounted(chromeos::MOUNT_ERROR_NONE, volume_info, false)); | |
| 557 } | 553 } |
| 558 } | 554 } |
| 559 | 555 |
| 556 void VolumeManager::DoMountEvent(chromeos::MountError error_code, |
| 557 const VolumeInfo& volume_info, |
| 558 bool is_remounting) { |
| 559 // TODO(kinaba): filter zip. |
| 560 |
| 561 if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition) |
| 562 mounted_volumes_[volume_info.volume_id] = volume_info; |
| 563 |
| 564 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 565 observers_, |
| 566 OnVolumeMounted(error_code, volume_info, is_remounting)); |
| 567 } |
| 568 |
| 569 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, |
| 570 const VolumeInfo& volume_info) { |
| 571 if (mounted_volumes_.find(volume_info.volume_id) == mounted_volumes_.end()) |
| 572 return; |
| 573 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 574 mounted_volumes_.erase(volume_info.volume_id); |
| 575 |
| 576 FOR_EACH_OBSERVER(VolumeManagerObserver, |
| 577 observers_, |
| 578 OnVolumeUnmounted(error_code, volume_info)); |
| 579 } |
| 580 |
| 560 } // namespace file_manager | 581 } // namespace file_manager |
| OLD | NEW |