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 "storage/browser/fileapi/quota/quota_backend_impl.h" | 5 #include "storage/browser/fileapi/quota/quota_backend_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 weak_ptr_factory_(this) { | 32 weak_ptr_factory_(this) { |
33 } | 33 } |
34 | 34 |
35 QuotaBackendImpl::~QuotaBackendImpl() { | 35 QuotaBackendImpl::~QuotaBackendImpl() { |
36 } | 36 } |
37 | 37 |
38 void QuotaBackendImpl::ReserveQuota(const GURL& origin, | 38 void QuotaBackendImpl::ReserveQuota(const GURL& origin, |
39 FileSystemType type, | 39 FileSystemType type, |
40 int64_t delta, | 40 int64_t delta, |
41 const ReserveQuotaCallback& callback) { | 41 const ReserveQuotaCallback& callback) { |
42 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 42 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
43 DCHECK(origin.is_valid()); | 43 DCHECK(origin.is_valid()); |
44 if (!delta) { | 44 if (!delta) { |
45 callback.Run(base::File::FILE_OK, 0); | 45 callback.Run(base::File::FILE_OK, 0); |
46 return; | 46 return; |
47 } | 47 } |
48 DCHECK(quota_manager_proxy_.get()); | 48 DCHECK(quota_manager_proxy_.get()); |
49 quota_manager_proxy_->GetUsageAndQuota( | 49 quota_manager_proxy_->GetUsageAndQuota( |
50 file_task_runner_.get(), | 50 file_task_runner_.get(), |
51 origin, | 51 origin, |
52 FileSystemTypeToQuotaStorageType(type), | 52 FileSystemTypeToQuotaStorageType(type), |
53 base::Bind(&QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota, | 53 base::Bind(&QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota, |
54 weak_ptr_factory_.GetWeakPtr(), | 54 weak_ptr_factory_.GetWeakPtr(), |
55 QuotaReservationInfo(origin, type, delta), | 55 QuotaReservationInfo(origin, type, delta), |
56 callback)); | 56 callback)); |
57 } | 57 } |
58 | 58 |
59 void QuotaBackendImpl::ReleaseReservedQuota(const GURL& origin, | 59 void QuotaBackendImpl::ReleaseReservedQuota(const GURL& origin, |
60 FileSystemType type, | 60 FileSystemType type, |
61 int64_t size) { | 61 int64_t size) { |
62 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 62 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
63 DCHECK(origin.is_valid()); | 63 DCHECK(origin.is_valid()); |
64 DCHECK_LE(0, size); | 64 DCHECK_LE(0, size); |
65 if (!size) | 65 if (!size) |
66 return; | 66 return; |
67 ReserveQuotaInternal(QuotaReservationInfo(origin, type, -size)); | 67 ReserveQuotaInternal(QuotaReservationInfo(origin, type, -size)); |
68 } | 68 } |
69 | 69 |
70 void QuotaBackendImpl::CommitQuotaUsage(const GURL& origin, | 70 void QuotaBackendImpl::CommitQuotaUsage(const GURL& origin, |
71 FileSystemType type, | 71 FileSystemType type, |
72 int64_t delta) { | 72 int64_t delta) { |
73 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 73 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
74 DCHECK(origin.is_valid()); | 74 DCHECK(origin.is_valid()); |
75 if (!delta) | 75 if (!delta) |
76 return; | 76 return; |
77 ReserveQuotaInternal(QuotaReservationInfo(origin, type, delta)); | 77 ReserveQuotaInternal(QuotaReservationInfo(origin, type, delta)); |
78 base::FilePath path; | 78 base::FilePath path; |
79 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) | 79 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) |
80 return; | 80 return; |
81 bool result = file_system_usage_cache_->AtomicUpdateUsageByDelta(path, delta); | 81 bool result = file_system_usage_cache_->AtomicUpdateUsageByDelta(path, delta); |
82 DCHECK(result); | 82 DCHECK(result); |
83 } | 83 } |
84 | 84 |
85 void QuotaBackendImpl::IncrementDirtyCount(const GURL& origin, | 85 void QuotaBackendImpl::IncrementDirtyCount(const GURL& origin, |
86 FileSystemType type) { | 86 FileSystemType type) { |
87 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 87 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
88 DCHECK(origin.is_valid()); | 88 DCHECK(origin.is_valid()); |
89 base::FilePath path; | 89 base::FilePath path; |
90 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) | 90 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) |
91 return; | 91 return; |
92 DCHECK(file_system_usage_cache_); | 92 DCHECK(file_system_usage_cache_); |
93 file_system_usage_cache_->IncrementDirty(path); | 93 file_system_usage_cache_->IncrementDirty(path); |
94 } | 94 } |
95 | 95 |
96 void QuotaBackendImpl::DecrementDirtyCount(const GURL& origin, | 96 void QuotaBackendImpl::DecrementDirtyCount(const GURL& origin, |
97 FileSystemType type) { | 97 FileSystemType type) { |
98 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 98 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
99 DCHECK(origin.is_valid()); | 99 DCHECK(origin.is_valid()); |
100 base::FilePath path; | 100 base::FilePath path; |
101 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) | 101 if (GetUsageCachePath(origin, type, &path) != base::File::FILE_OK) |
102 return; | 102 return; |
103 DCHECK(file_system_usage_cache_); | 103 DCHECK(file_system_usage_cache_); |
104 file_system_usage_cache_->DecrementDirty(path); | 104 file_system_usage_cache_->DecrementDirty(path); |
105 } | 105 } |
106 | 106 |
107 void QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota( | 107 void QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota( |
108 const QuotaReservationInfo& info, | 108 const QuotaReservationInfo& info, |
109 const ReserveQuotaCallback& callback, | 109 const ReserveQuotaCallback& callback, |
110 storage::QuotaStatusCode status, | 110 storage::QuotaStatusCode status, |
111 int64_t usage, | 111 int64_t usage, |
112 int64_t quota) { | 112 int64_t quota) { |
113 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 113 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
114 DCHECK(info.origin.is_valid()); | 114 DCHECK(info.origin.is_valid()); |
115 DCHECK_LE(0, usage); | 115 DCHECK_LE(0, usage); |
116 DCHECK_LE(0, quota); | 116 DCHECK_LE(0, quota); |
117 if (status != storage::kQuotaStatusOk) { | 117 if (status != storage::kQuotaStatusOk) { |
118 callback.Run(base::File::FILE_ERROR_FAILED, 0); | 118 callback.Run(base::File::FILE_ERROR_FAILED, 0); |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 QuotaReservationInfo normalized_info = info; | 122 QuotaReservationInfo normalized_info = info; |
123 if (info.delta > 0) { | 123 if (info.delta > 0) { |
124 int64_t new_usage = base::saturated_cast<int64_t>( | 124 int64_t new_usage = base::saturated_cast<int64_t>( |
125 usage + static_cast<uint64_t>(info.delta)); | 125 usage + static_cast<uint64_t>(info.delta)); |
126 if (quota < new_usage) | 126 if (quota < new_usage) |
127 new_usage = quota; | 127 new_usage = quota; |
128 normalized_info.delta = | 128 normalized_info.delta = |
129 std::max(static_cast<int64_t>(0), new_usage - usage); | 129 std::max(static_cast<int64_t>(0), new_usage - usage); |
130 } | 130 } |
131 | 131 |
132 ReserveQuotaInternal(normalized_info); | 132 ReserveQuotaInternal(normalized_info); |
133 if (callback.Run(base::File::FILE_OK, normalized_info.delta)) | 133 if (callback.Run(base::File::FILE_OK, normalized_info.delta)) |
134 return; | 134 return; |
135 // The requester could not accept the reserved quota. Revert it. | 135 // The requester could not accept the reserved quota. Revert it. |
136 ReserveQuotaInternal( | 136 ReserveQuotaInternal( |
137 QuotaReservationInfo(normalized_info.origin, | 137 QuotaReservationInfo(normalized_info.origin, |
138 normalized_info.type, | 138 normalized_info.type, |
139 -normalized_info.delta)); | 139 -normalized_info.delta)); |
140 } | 140 } |
141 | 141 |
142 void QuotaBackendImpl::ReserveQuotaInternal(const QuotaReservationInfo& info) { | 142 void QuotaBackendImpl::ReserveQuotaInternal(const QuotaReservationInfo& info) { |
143 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 143 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
144 DCHECK(info.origin.is_valid()); | 144 DCHECK(info.origin.is_valid()); |
145 DCHECK(quota_manager_proxy_.get()); | 145 DCHECK(quota_manager_proxy_.get()); |
146 quota_manager_proxy_->NotifyStorageModified( | 146 quota_manager_proxy_->NotifyStorageModified( |
147 storage::QuotaClient::kFileSystem, | 147 storage::QuotaClient::kFileSystem, |
148 info.origin, | 148 info.origin, |
149 FileSystemTypeToQuotaStorageType(info.type), | 149 FileSystemTypeToQuotaStorageType(info.type), |
150 info.delta); | 150 info.delta); |
151 } | 151 } |
152 | 152 |
153 base::File::Error QuotaBackendImpl::GetUsageCachePath( | 153 base::File::Error QuotaBackendImpl::GetUsageCachePath( |
154 const GURL& origin, | 154 const GURL& origin, |
155 FileSystemType type, | 155 FileSystemType type, |
156 base::FilePath* usage_file_path) { | 156 base::FilePath* usage_file_path) { |
157 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 157 DCHECK(file_task_runner_->RunsTasksInCurrentSequence()); |
158 DCHECK(origin.is_valid()); | 158 DCHECK(origin.is_valid()); |
159 DCHECK(usage_file_path); | 159 DCHECK(usage_file_path); |
160 base::File::Error error = base::File::FILE_OK; | 160 base::File::Error error = base::File::FILE_OK; |
161 *usage_file_path = | 161 *usage_file_path = |
162 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType( | 162 SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType( |
163 obfuscated_file_util_, origin, type, &error); | 163 obfuscated_file_util_, origin, type, &error); |
164 return error; | 164 return error; |
165 } | 165 } |
166 | 166 |
167 QuotaBackendImpl::QuotaReservationInfo::QuotaReservationInfo( | 167 QuotaBackendImpl::QuotaReservationInfo::QuotaReservationInfo( |
168 const GURL& origin, | 168 const GURL& origin, |
169 FileSystemType type, | 169 FileSystemType type, |
170 int64_t delta) | 170 int64_t delta) |
171 : origin(origin), type(type), delta(delta) {} | 171 : origin(origin), type(type), delta(delta) {} |
172 | 172 |
173 QuotaBackendImpl::QuotaReservationInfo::~QuotaReservationInfo() { | 173 QuotaBackendImpl::QuotaReservationInfo::~QuotaReservationInfo() { |
174 } | 174 } |
175 | 175 |
176 } // namespace storage | 176 } // namespace storage |
OLD | NEW |