| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 20 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | 21 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| 21 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h" | 22 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h" |
| 22 #include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h" | 23 #include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h" |
| 23 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 24 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 24 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 25 #include "chrome/browser/chromeos/file_manager/path_util.h" | 26 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 26 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" | 27 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" |
| 27 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 28 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
| 28 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 29 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
| 29 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 30 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 401 |
| 401 // Subscribe to storage monitor for MTP notifications. | 402 // Subscribe to storage monitor for MTP notifications. |
| 402 if (storage_monitor::StorageMonitor::GetInstance()) { | 403 if (storage_monitor::StorageMonitor::GetInstance()) { |
| 403 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( | 404 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( |
| 404 base::Bind(&VolumeManager::OnStorageMonitorInitialized, | 405 base::Bind(&VolumeManager::OnStorageMonitorInitialized, |
| 405 weak_ptr_factory_.GetWeakPtr())); | 406 weak_ptr_factory_.GetWeakPtr())); |
| 406 } | 407 } |
| 407 | 408 |
| 408 // Subscribe to ARC file system events. | 409 // Subscribe to ARC file system events. |
| 409 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | 410 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && |
| 410 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | 411 arc::IsArcAllowedForProfile(profile_)) { |
| 411 arc::ArcSessionManager::Get()->AddObserver(this); | 412 arc::ArcSessionManager::Get()->AddObserver(this); |
| 412 OnArcOptInChanged(arc::ArcSessionManager::Get()->IsArcEnabled()); | 413 OnArcOptInChanged(arc::ArcSessionManager::Get()->IsArcEnabled()); |
| 413 } | 414 } |
| 414 } | 415 } |
| 415 | 416 |
| 416 void VolumeManager::Shutdown() { | 417 void VolumeManager::Shutdown() { |
| 417 weak_ptr_factory_.InvalidateWeakPtrs(); | 418 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 418 | 419 |
| 419 snapshot_manager_.reset(); | 420 snapshot_manager_.reset(); |
| 420 pref_change_registrar_.RemoveAll(); | 421 pref_change_registrar_.RemoveAll(); |
| 421 disk_mount_manager_->RemoveObserver(this); | 422 disk_mount_manager_->RemoveObserver(this); |
| 422 if (storage_monitor::StorageMonitor::GetInstance()) | 423 if (storage_monitor::StorageMonitor::GetInstance()) |
| 423 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); | 424 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); |
| 424 | 425 |
| 425 if (drive_integration_service_) | 426 if (drive_integration_service_) |
| 426 drive_integration_service_->RemoveObserver(this); | 427 drive_integration_service_->RemoveObserver(this); |
| 427 | 428 |
| 428 if (file_system_provider_service_) | 429 if (file_system_provider_service_) |
| 429 file_system_provider_service_->RemoveObserver(this); | 430 file_system_provider_service_->RemoveObserver(this); |
| 430 | 431 |
| 431 // Unsubscribe from ARC file system events. | 432 // Unsubscribe from ARC file system events. |
| 432 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | 433 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && |
| 433 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | 434 arc::IsArcAllowedForProfile(profile_)) { |
| 434 auto* session_manager = arc::ArcSessionManager::Get(); | 435 auto* session_manager = arc::ArcSessionManager::Get(); |
| 435 // TODO(crbug.com/672829): We need nullptr check here because | 436 // TODO(crbug.com/672829): We need nullptr check here because |
| 436 // ArcSessionManager may or may not be alive at this point. | 437 // ArcSessionManager may or may not be alive at this point. |
| 437 if (session_manager) | 438 if (session_manager) |
| 438 session_manager->RemoveObserver(this); | 439 session_manager->RemoveObserver(this); |
| 439 } | 440 } |
| 440 } | 441 } |
| 441 | 442 |
| 442 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { | 443 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { |
| 443 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 444 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 disk_mount_manager_->UnmountPath( | 738 disk_mount_manager_->UnmountPath( |
| 738 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 739 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
| 739 base::Bind( | 740 base::Bind( |
| 740 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, | 741 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, |
| 741 weak_ptr_factory_.GetWeakPtr())); | 742 weak_ptr_factory_.GetWeakPtr())); |
| 742 } | 743 } |
| 743 | 744 |
| 744 void VolumeManager::OnArcOptInChanged(bool enabled) { | 745 void VolumeManager::OnArcOptInChanged(bool enabled) { |
| 745 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 746 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 746 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | 747 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); |
| 747 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | 748 DCHECK(arc::IsArcAllowedForProfile(profile_)); |
| 748 | 749 |
| 749 if (enabled == arc_volumes_mounted_) | 750 if (enabled == arc_volumes_mounted_) |
| 750 return; | 751 return; |
| 751 | 752 |
| 752 if (enabled) { | 753 if (enabled) { |
| 753 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 754 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
| 754 linked_ptr<Volume>( | 755 linked_ptr<Volume>( |
| 755 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | 756 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); |
| 756 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | 757 DoMountEvent(chromeos::MOUNT_ERROR_NONE, |
| 757 linked_ptr<Volume>( | 758 linked_ptr<Volume>( |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 986 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
| 986 return; | 987 return; |
| 987 if (error_code == chromeos::MOUNT_ERROR_NONE) | 988 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 988 mounted_volumes_.erase(volume->volume_id()); | 989 mounted_volumes_.erase(volume->volume_id()); |
| 989 | 990 |
| 990 for (auto& observer : observers_) | 991 for (auto& observer : observers_) |
| 991 observer.OnVolumeUnmounted(error_code, *volume.get()); | 992 observer.OnVolumeUnmounted(error_code, *volume.get()); |
| 992 } | 993 } |
| 993 | 994 |
| 994 } // namespace file_manager | 995 } // namespace file_manager |
| OLD | NEW |