| 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 "webkit/fileapi/quota_file_util.h" | 5 #include "webkit/fileapi/quota_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "webkit/fileapi/file_system_context.h" | 9 #include "webkit/fileapi/file_system_context.h" |
| 10 #include "webkit/fileapi/file_system_operation_context.h" | 10 #include "webkit/fileapi/file_system_operation_context.h" |
| 11 #include "webkit/fileapi/file_system_path_manager.h" | 11 #include "webkit/fileapi/file_system_path_manager.h" |
| 12 #include "webkit/fileapi/file_system_quota_util.h" | 12 #include "webkit/fileapi/file_system_quota_util.h" |
| 13 #include "webkit/fileapi/native_file_util.h" |
| 13 #include "webkit/quota/quota_manager.h" | 14 #include "webkit/quota/quota_manager.h" |
| 14 | 15 |
| 15 using quota::QuotaManagerProxy; | 16 using quota::QuotaManagerProxy; |
| 16 | 17 |
| 17 namespace fileapi { | 18 namespace fileapi { |
| 18 | 19 |
| 19 const int64 QuotaFileUtil::kNoLimit = kint64max; | 20 const int64 QuotaFileUtil::kNoLimit = kint64max; |
| 20 | 21 |
| 21 // See the comment in the header file as for these constants. | 22 // See the comment in the header file as for these constants. |
| 22 const int64 QuotaFileUtil::kFilePathCostPerChar = 2; | 23 const int64 QuotaFileUtil::kFilePathCostPerChar = 2; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 FileSystemOperationContext* operation_context_; | 64 FileSystemOperationContext* operation_context_; |
| 64 FileSystemQuotaUtil* quota_util_; | 65 FileSystemQuotaUtil* quota_util_; |
| 65 QuotaManagerProxy* quota_manager_proxy_; | 66 QuotaManagerProxy* quota_manager_proxy_; |
| 66 const GURL& origin_url_; | 67 const GURL& origin_url_; |
| 67 FileSystemType type_; | 68 FileSystemType type_; |
| 68 DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper); | 69 DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 } // namespace (anonymous) | 72 } // namespace (anonymous) |
| 72 | 73 |
| 73 QuotaFileUtil::QuotaFileUtil(FileSystemFileUtil* underlying_file_util) | 74 QuotaFileUtil::QuotaFileUtil(FileUtil* underlying_file_util) |
| 74 : underlying_file_util_(underlying_file_util) { | 75 : OverlayFileUtil(underlying_file_util) { |
| 75 } | 76 } |
| 76 | 77 |
| 77 QuotaFileUtil::~QuotaFileUtil() { | 78 QuotaFileUtil::~QuotaFileUtil() { |
| 78 } | 79 } |
| 79 | 80 |
| 80 // static | 81 // static |
| 81 QuotaFileUtil* QuotaFileUtil::CreateDefault() { | 82 QuotaFileUtil* QuotaFileUtil::CreateDefault() { |
| 82 return new QuotaFileUtil(new FileSystemFileUtil()); | 83 return new QuotaFileUtil(new NativeFileUtil()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 int64 QuotaFileUtil::ComputeFilePathCost(const FilePath& file_path) const { | 86 int64 QuotaFileUtil::ComputeFilePathCost(const FilePath& file_path) const { |
| 86 return kFilePathCostPerFile + | 87 return kFilePathCostPerFile + |
| 87 file_path.BaseName().value().length() * kFilePathCostPerChar; | 88 file_path.BaseName().value().length() * kFilePathCostPerChar; |
| 88 } | 89 } |
| 89 | 90 |
| 90 PlatformFileError QuotaFileUtil::CreateOrOpen( | 91 PlatformFileError QuotaFileUtil::CreateOrOpen( |
| 91 FileSystemOperationContext* fs_context, | 92 FileSystemOperationContext* fs_context, |
| 92 const FilePath& file_path, int file_flags, | 93 const FilePath& file_path, int file_flags, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 scoped_ptr<ScopedOriginUpdateHelper> helper; | 163 scoped_ptr<ScopedOriginUpdateHelper> helper; |
| 163 | 164 |
| 164 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth(); | 165 int64 allowed_bytes_growth = fs_context->allowed_bytes_growth(); |
| 165 int64 growth = 0; | 166 int64 growth = 0; |
| 166 | 167 |
| 167 if (!exclusive || !file_util::PathExists(file_path)) { | 168 if (!exclusive || !file_util::PathExists(file_path)) { |
| 168 if (recursive) { | 169 if (recursive) { |
| 169 FilePath last_path; | 170 FilePath last_path; |
| 170 for (FilePath path = fs_context->src_virtual_path(); | 171 for (FilePath path = fs_context->src_virtual_path(); |
| 171 path.value() != last_path.value() && | 172 path.value() != last_path.value() && |
| 172 !fs_context->src_file_system_file_util()->PathExists( | 173 !fs_context->src_file_util()->PathExists( |
| 173 fs_context, fs_context->src_virtual_path()); | 174 fs_context, fs_context->src_virtual_path()); |
| 174 path = path.DirName()) { | 175 path = path.DirName()) { |
| 175 growth += ComputeFilePathCost(fs_context->src_virtual_path()); | 176 growth += ComputeFilePathCost(fs_context->src_virtual_path()); |
| 176 last_path = path; | 177 last_path = path; |
| 177 } | 178 } |
| 178 } else { | 179 } else { |
| 179 growth += ComputeFilePathCost(fs_context->src_virtual_path()); | 180 growth += ComputeFilePathCost(fs_context->src_virtual_path()); |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 | 183 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 348 } |
| 348 *growth = src_file_info.size - dest_file_info.size + dest_file_path_cost; | 349 *growth = src_file_info.size - dest_file_info.size + dest_file_path_cost; |
| 349 if (allowed_bytes_growth != QuotaFileUtil::kNoLimit && | 350 if (allowed_bytes_growth != QuotaFileUtil::kNoLimit && |
| 350 *growth > allowed_bytes_growth) | 351 *growth > allowed_bytes_growth) |
| 351 return false; | 352 return false; |
| 352 | 353 |
| 353 return true; | 354 return true; |
| 354 } | 355 } |
| 355 | 356 |
| 356 } // namespace fileapi | 357 } // namespace fileapi |
| OLD | NEW |