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" |
29 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
30 #include "chromeos/chromeos_switches.h" | 35 #include "chromeos/chromeos_switches.h" |
31 #include "chromeos/disks/disk_mount_manager.h" | 36 #include "chromeos/disks/disk_mount_manager.h" |
37 #include "components/arc/arc_service_manager.h" | |
32 #include "components/drive/chromeos/file_system_interface.h" | 38 #include "components/drive/chromeos/file_system_interface.h" |
33 #include "components/drive/file_system_core_util.h" | 39 #include "components/drive/file_system_core_util.h" |
34 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
35 #include "components/storage_monitor/storage_monitor.h" | 41 #include "components/storage_monitor/storage_monitor.h" |
36 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
37 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
38 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 44 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
39 #include "storage/browser/fileapi/external_mount_points.h" | 45 #include "storage/browser/fileapi/external_mount_points.h" |
40 | 46 |
41 namespace file_manager { | 47 namespace file_manager { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: | 110 case VOLUME_TYPE_DOWNLOADS_DIRECTORY: |
105 return "downloads"; | 111 return "downloads"; |
106 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: | 112 case VOLUME_TYPE_REMOVABLE_DISK_PARTITION: |
107 return "removable"; | 113 return "removable"; |
108 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: | 114 case VOLUME_TYPE_MOUNTED_ARCHIVE_FILE: |
109 return "archive"; | 115 return "archive"; |
110 case VOLUME_TYPE_PROVIDED: | 116 case VOLUME_TYPE_PROVIDED: |
111 return "provided"; | 117 return "provided"; |
112 case VOLUME_TYPE_MTP: | 118 case VOLUME_TYPE_MTP: |
113 return "mtp"; | 119 return "mtp"; |
120 case VOLUME_TYPE_MEDIA_VIEW: | |
121 return "media_view"; | |
114 case VOLUME_TYPE_TESTING: | 122 case VOLUME_TYPE_TESTING: |
115 return "testing"; | 123 return "testing"; |
116 case NUM_VOLUME_TYPE: | 124 case NUM_VOLUME_TYPE: |
117 break; | 125 break; |
118 } | 126 } |
119 NOTREACHED(); | 127 NOTREACHED(); |
120 return ""; | 128 return ""; |
121 } | 129 } |
122 | 130 |
123 // Generates a unique volume ID for the given volume info. | 131 // 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; | 272 volume->is_read_only_ = read_only; |
265 volume->volume_id_ = kMtpVolumeIdPrefix + label; | 273 volume->volume_id_ = kMtpVolumeIdPrefix + label; |
266 volume->volume_label_ = label; | 274 volume->volume_label_ = label; |
267 volume->source_path_ = mount_path; | 275 volume->source_path_ = mount_path; |
268 volume->source_ = SOURCE_DEVICE; | 276 volume->source_ = SOURCE_DEVICE; |
269 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; | 277 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; |
270 return volume; | 278 return volume; |
271 } | 279 } |
272 | 280 |
273 // static | 281 // static |
282 Volume* Volume::CreateForMediaView(const std::string& root_document_id) { | |
283 Volume* const volume = new Volume; | |
284 volume->type_ = VOLUME_TYPE_MEDIA_VIEW; | |
285 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; | |
286 volume->source_ = SOURCE_SYSTEM; | |
287 volume->mount_path_ = arc::GetDocumentsProviderMountPath( | |
288 arc::kMediaDocumentsProviderAuthority, root_document_id); | |
289 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; | |
290 volume->volume_label_ = root_document_id; | |
291 volume->is_read_only_ = true; | |
292 volume->watchable_ = false; | |
293 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id); | |
294 return volume; | |
295 } | |
296 | |
297 // static | |
274 Volume* Volume::CreateForTesting(const base::FilePath& path, | 298 Volume* Volume::CreateForTesting(const base::FilePath& path, |
275 VolumeType volume_type, | 299 VolumeType volume_type, |
276 chromeos::DeviceType device_type, | 300 chromeos::DeviceType device_type, |
277 bool read_only) { | 301 bool read_only) { |
278 Volume* const volume = new Volume; | 302 Volume* const volume = new Volume; |
279 volume->type_ = volume_type; | 303 volume->type_ = volume_type; |
280 volume->device_type_ = device_type; | 304 volume->device_type_ = device_type; |
281 // Keep source_path empty. | 305 // Keep source_path empty. |
282 volume->source_ = SOURCE_DEVICE; | 306 volume->source_ = SOURCE_DEVICE; |
283 volume->mount_path_ = path; | 307 volume->mount_path_ = path; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 prefs::kExternalStorageReadOnly, | 399 prefs::kExternalStorageReadOnly, |
376 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, | 400 base::Bind(&VolumeManager::OnExternalStorageReadOnlyChanged, |
377 weak_ptr_factory_.GetWeakPtr())); | 401 weak_ptr_factory_.GetWeakPtr())); |
378 | 402 |
379 // Subscribe to storage monitor for MTP notifications. | 403 // Subscribe to storage monitor for MTP notifications. |
380 if (storage_monitor::StorageMonitor::GetInstance()) { | 404 if (storage_monitor::StorageMonitor::GetInstance()) { |
381 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( | 405 storage_monitor::StorageMonitor::GetInstance()->EnsureInitialized( |
382 base::Bind(&VolumeManager::OnStorageMonitorInitialized, | 406 base::Bind(&VolumeManager::OnStorageMonitorInitialized, |
383 weak_ptr_factory_.GetWeakPtr())); | 407 weak_ptr_factory_.GetWeakPtr())); |
384 } | 408 } |
409 | |
410 // Subscribe to ARC file system events. | |
411 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | |
412 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | |
413 arc::ArcServiceManager::Get()->GetService<arc::ArcFileSystemService>() | |
414 ->AddObserver(this); | |
415 } | |
385 } | 416 } |
386 | 417 |
387 void VolumeManager::Shutdown() { | 418 void VolumeManager::Shutdown() { |
388 weak_ptr_factory_.InvalidateWeakPtrs(); | 419 weak_ptr_factory_.InvalidateWeakPtrs(); |
389 | 420 |
390 snapshot_manager_.reset(); | 421 snapshot_manager_.reset(); |
391 pref_change_registrar_.RemoveAll(); | 422 pref_change_registrar_.RemoveAll(); |
392 disk_mount_manager_->RemoveObserver(this); | 423 disk_mount_manager_->RemoveObserver(this); |
393 if (storage_monitor::StorageMonitor::GetInstance()) | 424 if (storage_monitor::StorageMonitor::GetInstance()) |
394 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); | 425 storage_monitor::StorageMonitor::GetInstance()->RemoveObserver(this); |
395 | 426 |
396 if (drive_integration_service_) | 427 if (drive_integration_service_) |
397 drive_integration_service_->RemoveObserver(this); | 428 drive_integration_service_->RemoveObserver(this); |
398 | 429 |
399 if (file_system_provider_service_) | 430 if (file_system_provider_service_) |
400 file_system_provider_service_->RemoveObserver(this); | 431 file_system_provider_service_->RemoveObserver(this); |
432 | |
433 // Unsubscribe from ARC file system events. | |
434 if (base::FeatureList::IsEnabled(arc::kMediaViewFeature) && | |
435 arc::ArcSessionManager::IsAllowedForProfile(profile_)) { | |
436 arc::ArcServiceManager::Get()->GetService<arc::ArcFileSystemService>() | |
hidehiko
2017/01/12 09:00:46
ArcServiceManager is destroyed before KeyedService
Shuhei Takahashi
2017/01/12 09:29:00
Thanks for catching!
| |
437 ->RemoveObserver(this); | |
438 } | |
401 } | 439 } |
402 | 440 |
403 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { | 441 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { |
404 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 442 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
405 DCHECK(observer); | 443 DCHECK(observer); |
406 observers_.AddObserver(observer); | 444 observers_.AddObserver(observer); |
407 } | 445 } |
408 | 446 |
409 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { | 447 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { |
410 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 448 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 // Repeat until unmount all paths | 733 // Repeat until unmount all paths |
696 const std::string& mount_path = | 734 const std::string& mount_path = |
697 disk_mount_manager_->mount_points().begin()->second.mount_path; | 735 disk_mount_manager_->mount_points().begin()->second.mount_path; |
698 disk_mount_manager_->UnmountPath( | 736 disk_mount_manager_->UnmountPath( |
699 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 737 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
700 base::Bind( | 738 base::Bind( |
701 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, | 739 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, |
702 weak_ptr_factory_.GetWeakPtr())); | 740 weak_ptr_factory_.GetWeakPtr())); |
703 } | 741 } |
704 | 742 |
743 void VolumeManager::OnFileSystemsReady() { | |
744 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
745 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
746 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
747 | |
748 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
749 linked_ptr<Volume>( | |
750 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
751 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
752 linked_ptr<Volume>( | |
753 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
754 DoMountEvent(chromeos::MOUNT_ERROR_NONE, | |
755 linked_ptr<Volume>( | |
756 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
757 } | |
758 | |
759 void VolumeManager::OnFileSystemsClosed() { | |
760 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
761 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); | |
762 DCHECK(arc::ArcSessionManager::IsAllowedForProfile(profile_)); | |
763 | |
764 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
765 linked_ptr<Volume>( | |
766 Volume::CreateForMediaView(arc::kImagesRootDocumentId))); | |
767 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
768 linked_ptr<Volume>( | |
769 Volume::CreateForMediaView(arc::kVideosRootDocumentId))); | |
770 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, | |
771 linked_ptr<Volume>( | |
772 Volume::CreateForMediaView(arc::kAudioRootDocumentId))); | |
773 } | |
774 | |
705 void VolumeManager::OnExternalStorageDisabledChanged() { | 775 void VolumeManager::OnExternalStorageDisabledChanged() { |
706 // If the policy just got disabled we have to unmount every device currently | 776 // 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 | 777 // mounted. The opposite is fine - we can let the user re-plug their device to |
708 // make it available. | 778 // make it available. |
709 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 779 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
710 // We do not iterate on mount_points directly, because mount_points can | 780 // We do not iterate on mount_points directly, because mount_points can |
711 // be changed by UnmountPath(). | 781 // be changed by UnmountPath(). |
712 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? | 782 // TODO(hidehiko): Is it necessary to unmount mounted archives, too, here? |
713 if (disk_mount_manager_->mount_points().empty()) | 783 if (disk_mount_manager_->mount_points().empty()) |
714 return; | 784 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()) | 983 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) |
914 return; | 984 return; |
915 if (error_code == chromeos::MOUNT_ERROR_NONE) | 985 if (error_code == chromeos::MOUNT_ERROR_NONE) |
916 mounted_volumes_.erase(volume->volume_id()); | 986 mounted_volumes_.erase(volume->volume_id()); |
917 | 987 |
918 for (auto& observer : observers_) | 988 for (auto& observer : observers_) |
919 observer.OnVolumeUnmounted(error_code, *volume.get()); | 989 observer.OnVolumeUnmounted(error_code, *volume.get()); |
920 } | 990 } |
921 | 991 |
922 } // namespace file_manager | 992 } // namespace file_manager |
OLD | NEW |