OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/file_system_context.h" | 5 #include "webkit/fileapi/file_system_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 callback.Run(error, filesystem_name, filesystem_root); | 54 callback.Run(error, filesystem_name, filesystem_root); |
55 } | 55 } |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 FileSystemContext::FileSystemContext( | 59 FileSystemContext::FileSystemContext( |
60 scoped_ptr<FileSystemTaskRunners> task_runners, | 60 scoped_ptr<FileSystemTaskRunners> task_runners, |
61 ExternalMountPoints* external_mount_points, | 61 ExternalMountPoints* external_mount_points, |
62 quota::SpecialStoragePolicy* special_storage_policy, | 62 quota::SpecialStoragePolicy* special_storage_policy, |
63 quota::QuotaManagerProxy* quota_manager_proxy, | 63 quota::QuotaManagerProxy* quota_manager_proxy, |
| 64 ScopedVector<FileSystemMountPointProvider> additional_providers, |
64 const base::FilePath& partition_path, | 65 const base::FilePath& partition_path, |
65 const FileSystemOptions& options) | 66 const FileSystemOptions& options) |
66 : task_runners_(task_runners.Pass()), | 67 : task_runners_(task_runners.Pass()), |
67 quota_manager_proxy_(quota_manager_proxy), | 68 quota_manager_proxy_(quota_manager_proxy), |
68 sandbox_provider_( | 69 sandbox_provider_( |
69 new SandboxMountPointProvider( | 70 new SandboxMountPointProvider( |
70 quota_manager_proxy, | 71 quota_manager_proxy, |
71 task_runners_->file_task_runner(), | 72 task_runners_->file_task_runner(), |
72 partition_path, | 73 partition_path, |
73 options)), | 74 options)), |
74 isolated_provider_(new IsolatedMountPointProvider(partition_path)), | 75 isolated_provider_(new IsolatedMountPointProvider(partition_path)), |
| 76 additional_providers_(additional_providers.Pass()), |
75 external_mount_points_(external_mount_points), | 77 external_mount_points_(external_mount_points), |
76 partition_path_(partition_path) { | 78 partition_path_(partition_path) { |
77 DCHECK(task_runners_.get()); | 79 DCHECK(task_runners_.get()); |
78 | 80 |
79 if (quota_manager_proxy) { | 81 if (quota_manager_proxy) { |
80 quota_manager_proxy->RegisterClient(CreateQuotaClient( | 82 quota_manager_proxy->RegisterClient(CreateQuotaClient( |
81 this, options.is_incognito())); | 83 this, options.is_incognito())); |
82 } | 84 } |
83 | 85 |
| 86 RegisterMountPointProvider(sandbox_provider_.get()); |
| 87 RegisterMountPointProvider(isolated_provider_.get()); |
| 88 |
84 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
| 90 // TODO(kinuko): Move this out of webkit/fileapi layer. |
85 DCHECK(external_mount_points); | 91 DCHECK(external_mount_points); |
86 external_provider_.reset( | 92 external_provider_.reset( |
87 new chromeos::CrosMountPointProvider( | 93 new chromeos::CrosMountPointProvider( |
88 special_storage_policy, | 94 special_storage_policy, |
89 external_mount_points, | 95 external_mount_points, |
90 ExternalMountPoints::GetSystemInstance())); | 96 ExternalMountPoints::GetSystemInstance())); |
| 97 RegisterMountPointProvider(external_provider_.get()); |
91 #endif | 98 #endif |
92 | 99 |
| 100 for (ScopedVector<FileSystemMountPointProvider>::const_iterator iter = |
| 101 additional_providers_.begin(); |
| 102 iter != additional_providers_.end(); ++iter) { |
| 103 RegisterMountPointProvider(*iter); |
| 104 } |
| 105 |
| 106 // Additional mount points must be added before regular system-wide |
| 107 // mount points. |
93 if (external_mount_points) | 108 if (external_mount_points) |
94 url_crackers_.push_back(external_mount_points); | 109 url_crackers_.push_back(external_mount_points); |
95 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); | 110 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); |
96 url_crackers_.push_back(IsolatedContext::GetInstance()); | 111 url_crackers_.push_back(IsolatedContext::GetInstance()); |
97 } | 112 } |
98 | 113 |
99 bool FileSystemContext::DeleteDataForOriginOnFileThread( | 114 bool FileSystemContext::DeleteDataForOriginOnFileThread( |
100 const GURL& origin_url) { | 115 const GURL& origin_url) { |
101 DCHECK(task_runners_->file_task_runner()->RunsTasksOnCurrentThread()); | 116 DCHECK(task_runners_->file_task_runner()->RunsTasksOnCurrentThread()); |
102 DCHECK(sandbox_provider()); | 117 DCHECK(sandbox_provider()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 FileSystemMountPointProvider* mount_point_provider = | 159 FileSystemMountPointProvider* mount_point_provider = |
145 GetMountPointProvider(type); | 160 GetMountPointProvider(type); |
146 if (!mount_point_provider) | 161 if (!mount_point_provider) |
147 return NULL; | 162 return NULL; |
148 return mount_point_provider->GetCopyOrMoveFileValidatorFactory( | 163 return mount_point_provider->GetCopyOrMoveFileValidatorFactory( |
149 type, error_code); | 164 type, error_code); |
150 } | 165 } |
151 | 166 |
152 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( | 167 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( |
153 FileSystemType type) const { | 168 FileSystemType type) const { |
154 switch (type) { | 169 MountPointProviderMap::const_iterator found = provider_map_.find(type); |
155 case kFileSystemTypeTemporary: | 170 if (found != provider_map_.end()) |
156 case kFileSystemTypePersistent: | 171 return found->second; |
157 case kFileSystemTypeSyncable: | 172 NOTREACHED() << "Unknown filesystem type: " << type; |
158 return sandbox_provider_.get(); | 173 return NULL; |
159 case kFileSystemTypeExternal: | |
160 case kFileSystemTypeDrive: | |
161 case kFileSystemTypeRestrictedNativeLocal: | |
162 return external_provider_.get(); | |
163 case kFileSystemTypeIsolated: | |
164 case kFileSystemTypeDragged: | |
165 case kFileSystemTypeNativeMedia: | |
166 case kFileSystemTypeDeviceMedia: | |
167 return isolated_provider_.get(); | |
168 case kFileSystemTypeNativeLocal: | |
169 case kFileSystemTypeNativeForPlatformApp: | |
170 #if defined(OS_CHROMEOS) | |
171 return external_provider_.get(); | |
172 #else | |
173 return isolated_provider_.get(); | |
174 #endif | |
175 default: | |
176 if (provider_map_.find(type) != provider_map_.end()) | |
177 return provider_map_.find(type)->second; | |
178 // Fall through. | |
179 case kFileSystemTypeUnknown: | |
180 NOTREACHED(); | |
181 return NULL; | |
182 } | |
183 } | 174 } |
184 | 175 |
185 const UpdateObserverList* FileSystemContext::GetUpdateObservers( | 176 const UpdateObserverList* FileSystemContext::GetUpdateObservers( |
186 FileSystemType type) const { | 177 FileSystemType type) const { |
187 // Currently update observer is only available in SandboxMountPointProvider | 178 // Currently update observer is only available in SandboxMountPointProvider |
188 // and TestMountPointProvider. | 179 // and TestMountPointProvider. |
189 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be | 180 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be |
190 // added to FileSystemMountPointProvider interface and be called like | 181 // added to FileSystemMountPointProvider interface and be called like |
191 // other GetFoo() methods do. | 182 // other GetFoo() methods do. |
192 if (SandboxMountPointProvider::CanHandleType(type)) | 183 if (SandboxMountPointProvider::IsSandboxType(type)) |
193 return sandbox_provider()->GetUpdateObservers(type); | 184 return sandbox_provider()->GetUpdateObservers(type); |
194 if (type != kFileSystemTypeTest) | 185 if (type != kFileSystemTypeTest) |
195 return NULL; | 186 return NULL; |
196 FileSystemMountPointProvider* mount_point_provider = | 187 FileSystemMountPointProvider* mount_point_provider = |
197 GetMountPointProvider(type); | 188 GetMountPointProvider(type); |
198 return static_cast<TestMountPointProvider*>( | 189 return static_cast<TestMountPointProvider*>( |
199 mount_point_provider)->GetUpdateObservers(type); | 190 mount_point_provider)->GetUpdateObservers(type); |
200 } | 191 } |
201 | 192 |
202 SandboxMountPointProvider* | 193 SandboxMountPointProvider* |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 int64 offset) { | 304 int64 offset) { |
314 if (!url.is_valid()) | 305 if (!url.is_valid()) |
315 return scoped_ptr<FileStreamWriter>(); | 306 return scoped_ptr<FileStreamWriter>(); |
316 FileSystemMountPointProvider* mount_point_provider = | 307 FileSystemMountPointProvider* mount_point_provider = |
317 GetMountPointProvider(url.type()); | 308 GetMountPointProvider(url.type()); |
318 if (!mount_point_provider) | 309 if (!mount_point_provider) |
319 return scoped_ptr<FileStreamWriter>(); | 310 return scoped_ptr<FileStreamWriter>(); |
320 return mount_point_provider->CreateFileStreamWriter(url, offset, this); | 311 return mount_point_provider->CreateFileStreamWriter(url, offset, this); |
321 } | 312 } |
322 | 313 |
323 void FileSystemContext::RegisterMountPointProvider( | |
324 FileSystemType type, | |
325 FileSystemMountPointProvider* provider) { | |
326 DCHECK(provider); | |
327 DCHECK(provider_map_.find(type) == provider_map_.end()); | |
328 provider_map_[type] = provider; | |
329 } | |
330 | |
331 void FileSystemContext::SetLocalFileChangeTracker( | 314 void FileSystemContext::SetLocalFileChangeTracker( |
332 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | 315 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { |
333 DCHECK(!change_tracker_.get()); | 316 DCHECK(!change_tracker_.get()); |
334 DCHECK(tracker.get()); | 317 DCHECK(tracker.get()); |
335 change_tracker_ = tracker.Pass(); | 318 change_tracker_ = tracker.Pass(); |
336 sandbox_provider_->AddSyncableFileUpdateObserver( | 319 sandbox_provider_->AddSyncableFileUpdateObserver( |
337 change_tracker_.get(), | 320 change_tracker_.get(), |
338 task_runners_->file_task_runner()); | 321 task_runners_->file_task_runner()); |
339 sandbox_provider_->AddSyncableFileChangeObserver( | 322 sandbox_provider_->AddSyncableFileChangeObserver( |
340 change_tracker_.get(), | 323 change_tracker_.get(), |
(...skipping 19 matching lines...) Expand all Loading... |
360 FileSystemContext::~FileSystemContext() { | 343 FileSystemContext::~FileSystemContext() { |
361 task_runners_->file_task_runner()->DeleteSoon( | 344 task_runners_->file_task_runner()->DeleteSoon( |
362 FROM_HERE, change_tracker_.release()); | 345 FROM_HERE, change_tracker_.release()); |
363 } | 346 } |
364 | 347 |
365 void FileSystemContext::DeleteOnCorrectThread() const { | 348 void FileSystemContext::DeleteOnCorrectThread() const { |
366 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && | 349 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && |
367 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { | 350 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { |
368 return; | 351 return; |
369 } | 352 } |
370 STLDeleteContainerPairSecondPointers(provider_map_.begin(), | |
371 provider_map_.end()); | |
372 delete this; | 353 delete this; |
373 } | 354 } |
374 | 355 |
375 FileSystemURL FileSystemContext::CrackFileSystemURL( | 356 FileSystemURL FileSystemContext::CrackFileSystemURL( |
376 const FileSystemURL& url) const { | 357 const FileSystemURL& url) const { |
377 if (!url.is_valid()) | 358 if (!url.is_valid()) |
378 return FileSystemURL(); | 359 return FileSystemURL(); |
379 | 360 |
380 // The returned value in case there is no crackers which can crack the url. | 361 // The returned value in case there is no crackers which can crack the url. |
381 // This is valid situation for non isolated/external file systems. | 362 // This is valid situation for non isolated/external file systems. |
(...skipping 19 matching lines...) Expand all Loading... |
401 | 382 |
402 FileSystemFileUtil* FileSystemContext::GetFileUtil( | 383 FileSystemFileUtil* FileSystemContext::GetFileUtil( |
403 FileSystemType type) const { | 384 FileSystemType type) const { |
404 FileSystemMountPointProvider* mount_point_provider = | 385 FileSystemMountPointProvider* mount_point_provider = |
405 GetMountPointProvider(type); | 386 GetMountPointProvider(type); |
406 if (!mount_point_provider) | 387 if (!mount_point_provider) |
407 return NULL; | 388 return NULL; |
408 return mount_point_provider->GetFileUtil(type); | 389 return mount_point_provider->GetFileUtil(type); |
409 } | 390 } |
410 | 391 |
| 392 void FileSystemContext::RegisterMountPointProvider( |
| 393 FileSystemMountPointProvider* provider) { |
| 394 const FileSystemType mount_types[] = { |
| 395 kFileSystemTypeTemporary, |
| 396 kFileSystemTypePersistent, |
| 397 kFileSystemTypeIsolated, |
| 398 kFileSystemTypeExternal, |
| 399 }; |
| 400 // Register mount point providers for public mount types. |
| 401 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { |
| 402 if (provider->CanHandleType(mount_types[j])) { |
| 403 const bool inserted = provider_map_.insert( |
| 404 std::make_pair(mount_types[j], provider)).second; |
| 405 DCHECK(inserted); |
| 406 } |
| 407 } |
| 408 // Register mount point providers for internal types. |
| 409 for (int t = kFileSystemInternalTypeEnumStart + 1; |
| 410 t < kFileSystemInternalTypeEnumEnd; ++t) { |
| 411 FileSystemType type = static_cast<FileSystemType>(t); |
| 412 if (provider->CanHandleType(type)) { |
| 413 const bool inserted = provider_map_.insert( |
| 414 std::make_pair(type, provider)).second; |
| 415 DCHECK(inserted); |
| 416 } |
| 417 } |
| 418 } |
| 419 |
411 } // namespace fileapi | 420 } // namespace fileapi |
OLD | NEW |