Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/isolated_context.h" | 22 #include "webkit/fileapi/isolated_context.h" |
| 23 #include "webkit/fileapi/isolated_mount_point_provider.h" | 23 #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 24 #include "webkit/fileapi/mount_points.h" | 24 #include "webkit/fileapi/mount_points.h" |
| 25 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 25 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 26 #include "webkit/fileapi/syncable/local_file_change_tracker.h" | 26 #include "webkit/fileapi/syncable/local_file_change_tracker.h" |
| 27 #include "webkit/fileapi/syncable/local_file_sync_context.h" | 27 #include "webkit/fileapi/syncable/local_file_sync_context.h" |
| 28 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 28 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
| 29 #include "webkit/fileapi/test_mount_point_provider.h" | 29 #include "webkit/fileapi/test_mount_point_provider.h" |
| 30 #include "webkit/quota/quota_manager.h" | 30 #include "webkit/quota/quota_manager.h" |
| 31 #include "webkit/quota/special_storage_policy.h" | |
| 32 | |
| 33 #if defined(OS_CHROMEOS) | |
| 34 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | |
| 35 #endif | |
| 36 | 31 |
| 37 using quota::QuotaClient; | 32 using quota::QuotaClient; |
| 38 | 33 |
| 39 namespace fileapi { | 34 namespace fileapi { |
| 40 | 35 |
| 41 namespace { | 36 namespace { |
| 42 | 37 |
| 43 QuotaClient* CreateQuotaClient( | 38 QuotaClient* CreateQuotaClient( |
| 44 FileSystemContext* context, | 39 FileSystemContext* context, |
| 45 bool is_incognito) { | 40 bool is_incognito) { |
| 46 return new FileSystemQuotaClient(context, is_incognito); | 41 return new FileSystemQuotaClient(context, is_incognito); |
| 47 } | 42 } |
| 48 | 43 |
| 49 void DidOpenFileSystem( | 44 void DidOpenFileSystem( |
| 50 const FileSystemContext::OpenFileSystemCallback& callback, | 45 const FileSystemContext::OpenFileSystemCallback& callback, |
| 51 const GURL& filesystem_root, | 46 const GURL& filesystem_root, |
| 52 const std::string& filesystem_name, | 47 const std::string& filesystem_name, |
| 53 base::PlatformFileError error) { | 48 base::PlatformFileError error) { |
| 54 callback.Run(error, filesystem_name, filesystem_root); | 49 callback.Run(error, filesystem_name, filesystem_root); |
| 55 } | 50 } |
| 56 | 51 |
| 57 } // namespace | 52 } // namespace |
| 58 | 53 |
| 59 FileSystemContext::FileSystemContext( | 54 FileSystemContext::FileSystemContext( |
| 60 scoped_ptr<FileSystemTaskRunners> task_runners, | 55 scoped_ptr<FileSystemTaskRunners> task_runners, |
| 61 ExternalMountPoints* external_mount_points, | |
| 62 quota::SpecialStoragePolicy* special_storage_policy, | |
| 63 quota::QuotaManagerProxy* quota_manager_proxy, | 56 quota::QuotaManagerProxy* quota_manager_proxy, |
| 57 ScopedVector<FileSystemMountPointProvider> additional_providers, | |
| 58 const std::vector<MountPoints*>& additional_mount_points, | |
| 64 const base::FilePath& partition_path, | 59 const base::FilePath& partition_path, |
| 65 const FileSystemOptions& options) | 60 const FileSystemOptions& options) |
| 66 : task_runners_(task_runners.Pass()), | 61 : task_runners_(task_runners.Pass()), |
| 67 quota_manager_proxy_(quota_manager_proxy), | 62 quota_manager_proxy_(quota_manager_proxy), |
| 68 sandbox_provider_( | 63 sandbox_provider_( |
| 69 new SandboxMountPointProvider( | 64 new SandboxMountPointProvider( |
| 70 quota_manager_proxy, | 65 quota_manager_proxy, |
| 71 task_runners_->file_task_runner(), | 66 task_runners_->file_task_runner(), |
| 72 partition_path, | 67 partition_path, |
| 73 options)), | 68 options)), |
| 74 isolated_provider_(new IsolatedMountPointProvider(partition_path)), | 69 isolated_provider_(new IsolatedMountPointProvider(partition_path)), |
| 75 external_mount_points_(external_mount_points), | 70 additional_providers_(additional_providers.Pass()), |
| 76 partition_path_(partition_path) { | 71 partition_path_(partition_path) { |
| 77 DCHECK(task_runners_.get()); | 72 DCHECK(task_runners_.get()); |
| 78 | 73 |
| 74 RegisterMountPointProvider(sandbox_provider_.get()); | |
| 75 RegisterMountPointProvider(isolated_provider_.get()); | |
| 76 | |
| 77 for (ScopedVector<FileSystemMountPointProvider>::const_iterator iter = | |
| 78 additional_providers_.begin(); | |
| 79 iter != additional_providers_.end(); ++iter) { | |
| 80 RegisterMountPointProvider(*iter); | |
| 81 } | |
| 82 | |
| 79 if (quota_manager_proxy) { | 83 if (quota_manager_proxy) { |
| 80 quota_manager_proxy->RegisterClient(CreateQuotaClient( | 84 quota_manager_proxy->RegisterClient(CreateQuotaClient( |
| 81 this, options.is_incognito())); | 85 this, options.is_incognito())); |
| 82 } | 86 } |
| 83 | 87 |
| 84 #if defined(OS_CHROMEOS) | 88 // Additional mount points must be added before regular system-wide |
| 85 DCHECK(external_mount_points); | 89 // mount points. |
| 86 external_provider_.reset( | 90 for (std::vector<fileapi::MountPoints*>::const_iterator iter = |
| 87 new chromeos::CrosMountPointProvider( | 91 additional_mount_points.begin(); |
| 88 special_storage_policy, | 92 iter != additional_mount_points.end(); ++iter) { |
| 89 external_mount_points, | 93 url_crackers_.push_back(*iter); |
| 90 ExternalMountPoints::GetSystemInstance())); | 94 } |
| 91 #endif | 95 url_crackers_.push_back(fileapi::ExternalMountPoints::GetSystemInstance()); |
| 92 | 96 url_crackers_.push_back(fileapi::IsolatedContext::GetInstance()); |
| 93 if (external_mount_points) | |
| 94 url_crackers_.push_back(external_mount_points); | |
| 95 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); | |
| 96 url_crackers_.push_back(IsolatedContext::GetInstance()); | |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool FileSystemContext::DeleteDataForOriginOnFileThread( | 99 bool FileSystemContext::DeleteDataForOriginOnFileThread( |
| 100 const GURL& origin_url) { | 100 const GURL& origin_url) { |
| 101 DCHECK(task_runners_->file_task_runner()->RunsTasksOnCurrentThread()); | 101 DCHECK(task_runners_->file_task_runner()->RunsTasksOnCurrentThread()); |
| 102 DCHECK(sandbox_provider()); | 102 DCHECK(sandbox_provider()); |
| 103 DCHECK(origin_url == origin_url.GetOrigin()); | 103 DCHECK(origin_url == origin_url.GetOrigin()); |
| 104 | 104 |
| 105 // Delete temporary and persistent data. | 105 // Delete temporary and persistent data. |
| 106 return | 106 return |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 FileSystemMountPointProvider* mount_point_provider = | 144 FileSystemMountPointProvider* mount_point_provider = |
| 145 GetMountPointProvider(type); | 145 GetMountPointProvider(type); |
| 146 if (!mount_point_provider) | 146 if (!mount_point_provider) |
| 147 return NULL; | 147 return NULL; |
| 148 return mount_point_provider->GetCopyOrMoveFileValidatorFactory( | 148 return mount_point_provider->GetCopyOrMoveFileValidatorFactory( |
| 149 type, error_code); | 149 type, error_code); |
| 150 } | 150 } |
| 151 | 151 |
| 152 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( | 152 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( |
| 153 FileSystemType type) const { | 153 FileSystemType type) const { |
| 154 switch (type) { | 154 if (provider_map_.find(type) != provider_map_.end()) |
| 155 case kFileSystemTypeTemporary: | 155 return provider_map_.find(type)->second; |
|
tzik
2013/04/17 12:06:04
could you reuse the result of find(type)?
kinuko
2013/04/17 14:27:29
Done.
| |
| 156 case kFileSystemTypePersistent: | 156 NOTREACHED() << "Unknown filesystem type: " << type; |
| 157 case kFileSystemTypeSyncable: | 157 return NULL; |
| 158 return sandbox_provider_.get(); | |
| 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 } | 158 } |
| 184 | 159 |
| 185 const UpdateObserverList* FileSystemContext::GetUpdateObservers( | 160 const UpdateObserverList* FileSystemContext::GetUpdateObservers( |
| 186 FileSystemType type) const { | 161 FileSystemType type) const { |
| 187 // Currently update observer is only available in SandboxMountPointProvider | 162 // Currently update observer is only available in SandboxMountPointProvider |
| 188 // and TestMountPointProvider. | 163 // and TestMountPointProvider. |
| 189 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be | 164 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be |
| 190 // added to FileSystemMountPointProvider interface and be called like | 165 // added to FileSystemMountPointProvider interface and be called like |
| 191 // other GetFoo() methods do. | 166 // other GetFoo() methods do. |
| 192 if (SandboxMountPointProvider::CanHandleType(type)) | 167 if (SandboxMountPointProvider::IsSandboxType(type)) |
| 193 return sandbox_provider()->GetUpdateObservers(type); | 168 return sandbox_provider()->GetUpdateObservers(type); |
| 194 if (type != kFileSystemTypeTest) | 169 if (type != kFileSystemTypeTest) |
| 195 return NULL; | 170 return NULL; |
| 196 FileSystemMountPointProvider* mount_point_provider = | 171 FileSystemMountPointProvider* mount_point_provider = |
| 197 GetMountPointProvider(type); | 172 GetMountPointProvider(type); |
| 198 return static_cast<TestMountPointProvider*>( | 173 return static_cast<TestMountPointProvider*>( |
| 199 mount_point_provider)->GetUpdateObservers(type); | 174 mount_point_provider)->GetUpdateObservers(type); |
| 200 } | 175 } |
| 201 | 176 |
| 202 SandboxMountPointProvider* | 177 SandboxMountPointProvider* |
| 203 FileSystemContext::sandbox_provider() const { | 178 FileSystemContext::sandbox_provider() const { |
| 204 return sandbox_provider_.get(); | 179 return sandbox_provider_.get(); |
| 205 } | 180 } |
| 206 | 181 |
| 207 ExternalFileSystemMountPointProvider* | 182 ExternalFileSystemMountPointProvider* |
| 208 FileSystemContext::external_provider() const { | 183 FileSystemContext::external_provider() const { |
| 209 return external_provider_.get(); | 184 ExternalFileSystemMountPointProvider* external_provider = |
| 185 static_cast<ExternalFileSystemMountPointProvider*>( | |
| 186 GetMountPointProvider(kFileSystemTypeExternal)); | |
| 187 DCHECK(external_provider); | |
| 188 return external_provider; | |
| 210 } | 189 } |
| 211 | 190 |
| 212 void FileSystemContext::OpenFileSystem( | 191 void FileSystemContext::OpenFileSystem( |
| 213 const GURL& origin_url, | 192 const GURL& origin_url, |
| 214 FileSystemType type, | 193 FileSystemType type, |
| 215 bool create, | 194 bool create, |
| 216 const OpenFileSystemCallback& callback) { | 195 const OpenFileSystemCallback& callback) { |
| 217 DCHECK(!callback.is_null()); | 196 DCHECK(!callback.is_null()); |
| 218 | 197 |
| 219 FileSystemMountPointProvider* mount_point_provider = | 198 FileSystemMountPointProvider* mount_point_provider = |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 int64 offset) { | 292 int64 offset) { |
| 314 if (!url.is_valid()) | 293 if (!url.is_valid()) |
| 315 return scoped_ptr<FileStreamWriter>(); | 294 return scoped_ptr<FileStreamWriter>(); |
| 316 FileSystemMountPointProvider* mount_point_provider = | 295 FileSystemMountPointProvider* mount_point_provider = |
| 317 GetMountPointProvider(url.type()); | 296 GetMountPointProvider(url.type()); |
| 318 if (!mount_point_provider) | 297 if (!mount_point_provider) |
| 319 return scoped_ptr<FileStreamWriter>(); | 298 return scoped_ptr<FileStreamWriter>(); |
| 320 return mount_point_provider->CreateFileStreamWriter(url, offset, this); | 299 return mount_point_provider->CreateFileStreamWriter(url, offset, this); |
| 321 } | 300 } |
| 322 | 301 |
| 323 void FileSystemContext::RegisterMountPointProvider( | 302 void FileSystemContext::RegisterMountPointProviderForTesting( |
| 324 FileSystemType type, | 303 FileSystemType type, |
| 325 FileSystemMountPointProvider* provider) { | 304 FileSystemMountPointProvider* provider) { |
| 326 DCHECK(provider); | 305 DCHECK(provider); |
| 327 DCHECK(provider_map_.find(type) == provider_map_.end()); | 306 DCHECK(provider_map_.find(type) == provider_map_.end()); |
| 328 provider_map_[type] = provider; | 307 provider_map_[type] = provider; |
| 308 additional_providers_.push_back(provider); | |
| 329 } | 309 } |
| 330 | 310 |
| 331 void FileSystemContext::SetLocalFileChangeTracker( | 311 void FileSystemContext::SetLocalFileChangeTracker( |
| 332 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | 312 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { |
| 333 DCHECK(!change_tracker_.get()); | 313 DCHECK(!change_tracker_.get()); |
| 334 DCHECK(tracker.get()); | 314 DCHECK(tracker.get()); |
| 335 change_tracker_ = tracker.Pass(); | 315 change_tracker_ = tracker.Pass(); |
| 336 sandbox_provider_->AddSyncableFileUpdateObserver( | 316 sandbox_provider_->AddSyncableFileUpdateObserver( |
| 337 change_tracker_.get(), | 317 change_tracker_.get(), |
| 338 task_runners_->file_task_runner()); | 318 task_runners_->file_task_runner()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 360 FileSystemContext::~FileSystemContext() { | 340 FileSystemContext::~FileSystemContext() { |
| 361 task_runners_->file_task_runner()->DeleteSoon( | 341 task_runners_->file_task_runner()->DeleteSoon( |
| 362 FROM_HERE, change_tracker_.release()); | 342 FROM_HERE, change_tracker_.release()); |
| 363 } | 343 } |
| 364 | 344 |
| 365 void FileSystemContext::DeleteOnCorrectThread() const { | 345 void FileSystemContext::DeleteOnCorrectThread() const { |
| 366 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && | 346 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && |
| 367 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { | 347 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { |
| 368 return; | 348 return; |
| 369 } | 349 } |
| 370 STLDeleteContainerPairSecondPointers(provider_map_.begin(), | |
| 371 provider_map_.end()); | |
| 372 delete this; | 350 delete this; |
| 373 } | 351 } |
| 374 | 352 |
| 375 FileSystemURL FileSystemContext::CrackFileSystemURL( | 353 FileSystemURL FileSystemContext::CrackFileSystemURL( |
| 376 const FileSystemURL& url) const { | 354 const FileSystemURL& url) const { |
| 377 if (!url.is_valid()) | 355 if (!url.is_valid()) |
| 378 return FileSystemURL(); | 356 return FileSystemURL(); |
| 379 | 357 |
| 380 // The returned value in case there is no crackers which can crack the url. | 358 // 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. | 359 // This is valid situation for non isolated/external file systems. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 401 | 379 |
| 402 FileSystemFileUtil* FileSystemContext::GetFileUtil( | 380 FileSystemFileUtil* FileSystemContext::GetFileUtil( |
| 403 FileSystemType type) const { | 381 FileSystemType type) const { |
| 404 FileSystemMountPointProvider* mount_point_provider = | 382 FileSystemMountPointProvider* mount_point_provider = |
| 405 GetMountPointProvider(type); | 383 GetMountPointProvider(type); |
| 406 if (!mount_point_provider) | 384 if (!mount_point_provider) |
| 407 return NULL; | 385 return NULL; |
| 408 return mount_point_provider->GetFileUtil(type); | 386 return mount_point_provider->GetFileUtil(type); |
| 409 } | 387 } |
| 410 | 388 |
| 389 void FileSystemContext::RegisterMountPointProvider( | |
| 390 FileSystemMountPointProvider* provider) { | |
| 391 static const FileSystemType mount_types[] = { | |
|
tzik
2013/04/17 12:06:04
could you move this to the top of the file?
kinuko
2013/04/17 14:27:29
It's only referred in this method-- I just dropped
| |
| 392 kFileSystemTypeTemporary, | |
| 393 kFileSystemTypePersistent, | |
| 394 kFileSystemTypeIsolated, | |
| 395 kFileSystemTypeExternal, | |
| 396 }; | |
| 397 // Register mount point providers for public mount types. | |
| 398 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { | |
| 399 if (provider->CanHandleType(mount_types[j])) | |
| 400 provider_map_.insert(std::make_pair(mount_types[j], provider)); | |
|
tzik
2013/04/17 12:06:04
could you add DCHECK the .second of the result?
kinuko
2013/04/17 14:27:29
Done.
| |
| 401 } | |
| 402 // Register mount point providers for internal types. | |
| 403 for (int t = kFileSystemInternalTypeEnumStart; | |
|
tzik
2013/04/17 12:06:04
kFileSystemInternalTypeEnumStart + 1?
kinuko
2013/04/17 14:27:29
Done.
| |
| 404 t < kFileSystemInternalTypeEnumEnd; ++t) { | |
|
tzik
2013/04/17 12:06:04
indent?
kinuko
2013/04/17 14:27:29
Done.
| |
| 405 FileSystemType type = static_cast<FileSystemType>(t); | |
| 406 if (provider->CanHandleType(type)) | |
| 407 provider_map_.insert(std::make_pair(type, provider)); | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 } // namespace fileapi | 411 } // namespace fileapi |
| OLD | NEW |