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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 18 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
18 #include "chrome/browser/chromeos/drive/file_errors.h" | 19 #include "chrome/browser/chromeos/drive/file_errors.h" |
19 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 20 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
20 #include "chrome/browser/chromeos/drive/file_system_util.h" | 21 #include "chrome/browser/chromeos/drive/file_system_util.h" |
21 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" | 22 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" |
22 #include "chrome/browser/chromeos/file_manager/path_util.h" | 23 #include "chrome/browser/chromeos/file_manager/path_util.h" |
23 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" | 24 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" |
24 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" | 25 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" |
25 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 26 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
(...skipping 11 matching lines...) Expand all Loading... |
37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
38 #include "webkit/browser/fileapi/external_mount_points.h" | 39 #include "webkit/browser/fileapi/external_mount_points.h" |
39 | 40 |
40 namespace file_manager { | 41 namespace file_manager { |
41 namespace { | 42 namespace { |
42 | 43 |
43 // A named constant to be passed to the |is_remounting| parameter. | 44 // A named constant to be passed to the |is_remounting| parameter. |
44 const bool kNotRemounting = false; | 45 const bool kNotRemounting = false; |
45 | 46 |
46 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; | 47 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; |
| 48 const char kMtpVolumeIdPrefix [] = "mtp:"; |
47 | 49 |
48 // Registers |path| as the "Downloads" folder to the FileSystem API backend. | 50 // Registers |path| as the "Downloads" folder to the FileSystem API backend. |
49 // If another folder is already mounted. It revokes and overrides the old one. | 51 // If another folder is already mounted. It revokes and overrides the old one. |
50 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { | 52 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { |
51 // Although we show only profile's own "Downloads" folder in Files.app, | 53 // Although we show only profile's own "Downloads" folder in Files.app, |
52 // in the backend we need to mount all profile's download directory globally. | 54 // in the backend we need to mount all profile's download directory globally. |
53 // Otherwise, Files.app cannot support cross-profile file copies, etc. | 55 // Otherwise, Files.app cannot support cross-profile file copies, etc. |
54 // For this reason, we need to register to the global GetSystemInstance(). | 56 // For this reason, we need to register to the global GetSystemInstance(). |
55 const std::string mount_point_name = | 57 const std::string mount_point_name = |
56 file_manager::util::GetDownloadsMountPointName(profile); | 58 file_manager::util::GetDownloadsMountPointName(profile); |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 716 |
715 void VolumeManager::OnRemovableStorageAttached( | 717 void VolumeManager::OnRemovableStorageAttached( |
716 const storage_monitor::StorageInfo& info) { | 718 const storage_monitor::StorageInfo& info) { |
717 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) | 719 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) |
718 return; | 720 return; |
719 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) | 721 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) |
720 return; | 722 return; |
721 | 723 |
722 const base::FilePath path = base::FilePath::FromUTF8Unsafe(info.location()); | 724 const base::FilePath path = base::FilePath::FromUTF8Unsafe(info.location()); |
723 const std::string fsid = GetMountPointNameForMediaStorage(info); | 725 const std::string fsid = GetMountPointNameForMediaStorage(info); |
724 const std::string name = base::UTF16ToUTF8(info.GetDisplayName(false)); | 726 const std::string base_name = base::UTF16ToUTF8(info.model_name()); |
| 727 |
| 728 // Assign a fresh volume ID based on the volume name. |
| 729 std::string id = kMtpVolumeIdPrefix + base_name; |
| 730 for (int i = 2; mounted_volumes_.count(id); ++i) |
| 731 id = kMtpVolumeIdPrefix + base_name + base::StringPrintf(" (%d)", i); |
725 | 732 |
726 bool result = | 733 bool result = |
727 fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 734 fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
728 fsid, fileapi::kFileSystemTypeDeviceMediaAsFileStorage, | 735 fsid, fileapi::kFileSystemTypeDeviceMediaAsFileStorage, |
729 fileapi::FileSystemMountOption(), path); | 736 fileapi::FileSystemMountOption(), path); |
730 DCHECK(result); | 737 DCHECK(result); |
731 content::BrowserThread::PostTask( | 738 content::BrowserThread::PostTask( |
732 content::BrowserThread::IO, FROM_HERE, base::Bind( | 739 content::BrowserThread::IO, FROM_HERE, base::Bind( |
733 &MTPDeviceMapService::RegisterMTPFileSystem, | 740 &MTPDeviceMapService::RegisterMTPFileSystem, |
734 base::Unretained(MTPDeviceMapService::GetInstance()), | 741 base::Unretained(MTPDeviceMapService::GetInstance()), |
735 info.location(), fsid)); | 742 info.location(), fsid)); |
736 | 743 |
737 VolumeInfo volume_info; | 744 VolumeInfo volume_info; |
738 volume_info.type = VOLUME_TYPE_MTP; | 745 volume_info.type = VOLUME_TYPE_MTP; |
739 volume_info.mount_path = path; | 746 volume_info.mount_path = path; |
740 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; | 747 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; |
741 volume_info.is_parent = true; | 748 volume_info.is_parent = true; |
742 volume_info.is_read_only = true; | 749 volume_info.is_read_only = true; |
743 volume_info.volume_id = "mtp:" + name; | 750 volume_info.volume_id = id; |
744 volume_info.source_path = path; | 751 volume_info.source_path = path; |
745 volume_info.device_type = chromeos::DEVICE_TYPE_MOBILE; | 752 volume_info.device_type = chromeos::DEVICE_TYPE_MOBILE; |
746 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); | 753 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false); |
747 } | 754 } |
748 | 755 |
749 void VolumeManager::OnRemovableStorageDetached( | 756 void VolumeManager::OnRemovableStorageDetached( |
750 const storage_monitor::StorageInfo& info) { | 757 const storage_monitor::StorageInfo& info) { |
751 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) | 758 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) |
752 return; | 759 return; |
753 | 760 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 return; | 833 return; |
827 if (error_code == chromeos::MOUNT_ERROR_NONE) | 834 if (error_code == chromeos::MOUNT_ERROR_NONE) |
828 mounted_volumes_.erase(volume_info.volume_id); | 835 mounted_volumes_.erase(volume_info.volume_id); |
829 | 836 |
830 FOR_EACH_OBSERVER(VolumeManagerObserver, | 837 FOR_EACH_OBSERVER(VolumeManagerObserver, |
831 observers_, | 838 observers_, |
832 OnVolumeUnmounted(error_code, volume_info)); | 839 OnVolumeUnmounted(error_code, volume_info)); |
833 } | 840 } |
834 | 841 |
835 } // namespace file_manager | 842 } // namespace file_manager |
OLD | NEW |