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/file_system_provider_serv
ice.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 "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/file_system_provider_serv
ice_factory.h" |
12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 13 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
13 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 14 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
16 #include "chrome/browser/chromeos/file_system_provider/registry.h" | 17 #include "chrome/browser/chromeos/file_system_provider/registry.h" |
17 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" | 18 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" |
18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | |
19 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h" | 19 #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h" |
20 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
21 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
22 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
23 #include "extensions/common/permissions/api_permission.h" | 23 #include "extensions/common/permissions/api_permission.h" |
24 #include "extensions/common/permissions/permissions_data.h" | 24 #include "extensions/common/permissions/permissions_data.h" |
25 #include "storage/browser/fileapi/external_mount_points.h" | 25 #include "storage/browser/fileapi/external_mount_points.h" |
26 #include "storage/common/fileapi/file_system_mount_option.h" | 26 #include "storage/common/fileapi/file_system_mount_option.h" |
27 | 27 |
28 namespace chromeos { | 28 namespace chromeos { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 base::File::Error Service::UnmountFileSystem(const std::string& extension_id, | 197 base::File::Error Service::UnmountFileSystem(const std::string& extension_id, |
198 const std::string& file_system_id, | 198 const std::string& file_system_id, |
199 UnmountReason reason) { | 199 UnmountReason reason) { |
200 DCHECK(thread_checker_.CalledOnValidThread()); | 200 DCHECK(thread_checker_.CalledOnValidThread()); |
201 | 201 |
202 const ProvidedFileSystemMap::iterator file_system_it = | 202 const ProvidedFileSystemMap::iterator file_system_it = |
203 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); | 203 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); |
204 if (file_system_it == file_system_map_.end()) { | 204 if (file_system_it == file_system_map_.end()) { |
205 const ProvidedFileSystemInfo empty_file_system_info; | 205 const ProvidedFileSystemInfo empty_file_system_info; |
206 FOR_EACH_OBSERVER( | 206 FOR_EACH_OBSERVER( |
207 Observer, | 207 Observer, observers_, |
208 observers_, | |
209 OnProvidedFileSystemUnmount(empty_file_system_info, | 208 OnProvidedFileSystemUnmount(empty_file_system_info, |
210 base::File::FILE_ERROR_NOT_FOUND)); | 209 base::File::FILE_ERROR_NOT_FOUND)); |
211 return base::File::FILE_ERROR_NOT_FOUND; | 210 return base::File::FILE_ERROR_NOT_FOUND; |
212 } | 211 } |
213 | 212 |
214 storage::ExternalMountPoints* const mount_points = | 213 storage::ExternalMountPoints* const mount_points = |
215 storage::ExternalMountPoints::GetSystemInstance(); | 214 storage::ExternalMountPoints::GetSystemInstance(); |
216 DCHECK(mount_points); | 215 DCHECK(mount_points); |
217 | 216 |
218 const ProvidedFileSystemInfo& file_system_info = | 217 const ProvidedFileSystemInfo& file_system_info = |
219 file_system_it->second->GetFileSystemInfo(); | 218 file_system_it->second->GetFileSystemInfo(); |
220 | 219 |
221 const std::string mount_point_name = | 220 const std::string mount_point_name = |
222 file_system_info.mount_path().BaseName().value(); | 221 file_system_info.mount_path().BaseName().value(); |
223 if (!mount_points->RevokeFileSystem(mount_point_name)) { | 222 if (!mount_points->RevokeFileSystem(mount_point_name)) { |
224 FOR_EACH_OBSERVER( | 223 FOR_EACH_OBSERVER( |
225 Observer, | 224 Observer, observers_, |
226 observers_, | |
227 OnProvidedFileSystemUnmount(file_system_info, | 225 OnProvidedFileSystemUnmount(file_system_info, |
228 base::File::FILE_ERROR_INVALID_OPERATION)); | 226 base::File::FILE_ERROR_INVALID_OPERATION)); |
229 return base::File::FILE_ERROR_INVALID_OPERATION; | 227 return base::File::FILE_ERROR_INVALID_OPERATION; |
230 } | 228 } |
231 | 229 |
232 FOR_EACH_OBSERVER( | 230 FOR_EACH_OBSERVER( |
233 Observer, | 231 Observer, observers_, |
234 observers_, | |
235 OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK)); | 232 OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK)); |
236 | 233 |
237 mount_point_name_to_key_map_.erase(mount_point_name); | 234 mount_point_name_to_key_map_.erase(mount_point_name); |
238 | 235 |
239 if (reason == UNMOUNT_REASON_USER) { | 236 if (reason == UNMOUNT_REASON_USER) { |
240 registry_->ForgetFileSystem(file_system_info.extension_id(), | 237 registry_->ForgetFileSystem(file_system_info.extension_id(), |
241 file_system_info.file_system_id()); | 238 file_system_info.file_system_id()); |
242 } | 239 } |
243 | 240 |
244 delete file_system_it->second; | 241 delete file_system_it->second; |
245 file_system_map_.erase(file_system_it); | 242 file_system_map_.erase(file_system_it); |
246 | 243 |
247 return base::File::FILE_OK; | 244 return base::File::FILE_OK; |
248 } | 245 } |
249 | 246 |
250 bool Service::RequestUnmount(const std::string& extension_id, | 247 bool Service::RequestUnmount(const std::string& extension_id, |
251 const std::string& file_system_id) { | 248 const std::string& file_system_id) { |
252 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
253 | 250 |
254 ProvidedFileSystemMap::iterator file_system_it = | 251 ProvidedFileSystemMap::iterator file_system_it = |
255 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); | 252 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); |
256 if (file_system_it == file_system_map_.end()) | 253 if (file_system_it == file_system_map_.end()) |
257 return false; | 254 return false; |
258 | 255 |
259 file_system_it->second->RequestUnmount( | 256 file_system_it->second->RequestUnmount(base::Bind( |
260 base::Bind(&Service::OnRequestUnmountStatus, | 257 &Service::OnRequestUnmountStatus, weak_ptr_factory_.GetWeakPtr(), |
261 weak_ptr_factory_.GetWeakPtr(), | 258 file_system_it->second->GetFileSystemInfo())); |
262 file_system_it->second->GetFileSystemInfo())); | |
263 return true; | 259 return true; |
264 } | 260 } |
265 | 261 |
266 bool Service::RequestMount(const std::string& extension_id) { | 262 bool Service::RequestMount(const std::string& extension_id) { |
267 DCHECK(thread_checker_.CalledOnValidThread()); | 263 DCHECK(thread_checker_.CalledOnValidThread()); |
268 | 264 |
269 extensions::EventRouter* const event_router = | 265 extensions::EventRouter* const event_router = |
270 extensions::EventRouter::Get(profile_); | 266 extensions::EventRouter::Get(profile_); |
271 DCHECK(event_router); | 267 DCHECK(event_router); |
272 | 268 |
(...skipping 10 matching lines...) Expand all Loading... |
283 scoped_ptr<base::ListValue>(new base::ListValue())))); | 279 scoped_ptr<base::ListValue>(new base::ListValue())))); |
284 | 280 |
285 return true; | 281 return true; |
286 } | 282 } |
287 | 283 |
288 std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { | 284 std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { |
289 DCHECK(thread_checker_.CalledOnValidThread()); | 285 DCHECK(thread_checker_.CalledOnValidThread()); |
290 | 286 |
291 std::vector<ProvidedFileSystemInfo> result; | 287 std::vector<ProvidedFileSystemInfo> result; |
292 for (ProvidedFileSystemMap::const_iterator it = file_system_map_.begin(); | 288 for (ProvidedFileSystemMap::const_iterator it = file_system_map_.begin(); |
293 it != file_system_map_.end(); | 289 it != file_system_map_.end(); ++it) { |
294 ++it) { | |
295 result.push_back(it->second->GetFileSystemInfo()); | 290 result.push_back(it->second->GetFileSystemInfo()); |
296 } | 291 } |
297 return result; | 292 return result; |
298 } | 293 } |
299 | 294 |
300 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( | 295 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( |
301 const std::string& extension_id, | 296 const std::string& extension_id, |
302 const std::string& file_system_id) { | 297 const std::string& file_system_id) { |
303 DCHECK(thread_checker_.CalledOnValidThread()); | 298 DCHECK(thread_checker_.CalledOnValidThread()); |
304 | 299 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 return file_system_it->second; | 416 return file_system_it->second; |
422 } | 417 } |
423 | 418 |
424 void Service::OnRequestUnmountStatus( | 419 void Service::OnRequestUnmountStatus( |
425 const ProvidedFileSystemInfo& file_system_info, | 420 const ProvidedFileSystemInfo& file_system_info, |
426 base::File::Error error) { | 421 base::File::Error error) { |
427 // Notify observers about failure in unmounting, since mount() will not be | 422 // Notify observers about failure in unmounting, since mount() will not be |
428 // called by the provided file system. In case of success mount() will be | 423 // called by the provided file system. In case of success mount() will be |
429 // invoked, and observers notified, so there is no need to call them now. | 424 // invoked, and observers notified, so there is no need to call them now. |
430 if (error != base::File::FILE_OK) { | 425 if (error != base::File::FILE_OK) { |
431 FOR_EACH_OBSERVER(Observer, | 426 FOR_EACH_OBSERVER(Observer, observers_, |
432 observers_, | |
433 OnProvidedFileSystemUnmount(file_system_info, error)); | 427 OnProvidedFileSystemUnmount(file_system_info, error)); |
434 } | 428 } |
435 } | 429 } |
436 | 430 |
437 void Service::OnWatcherChanged(const ProvidedFileSystemInfo& file_system_info, | 431 void Service::OnWatcherChanged(const ProvidedFileSystemInfo& file_system_info, |
438 const Watcher& watcher, | 432 const Watcher& watcher, |
439 storage::WatcherManager::ChangeType change_type, | 433 storage::WatcherManager::ChangeType change_type, |
440 const Changes& changes, | 434 const Changes& changes, |
441 const base::Closure& callback) { | 435 const base::Closure& callback) { |
442 callback.Run(); | 436 callback.Run(); |
443 } | 437 } |
444 | 438 |
445 void Service::OnWatcherTagUpdated( | 439 void Service::OnWatcherTagUpdated( |
446 const ProvidedFileSystemInfo& file_system_info, | 440 const ProvidedFileSystemInfo& file_system_info, |
447 const Watcher& watcher) { | 441 const Watcher& watcher) { |
448 PrefService* const pref_service = profile_->GetPrefs(); | 442 PrefService* const pref_service = profile_->GetPrefs(); |
449 DCHECK(pref_service); | 443 DCHECK(pref_service); |
450 | 444 |
451 registry_->UpdateWatcherTag(file_system_info, watcher); | 445 registry_->UpdateWatcherTag(file_system_info, watcher); |
452 } | 446 } |
453 | 447 |
454 void Service::OnWatcherListChanged( | 448 void Service::OnWatcherListChanged( |
455 const ProvidedFileSystemInfo& file_system_info, | 449 const ProvidedFileSystemInfo& file_system_info, |
456 const Watchers& watchers) { | 450 const Watchers& watchers) { |
457 registry_->RememberFileSystem(file_system_info, watchers); | 451 registry_->RememberFileSystem(file_system_info, watchers); |
458 } | 452 } |
459 | 453 |
460 } // namespace file_system_provider | 454 } // namespace file_system_provider |
461 } // namespace chromeos | 455 } // namespace chromeos |
OLD | NEW |