| 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/browser/fileapi/sandbox_file_system_backend.h" | 5 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 kIncognito, | 53 kIncognito, |
| 54 kInvalidSchemeError, | 54 kInvalidSchemeError, |
| 55 kCreateDirectoryError, | 55 kCreateDirectoryError, |
| 56 kNotFound, | 56 kNotFound, |
| 57 kUnknownError, | 57 kUnknownError, |
| 58 kFileSystemErrorMax, | 58 kFileSystemErrorMax, |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; | 61 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; |
| 62 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; | 62 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; |
| 63 const char kSyncableOriginsCountLabel[] = "FileSystem.SyncableOriginsCount"; | |
| 64 | 63 |
| 65 // Restricted names. | 64 // Restricted names. |
| 66 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions | 65 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions |
| 67 const base::FilePath::CharType* const kRestrictedNames[] = { | 66 const base::FilePath::CharType* const kRestrictedNames[] = { |
| 68 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), | 67 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 // Restricted chars. | 70 // Restricted chars. |
| 72 const base::FilePath::CharType kRestrictedChars[] = { | 71 const base::FilePath::CharType kRestrictedChars[] = { |
| 73 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'), | 72 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 87 | 86 |
| 88 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { | 87 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { |
| 89 return enum_->HasFileSystemType(type); | 88 return enum_->HasFileSystemType(type); |
| 90 } | 89 } |
| 91 | 90 |
| 92 private: | 91 private: |
| 93 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; | 92 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 void DidOpenFileSystem( | 95 void DidOpenFileSystem( |
| 97 base::WeakPtr<SandboxFileSystemBackend> mount_point_provider, | 96 base::WeakPtr<SandboxFileSystemBackend> file_system_backend, |
| 98 const base::Callback<void(base::PlatformFileError error)>& callback, | 97 const base::Callback<void(base::PlatformFileError error)>& callback, |
| 99 base::PlatformFileError* error) { | 98 base::PlatformFileError* error) { |
| 100 if (mount_point_provider.get()) | 99 if (file_system_backend.get()) |
| 101 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); | 100 file_system_backend.get()->CollectOpenFileSystemMetrics(*error); |
| 102 callback.Run(*error); | 101 callback.Run(*error); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void OpenFileSystemOnFileThread( | 104 void OpenFileSystemOnFileThread( |
| 106 ObfuscatedFileUtil* file_util, | 105 ObfuscatedFileUtil* file_util, |
| 107 const GURL& origin_url, | 106 const GURL& origin_url, |
| 108 FileSystemType type, | 107 FileSystemType type, |
| 109 OpenFileSystemMode mode, | 108 OpenFileSystemMode mode, |
| 110 base::PlatformFileError* error_ptr) { | 109 base::PlatformFileError* error_ptr) { |
| 111 DCHECK(error_ptr); | 110 DCHECK(error_ptr); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 135 sandbox_context_(sandbox_context), | 134 sandbox_context_(sandbox_context), |
| 136 enable_temporary_file_system_in_incognito_(false), | 135 enable_temporary_file_system_in_incognito_(false), |
| 137 weak_factory_(this) { | 136 weak_factory_(this) { |
| 138 } | 137 } |
| 139 | 138 |
| 140 SandboxFileSystemBackend::~SandboxFileSystemBackend() { | 139 SandboxFileSystemBackend::~SandboxFileSystemBackend() { |
| 141 } | 140 } |
| 142 | 141 |
| 143 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { | 142 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { |
| 144 return type == kFileSystemTypeTemporary || | 143 return type == kFileSystemTypeTemporary || |
| 145 type == kFileSystemTypePersistent || | 144 type == kFileSystemTypePersistent; |
| 146 type == kFileSystemTypeSyncable || | |
| 147 type == kFileSystemTypeSyncableForInternalSync; | |
| 148 } | 145 } |
| 149 | 146 |
| 150 void SandboxFileSystemBackend::Initialize(const FileSystemContext* context) { | 147 void SandboxFileSystemBackend::Initialize(const FileSystemContext* context) { |
| 151 // Set quota observers. | 148 // Set quota observers. |
| 152 if (sandbox_context_->is_usage_tracking_enabled()) { | 149 if (sandbox_context_->is_usage_tracking_enabled()) { |
| 153 update_observers_ = update_observers_.AddObserver( | 150 update_observers_ = update_observers_.AddObserver( |
| 154 sandbox_context_->quota_observer(), | 151 sandbox_context_->quota_observer(), |
| 155 sandbox_context_->file_task_runner()); | 152 sandbox_context_->file_task_runner()); |
| 156 access_observers_ = access_observers_.AddObserver( | 153 access_observers_ = access_observers_.AddObserver( |
| 157 sandbox_context_->quota_observer(), NULL); | 154 sandbox_context_->quota_observer(), NULL); |
| 158 } | 155 } |
| 159 | 156 |
| 160 syncable_update_observers_ = update_observers_; | |
| 161 | |
| 162 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { | 157 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { |
| 163 // Post prepopulate task only if it's not already running on | 158 // Post prepopulate task only if it's not already running on |
| 164 // file_task_runner (which implies running in tests). | 159 // file_task_runner (which implies running in tests). |
| 165 sandbox_context_->file_task_runner()->PostTask( | 160 sandbox_context_->file_task_runner()->PostTask( |
| 166 FROM_HERE, | 161 FROM_HERE, |
| 167 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, | 162 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, |
| 168 base::Unretained(sandbox_sync_file_util()))); | 163 base::Unretained(sandbox_sync_file_util()))); |
| 169 } | 164 } |
| 170 } | 165 } |
| 171 | 166 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const FileSystemURL& url, | 243 const FileSystemURL& url, |
| 249 FileSystemContext* context, | 244 FileSystemContext* context, |
| 250 base::PlatformFileError* error_code) const { | 245 base::PlatformFileError* error_code) const { |
| 251 if (!IsAccessValid(url)) { | 246 if (!IsAccessValid(url)) { |
| 252 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 247 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
| 253 return NULL; | 248 return NULL; |
| 254 } | 249 } |
| 255 | 250 |
| 256 scoped_ptr<FileSystemOperationContext> operation_context( | 251 scoped_ptr<FileSystemOperationContext> operation_context( |
| 257 new FileSystemOperationContext(context)); | 252 new FileSystemOperationContext(context)); |
| 258 | |
| 259 // Copy the observer lists (assuming we only have small number of observers). | |
| 260 if (url.type() == kFileSystemTypeSyncable) { | |
| 261 operation_context->set_update_observers(syncable_update_observers_); | |
| 262 operation_context->set_change_observers(syncable_change_observers_); | |
| 263 return new sync_file_system::SyncableFileSystemOperation( | |
| 264 url, context, operation_context.Pass()); | |
| 265 } | |
| 266 | |
| 267 // For regular sandboxed types. | |
| 268 operation_context->set_update_observers(update_observers_); | 253 operation_context->set_update_observers(update_observers_); |
| 269 operation_context->set_change_observers(change_observers_); | 254 operation_context->set_change_observers(change_observers_); |
| 270 | 255 |
| 271 SpecialStoragePolicy* policy = sandbox_context_->special_storage_policy(); | 256 SpecialStoragePolicy* policy = sandbox_context_->special_storage_policy(); |
| 272 if (policy && policy->IsStorageUnlimited(url.origin())) | 257 if (policy && policy->IsStorageUnlimited(url.origin())) |
| 273 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); | 258 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); |
| 274 else | 259 else |
| 275 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); | 260 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); |
| 276 | 261 |
| 277 return new LocalFileSystemOperation(url, context, operation_context.Pass()); | 262 return new LocalFileSystemOperation(url, context, operation_context.Pass()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 if (enumerator->HasFileSystemType(type)) | 340 if (enumerator->HasFileSystemType(type)) |
| 356 origins->insert(origin); | 341 origins->insert(origin); |
| 357 } | 342 } |
| 358 switch (type) { | 343 switch (type) { |
| 359 case kFileSystemTypeTemporary: | 344 case kFileSystemTypeTemporary: |
| 360 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size()); | 345 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size()); |
| 361 break; | 346 break; |
| 362 case kFileSystemTypePersistent: | 347 case kFileSystemTypePersistent: |
| 363 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size()); | 348 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size()); |
| 364 break; | 349 break; |
| 365 case kFileSystemTypeSyncable: | |
| 366 UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size()); | |
| 367 break; | |
| 368 default: | 350 default: |
| 369 break; | 351 break; |
| 370 } | 352 } |
| 371 } | 353 } |
| 372 | 354 |
| 373 void SandboxFileSystemBackend::GetOriginsForHostOnFileThread( | 355 void SandboxFileSystemBackend::GetOriginsForHostOnFileThread( |
| 374 fileapi::FileSystemType type, const std::string& host, | 356 fileapi::FileSystemType type, const std::string& host, |
| 375 std::set<GURL>* origins) { | 357 std::set<GURL>* origins) { |
| 376 DCHECK(CanHandleType(type)); | 358 DCHECK(CanHandleType(type)); |
| 377 DCHECK(origins); | 359 DCHECK(origins); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 sandbox_context_->quota_observer()->SetUsageCacheEnabled(origin, type, false); | 428 sandbox_context_->quota_observer()->SetUsageCacheEnabled(origin, type, false); |
| 447 InvalidateUsageCache(origin, type); | 429 InvalidateUsageCache(origin, type); |
| 448 } | 430 } |
| 449 | 431 |
| 450 void SandboxFileSystemBackend::AddFileUpdateObserver( | 432 void SandboxFileSystemBackend::AddFileUpdateObserver( |
| 451 FileSystemType type, | 433 FileSystemType type, |
| 452 FileUpdateObserver* observer, | 434 FileUpdateObserver* observer, |
| 453 base::SequencedTaskRunner* task_runner) { | 435 base::SequencedTaskRunner* task_runner) { |
| 454 DCHECK(CanHandleType(type)); | 436 DCHECK(CanHandleType(type)); |
| 455 UpdateObserverList* list = &update_observers_; | 437 UpdateObserverList* list = &update_observers_; |
| 456 if (type == kFileSystemTypeSyncable) | |
| 457 list = &syncable_update_observers_; | |
| 458 *list = list->AddObserver(observer, task_runner); | 438 *list = list->AddObserver(observer, task_runner); |
| 459 } | 439 } |
| 460 | 440 |
| 461 void SandboxFileSystemBackend::AddFileChangeObserver( | 441 void SandboxFileSystemBackend::AddFileChangeObserver( |
| 462 FileSystemType type, | 442 FileSystemType type, |
| 463 FileChangeObserver* observer, | 443 FileChangeObserver* observer, |
| 464 base::SequencedTaskRunner* task_runner) { | 444 base::SequencedTaskRunner* task_runner) { |
| 465 DCHECK(CanHandleType(type)); | 445 DCHECK(CanHandleType(type)); |
| 466 ChangeObserverList* list = &change_observers_; | 446 ChangeObserverList* list = &change_observers_; |
| 467 if (type == kFileSystemTypeSyncable) | |
| 468 list = &syncable_change_observers_; | |
| 469 *list = list->AddObserver(observer, task_runner); | 447 *list = list->AddObserver(observer, task_runner); |
| 470 } | 448 } |
| 471 | 449 |
| 472 void SandboxFileSystemBackend::AddFileAccessObserver( | 450 void SandboxFileSystemBackend::AddFileAccessObserver( |
| 473 FileSystemType type, | 451 FileSystemType type, |
| 474 FileAccessObserver* observer, | 452 FileAccessObserver* observer, |
| 475 base::SequencedTaskRunner* task_runner) { | 453 base::SequencedTaskRunner* task_runner) { |
| 476 DCHECK(CanHandleType(type)); | 454 DCHECK(CanHandleType(type)); |
| 477 access_observers_ = access_observers_.AddObserver(observer, task_runner); | 455 access_observers_ = access_observers_.AddObserver(observer, task_runner); |
| 478 } | 456 } |
| 479 | 457 |
| 480 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers( | 458 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers( |
| 481 FileSystemType type) const { | 459 FileSystemType type) const { |
| 482 DCHECK(CanHandleType(type)); | 460 DCHECK(CanHandleType(type)); |
| 483 if (type == kFileSystemTypeSyncable) | |
| 484 return &syncable_update_observers_; | |
| 485 return &update_observers_; | 461 return &update_observers_; |
| 486 } | 462 } |
| 487 | 463 |
| 488 const ChangeObserverList* SandboxFileSystemBackend::GetChangeObservers( | 464 const ChangeObserverList* SandboxFileSystemBackend::GetChangeObservers( |
| 489 FileSystemType type) const { | 465 FileSystemType type) const { |
| 490 DCHECK(CanHandleType(type)); | 466 DCHECK(CanHandleType(type)); |
| 491 if (type == kFileSystemTypeSyncable) | |
| 492 return &syncable_change_observers_; | |
| 493 return &change_observers_; | 467 return &change_observers_; |
| 494 } | 468 } |
| 495 | 469 |
| 496 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers( | 470 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers( |
| 497 FileSystemType type) const { | 471 FileSystemType type) const { |
| 498 DCHECK(CanHandleType(type)); | 472 DCHECK(CanHandleType(type)); |
| 499 return &access_observers_; | 473 return &access_observers_; |
| 500 } | 474 } |
| 501 | 475 |
| 502 void SandboxFileSystemBackend::CollectOpenFileSystemMetrics( | 476 void SandboxFileSystemBackend::CollectOpenFileSystemMetrics( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 627 |
| 654 while (!(file_path_each = enumerator->Next()).empty()) { | 628 while (!(file_path_each = enumerator->Next()).empty()) { |
| 655 usage += enumerator->Size(); | 629 usage += enumerator->Size(); |
| 656 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); | 630 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); |
| 657 } | 631 } |
| 658 | 632 |
| 659 return usage; | 633 return usage; |
| 660 } | 634 } |
| 661 | 635 |
| 662 } // namespace fileapi | 636 } // namespace fileapi |
| OLD | NEW |