Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: webkit/quota/quota_manager.cc

Issue 14237003: Rename SpecialStoragePolicy::IsInstalledApp() to CanQueryDiskSize() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/quota/quota_manager.h ('k') | webkit/quota/quota_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webkit/quota/quota_manager.h" 5 #include "webkit/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <functional> 9 #include <functional>
10 #include <set> 10 #include <set>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3; 178 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3;
179 179
180 const int QuotaManager::kEvictionIntervalInMilliSeconds = 180 const int QuotaManager::kEvictionIntervalInMilliSeconds =
181 30 * kMinutesInMilliSeconds; 181 30 * kMinutesInMilliSeconds;
182 182
183 // Heuristics: assuming average cloud server allows a few Gigs storage 183 // Heuristics: assuming average cloud server allows a few Gigs storage
184 // on the server side and the storage needs to be shared for user data 184 // on the server side and the storage needs to be shared for user data
185 // and by multiple apps. 185 // and by multiple apps.
186 int64 QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes; 186 int64 QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes;
187 187
188 int64 CalculateQuotaForInstalledApp( 188 int64 CalculateQuotaForInstalledApp(
michaeln 2013/04/16 21:21:04 maybe change the name of this method too, not sure
kinuko 2013/04/17 04:33:38 Good catch, renamed this to CalculateQuotaWithDisk
189 int64 available_disk_space, int64 usage, int64 quota) { 189 int64 available_disk_space, int64 usage, int64 quota) {
190 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem || 190 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem ||
191 quota < usage) { 191 quota < usage) {
192 // No more space; cap the quota to the current usage. 192 // No more space; cap the quota to the current usage.
193 return usage; 193 return usage;
194 } 194 }
195 195
196 available_disk_space -= QuotaManager::kMinimumPreserveForSystem; 196 available_disk_space -= QuotaManager::kMinimumPreserveForSystem;
197 if (available_disk_space < quota - usage) 197 if (available_disk_space < quota - usage)
198 return available_disk_space + usage; 198 return available_disk_space + usage;
199 199
200 return quota; 200 return quota;
201 } 201 }
202 202
203 // Callback translators. 203 // Callback translators.
204 void CallGetUsageAndQuotaCallback( 204 void CallGetUsageAndQuotaCallback(
205 const QuotaManager::GetUsageAndQuotaCallback& callback, 205 const QuotaManager::GetUsageAndQuotaCallback& callback,
206 bool unlimited, 206 bool unlimited,
207 bool is_installed_app, 207 bool can_query_disk_size,
208 QuotaStatusCode status, 208 QuotaStatusCode status,
209 const QuotaAndUsage& quota_and_usage) { 209 const QuotaAndUsage& quota_and_usage) {
210 // Regular limited case. 210 // Regular limited case.
211 if (!unlimited) { 211 if (!unlimited) {
212 if (is_installed_app) { 212 if (can_query_disk_size) {
213 // Cap the quota by the available disk space. 213 // Cap the quota by the available disk space.
214 callback.Run(status, quota_and_usage.usage, 214 callback.Run(status, quota_and_usage.usage,
215 CalculateQuotaForInstalledApp( 215 CalculateQuotaForInstalledApp(
216 quota_and_usage.available_disk_space, 216 quota_and_usage.available_disk_space,
217 quota_and_usage.usage, 217 quota_and_usage.usage,
218 quota_and_usage.quota)); 218 quota_and_usage.quota));
219 return; 219 return;
220 } 220 }
221 callback.Run(status, quota_and_usage.usage, quota_and_usage.quota); 221 callback.Run(status, quota_and_usage.usage, quota_and_usage.quota);
222 return; 222 return;
223 } 223 }
224 224
225 int64 usage = quota_and_usage.unlimited_usage; 225 int64 usage = quota_and_usage.unlimited_usage;
226 226
227 // Unlimited case: this must be only for installed-app and extensions, 227 // Unlimited case: this must be only for apps with unlimitedStorage permission
228 // or only when --unlimited-storage flag is given. 228 // or only when --unlimited-storage flag is given.
229 // We return the available disk space (minus kMinimumPreserveForSystem). 229 // We assume we can expose the disk size for them and return the available
230 // disk space (minus kMinimumPreserveForSystem).
230 callback.Run(status, usage, 231 callback.Run(status, usage,
231 CalculateQuotaForInstalledApp( 232 CalculateQuotaForInstalledApp(
232 quota_and_usage.available_disk_space, 233 quota_and_usage.available_disk_space,
233 usage, QuotaManager::kNoLimit)); 234 usage, QuotaManager::kNoLimit));
234 } 235 }
235 236
236 void CallQuotaCallback( 237 void CallQuotaCallback(
237 const QuotaCallback& callback, 238 const QuotaCallback& callback,
238 QuotaStatusCode status, 239 QuotaStatusCode status,
239 const QuotaAndUsage& quota_and_usage) { 240 const QuotaAndUsage& quota_and_usage) {
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 } 961 }
961 962
962 void QuotaManager::GetUsageAndQuotaForWebApps( 963 void QuotaManager::GetUsageAndQuotaForWebApps(
963 const GURL& origin, 964 const GURL& origin,
964 StorageType type, 965 StorageType type,
965 const GetUsageAndQuotaCallback& callback) { 966 const GetUsageAndQuotaCallback& callback) {
966 DCHECK(origin == origin.GetOrigin()); 967 DCHECK(origin == origin.GetOrigin());
967 GetUsageAndQuotaInternal( 968 GetUsageAndQuotaInternal(
968 origin, type, false /* global */, 969 origin, type, false /* global */,
969 base::Bind(&CallGetUsageAndQuotaCallback, callback, 970 base::Bind(&CallGetUsageAndQuotaCallback, callback,
970 IsStorageUnlimited(origin, type), IsInstalledApp(origin))); 971 IsStorageUnlimited(origin, type), CanQueryDiskSize(origin)));
971 } 972 }
972 973
973 void QuotaManager::GetUsageAndQuota( 974 void QuotaManager::GetUsageAndQuota(
974 const GURL& origin, StorageType type, 975 const GURL& origin, StorageType type,
975 const GetUsageAndQuotaCallback& callback) { 976 const GetUsageAndQuotaCallback& callback) {
976 DCHECK(origin == origin.GetOrigin()); 977 DCHECK(origin == origin.GetOrigin());
977 978
978 if (IsStorageUnlimited(origin, type)) { 979 if (IsStorageUnlimited(origin, type)) {
979 CallGetUsageAndQuotaCallback( 980 CallGetUsageAndQuotaCallback(
980 callback, false, IsInstalledApp(origin), 981 callback, false, CanQueryDiskSize(origin),
981 kQuotaStatusOk, QuotaAndUsage::CreateForUnlimitedStorage()); 982 kQuotaStatusOk, QuotaAndUsage::CreateForUnlimitedStorage());
982 return; 983 return;
983 } 984 }
984 985
985 GetUsageAndQuotaForWebApps(origin, type, callback); 986 GetUsageAndQuotaForWebApps(origin, type, callback);
986 } 987 }
987 988
988 void QuotaManager::NotifyStorageAccessed( 989 void QuotaManager::NotifyStorageAccessed(
989 QuotaClient::ID client_id, 990 QuotaClient::ID client_id,
990 const GURL& origin, StorageType type) { 991 const GURL& origin, StorageType type) {
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1782
1782 QuotaManagerProxy::QuotaManagerProxy( 1783 QuotaManagerProxy::QuotaManagerProxy(
1783 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) 1784 QuotaManager* manager, base::SingleThreadTaskRunner* io_thread)
1784 : manager_(manager), io_thread_(io_thread) { 1785 : manager_(manager), io_thread_(io_thread) {
1785 } 1786 }
1786 1787
1787 QuotaManagerProxy::~QuotaManagerProxy() { 1788 QuotaManagerProxy::~QuotaManagerProxy() {
1788 } 1789 }
1789 1790
1790 } // namespace quota 1791 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/quota_manager.h ('k') | webkit/quota/quota_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698