OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/scoped_callback_factory.h" | 7 #include "base/memory/scoped_callback_factory.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webkit/fileapi/file_system_context.h" | 14 #include "webkit/fileapi/file_system_context.h" |
15 #include "webkit/fileapi/file_system_operation_context.h" | 15 #include "webkit/fileapi/file_system_operation_context.h" |
16 #include "webkit/fileapi/file_system_quota_client.h" | 16 #include "webkit/fileapi/file_system_quota_client.h" |
17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
18 #include "webkit/fileapi/file_system_usage_cache.h" | 18 #include "webkit/fileapi/file_system_usage_cache.h" |
19 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
20 #include "webkit/fileapi/obfuscated_file_system_file_util.h" | 20 #include "webkit/fileapi/obfuscated_file_util.h" |
21 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 21 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
22 #include "webkit/fileapi/quota_file_util.h" | 22 #include "webkit/fileapi/quota_file_util.h" |
23 #include "webkit/quota/quota_types.h" | 23 #include "webkit/quota/quota_types.h" |
24 | 24 |
25 namespace fileapi { | 25 namespace fileapi { |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char kDummyURL1[] = "http://www.dummy.org"; | 28 const char kDummyURL1[] = "http://www.dummy.org"; |
29 const char kDummyURL2[] = "http://www.example.com"; | 29 const char kDummyURL2[] = "http://www.example.com"; |
30 const char kDummyURL3[] = "http://www.bleh"; | 30 const char kDummyURL3[] = "http://www.bleh"; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 new FileSystemOperationContext(file_system_context_, file_util); | 140 new FileSystemOperationContext(file_system_context_, file_util); |
141 context->set_src_origin_url(GURL(origin_url)); | 141 context->set_src_origin_url(GURL(origin_url)); |
142 context->set_src_type(QuotaStorageTypeToFileSystemType(type)); | 142 context->set_src_type(QuotaStorageTypeToFileSystemType(type)); |
143 context->set_allowed_bytes_growth(100000000); | 143 context->set_allowed_bytes_growth(100000000); |
144 return context; | 144 return context; |
145 } | 145 } |
146 | 146 |
147 bool CreateFileSystemDirectory(const FilePath& path, | 147 bool CreateFileSystemDirectory(const FilePath& path, |
148 const std::string& origin_url, | 148 const std::string& origin_url, |
149 quota::StorageType type) { | 149 quota::StorageType type) { |
150 FileSystemFileUtil* file_util = | 150 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> |
151 file_system_context_->path_manager()->GetFileSystemFileUtil( | 151 GetFileUtil(QuotaStorageTypeToFileSystemType(type)); |
152 QuotaStorageTypeToFileSystemType(type)); | |
153 | 152 |
154 scoped_ptr<FileSystemOperationContext> context( | 153 scoped_ptr<FileSystemOperationContext> context( |
155 CreateFileSystemOperationContext(file_util, path, origin_url, type)); | 154 CreateFileSystemOperationContext(file_util, path, origin_url, type)); |
156 | 155 |
157 base::PlatformFileError result = | 156 base::PlatformFileError result = |
158 file_util->CreateDirectory(context.get(), path, false, false); | 157 file_util->CreateDirectory(context.get(), path, false, false); |
159 if (result != base::PLATFORM_FILE_OK) | 158 if (result != base::PLATFORM_FILE_OK) |
160 return false; | 159 return false; |
161 return true; | 160 return true; |
162 } | 161 } |
163 | 162 |
164 bool CreateFileSystemFile(const FilePath& path, | 163 bool CreateFileSystemFile(const FilePath& path, |
165 int64 file_size, | 164 int64 file_size, |
166 const std::string& origin_url, | 165 const std::string& origin_url, |
167 quota::StorageType type) { | 166 quota::StorageType type) { |
168 if (path.empty()) | 167 if (path.empty()) |
169 return false; | 168 return false; |
170 | 169 |
171 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> | 170 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> |
172 sandbox_provider()->GetFileSystemFileUtil(); | 171 sandbox_provider()->GetFileUtil(); |
173 | 172 |
174 scoped_ptr<FileSystemOperationContext> context( | 173 scoped_ptr<FileSystemOperationContext> context( |
175 CreateFileSystemOperationContext(file_util, path, origin_url, type)); | 174 CreateFileSystemOperationContext(file_util, path, origin_url, type)); |
176 | 175 |
177 bool created = false; | 176 bool created = false; |
178 if (base::PLATFORM_FILE_OK != | 177 if (base::PLATFORM_FILE_OK != |
179 file_util->EnsureFileExists(context.get(), path, &created)) | 178 file_util->EnsureFileExists(context.get(), path, &created)) |
180 return false; | 179 return false; |
181 EXPECT_TRUE(created); | 180 EXPECT_TRUE(created); |
182 if (base::PLATFORM_FILE_OK != | 181 if (base::PLATFORM_FILE_OK != |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, | 215 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, |
217 int num_files, | 216 int num_files, |
218 const std::string& origin_url, | 217 const std::string& origin_url, |
219 quota::StorageType type) { | 218 quota::StorageType type) { |
220 int64 file_paths_cost = 0; | 219 int64 file_paths_cost = 0; |
221 for (int i = 0; i < num_files; i++) { | 220 for (int i = 0; i < num_files; i++) { |
222 if (files[i].type == type && | 221 if (files[i].type == type && |
223 GURL(files[i].origin_url) == GURL(origin_url)) { | 222 GURL(files[i].origin_url) == GURL(origin_url)) { |
224 FilePath path = FilePath().AppendASCII(files[i].name); | 223 FilePath path = FilePath().AppendASCII(files[i].name); |
225 if (!path.empty()) { | 224 if (!path.empty()) { |
226 file_paths_cost += | 225 file_paths_cost += ObfuscatedFileUtil::ComputeFilePathCost(path); |
227 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); | |
228 } | 226 } |
229 } | 227 } |
230 } | 228 } |
231 return file_paths_cost; | 229 return file_paths_cost; |
232 } | 230 } |
233 | 231 |
234 void DeleteOriginData(FileSystemQuotaClient* quota_client, | 232 void DeleteOriginData(FileSystemQuotaClient* quota_client, |
235 const std::string& origin, | 233 const std::string& origin, |
236 quota::StorageType type) { | 234 quota::StorageType type) { |
237 deletion_status_ = quota::kQuotaStatusUnknown; | 235 deletion_status_ = quota::kQuotaStatusUnknown; |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 GetOriginUsage(quota_client.get(), | 595 GetOriginUsage(quota_client.get(), |
598 "https://bar.com/", | 596 "https://bar.com/", |
599 kPersistent)); | 597 kPersistent)); |
600 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 598 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
601 GetOriginUsage(quota_client.get(), | 599 GetOriginUsage(quota_client.get(), |
602 "https://bar.com/", | 600 "https://bar.com/", |
603 kTemporary)); | 601 kTemporary)); |
604 } | 602 } |
605 | 603 |
606 } // namespace fileapi | 604 } // namespace fileapi |
OLD | NEW |