| 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 "webkit/browser/fileapi/quota/quota_backend_impl.h" | 5 #include "webkit/browser/fileapi/quota/quota_backend_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 14 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
| 15 #include "webkit/browser/quota/quota_client.h" | 15 #include "webkit/browser/quota/quota_client.h" |
| 16 #include "webkit/browser/quota/quota_manager_proxy.h" | 16 #include "webkit/browser/quota/quota_manager_proxy.h" |
| 17 #include "webkit/common/fileapi/file_system_util.h" | 17 #include "webkit/common/fileapi/file_system_util.h" |
| 18 | 18 |
| 19 namespace fileapi { | 19 namespace storage { |
| 20 | 20 |
| 21 QuotaBackendImpl::QuotaBackendImpl( | 21 QuotaBackendImpl::QuotaBackendImpl( |
| 22 base::SequencedTaskRunner* file_task_runner, | 22 base::SequencedTaskRunner* file_task_runner, |
| 23 ObfuscatedFileUtil* obfuscated_file_util, | 23 ObfuscatedFileUtil* obfuscated_file_util, |
| 24 FileSystemUsageCache* file_system_usage_cache, | 24 FileSystemUsageCache* file_system_usage_cache, |
| 25 quota::QuotaManagerProxy* quota_manager_proxy) | 25 storage::QuotaManagerProxy* quota_manager_proxy) |
| 26 : file_task_runner_(file_task_runner), | 26 : file_task_runner_(file_task_runner), |
| 27 obfuscated_file_util_(obfuscated_file_util), | 27 obfuscated_file_util_(obfuscated_file_util), |
| 28 file_system_usage_cache_(file_system_usage_cache), | 28 file_system_usage_cache_(file_system_usage_cache), |
| 29 quota_manager_proxy_(quota_manager_proxy), | 29 quota_manager_proxy_(quota_manager_proxy), |
| 30 weak_ptr_factory_(this) { | 30 weak_ptr_factory_(this) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 QuotaBackendImpl::~QuotaBackendImpl() { | 33 QuotaBackendImpl::~QuotaBackendImpl() { |
| 34 } | 34 } |
| 35 | 35 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 base::FilePath path; | 95 base::FilePath path; |
| 96 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) | 96 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) |
| 97 return; | 97 return; |
| 98 DCHECK(file_system_usage_cache_); | 98 DCHECK(file_system_usage_cache_); |
| 99 file_system_usage_cache_->DecrementDirty(path); | 99 file_system_usage_cache_->DecrementDirty(path); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota( | 102 void QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota( |
| 103 const QuotaReservationInfo& info, | 103 const QuotaReservationInfo& info, |
| 104 const ReserveQuotaCallback& callback, | 104 const ReserveQuotaCallback& callback, |
| 105 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 105 storage::QuotaStatusCode status, |
| 106 int64 usage, |
| 107 int64 quota) { |
| 106 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 108 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| 107 DCHECK(info.origin.is_valid()); | 109 DCHECK(info.origin.is_valid()); |
| 108 DCHECK_LE(0, usage); | 110 DCHECK_LE(0, usage); |
| 109 DCHECK_LE(0, quota); | 111 DCHECK_LE(0, quota); |
| 110 if (status != quota::kQuotaStatusOk) { | 112 if (status != storage::kQuotaStatusOk) { |
| 111 callback.Run(base::File::FILE_ERROR_FAILED, 0); | 113 callback.Run(base::File::FILE_ERROR_FAILED, 0); |
| 112 return; | 114 return; |
| 113 } | 115 } |
| 114 | 116 |
| 115 QuotaReservationInfo normalized_info = info; | 117 QuotaReservationInfo normalized_info = info; |
| 116 if (info.delta > 0) { | 118 if (info.delta > 0) { |
| 117 int64 new_usage = | 119 int64 new_usage = |
| 118 base::saturated_cast<int64>(usage + static_cast<uint64>(info.delta)); | 120 base::saturated_cast<int64>(usage + static_cast<uint64>(info.delta)); |
| 119 if (quota < new_usage) | 121 if (quota < new_usage) |
| 120 new_usage = quota; | 122 new_usage = quota; |
| 121 normalized_info.delta = std::max(static_cast<int64>(0), new_usage - usage); | 123 normalized_info.delta = std::max(static_cast<int64>(0), new_usage - usage); |
| 122 } | 124 } |
| 123 | 125 |
| 124 ReserveQuotaInternal(normalized_info); | 126 ReserveQuotaInternal(normalized_info); |
| 125 if (callback.Run(base::File::FILE_OK, normalized_info.delta)) | 127 if (callback.Run(base::File::FILE_OK, normalized_info.delta)) |
| 126 return; | 128 return; |
| 127 // The requester could not accept the reserved quota. Revert it. | 129 // The requester could not accept the reserved quota. Revert it. |
| 128 ReserveQuotaInternal( | 130 ReserveQuotaInternal( |
| 129 QuotaReservationInfo(normalized_info.origin, | 131 QuotaReservationInfo(normalized_info.origin, |
| 130 normalized_info.type, | 132 normalized_info.type, |
| 131 -normalized_info.delta)); | 133 -normalized_info.delta)); |
| 132 } | 134 } |
| 133 | 135 |
| 134 void QuotaBackendImpl::ReserveQuotaInternal(const QuotaReservationInfo& info) { | 136 void QuotaBackendImpl::ReserveQuotaInternal(const QuotaReservationInfo& info) { |
| 135 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 137 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| 136 DCHECK(info.origin.is_valid()); | 138 DCHECK(info.origin.is_valid()); |
| 137 DCHECK(quota_manager_proxy_); | 139 DCHECK(quota_manager_proxy_); |
| 138 quota_manager_proxy_->NotifyStorageModified( | 140 quota_manager_proxy_->NotifyStorageModified( |
| 139 quota::QuotaClient::kFileSystem, info.origin, | 141 storage::QuotaClient::kFileSystem, |
| 140 FileSystemTypeToQuotaStorageType(info.type), info.delta); | 142 info.origin, |
| 143 FileSystemTypeToQuotaStorageType(info.type), |
| 144 info.delta); |
| 141 } | 145 } |
| 142 | 146 |
| 143 base::File::Error QuotaBackendImpl::GetUsageCachePath( | 147 base::File::Error QuotaBackendImpl::GetUsageCachePath( |
| 144 const GURL& origin, | 148 const GURL& origin, |
| 145 FileSystemType type, | 149 FileSystemType type, |
| 146 base::FilePath* usage_file_path) { | 150 base::FilePath* usage_file_path) { |
| 147 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 151 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| 148 DCHECK(origin.is_valid()); | 152 DCHECK(origin.is_valid()); |
| 149 DCHECK(usage_file_path); | 153 DCHECK(usage_file_path); |
| 150 base::File::Error error = base::File::FILE_OK; | 154 base::File::Error error = base::File::FILE_OK; |
| 151 *usage_file_path = | 155 *usage_file_path = |
| 152 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType( | 156 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType( |
| 153 obfuscated_file_util_, origin, type, &error); | 157 obfuscated_file_util_, origin, type, &error); |
| 154 return error; | 158 return error; |
| 155 } | 159 } |
| 156 | 160 |
| 157 QuotaBackendImpl::QuotaReservationInfo::QuotaReservationInfo( | 161 QuotaBackendImpl::QuotaReservationInfo::QuotaReservationInfo( |
| 158 const GURL& origin, FileSystemType type, int64 delta) | 162 const GURL& origin, FileSystemType type, int64 delta) |
| 159 : origin(origin), type(type), delta(delta) { | 163 : origin(origin), type(type), delta(delta) { |
| 160 } | 164 } |
| 161 | 165 |
| 162 QuotaBackendImpl::QuotaReservationInfo::~QuotaReservationInfo() { | 166 QuotaBackendImpl::QuotaReservationInfo::~QuotaReservationInfo() { |
| 163 } | 167 } |
| 164 | 168 |
| 165 } // namespace fileapi | 169 } // namespace storage |
| OLD | NEW |