| 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_test_helper.h" | 5 #include "webkit/browser/fileapi/sandbox_file_system_test_helper.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 #include "webkit/browser/fileapi/file_system_context.h" | 11 #include "webkit/browser/fileapi/file_system_context.h" |
| 12 #include "webkit/browser/fileapi/file_system_file_util.h" | 12 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 13 #include "webkit/browser/fileapi/file_system_operation_context.h" | 13 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 14 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 14 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 15 #include "webkit/browser/fileapi/file_system_task_runners.h" | 15 #include "webkit/browser/fileapi/file_system_task_runners.h" |
| 16 #include "webkit/browser/fileapi/file_system_url.h" | 16 #include "webkit/browser/fileapi/file_system_url.h" |
| 17 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 17 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
| 18 #include "webkit/browser/fileapi/mock_file_system_context.h" | 18 #include "webkit/browser/fileapi/mock_file_system_context.h" |
| 19 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" | 19 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
| 20 #include "webkit/browser/quota/mock_special_storage_policy.h" | 20 #include "webkit/browser/quota/mock_special_storage_policy.h" |
| 21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
| 22 | 22 |
| 23 namespace fileapi { | 23 namespace fileapi { |
| 24 | 24 |
| 25 SandboxFileSystemTestHelper::SandboxFileSystemTestHelper( | 25 SandboxFileSystemTestHelper::SandboxFileSystemTestHelper( |
| 26 const GURL& origin, FileSystemType type) | 26 const GURL& origin, FileSystemType type) |
| 27 : origin_(origin), type_(type), file_util_(NULL) { | 27 : origin_(origin), type_(type), file_util_(NULL) { |
| 28 } | 28 } |
| 29 | 29 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 55 | 55 |
| 56 SetUpFileSystem(); | 56 SetUpFileSystem(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SandboxFileSystemTestHelper::TearDown() { | 59 void SandboxFileSystemTestHelper::TearDown() { |
| 60 file_system_context_ = NULL; | 60 file_system_context_ = NULL; |
| 61 base::MessageLoop::current()->RunUntilIdle(); | 61 base::MessageLoop::current()->RunUntilIdle(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 base::FilePath SandboxFileSystemTestHelper::GetOriginRootPath() { | 64 base::FilePath SandboxFileSystemTestHelper::GetOriginRootPath() { |
| 65 return file_system_context_->sandbox_provider()-> | 65 return file_system_context_->sandbox_backend()-> |
| 66 GetBaseDirectoryForOriginAndType(origin_, type_, false); | 66 GetBaseDirectoryForOriginAndType(origin_, type_, false); |
| 67 } | 67 } |
| 68 | 68 |
| 69 base::FilePath SandboxFileSystemTestHelper::GetLocalPath( | 69 base::FilePath SandboxFileSystemTestHelper::GetLocalPath( |
| 70 const base::FilePath& path) { | 70 const base::FilePath& path) { |
| 71 DCHECK(file_util_); | 71 DCHECK(file_util_); |
| 72 base::FilePath local_path; | 72 base::FilePath local_path; |
| 73 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); | 73 scoped_ptr<FileSystemOperationContext> context(NewOperationContext()); |
| 74 file_util_->GetLocalFilePath(context.get(), CreateURL(path), &local_path); | 74 file_util_->GetLocalFilePath(context.get(), CreateURL(path), &local_path); |
| 75 return local_path; | 75 return local_path; |
| 76 } | 76 } |
| 77 | 77 |
| 78 base::FilePath SandboxFileSystemTestHelper::GetLocalPathFromASCII( | 78 base::FilePath SandboxFileSystemTestHelper::GetLocalPathFromASCII( |
| 79 const std::string& path) { | 79 const std::string& path) { |
| 80 return GetLocalPath(base::FilePath().AppendASCII(path)); | 80 return GetLocalPath(base::FilePath().AppendASCII(path)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 base::FilePath SandboxFileSystemTestHelper::GetUsageCachePath() const { | 83 base::FilePath SandboxFileSystemTestHelper::GetUsageCachePath() const { |
| 84 return file_system_context_-> | 84 return file_system_context_-> |
| 85 sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); | 85 sandbox_backend()->GetUsageCachePathForOriginAndType(origin_, type_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 FileSystemURL SandboxFileSystemTestHelper::CreateURL( | 88 FileSystemURL SandboxFileSystemTestHelper::CreateURL( |
| 89 const base::FilePath& path) const { | 89 const base::FilePath& path) const { |
| 90 return file_system_context_->CreateCrackedFileSystemURL(origin_, type_, path); | 90 return file_system_context_->CreateCrackedFileSystemURL(origin_, type_, path); |
| 91 } | 91 } |
| 92 | 92 |
| 93 int64 SandboxFileSystemTestHelper::GetCachedOriginUsage() const { | 93 int64 SandboxFileSystemTestHelper::GetCachedOriginUsage() const { |
| 94 return file_system_context_->GetQuotaUtil(type_) | 94 return file_system_context_->GetQuotaUtil(type_) |
| 95 ->GetOriginUsageOnFileThread(file_system_context_.get(), origin_, type_); | 95 ->GetOriginUsageOnFileThread(file_system_context_.get(), origin_, type_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 118 DCHECK(file_system_context_.get()); | 118 DCHECK(file_system_context_.get()); |
| 119 FileSystemOperationContext* context = | 119 FileSystemOperationContext* context = |
| 120 new FileSystemOperationContext(file_system_context_.get()); | 120 new FileSystemOperationContext(file_system_context_.get()); |
| 121 context->set_update_observers( | 121 context->set_update_observers( |
| 122 *file_system_context_->GetUpdateObservers(type_)); | 122 *file_system_context_->GetUpdateObservers(type_)); |
| 123 return context; | 123 return context; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void SandboxFileSystemTestHelper::AddFileChangeObserver( | 126 void SandboxFileSystemTestHelper::AddFileChangeObserver( |
| 127 FileChangeObserver* observer) { | 127 FileChangeObserver* observer) { |
| 128 file_system_context_->sandbox_provider()-> | 128 file_system_context_->sandbox_backend()-> |
| 129 AddFileChangeObserver(type_, observer, NULL); | 129 AddFileChangeObserver(type_, observer, NULL); |
| 130 } | 130 } |
| 131 | 131 |
| 132 FileSystemUsageCache* SandboxFileSystemTestHelper::usage_cache() { | 132 FileSystemUsageCache* SandboxFileSystemTestHelper::usage_cache() { |
| 133 return file_system_context()->sandbox_provider()->usage_cache(); | 133 return file_system_context()->sandbox_backend()->usage_cache(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void SandboxFileSystemTestHelper::SetUpFileSystem() { | 136 void SandboxFileSystemTestHelper::SetUpFileSystem() { |
| 137 DCHECK(file_system_context_.get()); | 137 DCHECK(file_system_context_.get()); |
| 138 DCHECK(file_system_context_->sandbox_provider()->CanHandleType(type_)); | 138 DCHECK(file_system_context_->sandbox_backend()->CanHandleType(type_)); |
| 139 | 139 |
| 140 file_util_ = file_system_context_->GetFileUtil(type_); | 140 file_util_ = file_system_context_->GetFileUtil(type_); |
| 141 DCHECK(file_util_); | 141 DCHECK(file_util_); |
| 142 | 142 |
| 143 // Prepare the origin's root directory. | 143 // Prepare the origin's root directory. |
| 144 file_system_context_->sandbox_provider()-> | 144 file_system_context_->sandbox_backend()-> |
| 145 GetBaseDirectoryForOriginAndType(origin_, type_, true /* create */); | 145 GetBaseDirectoryForOriginAndType(origin_, type_, true /* create */); |
| 146 | 146 |
| 147 // Initialize the usage cache file. | 147 // Initialize the usage cache file. |
| 148 base::FilePath usage_cache_path = GetUsageCachePath(); | 148 base::FilePath usage_cache_path = GetUsageCachePath(); |
| 149 if (!usage_cache_path.empty()) | 149 if (!usage_cache_path.empty()) |
| 150 usage_cache()->UpdateUsage(usage_cache_path, 0); | 150 usage_cache()->UpdateUsage(usage_cache_path, 0); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace fileapi | 153 } // namespace fileapi |
| OLD | NEW |