| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/public/test/sandbox_file_system_test_helper.h" | 5 #include "content/public/test/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/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/public/test/mock_special_storage_policy.h" | 10 #include "content/public/test/mock_special_storage_policy.h" |
| 11 #include "content/public/test/test_file_system_context.h" | 11 #include "content/public/test/test_file_system_context.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "webkit/browser/fileapi/file_system_context.h" | 13 #include "webkit/browser/fileapi/file_system_context.h" |
| 14 #include "webkit/browser/fileapi/file_system_file_util.h" | 14 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 15 #include "webkit/browser/fileapi/file_system_operation_context.h" | 15 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 16 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 16 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 17 #include "webkit/browser/fileapi/file_system_url.h" | 17 #include "webkit/browser/fileapi/file_system_url.h" |
| 18 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 18 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
| 19 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 19 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
| 20 #include "webkit/browser/quota/quota_manager_proxy.h" | 20 #include "webkit/browser/quota/quota_manager_proxy.h" |
| 21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
| 22 | 22 |
| 23 using fileapi::FileSystemContext; | 23 using storage::FileSystemContext; |
| 24 using fileapi::FileSystemOperationContext; | 24 using storage::FileSystemOperationContext; |
| 25 using fileapi::FileSystemOperationRunner; | 25 using storage::FileSystemOperationRunner; |
| 26 using fileapi::FileSystemURL; | 26 using storage::FileSystemURL; |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 SandboxFileSystemTestHelper::SandboxFileSystemTestHelper( | 30 SandboxFileSystemTestHelper::SandboxFileSystemTestHelper( |
| 31 const GURL& origin, | 31 const GURL& origin, |
| 32 fileapi::FileSystemType type) | 32 storage::FileSystemType type) |
| 33 : origin_(origin), type_(type), file_util_(NULL) { | 33 : origin_(origin), type_(type), file_util_(NULL) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 SandboxFileSystemTestHelper::SandboxFileSystemTestHelper() | 36 SandboxFileSystemTestHelper::SandboxFileSystemTestHelper() |
| 37 : origin_(GURL("http://foo.com")), | 37 : origin_(GURL("http://foo.com")), |
| 38 type_(fileapi::kFileSystemTypeTemporary), | 38 type_(storage::kFileSystemTypeTemporary), |
| 39 file_util_(NULL) { | 39 file_util_(NULL) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 SandboxFileSystemTestHelper::~SandboxFileSystemTestHelper() { | 42 SandboxFileSystemTestHelper::~SandboxFileSystemTestHelper() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SandboxFileSystemTestHelper::SetUp(const base::FilePath& base_dir) { | 45 void SandboxFileSystemTestHelper::SetUp(const base::FilePath& base_dir) { |
| 46 SetUp(base_dir, NULL); | 46 SetUp(base_dir, NULL); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void SandboxFileSystemTestHelper::SetUp( | 49 void SandboxFileSystemTestHelper::SetUp( |
| 50 FileSystemContext* file_system_context) { | 50 FileSystemContext* file_system_context) { |
| 51 file_system_context_ = file_system_context; | 51 file_system_context_ = file_system_context; |
| 52 | 52 |
| 53 SetUpFileSystem(); | 53 SetUpFileSystem(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void SandboxFileSystemTestHelper::SetUp( | 56 void SandboxFileSystemTestHelper::SetUp( |
| 57 const base::FilePath& base_dir, | 57 const base::FilePath& base_dir, |
| 58 quota::QuotaManagerProxy* quota_manager_proxy) { | 58 storage::QuotaManagerProxy* quota_manager_proxy) { |
| 59 file_system_context_ = CreateFileSystemContextForTesting( | 59 file_system_context_ = CreateFileSystemContextForTesting( |
| 60 quota_manager_proxy, base_dir); | 60 quota_manager_proxy, base_dir); |
| 61 | 61 |
| 62 SetUpFileSystem(); | 62 SetUpFileSystem(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void SandboxFileSystemTestHelper::TearDown() { | 65 void SandboxFileSystemTestHelper::TearDown() { |
| 66 file_system_context_ = NULL; | 66 file_system_context_ = NULL; |
| 67 base::RunLoop().RunUntilIdle(); | 67 base::RunLoop().RunUntilIdle(); |
| 68 } | 68 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 99 int64 SandboxFileSystemTestHelper::GetCachedOriginUsage() const { | 99 int64 SandboxFileSystemTestHelper::GetCachedOriginUsage() const { |
| 100 return file_system_context_->GetQuotaUtil(type_) | 100 return file_system_context_->GetQuotaUtil(type_) |
| 101 ->GetOriginUsageOnFileTaskRunner( | 101 ->GetOriginUsageOnFileTaskRunner( |
| 102 file_system_context_.get(), origin_, type_); | 102 file_system_context_.get(), origin_, type_); |
| 103 } | 103 } |
| 104 | 104 |
| 105 int64 SandboxFileSystemTestHelper::ComputeCurrentOriginUsage() { | 105 int64 SandboxFileSystemTestHelper::ComputeCurrentOriginUsage() { |
| 106 usage_cache()->CloseCacheFiles(); | 106 usage_cache()->CloseCacheFiles(); |
| 107 int64 size = base::ComputeDirectorySize(GetOriginRootPath()); | 107 int64 size = base::ComputeDirectorySize(GetOriginRootPath()); |
| 108 if (base::PathExists(GetUsageCachePath())) | 108 if (base::PathExists(GetUsageCachePath())) |
| 109 size -= fileapi::FileSystemUsageCache::kUsageFileSize; | 109 size -= storage::FileSystemUsageCache::kUsageFileSize; |
| 110 return size; | 110 return size; |
| 111 } | 111 } |
| 112 | 112 |
| 113 int64 | 113 int64 |
| 114 SandboxFileSystemTestHelper::ComputeCurrentDirectoryDatabaseUsage() { | 114 SandboxFileSystemTestHelper::ComputeCurrentDirectoryDatabaseUsage() { |
| 115 return base::ComputeDirectorySize( | 115 return base::ComputeDirectorySize( |
| 116 GetOriginRootPath().AppendASCII("Paths")); | 116 GetOriginRootPath().AppendASCII("Paths")); |
| 117 } | 117 } |
| 118 | 118 |
| 119 FileSystemOperationRunner* SandboxFileSystemTestHelper::operation_runner() { | 119 FileSystemOperationRunner* SandboxFileSystemTestHelper::operation_runner() { |
| 120 return file_system_context_->operation_runner(); | 120 return file_system_context_->operation_runner(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 FileSystemOperationContext* | 123 FileSystemOperationContext* |
| 124 SandboxFileSystemTestHelper::NewOperationContext() { | 124 SandboxFileSystemTestHelper::NewOperationContext() { |
| 125 DCHECK(file_system_context_.get()); | 125 DCHECK(file_system_context_.get()); |
| 126 FileSystemOperationContext* context = | 126 FileSystemOperationContext* context = |
| 127 new FileSystemOperationContext(file_system_context_.get()); | 127 new FileSystemOperationContext(file_system_context_.get()); |
| 128 context->set_update_observers( | 128 context->set_update_observers( |
| 129 *file_system_context_->GetUpdateObservers(type_)); | 129 *file_system_context_->GetUpdateObservers(type_)); |
| 130 return context; | 130 return context; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void SandboxFileSystemTestHelper::AddFileChangeObserver( | 133 void SandboxFileSystemTestHelper::AddFileChangeObserver( |
| 134 fileapi::FileChangeObserver* observer) { | 134 storage::FileChangeObserver* observer) { |
| 135 file_system_context_->sandbox_backend()->GetQuotaUtil()-> | 135 file_system_context_->sandbox_backend()->GetQuotaUtil()-> |
| 136 AddFileChangeObserver(type_, observer, NULL); | 136 AddFileChangeObserver(type_, observer, NULL); |
| 137 } | 137 } |
| 138 | 138 |
| 139 fileapi::FileSystemUsageCache* SandboxFileSystemTestHelper::usage_cache() { | 139 storage::FileSystemUsageCache* SandboxFileSystemTestHelper::usage_cache() { |
| 140 return file_system_context()->sandbox_delegate()->usage_cache(); | 140 return file_system_context()->sandbox_delegate()->usage_cache(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SandboxFileSystemTestHelper::SetUpFileSystem() { | 143 void SandboxFileSystemTestHelper::SetUpFileSystem() { |
| 144 DCHECK(file_system_context_.get()); | 144 DCHECK(file_system_context_.get()); |
| 145 DCHECK(file_system_context_->sandbox_backend()->CanHandleType(type_)); | 145 DCHECK(file_system_context_->sandbox_backend()->CanHandleType(type_)); |
| 146 | 146 |
| 147 file_util_ = file_system_context_->sandbox_delegate()->sync_file_util(); | 147 file_util_ = file_system_context_->sandbox_delegate()->sync_file_util(); |
| 148 DCHECK(file_util_); | 148 DCHECK(file_util_); |
| 149 | 149 |
| 150 // Prepare the origin's root directory. | 150 // Prepare the origin's root directory. |
| 151 file_system_context_->sandbox_delegate()-> | 151 file_system_context_->sandbox_delegate()-> |
| 152 GetBaseDirectoryForOriginAndType(origin_, type_, true /* create */); | 152 GetBaseDirectoryForOriginAndType(origin_, type_, true /* create */); |
| 153 | 153 |
| 154 // Initialize the usage cache file. | 154 // Initialize the usage cache file. |
| 155 base::FilePath usage_cache_path = GetUsageCachePath(); | 155 base::FilePath usage_cache_path = GetUsageCachePath(); |
| 156 if (!usage_cache_path.empty()) | 156 if (!usage_cache_path.empty()) |
| 157 usage_cache()->UpdateUsage(usage_cache_path, 0); | 157 usage_cache()->UpdateUsage(usage_cache_path, 0); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace content | 160 } // namespace content |
| OLD | NEW |