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" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 observers_.RemoveObserver(observer); | 94 observers_.RemoveObserver(observer); |
95 } | 95 } |
96 | 96 |
97 void Service::SetFileSystemFactoryForTesting( | 97 void Service::SetFileSystemFactoryForTesting( |
98 const FileSystemFactoryCallback& factory_callback) { | 98 const FileSystemFactoryCallback& factory_callback) { |
99 DCHECK(!factory_callback.is_null()); | 99 DCHECK(!factory_callback.is_null()); |
100 file_system_factory_ = factory_callback; | 100 file_system_factory_ = factory_callback; |
101 } | 101 } |
102 | 102 |
103 bool Service::MountFileSystem(const std::string& extension_id, | 103 bool Service::MountFileSystem(const std::string& extension_id, |
104 const std::string& file_system_id, | 104 const MountOptions& options) { |
105 const std::string& display_name, | |
106 bool writable, | |
107 bool supports_notify_tag) { | |
108 DCHECK(thread_checker_.CalledOnValidThread()); | 105 DCHECK(thread_checker_.CalledOnValidThread()); |
109 | 106 |
110 // If already exists a file system provided by the same extension with this | 107 // If already exists a file system provided by the same extension with this |
111 // id, then abort. | 108 // id, then abort. |
112 if (GetProvidedFileSystem(extension_id, file_system_id)) { | 109 if (GetProvidedFileSystem(extension_id, options.file_system_id)) { |
113 FOR_EACH_OBSERVER(Observer, | 110 FOR_EACH_OBSERVER(Observer, |
114 observers_, | 111 observers_, |
115 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 112 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
116 base::File::FILE_ERROR_EXISTS)); | 113 base::File::FILE_ERROR_EXISTS)); |
117 return false; | 114 return false; |
118 } | 115 } |
119 | 116 |
120 // Restrict number of file systems to prevent system abusing. | 117 // Restrict number of file systems to prevent system abusing. |
121 if (file_system_map_.size() + 1 > kMaxFileSystems) { | 118 if (file_system_map_.size() + 1 > kMaxFileSystems) { |
122 FOR_EACH_OBSERVER( | 119 FOR_EACH_OBSERVER( |
123 Observer, | 120 Observer, |
124 observers_, | 121 observers_, |
125 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 122 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
126 base::File::FILE_ERROR_TOO_MANY_OPENED)); | 123 base::File::FILE_ERROR_TOO_MANY_OPENED)); |
127 return false; | 124 return false; |
128 } | 125 } |
129 | 126 |
130 storage::ExternalMountPoints* const mount_points = | 127 storage::ExternalMountPoints* const mount_points = |
131 storage::ExternalMountPoints::GetSystemInstance(); | 128 storage::ExternalMountPoints::GetSystemInstance(); |
132 DCHECK(mount_points); | 129 DCHECK(mount_points); |
133 | 130 |
134 // The mount point path and name are unique per system, since they are system | 131 // The mount point path and name are unique per system, since they are system |
135 // wide. This is necessary for copying between profiles. | 132 // wide. This is necessary for copying between profiles. |
136 const base::FilePath& mount_path = | 133 const base::FilePath& mount_path = |
137 util::GetMountPath(profile_, extension_id, file_system_id); | 134 util::GetMountPath(profile_, extension_id, options.file_system_id); |
138 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); | 135 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); |
139 | 136 |
140 if (!mount_points->RegisterFileSystem(mount_point_name, | 137 if (!mount_points->RegisterFileSystem(mount_point_name, |
141 storage::kFileSystemTypeProvided, | 138 storage::kFileSystemTypeProvided, |
142 storage::FileSystemMountOption(), | 139 storage::FileSystemMountOption(), |
143 mount_path)) { | 140 mount_path)) { |
144 FOR_EACH_OBSERVER( | 141 FOR_EACH_OBSERVER( |
145 Observer, | 142 Observer, |
146 observers_, | 143 observers_, |
147 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 144 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
148 base::File::FILE_ERROR_INVALID_OPERATION)); | 145 base::File::FILE_ERROR_INVALID_OPERATION)); |
149 return false; | 146 return false; |
150 } | 147 } |
151 | 148 |
152 // Store the file system descriptor. Use the mount point name as the file | 149 // Store the file system descriptor. Use the mount point name as the file |
153 // system provider file system id. | 150 // system provider file system id. |
154 // Examples: | 151 // Examples: |
155 // file_system_id = hello_world | 152 // file_system_id = hello_world |
156 // mount_point_name = b33f1337-hello_world-5aa5 | 153 // mount_point_name = b33f1337-hello_world-5aa5 |
157 // writable = false | 154 // writable = false |
158 // supports_notify_tag = false | 155 // supports_notify_tag = false |
159 // mount_path = /provided/b33f1337-hello_world-5aa5 | 156 // mount_path = /provided/b33f1337-hello_world-5aa5 |
160 ProvidedFileSystemInfo file_system_info(extension_id, | 157 ProvidedFileSystemInfo file_system_info(extension_id, options, mount_path); |
161 file_system_id, | |
162 display_name, | |
163 writable, | |
164 supports_notify_tag, | |
165 mount_path); | |
166 | 158 |
167 ProvidedFileSystemInterface* file_system = | 159 ProvidedFileSystemInterface* file_system = |
168 file_system_factory_.Run(profile_, file_system_info); | 160 file_system_factory_.Run(profile_, file_system_info); |
169 DCHECK(file_system); | 161 DCHECK(file_system); |
170 file_system_map_[FileSystemKey(extension_id, file_system_id)] = file_system; | 162 file_system_map_[FileSystemKey(extension_id, options.file_system_id)] = |
| 163 file_system; |
171 mount_point_name_to_key_map_[mount_point_name] = | 164 mount_point_name_to_key_map_[mount_point_name] = |
172 FileSystemKey(extension_id, file_system_id); | 165 FileSystemKey(extension_id, options.file_system_id); |
173 RememberFileSystem(file_system_info); | 166 RememberFileSystem(file_system_info); |
174 | 167 |
175 FOR_EACH_OBSERVER( | 168 FOR_EACH_OBSERVER( |
176 Observer, | 169 Observer, |
177 observers_, | 170 observers_, |
178 OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK)); | 171 OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK)); |
179 | 172 |
180 return true; | 173 return true; |
181 } | 174 } |
182 | 175 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 &display_name) || | 436 &display_name) || |
444 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, | 437 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, |
445 &writable) || | 438 &writable) || |
446 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, | 439 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, |
447 &supports_notify_tag) || | 440 &supports_notify_tag) || |
448 file_system_id.empty() || display_name.empty()) { | 441 file_system_id.empty() || display_name.empty()) { |
449 LOG(ERROR) | 442 LOG(ERROR) |
450 << "Malformed provided file system information in preferences."; | 443 << "Malformed provided file system information in preferences."; |
451 continue; | 444 continue; |
452 } | 445 } |
453 const bool result = MountFileSystem(extension_id, | 446 MountOptions options; |
454 file_system_id, | 447 options.file_system_id = file_system_id; |
455 display_name, | 448 options.display_name = display_name; |
456 writable, | 449 options.writable = writable; |
457 supports_notify_tag); | 450 options.supports_notify_tag = supports_notify_tag; |
| 451 const bool result = MountFileSystem(extension_id, options); |
458 if (!result) { | 452 if (!result) { |
459 LOG(ERROR) << "Failed to restore a provided file system from " | 453 LOG(ERROR) << "Failed to restore a provided file system from " |
460 << "preferences: " << extension_id << ", " << file_system_id | 454 << "preferences: " << extension_id << ", " << file_system_id |
461 << ", " << display_name << "."; | 455 << ", " << display_name << "."; |
462 // Since remounting of the file system failed, then remove it from | 456 // Since remounting of the file system failed, then remove it from |
463 // preferences to avoid remounting it over and over again with a failure. | 457 // preferences to avoid remounting it over and over again with a failure. |
464 ForgetFileSystem(extension_id, file_system_id); | 458 ForgetFileSystem(extension_id, file_system_id); |
465 } | 459 } |
466 } | 460 } |
467 } | 461 } |
468 | 462 |
469 } // namespace file_system_provider | 463 } // namespace file_system_provider |
470 } // namespace chromeos | 464 } // namespace chromeos |
OLD | NEW |