| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 FileSystemOperationContext* CreateFileSystemOperationContext( | 122 FileSystemOperationContext* CreateFileSystemOperationContext( |
| 123 FileSystemType type) { | 123 FileSystemType type) { |
| 124 FileSystemOperationContext* context = | 124 FileSystemOperationContext* context = |
| 125 new FileSystemOperationContext(file_system_context_); | 125 new FileSystemOperationContext(file_system_context_); |
| 126 context->set_allowed_bytes_growth(100000000); | 126 context->set_allowed_bytes_growth(100000000); |
| 127 context->set_update_observers( | 127 context->set_update_observers( |
| 128 *file_system_context_->GetUpdateObservers(type)); | 128 *file_system_context_->GetUpdateObservers(type)); |
| 129 return context; | 129 return context; |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool CreateFileSystemDirectory(const FilePath& file_path, | 132 bool CreateFileSystemDirectory(const base::FilePath& file_path, |
| 133 const std::string& origin_url, | 133 const std::string& origin_url, |
| 134 quota::StorageType storage_type) { | 134 quota::StorageType storage_type) { |
| 135 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 135 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 136 FileSystemFileUtil* file_util = file_system_context_->GetFileUtil(type); | 136 FileSystemFileUtil* file_util = file_system_context_->GetFileUtil(type); |
| 137 | 137 |
| 138 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 138 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
| 139 GURL(origin_url), type, file_path); | 139 GURL(origin_url), type, file_path); |
| 140 scoped_ptr<FileSystemOperationContext> context( | 140 scoped_ptr<FileSystemOperationContext> context( |
| 141 CreateFileSystemOperationContext(type)); | 141 CreateFileSystemOperationContext(type)); |
| 142 | 142 |
| 143 base::PlatformFileError result = | 143 base::PlatformFileError result = |
| 144 file_util->CreateDirectory(context.get(), url, false, false); | 144 file_util->CreateDirectory(context.get(), url, false, false); |
| 145 if (result != base::PLATFORM_FILE_OK) | 145 if (result != base::PLATFORM_FILE_OK) |
| 146 return false; | 146 return false; |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 bool CreateFileSystemFile(const FilePath& file_path, | 150 bool CreateFileSystemFile(const base::FilePath& file_path, |
| 151 int64 file_size, | 151 int64 file_size, |
| 152 const std::string& origin_url, | 152 const std::string& origin_url, |
| 153 quota::StorageType storage_type) { | 153 quota::StorageType storage_type) { |
| 154 if (file_path.empty()) | 154 if (file_path.empty()) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 157 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 158 FileSystemFileUtil* file_util = file_system_context_-> | 158 FileSystemFileUtil* file_util = file_system_context_-> |
| 159 sandbox_provider()->GetFileUtil(type); | 159 sandbox_provider()->GetFileUtil(type); |
| 160 | 160 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 171 if (base::PLATFORM_FILE_OK != | 171 if (base::PLATFORM_FILE_OK != |
| 172 file_util->Truncate(context.get(), url, file_size)) | 172 file_util->Truncate(context.get(), url, file_size)) |
| 173 return false; | 173 return false; |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void InitializeOriginFiles(FileSystemQuotaClient* quota_client, | 177 void InitializeOriginFiles(FileSystemQuotaClient* quota_client, |
| 178 const TestFile* files, | 178 const TestFile* files, |
| 179 int num_files) { | 179 int num_files) { |
| 180 for (int i = 0; i < num_files; i++) { | 180 for (int i = 0; i < num_files; i++) { |
| 181 FilePath path = FilePath().AppendASCII(files[i].name); | 181 base::FilePath path = base::FilePath().AppendASCII(files[i].name); |
| 182 if (files[i].isDirectory) { | 182 if (files[i].isDirectory) { |
| 183 ASSERT_TRUE(CreateFileSystemDirectory( | 183 ASSERT_TRUE(CreateFileSystemDirectory( |
| 184 path, files[i].origin_url, files[i].type)); | 184 path, files[i].origin_url, files[i].type)); |
| 185 if (path.empty()) { | 185 if (path.empty()) { |
| 186 // Create the usage cache. | 186 // Create the usage cache. |
| 187 // HACK--we always create the root [an empty path] first. If we | 187 // HACK--we always create the root [an empty path] first. If we |
| 188 // create it later, this will fail due to a quota mismatch. If we | 188 // create it later, this will fail due to a quota mismatch. If we |
| 189 // call this before we create the root, it succeeds, but hasn't | 189 // call this before we create the root, it succeeds, but hasn't |
| 190 // actually created the cache. | 190 // actually created the cache. |
| 191 ASSERT_EQ(0, GetOriginUsage( | 191 ASSERT_EQ(0, GetOriginUsage( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 203 // count the basename of each addition. A recursive creation of a path, which | 203 // count the basename of each addition. A recursive creation of a path, which |
| 204 // created more than one directory in a single shot, would break this. | 204 // created more than one directory in a single shot, would break this. |
| 205 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, | 205 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, |
| 206 int num_files, | 206 int num_files, |
| 207 const std::string& origin_url, | 207 const std::string& origin_url, |
| 208 quota::StorageType type) { | 208 quota::StorageType type) { |
| 209 int64 file_paths_cost = 0; | 209 int64 file_paths_cost = 0; |
| 210 for (int i = 0; i < num_files; i++) { | 210 for (int i = 0; i < num_files; i++) { |
| 211 if (files[i].type == type && | 211 if (files[i].type == type && |
| 212 GURL(files[i].origin_url) == GURL(origin_url)) { | 212 GURL(files[i].origin_url) == GURL(origin_url)) { |
| 213 FilePath path = FilePath().AppendASCII(files[i].name); | 213 base::FilePath path = base::FilePath().AppendASCII(files[i].name); |
| 214 if (!path.empty()) { | 214 if (!path.empty()) { |
| 215 file_paths_cost += ObfuscatedFileUtil::ComputeFilePathCost(path); | 215 file_paths_cost += ObfuscatedFileUtil::ComputeFilePathCost(path); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 return file_paths_cost; | 219 return file_paths_cost; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void DeleteOriginData(FileSystemQuotaClient* quota_client, | 222 void DeleteOriginData(FileSystemQuotaClient* quota_client, |
| 223 const std::string& origin, | 223 const std::string& origin, |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 GetOriginUsage(quota_client.get(), | 586 GetOriginUsage(quota_client.get(), |
| 587 "https://bar.com/", | 587 "https://bar.com/", |
| 588 kPersistent)); | 588 kPersistent)); |
| 589 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 589 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
| 590 GetOriginUsage(quota_client.get(), | 590 GetOriginUsage(quota_client.get(), |
| 591 "https://bar.com/", | 591 "https://bar.com/", |
| 592 kTemporary)); | 592 kTemporary)); |
| 593 } | 593 } |
| 594 | 594 |
| 595 } // namespace fileapi | 595 } // namespace fileapi |
| OLD | NEW |