Chromium Code Reviews| 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/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | |
| 21 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" | |
| 22 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_service.h" | |
| 23 #include "chrome/browser/chromeos/arc/fileapi/arc_media_view_util.h" | |
| 19 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 24 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 20 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 21 #include "chrome/browser/chromeos/file_manager/path_util.h" | 26 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 22 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" | 27 #include "chrome/browser/chromeos/file_manager/snapshot_manager.h" |
| 23 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 28 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
| 24 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 29 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
| 25 #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" |
| 26 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 27 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" | 32 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: | 109 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: |
| 105 return "downloads"; | 110 return "downloads"; |
| 106 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: | 111 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: |
| 107 return "removable"; | 112 return "removable"; |
| 108 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: | 113 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: |
| 109 return "archive"; | 114 return "archive"; |
| 110 case VOLUME_TYPE_PROVIDED: | 115 case VOLUME_TYPE_PROVIDED: |
| 111 return "provided"; | 116 return "provided"; |
| 112 case VOLUME_TYPE_MTP: | 117 case VOLUME_TYPE_MTP: |
| 113 return "mtp"; | 118 return "mtp"; |
| 119 case VOLUME_TYPE_MEDIA_VIEW: | |
| 120 return "media_view"; | |
| 114 case VOLUME_TYPE_TESTING: | 121 case VOLUME_TYPE_TESTING: |
| 115 return "testing"; | 122 return "testing"; |
| 116 case NUM_VOLUME_TYPE: | 123 case NUM_VOLUME_TYPE: |
| 117 break; | 124 break; |
| 118 } | 125 } |
| 119 NOTREACHED(); | 126 NOTREACHED(); |
| 120 return ""; | 127 return ""; |
| 121 } | 128 } |
| 122 | 129 |
| 123 // Generates a unique volume ID for the given volume info. | 130 // Generates a unique volume ID for the given volume info. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 volume->is_read_only_ = read_only; | 271 volume->is_read_only_ = read_only; |
| 265 volume->volume_id_ = kMtpVolumeIdPrefix + label; | 272 volume->volume_id_ = kMtpVolumeIdPrefix + label; |
| 266 volume->volume_label_ = label; | 273 volume->volume_label_ = label; |
| 267 volume->source_path_ = mount_path; | 274 volume->source_path_ = mount_path; |
| 268 volume->source_ = SOURCE_DEVICE; | 275 volume->source_ = SOURCE_DEVICE; |
| 269 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; | 276 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; |
| 270 return volume; | 277 return volume; |
| 271 } | 278 } |
| 272 | 279 |
| 273 // static | 280 // static |
| 281 Volume* Volume::CreateForMediaView(const std::string& root_document_id) { | |
| 282 Volume* const volume = new Volume; | |
| 283 volume->type_ = VOLUME_TYPE_MEDIA_VIEW; | |
| 284 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | |
| 285 volume->source_ = SOURCE_SYSTEM; | |
| 286 volume->mount_path_ = arc::GetDocumentsProviderMountPath( | |
| 287 arc::kMediaDocumentsProviderAuthority, root_document_id); | |
| 288 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | |
| 289 volume->volume_label_ = root_document_id; | |
| 290 volume->is_read_only_ = true; | |
| 291 volume->watchable_ = false; | |
| 292 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id); | |
| 293 return volume; | |
| 294 } | |
| 295 | |
| 296 // static | |
| 274 Volume* Volume::CreateForTesting(const base::FilePath& path, | 297 Volume* Volume::CreateForTesting(const base::FilePath& path, |
| 275 VolumeType volume_type, | 298 VolumeType volume_type, |
| 276 chromeos::DeviceType device_type, | 299 chromeos::DeviceType device_type, |
| 277 bool read_only) { | 300 bool read_only) { |
| 278 Volume* const volume = new Volume; | 301 Volume* const volume = new Volume; |
| 279 volume->type_ = volume_type; | 302 volume->type_ = volume_type; |
| 280 volume->device_type_ = device_type; | 303 volume->device_type_ = device_type; |
| 281 // Keep source_path empty. | 304 // Keep source_path empty. |
| 282 volume->source_ = SOURCE_DEVICE; | 305 volume->source_ = SOURCE_DEVICE; |
| 283 volume->mount_path_ = path; | 306 volume->mount_path_ = path; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 prefs::kExternalStorageReadOnly, | 398 prefs::kExternalStorageReadOnly, |
| 376 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, | 399 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, |
| 377 weak_ptr_factory_.GetWeakPtr())); | 400 weak_ptr_factory_.GetWeakPtr())); |
| 378 | 401 |
| 379 // Subscribe to storage monitor for MTP notifications. | 402 // Subscribe to storage monitor for MTP notifications. |
| 380 if (storage_monitor::StorageMonitor::GetInstance()) { | 403 if (storage_monitor::StorageMonitor::GetInstance()) { |
| 381 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( | 404 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( |
| 382 base::Bind(&VolumeManager::OnStorageMonitorInitialized, | 405 base::Bind(&VolumeManager::OnStorageMonitorInitialized, |
| 383 weak_ptr_factory_.GetWeakPtr())); | 406 weak_ptr_factory_.GetWeakPtr())); |
| 384 } | 407 } |
| 408 | |
| 409 // Subscribe to ARC events. | |
| 410 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | |
| 411 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | |
| 412 arc::ArcServiceManager::Get()->AddObserver(this); | |
| 413 arc::ArcServiceManager::Get()->file_system_service()->AddObserver(this); | |
| 414 } | |
| 385 } | 415 } |
| 386 | 416 |
| 387 void VolumeManager::Shutdown() { | 417 void VolumeManager::Shutdown() { |
| 388 weak_ptr_factory_.InvalidateWeakPtrs(); | 418 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 389 | 419 |
| 390 snapshot_manager_.reset(); | 420 snapshot_manager_.reset(); |
| 391 pref_change_registrar_.RemoveAll(); | 421 pref_change_registrar_.RemoveAll(); |
| 392 disk_mount_manager_->RemoveObserver(this); | 422 disk_mount_manager_->RemoveObserver(this); |
| 393 if (storage_monitor::StorageMonitor::GetInstance()) | 423 if (storage_monitor::StorageMonitor::GetInstance()) |
| 394 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); | 424 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 // Repeat until unmount all paths | 725 // Repeat until unmount all paths |
| 696 const std::string& mount_path = | 726 const std::string& mount_path = |
| 697 disk_mount_manager_->mount_points().begin()->second.mount_path; | 727 disk_mount_manager_->mount_points().begin()->second.mount_path; |
| 698 disk_mount_manager_->UnmountPath( | 728 disk_mount_manager_->UnmountPath( |
| 699 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 729 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
| 700 base::Bind( | 730 base::Bind( |
| 701 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, | 731 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, |
| 702 weak_ptr_factory_.GetWeakPtr())); | 732 weak_ptr_factory_.GetWeakPtr())); |
| 703 } | 733 } |
| 704 | 734 |
| 735 void VolumeManager::OnFileSystemsReady() { | |
| 736 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 737 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
| 738 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
| 739 | |
| 740 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
| 741 linked_ptr<Volume>( | |
| 742 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
| 743 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
| 744 linked_ptr<Volume>( | |
| 745 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
| 746 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
| 747 linked_ptr<Volume>( | |
| 748 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
| 749 } | |
| 750 | |
| 751 void VolumeManager::OnArcShutdown() { | |
|
Luis Héctor Chávez
2017/01/10 18:51:35
Unfortunately this was reverted :(
Shuhei Takahashi
2017/01/11 15:20:43
Thanks for heads-up. Rebased on tot.
| |
| 752 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 753 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
| 754 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
| 755 | |
| 756 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
|
Luis Héctor Chávez
2017/01/10 18:51:35
What happens if OnFileSystemsReady() was never cal
Shuhei Takahashi
2017/01/11 15:20:43
It is okay to call DoUnmountEvent() even if mounts
| |
| 757 linked_ptr<Volume>( | |
| 758 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
| 759 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
| 760 linked_ptr<Volume>( | |
| 761 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
| 762 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
| 763 linked_ptr<Volume>( | |
| 764 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
| 765 | |
| 766 // Unsubscribe from ARC events. | |
| 767 arc::ArcServiceManager::Get()->RemoveObserver(this); | |
| 768 arc::ArcServiceManager::Get()->file_system_service()->RemoveObserver(this); | |
|
Luis Héctor Chávez
2017/01/10 18:51:35
nit: unsubscribe in the reverse order in which you
Shuhei Takahashi
2017/01/11 15:20:43
Done (actually we now observe only one instance).
| |
| 769 } | |
| 770 | |
| 705 void VolumeManager::OnExternalStorageDisabledChanged() { | 771 void VolumeManager::OnExternalStorageDisabledChanged() { |
| 706 // If the policy just got disabled we have to unmount every device currently | 772 // If the policy just got disabled we have to unmount every device currently |
| 707 // mounted. The opposite is fine - we can let the user re-plug their device to | 773 // mounted. The opposite is fine - we can let the user re-plug their device to |
| 708 // make it available. | 774 // make it available. |
| 709 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 775 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 710 // We do not iterate on mount_points directly, because mount_points can | 776 // We do not iterate on mount_points directly, because mount_points can |
| 711 // be changed by UnmountPath(). | 777 // be changed by UnmountPath(). |
| 712 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? | 778 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? |
| 713 if (disk_mount_manager_->mount_points().empty()) | 779 if (disk_mount_manager_->mount_points().empty()) |
| 714 return; | 780 return; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) | 979 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
| 914 return; | 980 return; |
| 915 if (error_code == chromeos::MOUNT_ERROR_NONE) | 981 if (error_code == chromeos::MOUNT_ERROR_NONE) |
| 916 mounted_volumes_.erase(volume->volume_id()); | 982 mounted_volumes_.erase(volume->volume_id()); |
| 917 | 983 |
| 918 for (auto& observer : observers_) | 984 for (auto& observer : observers_) |
| 919 observer.OnVolumeUnmounted(error_code, *volume.get()); | 985 observer.OnVolumeUnmounted(error_code, *volume.get()); |
| 920 } | 986 } |
| 921 | 987 |
| 922 } // namespace file_manager | 988 } // namespace file_manager |
| OLD | NEW |