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

Side by Side Diff: storage/browser/quota/quota_manager.cc

Issue 1498003003: Remove kint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: INT64_MAX Created 5 years 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
« no previous file with comments | « storage/browser/quota/quota_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quota/quota_manager.h" 5 #include "storage/browser/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <limits>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
14 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
15 #include "base/profiler/scoped_tracker.h" 16 #include "base/profiler/scoped_tracker.h"
16 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
(...skipping 11 matching lines...) Expand all
30 31
31 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 32 #define UMA_HISTOGRAM_MBYTES(name, sample) \
32 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 33 UMA_HISTOGRAM_CUSTOM_COUNTS( \
33 (name), static_cast<int>((sample) / kMBytes), \ 34 (name), static_cast<int>((sample) / kMBytes), \
34 1, 10 * 1024 * 1024 /* 10TB */, 100) 35 1, 10 * 1024 * 1024 /* 10TB */, 100)
35 36
36 namespace storage { 37 namespace storage {
37 38
38 namespace { 39 namespace {
39 40
40 const int64 kMBytes = 1024 * 1024; 41 const int64_t kMBytes = 1024 * 1024;
41 const int kMinutesInMilliSeconds = 60 * 1000; 42 const int kMinutesInMilliSeconds = 60 * 1000;
42 43
43 const int64 kReportHistogramInterval = 60 * 60 * 1000; // 1 hour 44 const int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour
44 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33% 45 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33%
45 46
46 } // namespace 47 } // namespace
47 48
48 // Arbitrary for now, but must be reasonably small so that 49 // Arbitrary for now, but must be reasonably small so that
49 // in-memory databases can fit. 50 // in-memory databases can fit.
50 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this. 51 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this.
51 const int64 QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes; 52 const int64_t QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes;
52 53
53 const int64 QuotaManager::kNoLimit = kint64max; 54 const int64_t QuotaManager::kNoLimit = INT64_MAX;
54 55
55 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20% 56 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20%
56 57
57 // Cap size for per-host persistent quota determined by the histogram. 58 // Cap size for per-host persistent quota determined by the histogram.
58 // This is a bit lax value because the histogram says nothing about per-host 59 // This is a bit lax value because the histogram says nothing about per-host
59 // persistent storage usage and we determined by global persistent storage 60 // persistent storage usage and we determined by global persistent storage
60 // usage that is less than 10GB for almost all users. 61 // usage that is less than 10GB for almost all users.
61 const int64 QuotaManager::kPerHostPersistentQuotaLimit = 10 * 1024 * kMBytes; 62 const int64_t QuotaManager::kPerHostPersistentQuotaLimit = 10 * 1024 * kMBytes;
62 63
63 const char QuotaManager::kDatabaseName[] = "QuotaManager"; 64 const char QuotaManager::kDatabaseName[] = "QuotaManager";
64 65
65 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3; 66 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3;
66 67
67 // Preserve kMinimumPreserveForSystem disk space for system book-keeping 68 // Preserve kMinimumPreserveForSystem disk space for system book-keeping
68 // when returning the quota to unlimited apps/extensions. 69 // when returning the quota to unlimited apps/extensions.
69 // TODO(kinuko): This should be like 10% of the actual disk space. 70 // TODO(kinuko): This should be like 10% of the actual disk space.
70 // For now we simply use a constant as getting the disk size needs 71 // For now we simply use a constant as getting the disk size needs
71 // platform-dependent code. (http://crbug.com/178976) 72 // platform-dependent code. (http://crbug.com/178976)
72 int64 QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes; 73 int64_t QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes;
73 74
74 const int QuotaManager::kEvictionIntervalInMilliSeconds = 75 const int QuotaManager::kEvictionIntervalInMilliSeconds =
75 30 * kMinutesInMilliSeconds; 76 30 * kMinutesInMilliSeconds;
76 77
77 const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] = 78 const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] =
78 "Quota.TimeBetweenRepeatedOriginEvictions"; 79 "Quota.TimeBetweenRepeatedOriginEvictions";
79 const char QuotaManager::kEvictedOriginAccessedCountHistogram[] = 80 const char QuotaManager::kEvictedOriginAccessedCountHistogram[] =
80 "Quota.EvictedOriginAccessCount"; 81 "Quota.EvictedOriginAccessCount";
81 const char QuotaManager::kEvictedOriginTimeSinceAccessHistogram[] = 82 const char QuotaManager::kEvictedOriginTimeSinceAccessHistogram[] =
82 "Quota.EvictedOriginTimeSinceAccess"; 83 "Quota.EvictedOriginTimeSinceAccess";
83 84
84 // Heuristics: assuming average cloud server allows a few Gigs storage 85 // Heuristics: assuming average cloud server allows a few Gigs storage
85 // on the server side and the storage needs to be shared for user data 86 // on the server side and the storage needs to be shared for user data
86 // and by multiple apps. 87 // and by multiple apps.
87 int64 QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes; 88 int64_t QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes;
88 89
89 namespace { 90 namespace {
90 91
91 void CountOriginType(const std::set<GURL>& origins, 92 void CountOriginType(const std::set<GURL>& origins,
92 SpecialStoragePolicy* policy, 93 SpecialStoragePolicy* policy,
93 size_t* protected_origins, 94 size_t* protected_origins,
94 size_t* unlimited_origins) { 95 size_t* unlimited_origins) {
95 DCHECK(protected_origins); 96 DCHECK(protected_origins);
96 DCHECK(unlimited_origins); 97 DCHECK(unlimited_origins);
97 *protected_origins = 0; 98 *protected_origins = 0;
98 *unlimited_origins = 0; 99 *unlimited_origins = 0;
99 if (!policy) 100 if (!policy)
100 return; 101 return;
101 for (std::set<GURL>::const_iterator itr = origins.begin(); 102 for (std::set<GURL>::const_iterator itr = origins.begin();
102 itr != origins.end(); 103 itr != origins.end();
103 ++itr) { 104 ++itr) {
104 if (policy->IsStorageProtected(*itr)) 105 if (policy->IsStorageProtected(*itr))
105 ++*protected_origins; 106 ++*protected_origins;
106 if (policy->IsStorageUnlimited(*itr)) 107 if (policy->IsStorageUnlimited(*itr))
107 ++*unlimited_origins; 108 ++*unlimited_origins;
108 } 109 }
109 } 110 }
110 111
111 bool SetTemporaryGlobalOverrideQuotaOnDBThread(int64* new_quota, 112 bool SetTemporaryGlobalOverrideQuotaOnDBThread(int64_t* new_quota,
112 QuotaDatabase* database) { 113 QuotaDatabase* database) {
113 DCHECK(database); 114 DCHECK(database);
114 if (!database->SetQuotaConfigValue( 115 if (!database->SetQuotaConfigValue(
115 QuotaDatabase::kTemporaryQuotaOverrideKey, *new_quota)) { 116 QuotaDatabase::kTemporaryQuotaOverrideKey, *new_quota)) {
116 *new_quota = -1; 117 *new_quota = -1;
117 return false; 118 return false;
118 } 119 }
119 return true; 120 return true;
120 } 121 }
121 122
122 bool GetPersistentHostQuotaOnDBThread(const std::string& host, 123 bool GetPersistentHostQuotaOnDBThread(const std::string& host,
123 int64* quota, 124 int64_t* quota,
124 QuotaDatabase* database) { 125 QuotaDatabase* database) {
125 DCHECK(database); 126 DCHECK(database);
126 database->GetHostQuota(host, kStorageTypePersistent, quota); 127 database->GetHostQuota(host, kStorageTypePersistent, quota);
127 return true; 128 return true;
128 } 129 }
129 130
130 bool SetPersistentHostQuotaOnDBThread(const std::string& host, 131 bool SetPersistentHostQuotaOnDBThread(const std::string& host,
131 int64* new_quota, 132 int64_t* new_quota,
132 QuotaDatabase* database) { 133 QuotaDatabase* database) {
133 DCHECK(database); 134 DCHECK(database);
134 if (database->SetHostQuota(host, kStorageTypePersistent, *new_quota)) 135 if (database->SetHostQuota(host, kStorageTypePersistent, *new_quota))
135 return true; 136 return true;
136 *new_quota = 0; 137 *new_quota = 0;
137 return false; 138 return false;
138 } 139 }
139 140
140 bool InitializeOnDBThread(int64* temporary_quota_override, 141 bool InitializeOnDBThread(int64_t* temporary_quota_override,
141 int64* desired_available_space, 142 int64_t* desired_available_space,
142 QuotaDatabase* database) { 143 QuotaDatabase* database) {
143 DCHECK(database); 144 DCHECK(database);
144 database->GetQuotaConfigValue(QuotaDatabase::kTemporaryQuotaOverrideKey, 145 database->GetQuotaConfigValue(QuotaDatabase::kTemporaryQuotaOverrideKey,
145 temporary_quota_override); 146 temporary_quota_override);
146 database->GetQuotaConfigValue(QuotaDatabase::kDesiredAvailableSpaceKey, 147 database->GetQuotaConfigValue(QuotaDatabase::kDesiredAvailableSpaceKey,
147 desired_available_space); 148 desired_available_space);
148 return true; 149 return true;
149 } 150 }
150 151
151 bool GetLRUOriginOnDBThread(StorageType type, 152 bool GetLRUOriginOnDBThread(StorageType type,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 220 }
220 221
221 bool UpdateModifiedTimeOnDBThread(const GURL& origin, 222 bool UpdateModifiedTimeOnDBThread(const GURL& origin,
222 StorageType type, 223 StorageType type,
223 base::Time modified_time, 224 base::Time modified_time,
224 QuotaDatabase* database) { 225 QuotaDatabase* database) {
225 DCHECK(database); 226 DCHECK(database);
226 return database->SetOriginLastModifiedTime(origin, type, modified_time); 227 return database->SetOriginLastModifiedTime(origin, type, modified_time);
227 } 228 }
228 229
229 int64 CallSystemGetAmountOfFreeDiskSpace(const base::FilePath& profile_path) { 230 int64_t CallSystemGetAmountOfFreeDiskSpace(const base::FilePath& profile_path) {
230 // crbug.com/349708 231 // crbug.com/349708
231 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace"); 232 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace");
232 233
233 // Ensure the profile path exists. 234 // Ensure the profile path exists.
234 if (!base::CreateDirectory(profile_path)) { 235 if (!base::CreateDirectory(profile_path)) {
235 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); 236 LOG(WARNING) << "Create directory failed for path" << profile_path.value();
236 return 0; 237 return 0;
237 } 238 }
238 return base::SysInfo::AmountOfFreeDiskSpace(profile_path); 239 return base::SysInfo::AmountOfFreeDiskSpace(profile_path);
239 } 240 }
240 241
241 int64 CalculateTemporaryGlobalQuota(int64 global_limited_usage, 242 int64_t CalculateTemporaryGlobalQuota(int64_t global_limited_usage,
242 int64 available_space) { 243 int64_t available_space) {
243 DCHECK_GE(global_limited_usage, 0); 244 DCHECK_GE(global_limited_usage, 0);
244 int64 avail_space = available_space; 245 int64_t avail_space = available_space;
245 if (avail_space < kint64max - global_limited_usage) { 246 if (avail_space <
247 std::numeric_limits<int64_t>::max() - global_limited_usage) {
246 // We basically calculate the temporary quota by 248 // We basically calculate the temporary quota by
247 // [available_space + space_used_for_temp] * kTempQuotaRatio, 249 // [available_space + space_used_for_temp] * kTempQuotaRatio,
248 // but make sure we'll have no overflow. 250 // but make sure we'll have no overflow.
249 avail_space += global_limited_usage; 251 avail_space += global_limited_usage;
250 } 252 }
251 return avail_space * kTemporaryQuotaRatioToAvail; 253 return avail_space * kTemporaryQuotaRatioToAvail;
252 } 254 }
253 255
254 void DispatchTemporaryGlobalQuotaCallback( 256 void DispatchTemporaryGlobalQuotaCallback(
255 const QuotaCallback& callback, 257 const QuotaCallback& callback,
256 QuotaStatusCode status, 258 QuotaStatusCode status,
257 const UsageAndQuota& usage_and_quota) { 259 const UsageAndQuota& usage_and_quota) {
258 if (status != kQuotaStatusOk) { 260 if (status != kQuotaStatusOk) {
259 callback.Run(status, 0); 261 callback.Run(status, 0);
260 return; 262 return;
261 } 263 }
262 264
263 callback.Run(status, CalculateTemporaryGlobalQuota( 265 callback.Run(status, CalculateTemporaryGlobalQuota(
264 usage_and_quota.global_limited_usage, 266 usage_and_quota.global_limited_usage,
265 usage_and_quota.available_disk_space)); 267 usage_and_quota.available_disk_space));
266 } 268 }
267 269
268 int64 CalculateQuotaWithDiskSpace( 270 int64_t CalculateQuotaWithDiskSpace(int64_t available_disk_space,
269 int64 available_disk_space, int64 usage, int64 quota) { 271 int64_t usage,
272 int64_t quota) {
270 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem) { 273 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem) {
271 LOG(WARNING) 274 LOG(WARNING)
272 << "Running out of disk space for profile." 275 << "Running out of disk space for profile."
273 << " QuotaManager starts forbidding further quota consumption."; 276 << " QuotaManager starts forbidding further quota consumption.";
274 return usage; 277 return usage;
275 } 278 }
276 279
277 if (quota < usage) { 280 if (quota < usage) {
278 // No more space; cap the quota to the current usage. 281 // No more space; cap the quota to the current usage.
279 return usage; 282 return usage;
280 } 283 }
281 284
282 available_disk_space -= QuotaManager::kMinimumPreserveForSystem; 285 available_disk_space -= QuotaManager::kMinimumPreserveForSystem;
283 if (available_disk_space < quota - usage) 286 if (available_disk_space < quota - usage)
284 return available_disk_space + usage; 287 return available_disk_space + usage;
285 288
286 return quota; 289 return quota;
287 } 290 }
288 291
289 int64 CalculateTemporaryHostQuota(int64 host_usage, 292 int64_t CalculateTemporaryHostQuota(int64_t host_usage,
290 int64 global_quota, 293 int64_t global_quota,
291 int64 global_limited_usage) { 294 int64_t global_limited_usage) {
292 DCHECK_GE(global_limited_usage, 0); 295 DCHECK_GE(global_limited_usage, 0);
293 int64 host_quota = global_quota / QuotaManager::kPerHostTemporaryPortion; 296 int64_t host_quota = global_quota / QuotaManager::kPerHostTemporaryPortion;
294 if (global_limited_usage > global_quota) 297 if (global_limited_usage > global_quota)
295 host_quota = std::min(host_quota, host_usage); 298 host_quota = std::min(host_quota, host_usage);
296 return host_quota; 299 return host_quota;
297 } 300 }
298 301
299 void DispatchUsageAndQuotaForWebApps( 302 void DispatchUsageAndQuotaForWebApps(
300 StorageType type, 303 StorageType type,
301 bool is_incognito, 304 bool is_incognito,
302 bool is_unlimited, 305 bool is_unlimited,
303 bool can_query_disk_size, 306 bool can_query_disk_size,
304 const QuotaManager::GetUsageAndQuotaCallback& callback, 307 const QuotaManager::GetUsageAndQuotaCallback& callback,
305 QuotaStatusCode status, 308 QuotaStatusCode status,
306 const UsageAndQuota& usage_and_quota) { 309 const UsageAndQuota& usage_and_quota) {
307 if (status != kQuotaStatusOk) { 310 if (status != kQuotaStatusOk) {
308 callback.Run(status, 0, 0); 311 callback.Run(status, 0, 0);
309 return; 312 return;
310 } 313 }
311 314
312 int64 usage = usage_and_quota.usage; 315 int64_t usage = usage_and_quota.usage;
313 int64 quota = usage_and_quota.quota; 316 int64_t quota = usage_and_quota.quota;
314 317
315 if (type == kStorageTypeTemporary && !is_unlimited) { 318 if (type == kStorageTypeTemporary && !is_unlimited) {
316 quota = CalculateTemporaryHostQuota( 319 quota = CalculateTemporaryHostQuota(
317 usage, quota, usage_and_quota.global_limited_usage); 320 usage, quota, usage_and_quota.global_limited_usage);
318 } 321 }
319 322
320 if (is_incognito) { 323 if (is_incognito) {
321 quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit); 324 quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit);
322 callback.Run(status, usage, quota); 325 callback.Run(status, usage, quota);
323 return; 326 return;
(...skipping 17 matching lines...) Expand all
341 344
342 } // namespace 345 } // namespace
343 346
344 UsageAndQuota::UsageAndQuota() 347 UsageAndQuota::UsageAndQuota()
345 : usage(0), 348 : usage(0),
346 global_limited_usage(0), 349 global_limited_usage(0),
347 quota(0), 350 quota(0),
348 available_disk_space(0) { 351 available_disk_space(0) {
349 } 352 }
350 353
351 UsageAndQuota::UsageAndQuota( 354 UsageAndQuota::UsageAndQuota(int64_t usage,
352 int64 usage, 355 int64_t global_limited_usage,
353 int64 global_limited_usage, 356 int64_t quota,
354 int64 quota, 357 int64_t available_disk_space)
355 int64 available_disk_space)
356 : usage(usage), 358 : usage(usage),
357 global_limited_usage(global_limited_usage), 359 global_limited_usage(global_limited_usage),
358 quota(quota), 360 quota(quota),
359 available_disk_space(available_disk_space) { 361 available_disk_space(available_disk_space) {}
360 }
361 362
362 class UsageAndQuotaCallbackDispatcher 363 class UsageAndQuotaCallbackDispatcher
363 : public QuotaTask, 364 : public QuotaTask,
364 public base::SupportsWeakPtr<UsageAndQuotaCallbackDispatcher> { 365 public base::SupportsWeakPtr<UsageAndQuotaCallbackDispatcher> {
365 public: 366 public:
366 explicit UsageAndQuotaCallbackDispatcher(QuotaManager* manager) 367 explicit UsageAndQuotaCallbackDispatcher(QuotaManager* manager)
367 : QuotaTask(manager), 368 : QuotaTask(manager),
368 has_usage_(false), 369 has_usage_(false),
369 has_global_limited_usage_(false), 370 has_global_limited_usage_(false),
370 has_quota_(false), 371 has_quota_(false),
371 has_available_disk_space_(false), 372 has_available_disk_space_(false),
372 status_(kQuotaStatusUnknown), 373 status_(kQuotaStatusUnknown),
373 usage_and_quota_(-1, -1, -1, -1), 374 usage_and_quota_(-1, -1, -1, -1),
374 waiting_callbacks_(1) {} 375 waiting_callbacks_(1) {}
375 376
376 ~UsageAndQuotaCallbackDispatcher() override {} 377 ~UsageAndQuotaCallbackDispatcher() override {}
377 378
378 void WaitForResults(const QuotaManager::UsageAndQuotaCallback& callback) { 379 void WaitForResults(const QuotaManager::UsageAndQuotaCallback& callback) {
379 callback_ = callback; 380 callback_ = callback;
380 Start(); 381 Start();
381 } 382 }
382 383
383 void set_usage(int64 usage) { 384 void set_usage(int64_t usage) {
384 usage_and_quota_.usage = usage; 385 usage_and_quota_.usage = usage;
385 has_usage_ = true; 386 has_usage_ = true;
386 } 387 }
387 388
388 void set_global_limited_usage(int64 global_limited_usage) { 389 void set_global_limited_usage(int64_t global_limited_usage) {
389 usage_and_quota_.global_limited_usage = global_limited_usage; 390 usage_and_quota_.global_limited_usage = global_limited_usage;
390 has_global_limited_usage_ = true; 391 has_global_limited_usage_ = true;
391 } 392 }
392 393
393 void set_quota(int64 quota) { 394 void set_quota(int64_t quota) {
394 usage_and_quota_.quota = quota; 395 usage_and_quota_.quota = quota;
395 has_quota_ = true; 396 has_quota_ = true;
396 } 397 }
397 398
398 void set_available_disk_space(int64 available_disk_space) { 399 void set_available_disk_space(int64_t available_disk_space) {
399 usage_and_quota_.available_disk_space = available_disk_space; 400 usage_and_quota_.available_disk_space = available_disk_space;
400 has_available_disk_space_ = true; 401 has_available_disk_space_ = true;
401 } 402 }
402 403
403 UsageCallback GetHostUsageCallback() { 404 UsageCallback GetHostUsageCallback() {
404 ++waiting_callbacks_; 405 ++waiting_callbacks_;
405 has_usage_ = true; 406 has_usage_ = true;
406 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetHostUsage, 407 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetHostUsage,
407 AsWeakPtr()); 408 AsWeakPtr());
408 } 409 }
(...skipping 14 matching lines...) Expand all
423 } 424 }
424 425
425 QuotaCallback GetAvailableSpaceCallback() { 426 QuotaCallback GetAvailableSpaceCallback() {
426 ++waiting_callbacks_; 427 ++waiting_callbacks_;
427 has_available_disk_space_ = true; 428 has_available_disk_space_ = true;
428 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace, 429 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace,
429 AsWeakPtr()); 430 AsWeakPtr());
430 } 431 }
431 432
432 private: 433 private:
433 void DidGetHostUsage(int64 usage) { 434 void DidGetHostUsage(int64_t usage) {
434 if (status_ == kQuotaStatusUnknown) 435 if (status_ == kQuotaStatusUnknown)
435 status_ = kQuotaStatusOk; 436 status_ = kQuotaStatusOk;
436 usage_and_quota_.usage = usage; 437 usage_and_quota_.usage = usage;
437 CheckCompleted(); 438 CheckCompleted();
438 } 439 }
439 440
440 void DidGetGlobalLimitedUsage(int64 limited_usage) { 441 void DidGetGlobalLimitedUsage(int64_t limited_usage) {
441 if (status_ == kQuotaStatusUnknown) 442 if (status_ == kQuotaStatusUnknown)
442 status_ = kQuotaStatusOk; 443 status_ = kQuotaStatusOk;
443 usage_and_quota_.global_limited_usage = limited_usage; 444 usage_and_quota_.global_limited_usage = limited_usage;
444 CheckCompleted(); 445 CheckCompleted();
445 } 446 }
446 447
447 void DidGetQuota(QuotaStatusCode status, int64 quota) { 448 void DidGetQuota(QuotaStatusCode status, int64_t quota) {
448 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) 449 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk)
449 status_ = status; 450 status_ = status;
450 usage_and_quota_.quota = quota; 451 usage_and_quota_.quota = quota;
451 CheckCompleted(); 452 CheckCompleted();
452 } 453 }
453 454
454 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) { 455 void DidGetAvailableSpace(QuotaStatusCode status, int64_t space) {
455 // crbug.com/349708 456 // crbug.com/349708
456 TRACE_EVENT0( 457 TRACE_EVENT0(
457 "io", "UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace"); 458 "io", "UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace");
458 459
459 DCHECK_GE(space, 0); 460 DCHECK_GE(space, 0);
460 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) 461 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk)
461 status_ = status; 462 status_ = status;
462 usage_and_quota_.available_disk_space = space; 463 usage_and_quota_.available_disk_space = space;
463 CheckCompleted(); 464 CheckCompleted();
464 } 465 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 DeleteSoon(); 549 DeleteSoon();
549 } 550 }
550 551
551 void Aborted() override { 552 void Aborted() override {
552 callback_.Run(UsageInfoEntries()); 553 callback_.Run(UsageInfoEntries());
553 DeleteSoon(); 554 DeleteSoon();
554 } 555 }
555 556
556 private: 557 private:
557 void AddEntries(StorageType type, UsageTracker* tracker) { 558 void AddEntries(StorageType type, UsageTracker* tracker) {
558 std::map<std::string, int64> host_usage; 559 std::map<std::string, int64_t> host_usage;
559 tracker->GetCachedHostsUsage(&host_usage); 560 tracker->GetCachedHostsUsage(&host_usage);
560 for (std::map<std::string, int64>::const_iterator iter = host_usage.begin(); 561 for (std::map<std::string, int64_t>::const_iterator iter =
561 iter != host_usage.end(); 562 host_usage.begin();
562 ++iter) { 563 iter != host_usage.end(); ++iter) {
563 entries_.push_back(UsageInfo(iter->first, type, iter->second)); 564 entries_.push_back(UsageInfo(iter->first, type, iter->second));
564 } 565 }
565 if (--remaining_trackers_ == 0) 566 if (--remaining_trackers_ == 0)
566 CallCompleted(); 567 CallCompleted();
567 } 568 }
568 569
569 void DidGetGlobalUsage(StorageType type, int64, int64) { 570 void DidGetGlobalUsage(StorageType type, int64_t, int64_t) {
570 DCHECK(manager()->GetUsageTracker(type)); 571 DCHECK(manager()->GetUsageTracker(type));
571 AddEntries(type, manager()->GetUsageTracker(type)); 572 AddEntries(type, manager()->GetUsageTracker(type));
572 } 573 }
573 574
574 QuotaManager* manager() const { 575 QuotaManager* manager() const {
575 return static_cast<QuotaManager*>(observer()); 576 return static_cast<QuotaManager*>(observer());
576 } 577 }
577 578
578 GetUsageInfoCallback callback_; 579 GetUsageInfoCallback callback_;
579 UsageInfoEntries entries_; 580 UsageInfoEntries entries_;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 GetUsageAndQuotaForWebApps(origin, type, callback); 958 GetUsageAndQuotaForWebApps(origin, type, callback);
958 } 959 }
959 960
960 void QuotaManager::NotifyStorageAccessed( 961 void QuotaManager::NotifyStorageAccessed(
961 QuotaClient::ID client_id, 962 QuotaClient::ID client_id,
962 const GURL& origin, StorageType type) { 963 const GURL& origin, StorageType type) {
963 DCHECK(origin == origin.GetOrigin()); 964 DCHECK(origin == origin.GetOrigin());
964 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); 965 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now());
965 } 966 }
966 967
967 void QuotaManager::NotifyStorageModified( 968 void QuotaManager::NotifyStorageModified(QuotaClient::ID client_id,
968 QuotaClient::ID client_id, 969 const GURL& origin,
969 const GURL& origin, StorageType type, int64 delta) { 970 StorageType type,
971 int64_t delta) {
970 DCHECK(origin == origin.GetOrigin()); 972 DCHECK(origin == origin.GetOrigin());
971 NotifyStorageModifiedInternal(client_id, origin, type, delta, 973 NotifyStorageModifiedInternal(client_id, origin, type, delta,
972 base::Time::Now()); 974 base::Time::Now());
973 } 975 }
974 976
975 void QuotaManager::NotifyOriginInUse(const GURL& origin) { 977 void QuotaManager::NotifyOriginInUse(const GURL& origin) {
976 DCHECK(io_thread_->BelongsToCurrentThread()); 978 DCHECK(io_thread_->BelongsToCurrentThread());
977 origins_in_use_[origin]++; 979 origins_in_use_[origin]++;
978 } 980 }
979 981
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 UsageAndQuotaCallbackDispatcher* dispatcher = 1054 UsageAndQuotaCallbackDispatcher* dispatcher =
1053 new UsageAndQuotaCallbackDispatcher(this); 1055 new UsageAndQuotaCallbackDispatcher(this);
1054 GetUsageTracker(kStorageTypeTemporary)-> 1056 GetUsageTracker(kStorageTypeTemporary)->
1055 GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); 1057 GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
1056 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); 1058 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
1057 dispatcher->WaitForResults( 1059 dispatcher->WaitForResults(
1058 base::Bind(&DispatchTemporaryGlobalQuotaCallback, callback)); 1060 base::Bind(&DispatchTemporaryGlobalQuotaCallback, callback));
1059 } 1061 }
1060 1062
1061 void QuotaManager::SetTemporaryGlobalOverrideQuota( 1063 void QuotaManager::SetTemporaryGlobalOverrideQuota(
1062 int64 new_quota, const QuotaCallback& callback) { 1064 int64_t new_quota,
1065 const QuotaCallback& callback) {
1063 LazyInitialize(); 1066 LazyInitialize();
1064 1067
1065 if (new_quota < 0) { 1068 if (new_quota < 0) {
1066 if (!callback.is_null()) 1069 if (!callback.is_null())
1067 callback.Run(kQuotaErrorInvalidModification, -1); 1070 callback.Run(kQuotaErrorInvalidModification, -1);
1068 return; 1071 return;
1069 } 1072 }
1070 1073
1071 if (db_disabled_) { 1074 if (db_disabled_) {
1072 if (!callback.is_null()) 1075 if (!callback.is_null())
1073 callback.Run(kQuotaErrorInvalidAccess, -1); 1076 callback.Run(kQuotaErrorInvalidAccess, -1);
1074 return; 1077 return;
1075 } 1078 }
1076 1079
1077 int64* new_quota_ptr = new int64(new_quota); 1080 int64_t* new_quota_ptr = new int64_t(new_quota);
1078 PostTaskAndReplyWithResultForDBThread( 1081 PostTaskAndReplyWithResultForDBThread(
1079 FROM_HERE, 1082 FROM_HERE,
1080 base::Bind(&SetTemporaryGlobalOverrideQuotaOnDBThread, 1083 base::Bind(&SetTemporaryGlobalOverrideQuotaOnDBThread,
1081 base::Unretained(new_quota_ptr)), 1084 base::Unretained(new_quota_ptr)),
1082 base::Bind(&QuotaManager::DidSetTemporaryGlobalOverrideQuota, 1085 base::Bind(&QuotaManager::DidSetTemporaryGlobalOverrideQuota,
1083 weak_factory_.GetWeakPtr(), 1086 weak_factory_.GetWeakPtr(),
1084 callback, 1087 callback,
1085 base::Owned(new_quota_ptr))); 1088 base::Owned(new_quota_ptr)));
1086 } 1089 }
1087 1090
1088 void QuotaManager::GetPersistentHostQuota(const std::string& host, 1091 void QuotaManager::GetPersistentHostQuota(const std::string& host,
1089 const QuotaCallback& callback) { 1092 const QuotaCallback& callback) {
1090 LazyInitialize(); 1093 LazyInitialize();
1091 if (host.empty()) { 1094 if (host.empty()) {
1092 // This could happen if we are called on file:///. 1095 // This could happen if we are called on file:///.
1093 // TODO(kinuko) We may want to respect --allow-file-access-from-files 1096 // TODO(kinuko) We may want to respect --allow-file-access-from-files
1094 // command line switch. 1097 // command line switch.
1095 callback.Run(kQuotaStatusOk, 0); 1098 callback.Run(kQuotaStatusOk, 0);
1096 return; 1099 return;
1097 } 1100 }
1098 1101
1099 if (!persistent_host_quota_callbacks_.Add(host, callback)) 1102 if (!persistent_host_quota_callbacks_.Add(host, callback))
1100 return; 1103 return;
1101 1104
1102 int64* quota_ptr = new int64(0); 1105 int64_t* quota_ptr = new int64_t(0);
1103 PostTaskAndReplyWithResultForDBThread( 1106 PostTaskAndReplyWithResultForDBThread(
1104 FROM_HERE, 1107 FROM_HERE,
1105 base::Bind(&GetPersistentHostQuotaOnDBThread, 1108 base::Bind(&GetPersistentHostQuotaOnDBThread,
1106 host, 1109 host,
1107 base::Unretained(quota_ptr)), 1110 base::Unretained(quota_ptr)),
1108 base::Bind(&QuotaManager::DidGetPersistentHostQuota, 1111 base::Bind(&QuotaManager::DidGetPersistentHostQuota,
1109 weak_factory_.GetWeakPtr(), 1112 weak_factory_.GetWeakPtr(),
1110 host, 1113 host,
1111 base::Owned(quota_ptr))); 1114 base::Owned(quota_ptr)));
1112 } 1115 }
1113 1116
1114 void QuotaManager::SetPersistentHostQuota(const std::string& host, 1117 void QuotaManager::SetPersistentHostQuota(const std::string& host,
1115 int64 new_quota, 1118 int64_t new_quota,
1116 const QuotaCallback& callback) { 1119 const QuotaCallback& callback) {
1117 LazyInitialize(); 1120 LazyInitialize();
1118 if (host.empty()) { 1121 if (host.empty()) {
1119 // This could happen if we are called on file:///. 1122 // This could happen if we are called on file:///.
1120 callback.Run(kQuotaErrorNotSupported, 0); 1123 callback.Run(kQuotaErrorNotSupported, 0);
1121 return; 1124 return;
1122 } 1125 }
1123 1126
1124 if (new_quota < 0) { 1127 if (new_quota < 0) {
1125 callback.Run(kQuotaErrorInvalidModification, -1); 1128 callback.Run(kQuotaErrorInvalidModification, -1);
1126 return; 1129 return;
1127 } 1130 }
1128 1131
1129 if (kPerHostPersistentQuotaLimit < new_quota) { 1132 if (kPerHostPersistentQuotaLimit < new_quota) {
1130 // Cap the requested size at the per-host quota limit. 1133 // Cap the requested size at the per-host quota limit.
1131 new_quota = kPerHostPersistentQuotaLimit; 1134 new_quota = kPerHostPersistentQuotaLimit;
1132 } 1135 }
1133 1136
1134 if (db_disabled_) { 1137 if (db_disabled_) {
1135 callback.Run(kQuotaErrorInvalidAccess, -1); 1138 callback.Run(kQuotaErrorInvalidAccess, -1);
1136 return; 1139 return;
1137 } 1140 }
1138 1141
1139 int64* new_quota_ptr = new int64(new_quota); 1142 int64_t* new_quota_ptr = new int64_t(new_quota);
1140 PostTaskAndReplyWithResultForDBThread( 1143 PostTaskAndReplyWithResultForDBThread(
1141 FROM_HERE, 1144 FROM_HERE,
1142 base::Bind(&SetPersistentHostQuotaOnDBThread, 1145 base::Bind(&SetPersistentHostQuotaOnDBThread,
1143 host, 1146 host,
1144 base::Unretained(new_quota_ptr)), 1147 base::Unretained(new_quota_ptr)),
1145 base::Bind(&QuotaManager::DidSetPersistentHostQuota, 1148 base::Bind(&QuotaManager::DidSetPersistentHostQuota,
1146 weak_factory_.GetWeakPtr(), 1149 weak_factory_.GetWeakPtr(),
1147 host, 1150 host,
1148 callback, 1151 callback,
1149 base::Owned(new_quota_ptr))); 1152 base::Owned(new_quota_ptr)));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 bool QuotaManager::IsTrackingHostUsage(StorageType type, 1185 bool QuotaManager::IsTrackingHostUsage(StorageType type,
1183 QuotaClient::ID client_id) const { 1186 QuotaClient::ID client_id) const {
1184 UsageTracker* tracker = GetUsageTracker(type); 1187 UsageTracker* tracker = GetUsageTracker(type);
1185 return tracker && tracker->GetClientTracker(client_id); 1188 return tracker && tracker->GetClientTracker(client_id);
1186 } 1189 }
1187 1190
1188 void QuotaManager::GetStatistics( 1191 void QuotaManager::GetStatistics(
1189 std::map<std::string, std::string>* statistics) { 1192 std::map<std::string, std::string>* statistics) {
1190 DCHECK(statistics); 1193 DCHECK(statistics);
1191 if (temporary_storage_evictor_) { 1194 if (temporary_storage_evictor_) {
1192 std::map<std::string, int64> stats; 1195 std::map<std::string, int64_t> stats;
1193 temporary_storage_evictor_->GetStatistics(&stats); 1196 temporary_storage_evictor_->GetStatistics(&stats);
1194 for (std::map<std::string, int64>::iterator p = stats.begin(); 1197 for (std::map<std::string, int64_t>::iterator p = stats.begin();
1195 p != stats.end(); 1198 p != stats.end(); ++p) {
1196 ++p)
1197 (*statistics)[p->first] = base::Int64ToString(p->second); 1199 (*statistics)[p->first] = base::Int64ToString(p->second);
1200 }
1198 } 1201 }
1199 } 1202 }
1200 1203
1201 bool QuotaManager::IsStorageUnlimited(const GURL& origin, 1204 bool QuotaManager::IsStorageUnlimited(const GURL& origin,
1202 StorageType type) const { 1205 StorageType type) const {
1203 // For syncable storage we should always enforce quota (since the 1206 // For syncable storage we should always enforce quota (since the
1204 // quota must be capped by the server limit). 1207 // quota must be capped by the server limit).
1205 if (type == kStorageTypeSyncable) 1208 if (type == kStorageTypeSyncable)
1206 return false; 1209 return false;
1207 if (type == kStorageTypeQuotaNotManaged) 1210 if (type == kStorageTypeQuotaNotManaged)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 temporary_usage_tracker_.reset(new UsageTracker( 1303 temporary_usage_tracker_.reset(new UsageTracker(
1301 clients_, kStorageTypeTemporary, special_storage_policy_.get(), 1304 clients_, kStorageTypeTemporary, special_storage_policy_.get(),
1302 storage_monitor_.get())); 1305 storage_monitor_.get()));
1303 persistent_usage_tracker_.reset(new UsageTracker( 1306 persistent_usage_tracker_.reset(new UsageTracker(
1304 clients_, kStorageTypePersistent, special_storage_policy_.get(), 1307 clients_, kStorageTypePersistent, special_storage_policy_.get(),
1305 storage_monitor_.get())); 1308 storage_monitor_.get()));
1306 syncable_usage_tracker_.reset(new UsageTracker( 1309 syncable_usage_tracker_.reset(new UsageTracker(
1307 clients_, kStorageTypeSyncable, special_storage_policy_.get(), 1310 clients_, kStorageTypeSyncable, special_storage_policy_.get(),
1308 storage_monitor_.get())); 1311 storage_monitor_.get()));
1309 1312
1310 int64* temporary_quota_override = new int64(-1); 1313 int64_t* temporary_quota_override = new int64_t(-1);
1311 int64* desired_available_space = new int64(-1); 1314 int64_t* desired_available_space = new int64_t(-1);
1312 PostTaskAndReplyWithResultForDBThread( 1315 PostTaskAndReplyWithResultForDBThread(
1313 FROM_HERE, 1316 FROM_HERE,
1314 base::Bind(&InitializeOnDBThread, 1317 base::Bind(&InitializeOnDBThread,
1315 base::Unretained(temporary_quota_override), 1318 base::Unretained(temporary_quota_override),
1316 base::Unretained(desired_available_space)), 1319 base::Unretained(desired_available_space)),
1317 base::Bind(&QuotaManager::DidInitialize, 1320 base::Bind(&QuotaManager::DidInitialize,
1318 weak_factory_.GetWeakPtr(), 1321 weak_factory_.GetWeakPtr(),
1319 base::Owned(temporary_quota_override), 1322 base::Owned(temporary_quota_override),
1320 base::Owned(desired_available_space))); 1323 base::Owned(desired_available_space)));
1321 } 1324 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 1365
1363 if (db_disabled_) 1366 if (db_disabled_)
1364 return; 1367 return;
1365 PostTaskAndReplyWithResultForDBThread( 1368 PostTaskAndReplyWithResultForDBThread(
1366 FROM_HERE, 1369 FROM_HERE,
1367 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time), 1370 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time),
1368 base::Bind(&QuotaManager::DidDatabaseWork, 1371 base::Bind(&QuotaManager::DidDatabaseWork,
1369 weak_factory_.GetWeakPtr())); 1372 weak_factory_.GetWeakPtr()));
1370 } 1373 }
1371 1374
1372 void QuotaManager::NotifyStorageModifiedInternal( 1375 void QuotaManager::NotifyStorageModifiedInternal(QuotaClient::ID client_id,
1373 QuotaClient::ID client_id, 1376 const GURL& origin,
1374 const GURL& origin, 1377 StorageType type,
1375 StorageType type, 1378 int64_t delta,
1376 int64 delta, 1379 base::Time modified_time) {
1377 base::Time modified_time) {
1378 LazyInitialize(); 1380 LazyInitialize();
1379 DCHECK(GetUsageTracker(type)); 1381 DCHECK(GetUsageTracker(type));
1380 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); 1382 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta);
1381 1383
1382 PostTaskAndReplyWithResultForDBThread( 1384 PostTaskAndReplyWithResultForDBThread(
1383 FROM_HERE, 1385 FROM_HERE,
1384 base::Bind(&UpdateModifiedTimeOnDBThread, origin, type, modified_time), 1386 base::Bind(&UpdateModifiedTimeOnDBThread, origin, type, modified_time),
1385 base::Bind(&QuotaManager::DidDatabaseWork, 1387 base::Bind(&QuotaManager::DidDatabaseWork,
1386 weak_factory_.GetWeakPtr())); 1388 weak_factory_.GetWeakPtr()));
1387 } 1389 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 base::Bind( 1473 base::Bind(
1472 &QuotaManager::DidGetTemporaryGlobalUsageForHistogram, 1474 &QuotaManager::DidGetTemporaryGlobalUsageForHistogram,
1473 weak_factory_.GetWeakPtr())); 1475 weak_factory_.GetWeakPtr()));
1474 GetGlobalUsage(kStorageTypePersistent, 1476 GetGlobalUsage(kStorageTypePersistent,
1475 base::Bind( 1477 base::Bind(
1476 &QuotaManager::DidGetPersistentGlobalUsageForHistogram, 1478 &QuotaManager::DidGetPersistentGlobalUsageForHistogram,
1477 weak_factory_.GetWeakPtr())); 1479 weak_factory_.GetWeakPtr()));
1478 } 1480 }
1479 1481
1480 void QuotaManager::DidGetTemporaryGlobalUsageForHistogram( 1482 void QuotaManager::DidGetTemporaryGlobalUsageForHistogram(
1481 int64 usage, 1483 int64_t usage,
1482 int64 unlimited_usage) { 1484 int64_t unlimited_usage) {
1483 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage); 1485 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfTemporaryStorage", usage);
1484 1486
1485 std::set<GURL> origins; 1487 std::set<GURL> origins;
1486 GetCachedOrigins(kStorageTypeTemporary, &origins); 1488 GetCachedOrigins(kStorageTypeTemporary, &origins);
1487 1489
1488 size_t num_origins = origins.size(); 1490 size_t num_origins = origins.size();
1489 size_t protected_origins = 0; 1491 size_t protected_origins = 0;
1490 size_t unlimited_origins = 0; 1492 size_t unlimited_origins = 0;
1491 CountOriginType(origins, 1493 CountOriginType(origins,
1492 special_storage_policy_.get(), 1494 special_storage_policy_.get(),
1493 &protected_origins, 1495 &protected_origins,
1494 &unlimited_origins); 1496 &unlimited_origins);
1495 1497
1496 UMA_HISTOGRAM_COUNTS("Quota.NumberOfTemporaryStorageOrigins", 1498 UMA_HISTOGRAM_COUNTS("Quota.NumberOfTemporaryStorageOrigins",
1497 num_origins); 1499 num_origins);
1498 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedTemporaryStorageOrigins", 1500 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedTemporaryStorageOrigins",
1499 protected_origins); 1501 protected_origins);
1500 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedTemporaryStorageOrigins", 1502 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedTemporaryStorageOrigins",
1501 unlimited_origins); 1503 unlimited_origins);
1502 } 1504 }
1503 1505
1504 void QuotaManager::DidGetPersistentGlobalUsageForHistogram( 1506 void QuotaManager::DidGetPersistentGlobalUsageForHistogram(
1505 int64 usage, 1507 int64_t usage,
1506 int64 unlimited_usage) { 1508 int64_t unlimited_usage) {
1507 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfPersistentStorage", usage); 1509 UMA_HISTOGRAM_MBYTES("Quota.GlobalUsageOfPersistentStorage", usage);
1508 1510
1509 std::set<GURL> origins; 1511 std::set<GURL> origins;
1510 GetCachedOrigins(kStorageTypePersistent, &origins); 1512 GetCachedOrigins(kStorageTypePersistent, &origins);
1511 1513
1512 size_t num_origins = origins.size(); 1514 size_t num_origins = origins.size();
1513 size_t protected_origins = 0; 1515 size_t protected_origins = 0;
1514 size_t unlimited_origins = 0; 1516 size_t unlimited_origins = 0;
1515 CountOriginType(origins, 1517 CountOriginType(origins,
1516 special_storage_policy_.get(), 1518 special_storage_policy_.get(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 } else { 1553 } else {
1552 callback.Run(origin); 1554 callback.Run(origin);
1553 } 1555 }
1554 access_notified_origins_.clear(); 1556 access_notified_origins_.clear();
1555 1557
1556 is_getting_eviction_origin_ = false; 1558 is_getting_eviction_origin_ = false;
1557 } 1559 }
1558 1560
1559 void QuotaManager::GetEvictionOrigin(StorageType type, 1561 void QuotaManager::GetEvictionOrigin(StorageType type,
1560 const std::set<GURL>& extra_exceptions, 1562 const std::set<GURL>& extra_exceptions,
1561 int64 global_quota, 1563 int64_t global_quota,
1562 const GetOriginCallback& callback) { 1564 const GetOriginCallback& callback) {
1563 LazyInitialize(); 1565 LazyInitialize();
1564 // This must not be called while there's an in-flight task. 1566 // This must not be called while there's an in-flight task.
1565 DCHECK(!is_getting_eviction_origin_); 1567 DCHECK(!is_getting_eviction_origin_);
1566 is_getting_eviction_origin_ = true; 1568 is_getting_eviction_origin_ = true;
1567 1569
1568 GetOriginCallback did_get_origin_callback = 1570 GetOriginCallback did_get_origin_callback =
1569 base::Bind(&QuotaManager::DidGetEvictionOrigin, 1571 base::Bind(&QuotaManager::DidGetEvictionOrigin,
1570 weak_factory_.GetWeakPtr(), callback); 1572 weak_factory_.GetWeakPtr(), callback);
1571 1573
1572 if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) { 1574 if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) {
1573 std::map<GURL, int64> usage_map; 1575 std::map<GURL, int64_t> usage_map;
1574 // The cached origins are populated by the prior call to 1576 // The cached origins are populated by the prior call to
1575 // GetUsageAndQuotaForEviction(). 1577 // GetUsageAndQuotaForEviction().
1576 GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map); 1578 GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map);
1577 1579
1578 temporary_storage_eviction_policy_->GetEvictionOrigin( 1580 temporary_storage_eviction_policy_->GetEvictionOrigin(
1579 special_storage_policy_, GetEvictionOriginExceptions(extra_exceptions), 1581 special_storage_policy_, GetEvictionOriginExceptions(extra_exceptions),
1580 usage_map, global_quota, did_get_origin_callback); 1582 usage_map, global_quota, did_get_origin_callback);
1581 1583
1582 return; 1584 return;
1583 } 1585 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 PostTaskAndReplyWithResultForDBThread( 1636 PostTaskAndReplyWithResultForDBThread(
1635 FROM_HERE, base::Bind(&GetLRUOriginOnDBThread, type, 1637 FROM_HERE, base::Bind(&GetLRUOriginOnDBThread, type,
1636 GetEvictionOriginExceptions(std::set<GURL>()), 1638 GetEvictionOriginExceptions(std::set<GURL>()),
1637 special_storage_policy_, base::Unretained(url)), 1639 special_storage_policy_, base::Unretained(url)),
1638 base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(), 1640 base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(),
1639 base::Owned(url))); 1641 base::Owned(url)));
1640 } 1642 }
1641 1643
1642 void QuotaManager::DidSetTemporaryGlobalOverrideQuota( 1644 void QuotaManager::DidSetTemporaryGlobalOverrideQuota(
1643 const QuotaCallback& callback, 1645 const QuotaCallback& callback,
1644 const int64* new_quota, 1646 const int64_t* new_quota,
1645 bool success) { 1647 bool success) {
1646 QuotaStatusCode status = kQuotaErrorInvalidAccess; 1648 QuotaStatusCode status = kQuotaErrorInvalidAccess;
1647 DidDatabaseWork(success); 1649 DidDatabaseWork(success);
1648 if (success) { 1650 if (success) {
1649 temporary_quota_override_ = *new_quota; 1651 temporary_quota_override_ = *new_quota;
1650 status = kQuotaStatusOk; 1652 status = kQuotaStatusOk;
1651 } 1653 }
1652 1654
1653 if (callback.is_null()) 1655 if (callback.is_null())
1654 return; 1656 return;
1655 1657
1656 callback.Run(status, *new_quota); 1658 callback.Run(status, *new_quota);
1657 } 1659 }
1658 1660
1659 void QuotaManager::DidGetPersistentHostQuota(const std::string& host, 1661 void QuotaManager::DidGetPersistentHostQuota(const std::string& host,
1660 const int64* quota, 1662 const int64_t* quota,
1661 bool success) { 1663 bool success) {
1662 DidDatabaseWork(success); 1664 DidDatabaseWork(success);
1663 persistent_host_quota_callbacks_.Run(host, kQuotaStatusOk, *quota); 1665 persistent_host_quota_callbacks_.Run(host, kQuotaStatusOk, *quota);
1664 } 1666 }
1665 1667
1666 void QuotaManager::DidSetPersistentHostQuota(const std::string& host, 1668 void QuotaManager::DidSetPersistentHostQuota(const std::string& host,
1667 const QuotaCallback& callback, 1669 const QuotaCallback& callback,
1668 const int64* new_quota, 1670 const int64_t* new_quota,
1669 bool success) { 1671 bool success) {
1670 DidDatabaseWork(success); 1672 DidDatabaseWork(success);
1671 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota); 1673 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota);
1672 } 1674 }
1673 1675
1674 void QuotaManager::DidInitialize(int64* temporary_quota_override, 1676 void QuotaManager::DidInitialize(int64_t* temporary_quota_override,
1675 int64* desired_available_space, 1677 int64_t* desired_available_space,
1676 bool success) { 1678 bool success) {
1677 temporary_quota_override_ = *temporary_quota_override; 1679 temporary_quota_override_ = *temporary_quota_override;
1678 desired_available_space_ = *desired_available_space; 1680 desired_available_space_ = *desired_available_space;
1679 temporary_quota_initialized_ = true; 1681 temporary_quota_initialized_ = true;
1680 DidDatabaseWork(success); 1682 DidDatabaseWork(success);
1681 1683
1682 histogram_timer_.Start(FROM_HERE, 1684 histogram_timer_.Start(FROM_HERE,
1683 base::TimeDelta::FromMilliseconds( 1685 base::TimeDelta::FromMilliseconds(
1684 kReportHistogramInterval), 1686 kReportHistogramInterval),
1685 this, &QuotaManager::ReportHistogram); 1687 this, &QuotaManager::ReportHistogram);
1686 1688
1687 db_initialization_callbacks_.Run(); 1689 db_initialization_callbacks_.Run();
1688 GetTemporaryGlobalQuota( 1690 GetTemporaryGlobalQuota(
1689 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota, 1691 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
1690 weak_factory_.GetWeakPtr())); 1692 weak_factory_.GetWeakPtr()));
1691 } 1693 }
1692 1694
1693 void QuotaManager::DidGetLRUOrigin(const GURL* origin, 1695 void QuotaManager::DidGetLRUOrigin(const GURL* origin,
1694 bool success) { 1696 bool success) {
1695 DidDatabaseWork(success); 1697 DidDatabaseWork(success);
1696 1698
1697 lru_origin_callback_.Run(*origin); 1699 lru_origin_callback_.Run(*origin);
1698 lru_origin_callback_.Reset(); 1700 lru_origin_callback_.Reset();
1699 } 1701 }
1700 1702
1701 void QuotaManager::DidGetInitialTemporaryGlobalQuota( 1703 void QuotaManager::DidGetInitialTemporaryGlobalQuota(QuotaStatusCode status,
1702 QuotaStatusCode status, int64 quota_unused) { 1704 int64_t quota_unused) {
1703 if (eviction_disabled_) 1705 if (eviction_disabled_)
1704 return; 1706 return;
1705 1707
1706 std::set<GURL>* origins = new std::set<GURL>; 1708 std::set<GURL>* origins = new std::set<GURL>;
1707 temporary_usage_tracker_->GetCachedOrigins(origins); 1709 temporary_usage_tracker_->GetCachedOrigins(origins);
1708 // This will call the StartEviction() when initial origin registration 1710 // This will call the StartEviction() when initial origin registration
1709 // is completed. 1711 // is completed.
1710 PostTaskAndReplyWithResultForDBThread( 1712 PostTaskAndReplyWithResultForDBThread(
1711 FROM_HERE, 1713 FROM_HERE,
1712 base::Bind(&InitializeTemporaryOriginsInfoOnDBThread, 1714 base::Bind(&InitializeTemporaryOriginsInfoOnDBThread,
1713 base::Owned(origins)), 1715 base::Owned(origins)),
1714 base::Bind(&QuotaManager::DidInitializeTemporaryOriginsInfo, 1716 base::Bind(&QuotaManager::DidInitializeTemporaryOriginsInfo,
1715 weak_factory_.GetWeakPtr())); 1717 weak_factory_.GetWeakPtr()));
1716 } 1718 }
1717 1719
1718 void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) { 1720 void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) {
1719 DidDatabaseWork(success); 1721 DidDatabaseWork(success);
1720 if (success) 1722 if (success)
1721 StartEviction(); 1723 StartEviction();
1722 } 1724 }
1723 1725
1724 void QuotaManager::DidGetAvailableSpace(int64 space) { 1726 void QuotaManager::DidGetAvailableSpace(int64_t space) {
1725 // crbug.com/349708 1727 // crbug.com/349708
1726 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace", 1728 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace",
1727 "n_callbacks", available_space_callbacks_.size()); 1729 "n_callbacks", available_space_callbacks_.size());
1728 1730
1729 available_space_callbacks_.Run(kQuotaStatusOk, space); 1731 available_space_callbacks_.Run(kQuotaStatusOk, space);
1730 } 1732 }
1731 1733
1732 void QuotaManager::DidDatabaseWork(bool success) { 1734 void QuotaManager::DidDatabaseWork(bool success) {
1733 db_disabled_ = !success; 1735 db_disabled_ = !success;
1734 } 1736 }
(...skipping 14 matching lines...) Expand all
1749 // |database_|, therefore we can be sure that database_ is alive when this 1751 // |database_|, therefore we can be sure that database_ is alive when this
1750 // task runs. 1752 // task runs.
1751 base::PostTaskAndReplyWithResult( 1753 base::PostTaskAndReplyWithResult(
1752 db_thread_.get(), 1754 db_thread_.get(),
1753 from_here, 1755 from_here,
1754 base::Bind(task, base::Unretained(database_.get())), 1756 base::Bind(task, base::Unretained(database_.get())),
1755 reply); 1757 reply);
1756 } 1758 }
1757 1759
1758 } // namespace storage 1760 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/quota/quota_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698