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