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