| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_system_provider/service.h" | 5 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 11 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 12 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 16 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 16 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
| 19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "webkit/browser/fileapi/external_mount_points.h" | 21 #include "storage/browser/fileapi/external_mount_points.h" |
| 22 | 22 |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 namespace file_system_provider { | 24 namespace file_system_provider { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Maximum number of file systems to be mounted in the same time, per profile. | 27 // Maximum number of file systems to be mounted in the same time, per profile. |
| 28 const size_t kMaxFileSystems = 16; | 28 const size_t kMaxFileSystems = 16; |
| 29 | 29 |
| 30 // Default factory for provided file systems. |profile| must not be NULL. | 30 // Default factory for provided file systems. |profile| must not be NULL. |
| 31 ProvidedFileSystemInterface* CreateProvidedFileSystem( | 31 ProvidedFileSystemInterface* CreateProvidedFileSystem( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Restrict number of file systems to prevent system abusing. | 119 // Restrict number of file systems to prevent system abusing. |
| 120 if (file_system_map_.size() + 1 > kMaxFileSystems) { | 120 if (file_system_map_.size() + 1 > kMaxFileSystems) { |
| 121 FOR_EACH_OBSERVER( | 121 FOR_EACH_OBSERVER( |
| 122 Observer, | 122 Observer, |
| 123 observers_, | 123 observers_, |
| 124 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 124 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
| 125 base::File::FILE_ERROR_TOO_MANY_OPENED)); | 125 base::File::FILE_ERROR_TOO_MANY_OPENED)); |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 fileapi::ExternalMountPoints* const mount_points = | 129 storage::ExternalMountPoints* const mount_points = |
| 130 fileapi::ExternalMountPoints::GetSystemInstance(); | 130 storage::ExternalMountPoints::GetSystemInstance(); |
| 131 DCHECK(mount_points); | 131 DCHECK(mount_points); |
| 132 | 132 |
| 133 // The mount point path and name are unique per system, since they are system | 133 // The mount point path and name are unique per system, since they are system |
| 134 // wide. This is necessary for copying between profiles. | 134 // wide. This is necessary for copying between profiles. |
| 135 const base::FilePath& mount_path = | 135 const base::FilePath& mount_path = |
| 136 util::GetMountPath(profile_, extension_id, file_system_id); | 136 util::GetMountPath(profile_, extension_id, file_system_id); |
| 137 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); | 137 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); |
| 138 | 138 |
| 139 if (!mount_points->RegisterFileSystem(mount_point_name, | 139 if (!mount_points->RegisterFileSystem(mount_point_name, |
| 140 fileapi::kFileSystemTypeProvided, | 140 storage::kFileSystemTypeProvided, |
| 141 fileapi::FileSystemMountOption(), | 141 storage::FileSystemMountOption(), |
| 142 mount_path)) { | 142 mount_path)) { |
| 143 FOR_EACH_OBSERVER( | 143 FOR_EACH_OBSERVER( |
| 144 Observer, | 144 Observer, |
| 145 observers_, | 145 observers_, |
| 146 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 146 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
| 147 base::File::FILE_ERROR_INVALID_OPERATION)); | 147 base::File::FILE_ERROR_INVALID_OPERATION)); |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Store the file system descriptor. Use the mount point name as the file | 151 // Store the file system descriptor. Use the mount point name as the file |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (file_system_it == file_system_map_.end()) { | 184 if (file_system_it == file_system_map_.end()) { |
| 185 const ProvidedFileSystemInfo empty_file_system_info; | 185 const ProvidedFileSystemInfo empty_file_system_info; |
| 186 FOR_EACH_OBSERVER( | 186 FOR_EACH_OBSERVER( |
| 187 Observer, | 187 Observer, |
| 188 observers_, | 188 observers_, |
| 189 OnProvidedFileSystemUnmount(empty_file_system_info, | 189 OnProvidedFileSystemUnmount(empty_file_system_info, |
| 190 base::File::FILE_ERROR_NOT_FOUND)); | 190 base::File::FILE_ERROR_NOT_FOUND)); |
| 191 return false; | 191 return false; |
| 192 } | 192 } |
| 193 | 193 |
| 194 fileapi::ExternalMountPoints* const mount_points = | 194 storage::ExternalMountPoints* const mount_points = |
| 195 fileapi::ExternalMountPoints::GetSystemInstance(); | 195 storage::ExternalMountPoints::GetSystemInstance(); |
| 196 DCHECK(mount_points); | 196 DCHECK(mount_points); |
| 197 | 197 |
| 198 const ProvidedFileSystemInfo& file_system_info = | 198 const ProvidedFileSystemInfo& file_system_info = |
| 199 file_system_it->second->GetFileSystemInfo(); | 199 file_system_it->second->GetFileSystemInfo(); |
| 200 | 200 |
| 201 const std::string mount_point_name = | 201 const std::string mount_point_name = |
| 202 file_system_info.mount_path().BaseName().value(); | 202 file_system_info.mount_path().BaseName().value(); |
| 203 if (!mount_points->RevokeFileSystem(mount_point_name)) { | 203 if (!mount_points->RevokeFileSystem(mount_point_name)) { |
| 204 FOR_EACH_OBSERVER( | 204 FOR_EACH_OBSERVER( |
| 205 Observer, | 205 Observer, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 << ", " << display_name << "."; | 425 << ", " << display_name << "."; |
| 426 // Since remounting of the file system failed, then remove it from | 426 // Since remounting of the file system failed, then remove it from |
| 427 // preferences to avoid remounting it over and over again with a failure. | 427 // preferences to avoid remounting it over and over again with a failure. |
| 428 ForgetFileSystem(extension_id, file_system_id); | 428 ForgetFileSystem(extension_id, file_system_id); |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace file_system_provider | 433 } // namespace file_system_provider |
| 434 } // namespace chromeos | 434 } // namespace chromeos |
| OLD | NEW |