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

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

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: poolSize Created 4 years, 4 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <functional> 11 #include <functional>
12 #include <limits> 12 #include <limits>
13 #include <memory> 13 #include <memory>
14 #include <utility> 14 #include <utility>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/bind_helpers.h" 17 #include "base/bind_helpers.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
22 #include "base/numerics/safe_conversions.h" 22 #include "base/numerics/safe_conversions.h"
23 #include "base/profiler/scoped_tracker.h" 23 #include "base/profiler/scoped_tracker.h"
24 #include "base/sequenced_task_runner.h" 24 #include "base/sequenced_task_runner.h"
25 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
26 #include "base/strings/string_number_conversions.h" 26 #include "base/strings/string_number_conversions.h"
27 #include "base/sys_info.h" 27 #include "base/sys_info.h"
28 #include "base/task_runner_util.h" 28 #include "base/task_runner_util.h"
29 #include "base/threading/thread_task_runner_handle.h"
29 #include "base/time/time.h" 30 #include "base/time/time.h"
30 #include "base/trace_event/trace_event.h" 31 #include "base/trace_event/trace_event.h"
31 #include "net/base/url_util.h" 32 #include "net/base/url_util.h"
32 #include "storage/browser/quota/client_usage_tracker.h" 33 #include "storage/browser/quota/client_usage_tracker.h"
33 #include "storage/browser/quota/quota_manager_proxy.h" 34 #include "storage/browser/quota/quota_manager_proxy.h"
34 #include "storage/browser/quota/quota_temporary_storage_evictor.h" 35 #include "storage/browser/quota/quota_temporary_storage_evictor.h"
35 #include "storage/browser/quota/storage_monitor.h" 36 #include "storage/browser/quota/storage_monitor.h"
36 #include "storage/browser/quota/usage_tracker.h" 37 #include "storage/browser/quota/usage_tracker.h"
37 #include "storage/common/quota/quota_types.h" 38 #include "storage/common/quota/quota_types.h"
38 39
39 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 40 #define UMA_HISTOGRAM_MBYTES(name, sample) \
40 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 41 UMA_HISTOGRAM_CUSTOM_COUNTS( \
41 (name), static_cast<int>((sample) / kMBytes), \ 42 (name), static_cast<int>((sample) / kMBytes), \
42 1, 10 * 1024 * 1024 /* 10TB */, 100) 43 1, 10 * 1024 * 1024 /* 10TB */, 100)
43 44
44 namespace storage { 45 namespace storage {
45 46
46 namespace { 47 namespace {
47 48
48 const int64_t kMBytes = 1024 * 1024; 49 const int64_t kMBytes = 1024 * 1024;
49 const int kMinutesInMilliSeconds = 60 * 1000; 50 const int kMinutesInMilliSeconds = 60 * 1000;
50
51 const int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour 51 const int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour
52 const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33%
53 52
54 } // namespace 53 } // namespace
55 54
56 // Arbitrary for now, but must be reasonably small so that
57 // in-memory databases can fit.
58 // TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this.
59 const int64_t QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes;
60
61 const int64_t QuotaManager::kNoLimit = INT64_MAX; 55 const int64_t QuotaManager::kNoLimit = INT64_MAX;
62 56
57 // TODO(michaeln): REMOVE
63 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20% 58 const int QuotaManager::kPerHostTemporaryPortion = 5; // 20%
64 59
65 // Cap size for per-host persistent quota determined by the histogram. 60 // Cap size for per-host persistent quota determined by the histogram.
66 // This is a bit lax value because the histogram says nothing about per-host 61 // This is a bit lax value because the histogram says nothing about per-host
67 // persistent storage usage and we determined by global persistent storage 62 // persistent storage usage and we determined by global persistent storage
68 // usage that is less than 10GB for almost all users. 63 // usage that is less than 10GB for almost all users.
69 const int64_t QuotaManager::kPerHostPersistentQuotaLimit = 10 * 1024 * kMBytes; 64 const int64_t QuotaManager::kPerHostPersistentQuotaLimit = 10 * 1024 * kMBytes;
70 65
66 // TODO(michaeln): REMOVE
67 int64_t QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes;
68
71 const char QuotaManager::kDatabaseName[] = "QuotaManager"; 69 const char QuotaManager::kDatabaseName[] = "QuotaManager";
72 70
73 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3; 71 const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3;
74
75 // Preserve kMinimumPreserveForSystem disk space for system book-keeping
76 // when returning the quota to unlimited apps/extensions.
77 // TODO(kinuko): This should be like 10% of the actual disk space.
78 // For now we simply use a constant as getting the disk size needs
79 // platform-dependent code. (http://crbug.com/178976)
80 int64_t QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes;
81
82 const int QuotaManager::kEvictionIntervalInMilliSeconds = 72 const int QuotaManager::kEvictionIntervalInMilliSeconds =
83 30 * kMinutesInMilliSeconds; 73 30 * kMinutesInMilliSeconds;
84 74
85 const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] = 75 const char QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram[] =
86 "Quota.TimeBetweenRepeatedOriginEvictions"; 76 "Quota.TimeBetweenRepeatedOriginEvictions";
87 const char QuotaManager::kEvictedOriginAccessedCountHistogram[] = 77 const char QuotaManager::kEvictedOriginAccessedCountHistogram[] =
88 "Quota.EvictedOriginAccessCount"; 78 "Quota.EvictedOriginAccessCount";
89 const char QuotaManager::kEvictedOriginTimeSinceAccessHistogram[] = 79 const char QuotaManager::kEvictedOriginTimeSinceAccessHistogram[] =
90 "Quota.EvictedOriginTimeSinceAccess"; 80 "Quota.EvictedOriginTimeSinceAccess";
91 81
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 217 }
228 218
229 bool UpdateModifiedTimeOnDBThread(const GURL& origin, 219 bool UpdateModifiedTimeOnDBThread(const GURL& origin,
230 StorageType type, 220 StorageType type,
231 base::Time modified_time, 221 base::Time modified_time,
232 QuotaDatabase* database) { 222 QuotaDatabase* database) {
233 DCHECK(database); 223 DCHECK(database);
234 return database->SetOriginLastModifiedTime(origin, type, modified_time); 224 return database->SetOriginLastModifiedTime(origin, type, modified_time);
235 } 225 }
236 226
237 int64_t CalculateTemporaryGlobalQuota(int64_t global_limited_usage, 227 // TODO: cleanup??
238 int64_t available_space) {
239 DCHECK_GE(global_limited_usage, 0);
240 int64_t avail_space = available_space;
241 if (avail_space <
242 std::numeric_limits<int64_t>::max() - global_limited_usage) {
243 // We basically calculate the temporary quota by
244 // [available_space + space_used_for_temp] * kTempQuotaRatio,
245 // but make sure we'll have no overflow.
246 avail_space += global_limited_usage;
247 }
248 int64_t pool_size = avail_space * kTemporaryQuotaRatioToAvail;
249 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size);
250 return pool_size;
251 }
252
253 void DispatchTemporaryGlobalQuotaCallback(
254 const QuotaCallback& callback,
255 QuotaStatusCode status,
256 const UsageAndQuota& usage_and_quota) {
257 if (status != kQuotaStatusOk) {
258 callback.Run(status, 0);
259 return;
260 }
261
262 callback.Run(status, CalculateTemporaryGlobalQuota(
263 usage_and_quota.global_limited_usage,
264 usage_and_quota.available_disk_space));
265 }
266
267 int64_t CalculateQuotaWithDiskSpace(int64_t available_disk_space,
268 int64_t usage,
269 int64_t quota) {
270 if (available_disk_space < QuotaManager::kMinimumPreserveForSystem) {
271 LOG(WARNING)
272 << "Running out of disk space for profile."
273 << " QuotaManager starts forbidding further quota consumption.";
274 return usage;
275 }
276
277 if (quota < usage) {
278 // No more space; cap the quota to the current usage.
279 return usage;
280 }
281
282 available_disk_space -= QuotaManager::kMinimumPreserveForSystem;
283 if (available_disk_space < quota - usage)
284 return available_disk_space + usage;
285
286 return quota;
287 }
288
289 int64_t CalculateTemporaryHostQuota(int64_t host_usage,
290 int64_t global_quota,
291 int64_t global_limited_usage) {
292 DCHECK_GE(global_limited_usage, 0);
293 int64_t host_quota = global_quota / QuotaManager::kPerHostTemporaryPortion;
294 if (global_limited_usage > global_quota)
295 host_quota = std::min(host_quota, host_usage);
296 return host_quota;
297 }
298
299 void DispatchUsageAndQuotaForWebApps( 228 void DispatchUsageAndQuotaForWebApps(
300 StorageType type, 229 StorageType type,
301 bool is_incognito, 230 bool is_incognito,
302 bool is_unlimited, 231 bool is_unlimited,
303 bool can_query_disk_size, 232 int64_t cached_usage_for_incognito,
304 const QuotaManager::GetUsageAndQuotaCallback& callback, 233 const QuotaManager::GetUsageAndQuotaCallback& callback,
305 QuotaStatusCode status, 234 QuotaStatusCode status,
306 const UsageAndQuota& usage_and_quota) { 235 const XUsageAndQuota& usage_and_quota) {
236 DCHECK(type == kStorageTypeTemporary || type == kStorageTypePersistent ||
237 type == kStorageTypeSyncable);
307 if (status != kQuotaStatusOk) { 238 if (status != kQuotaStatusOk) {
308 callback.Run(status, 0, 0); 239 callback.Run(status, 0, 0);
309 return; 240 return;
310 } 241 }
311 242
312 int64_t usage = usage_and_quota.usage; 243 //int64_t available = usage_and_quota.available_disk_space;
313 int64_t quota = usage_and_quota.quota; 244 if (is_incognito) {
314 245 //int64_t incognito_space_avalable = pool_size -
315 if (type == kStorageTypeTemporary && !is_unlimited) { 246 // cached_usage_for_incognito;
316 quota = CalculateTemporaryHostQuota( 247 //available = std::max(INT64_C(0), incognito_space_avalable);
317 usage, quota, usage_and_quota.global_limited_usage);
318 } 248 }
319 249
320 if (is_incognito) { 250 // For persistent and syncable, usage_and_quota.quota contains a
321 quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit); 251 // per-host value. For the temporary type, usage_and_quota.quota
322 callback.Run(status, usage, quota); 252 // contains the shared poolsize. Hoever, if the origin is unlimited,
323 return; 253 // it will contain kNoLimit which is INT64_MAX.
324 } 254 int64_t desired_host_quota = usage_and_quota.quota;
255 if (type == kStorageTypeTemporary)
256 desired_host_quota /= QuotaManager::kPerHostTemporaryPortion;
325 257
326 // For apps with unlimited permission or can_query_disk_size is true (and not 258 int min_preserve = !is_unlimited && (type == kStorageTypeTemporary) ?
327 // in incognito mode). 259 desired_host_quota : QuotaManager::kMinimumPreserveForSystem;
328 // We assume we can expose the actual disk size for them and cap the quota by
329 // the available disk space.
330 if (is_unlimited || can_query_disk_size) {
331 quota = CalculateQuotaWithDiskSpace(
332 usage_and_quota.available_disk_space,
333 usage, quota);
334 }
335 260
336 callback.Run(status, usage, quota); 261 // Constrain the desired |host_quota| to something that fits.
262 // If available space is too low, cap usage at current levels.
263 // If it's close to being too low, cap growth to avoid it getting too low.
264 // We define "too low" as not enough room for another hosts
265 // nominal desired amount of data.
266 // Note: for incognito, available space is a number based on
267 // system memory.
268 int64_t host_quota = std::min(
269 desired_host_quota,
270 usage_and_quota.usage +
271 std::max(INT64_C(0),
272 usage_and_quota.available_disk_space - min_preserve));
337 273
338 if (type == kStorageTypeTemporary && !is_unlimited) 274 callback.Run(status, usage_and_quota.usage, host_quota);
339 UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", quota); 275 if (type == kStorageTypeTemporary && !is_incognito && !is_unlimited)
276 UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", host_quota);
340 } 277 }
341 278
342 } // namespace 279 } // namespace
343 280
344 UsageAndQuota::UsageAndQuota() 281 XUsageAndQuota::XUsageAndQuota()
345 : usage(0), 282 : usage(0),
346 global_limited_usage(0), 283 global_limited_usage(0),
347 quota(0), 284 quota(0),
348 available_disk_space(0) { 285 available_disk_space(0) {
349 } 286 }
350 287
351 UsageAndQuota::UsageAndQuota(int64_t usage, 288 XUsageAndQuota::XUsageAndQuota(int64_t usage,
352 int64_t global_limited_usage, 289 int64_t global_limited_usage,
353 int64_t quota, 290 int64_t quota,
354 int64_t available_disk_space) 291 int64_t available_disk_space)
355 : usage(usage), 292 : usage(usage),
356 global_limited_usage(global_limited_usage), 293 global_limited_usage(global_limited_usage),
357 quota(quota), 294 quota(quota),
358 available_disk_space(available_disk_space) {} 295 available_disk_space(available_disk_space) {}
359 296
297 // TODO: cleanup???
360 class UsageAndQuotaCallbackDispatcher 298 class UsageAndQuotaCallbackDispatcher
361 : public QuotaTask, 299 : public QuotaTask,
362 public base::SupportsWeakPtr<UsageAndQuotaCallbackDispatcher> { 300 public base::SupportsWeakPtr<UsageAndQuotaCallbackDispatcher> {
363 public: 301 public:
364 explicit UsageAndQuotaCallbackDispatcher(QuotaManager* manager) 302 explicit UsageAndQuotaCallbackDispatcher(QuotaManager* manager)
365 : QuotaTask(manager), 303 : QuotaTask(manager),
366 has_usage_(false), 304 has_usage_(false),
367 has_global_limited_usage_(false), 305 has_global_limited_usage_(false),
368 has_quota_(false), 306 has_quota_(false),
369 has_available_disk_space_(false), 307 has_available_disk_space_(false),
370 status_(kQuotaStatusUnknown), 308 status_(kQuotaStatusUnknown),
371 usage_and_quota_(-1, -1, -1, -1), 309 usage_and_quota_(-1, -1, -1, -1),
372 waiting_callbacks_(1) {} 310 waiting_callbacks_(1) {}
373 311
374 ~UsageAndQuotaCallbackDispatcher() override {} 312 ~UsageAndQuotaCallbackDispatcher() override {}
375 313
376 void WaitForResults(const QuotaManager::UsageAndQuotaCallback& callback) { 314 void WaitForResults(const QuotaManager::XUsageAndQuotaCallback& callback) {
377 callback_ = callback; 315 callback_ = callback;
378 Start(); 316 Start();
379 } 317 }
380 318
381 void set_usage(int64_t usage) { 319 void set_usage(int64_t usage) {
382 usage_and_quota_.usage = usage; 320 usage_and_quota_.usage = usage;
383 has_usage_ = true; 321 has_usage_ = true;
384 } 322 }
385 323
386 void set_global_limited_usage(int64_t global_limited_usage) { 324 void set_global_limited_usage(int64_t global_limited_usage) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 AsWeakPtr()); 358 AsWeakPtr());
421 } 359 }
422 360
423 QuotaCallback GetAvailableSpaceCallback() { 361 QuotaCallback GetAvailableSpaceCallback() {
424 ++waiting_callbacks_; 362 ++waiting_callbacks_;
425 has_available_disk_space_ = true; 363 has_available_disk_space_ = true;
426 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace, 364 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace,
427 AsWeakPtr()); 365 AsWeakPtr());
428 } 366 }
429 367
368 TemporaryStorageConfigurationCallback GetTempStorageConfigCallback() {
369 ++waiting_callbacks_;
370 return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetTempStorageConfig,
371 AsWeakPtr());
372 }
373
430 private: 374 private:
431 void DidGetHostUsage(int64_t usage) { 375 void DidGetHostUsage(int64_t usage) {
432 if (status_ == kQuotaStatusUnknown) 376 if (status_ == kQuotaStatusUnknown)
433 status_ = kQuotaStatusOk; 377 status_ = kQuotaStatusOk;
434 usage_and_quota_.usage = usage; 378 usage_and_quota_.usage = usage;
435 CheckCompleted(); 379 CheckCompleted();
436 } 380 }
437 381
438 void DidGetGlobalLimitedUsage(int64_t limited_usage) { 382 void DidGetGlobalLimitedUsage(int64_t limited_usage) {
439 if (status_ == kQuotaStatusUnknown) 383 if (status_ == kQuotaStatusUnknown)
(...skipping 14 matching lines...) Expand all
454 TRACE_EVENT0( 398 TRACE_EVENT0(
455 "io", "UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace"); 399 "io", "UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace");
456 400
457 DCHECK_GE(space, 0); 401 DCHECK_GE(space, 0);
458 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) 402 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk)
459 status_ = status; 403 status_ = status;
460 usage_and_quota_.available_disk_space = space; 404 usage_and_quota_.available_disk_space = space;
461 CheckCompleted(); 405 CheckCompleted();
462 } 406 }
463 407
408 void DidGetTempStorageConfig(const TemporaryStorageConfiguration& config) {
409 storage_config_ = config;
410 CheckCompleted();
411 }
412
464 void Run() override { 413 void Run() override {
465 // We initialize waiting_callbacks to 1 so that we won't run 414 // We initialize waiting_callbacks to 1 so that we won't run
466 // the completion callback until here even some of the callbacks 415 // the completion callback until here even some of the callbacks
467 // are dispatched synchronously. 416 // are dispatched synchronously.
468 CheckCompleted(); 417 CheckCompleted();
469 } 418 }
470 419
471 void Aborted() override { 420 void Aborted() override {
472 callback_.Run(kQuotaErrorAbort, UsageAndQuota()); 421 callback_.Run(kQuotaErrorAbort, XUsageAndQuota());
473 DeleteSoon(); 422 DeleteSoon();
474 } 423 }
475 424
476 void Completed() override { 425 void Completed() override {
477 // crbug.com/349708 426 // crbug.com/349708
478 TRACE_EVENT0("io", "UsageAndQuotaCallbackDispatcher::Completed"); 427 TRACE_EVENT0("io", "UsageAndQuotaCallbackDispatcher::Completed");
479 428
480 DCHECK(!has_usage_ || usage_and_quota_.usage >= 0); 429 DCHECK(!has_usage_ || usage_and_quota_.usage >= 0);
481 DCHECK(!has_global_limited_usage_ || 430 DCHECK(!has_global_limited_usage_ ||
482 usage_and_quota_.global_limited_usage >= 0); 431 usage_and_quota_.global_limited_usage >= 0);
(...skipping 10 matching lines...) Expand all
493 CallCompleted(); 442 CallCompleted();
494 } 443 }
495 444
496 // For sanity checks, they're checked only when DCHECK is on. 445 // For sanity checks, they're checked only when DCHECK is on.
497 bool has_usage_; 446 bool has_usage_;
498 bool has_global_limited_usage_; 447 bool has_global_limited_usage_;
499 bool has_quota_; 448 bool has_quota_;
500 bool has_available_disk_space_; 449 bool has_available_disk_space_;
501 450
502 QuotaStatusCode status_; 451 QuotaStatusCode status_;
503 UsageAndQuota usage_and_quota_; 452 XUsageAndQuota usage_and_quota_;
504 QuotaManager::UsageAndQuotaCallback callback_; 453 TemporaryStorageConfiguration storage_config_;
454 QuotaManager::XUsageAndQuotaCallback callback_;
505 int waiting_callbacks_; 455 int waiting_callbacks_;
506 456
507 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaCallbackDispatcher); 457 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaCallbackDispatcher);
508 }; 458 };
509 459
510 class QuotaManager::GetUsageInfoTask : public QuotaTask { 460 class QuotaManager::GetUsageInfoTask : public QuotaTask {
511 public: 461 public:
512 GetUsageInfoTask( 462 GetUsageInfoTask(
513 QuotaManager* manager, 463 QuotaManager* manager,
514 const GetUsageInfoCallback& callback) 464 const GetUsageInfoCallback& callback)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 OriginInfoTableEntries entries_; 809 OriginInfoTableEntries entries_;
860 }; 810 };
861 811
862 // QuotaManager --------------------------------------------------------------- 812 // QuotaManager ---------------------------------------------------------------
863 813
864 QuotaManager::QuotaManager( 814 QuotaManager::QuotaManager(
865 bool is_incognito, 815 bool is_incognito,
866 const base::FilePath& profile_path, 816 const base::FilePath& profile_path,
867 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, 817 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
868 const scoped_refptr<base::SequencedTaskRunner>& db_thread, 818 const scoped_refptr<base::SequencedTaskRunner>& db_thread,
869 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy) 819 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy,
820 GetTemporaryStorageConfigurationFunc get_config_function)
870 : is_incognito_(is_incognito), 821 : is_incognito_(is_incognito),
871 profile_path_(profile_path), 822 profile_path_(profile_path),
872 proxy_(new QuotaManagerProxy(this, io_thread)), 823 proxy_(new QuotaManagerProxy(this, io_thread)),
873 db_disabled_(false), 824 db_disabled_(false),
874 eviction_disabled_(false), 825 eviction_disabled_(false),
826 get_config_function_(get_config_function),
827 get_config_task_runner_(base::ThreadTaskRunnerHandle::Get()),
875 io_thread_(io_thread), 828 io_thread_(io_thread),
876 db_thread_(db_thread), 829 db_thread_(db_thread),
877 is_getting_eviction_origin_(false), 830 is_getting_eviction_origin_(false),
878 temporary_quota_initialized_(false),
879 temporary_quota_override_(-1),
880 special_storage_policy_(special_storage_policy), 831 special_storage_policy_(special_storage_policy),
881 get_volume_info_fn_(&QuotaManager::GetVolumeInfo), 832 get_volume_info_fn_(&QuotaManager::GetVolumeInfo),
882 storage_monitor_(new StorageMonitor(this)), 833 storage_monitor_(new StorageMonitor(this)),
883 weak_factory_(this) {} 834 weak_factory_(this) {
835 // Reset to ensure we refresh the config the first times it's accessed.
836 storage_config_.refresh_interval = base::TimeDelta();
837 }
838
839 void QuotaManager::SetTemporaryStorageConfiguration(
840 const TemporaryStorageConfiguration& config) {
841 storage_config_ = config;
842 storage_config_timestamp_ = base::TimeTicks::Now();
843 }
884 844
885 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 845 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
886 LazyInitialize(); 846 LazyInitialize();
887 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 847 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
888 get_usage_info->Start(); 848 get_usage_info->Start();
889 } 849 }
890 850
891 void QuotaManager::GetUsageAndQuotaForWebApps( 851 void QuotaManager::GetUsageAndQuotaForWebApps(
892 const GURL& origin, 852 const GURL& origin,
893 StorageType type, 853 StorageType type,
894 const GetUsageAndQuotaCallback& callback) { 854 const GetUsageAndQuotaCallback& callback) {
895 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 855 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
896 tracked_objects::ScopedTracker tracking_profile( 856 tracked_objects::ScopedTracker tracking_profile(
897 FROM_HERE_WITH_EXPLICIT_FUNCTION( 857 FROM_HERE_WITH_EXPLICIT_FUNCTION(
898 "477117 QuotaManager::GetUsageAndQuotaForWebApps")); 858 "477117 QuotaManager::GetUsageAndQuotaForWebApps"));
899 if (type != kStorageTypeTemporary && 859 if (type != kStorageTypeTemporary &&
900 type != kStorageTypePersistent && 860 type != kStorageTypePersistent &&
901 type != kStorageTypeSyncable) { 861 type != kStorageTypeSyncable) {
902 callback.Run(kQuotaErrorNotSupported, 0, 0); 862 callback.Run(kQuotaErrorNotSupported, 0, 0);
903 return; 863 return;
904 } 864 }
865 if (is_incognito_ && type != kStorageTypeTemporary) {
866 callback.Run(kQuotaErrorNotSupported, 0, 0);
867 return;
868 }
905 869
906 DCHECK(origin == origin.GetOrigin()); 870 DCHECK(origin == origin.GetOrigin());
907 LazyInitialize(); 871 LazyInitialize();
908 872
909 bool unlimited = IsStorageUnlimited(origin, type); 873 bool is_unlimited = IsStorageUnlimited(origin, type);
910 bool can_query_disk_size = CanQueryDiskSize(origin);
911 874
912 UsageAndQuotaCallbackDispatcher* dispatcher = 875 UsageAndQuotaCallbackDispatcher* dispatcher =
913 new UsageAndQuotaCallbackDispatcher(this); 876 new UsageAndQuotaCallbackDispatcher(this);
914 877
915 if (unlimited) { 878 if (is_unlimited) {
916 dispatcher->set_quota(kNoLimit); 879 dispatcher->set_quota(kNoLimit);
917 } else { 880 } else {
918 if (type == kStorageTypeTemporary) { 881 if (type == kStorageTypeTemporary) {
919 GetUsageTracker(type)->GetGlobalLimitedUsage(
920 dispatcher->GetGlobalLimitedUsageCallback());
921 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); 882 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback());
922 } else if (type == kStorageTypePersistent) { 883 } else if (type == kStorageTypePersistent) {
923 GetPersistentHostQuota(net::GetHostOrSpecFromURL(origin), 884 GetPersistentHostQuota(net::GetHostOrSpecFromURL(origin),
924 dispatcher->GetQuotaCallback()); 885 dispatcher->GetQuotaCallback());
925 } else { 886 } else {
926 dispatcher->set_quota(kSyncableStorageDefaultHostQuota); 887 dispatcher->set_quota(kSyncableStorageDefaultHostQuota);
927 } 888 }
928 } 889 }
929 890
930 DCHECK(GetUsageTracker(type));
931 GetUsageTracker(type)->GetHostUsage(net::GetHostOrSpecFromURL(origin), 891 GetUsageTracker(type)->GetHostUsage(net::GetHostOrSpecFromURL(origin),
932 dispatcher->GetHostUsageCallback()); 892 dispatcher->GetHostUsageCallback());
933 893
934 if (!is_incognito_ && (unlimited || can_query_disk_size)) 894 int64_t cached_usage_for_incognito = 0;
935 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); 895 if (!is_incognito_) {
896 xGetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
897 } else {
898 cached_usage_for_incognito = GetUsageTracker(type)->GetCachedUsage();
899 }
936 900
937 dispatcher->WaitForResults(base::Bind( 901 dispatcher->WaitForResults(base::Bind(
938 &DispatchUsageAndQuotaForWebApps, 902 &DispatchUsageAndQuotaForWebApps,
939 type, is_incognito_, unlimited, can_query_disk_size, 903 type, is_incognito_, is_unlimited,
940 callback)); 904 cached_usage_for_incognito, callback));
941 } 905 }
942 906
943 void QuotaManager::GetUsageAndQuota( 907 void QuotaManager::GetUsageAndQuota(
944 const GURL& origin, StorageType type, 908 const GURL& origin, StorageType type,
945 const GetUsageAndQuotaCallback& callback) { 909 const GetUsageAndQuotaCallback& callback) {
946 DCHECK(origin == origin.GetOrigin()); 910 DCHECK(origin == origin.GetOrigin());
947 911
948 if (IsStorageUnlimited(origin, type)) { 912 if (IsStorageUnlimited(origin, type)) {
949 callback.Run(kQuotaStatusOk, 0, kNoLimit); 913 callback.Run(kQuotaStatusOk, 0, kNoLimit);
950 return; 914 return;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 if (host.empty() || clients_.empty()) { 976 if (host.empty() || clients_.empty()) {
1013 callback.Run(kQuotaStatusOk); 977 callback.Run(kQuotaStatusOk);
1014 return; 978 return;
1015 } 979 }
1016 980
1017 HostDataDeleter* deleter = 981 HostDataDeleter* deleter =
1018 new HostDataDeleter(this, host, type, quota_client_mask, callback); 982 new HostDataDeleter(this, host, type, quota_client_mask, callback);
1019 deleter->Start(); 983 deleter->Start();
1020 } 984 }
1021 985
1022 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { 986 void QuotaManager::xGetAvailableSpace(const AvailableSpaceCallback& callback) {
1023 if (!available_space_callbacks_.Add(callback)) 987 if (!available_space_callbacks_.Add(callback))
1024 return; 988 return;
1025 // crbug.com/349708 989 // crbug.com/349708
1026 TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace"); 990 TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace");
1027 991
1028 PostTaskAndReplyWithResult( 992 // TODO: if (incognito) return poolsize - globalusage;
993 base::PostTaskAndReplyWithResult(
1029 db_thread_.get(), 994 db_thread_.get(),
1030 FROM_HERE, 995 FROM_HERE,
1031 base::Bind(&QuotaManager::CallGetAmountOfFreeDiskSpace, 996 base::Bind(&QuotaManager::CallGetAmountOfFreeDiskSpace,
1032 get_volume_info_fn_, profile_path_), 997 get_volume_info_fn_, profile_path_),
1033 base::Bind(&QuotaManager::DidGetAvailableSpace, 998 base::Bind(&QuotaManager::DidGetAvailableSpace,
1034 weak_factory_.GetWeakPtr())); 999 weak_factory_.GetWeakPtr()));
1035 } 1000 }
1036 1001
1002 namespace {
1003 void ContinueGetTemporaryQuota(
1004 const QuotaCallback& callback,
1005 const TemporaryStorageConfiguration& pool_config) {
1006 callback.Run(kQuotaStatusOk, pool_config.pool_size);
1007 }
1008 }
1009
1037 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { 1010 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) {
1038 LazyInitialize(); 1011 LazyInitialize();
1039 if (!temporary_quota_initialized_) { 1012 GetTemporaryStorageConfig(
1040 db_initialization_callbacks_.Add(base::Bind( 1013 base::Bind(&ContinueGetTemporaryQuota, callback));
1041 &QuotaManager::GetTemporaryGlobalQuota,
1042 weak_factory_.GetWeakPtr(), callback));
1043 return;
1044 }
1045
1046 if (temporary_quota_override_ > 0) {
1047 callback.Run(kQuotaStatusOk, temporary_quota_override_);
1048 return;
1049 }
1050
1051 UsageAndQuotaCallbackDispatcher* dispatcher =
1052 new UsageAndQuotaCallbackDispatcher(this);
1053 GetUsageTracker(kStorageTypeTemporary)->
1054 GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
1055 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
1056 dispatcher->WaitForResults(
1057 base::Bind(&DispatchTemporaryGlobalQuotaCallback, callback));
1058 }
1059
1060 void QuotaManager::SetTemporaryGlobalOverrideQuota(
1061 int64_t new_quota,
1062 const QuotaCallback& callback) {
1063 LazyInitialize();
1064
1065 if (new_quota < 0) {
1066 if (!callback.is_null())
1067 callback.Run(kQuotaErrorInvalidModification, -1);
1068 return;
1069 }
1070
1071 if (db_disabled_) {
1072 if (!callback.is_null())
1073 callback.Run(kQuotaErrorInvalidAccess, -1);
1074 return;
1075 }
1076
1077 int64_t* new_quota_ptr = new int64_t(new_quota);
1078 PostTaskAndReplyWithResultForDBThread(
1079 FROM_HERE,
1080 base::Bind(&SetTemporaryGlobalOverrideQuotaOnDBThread,
1081 base::Unretained(new_quota_ptr)),
1082 base::Bind(&QuotaManager::DidSetTemporaryGlobalOverrideQuota,
1083 weak_factory_.GetWeakPtr(),
1084 callback,
1085 base::Owned(new_quota_ptr)));
1086 } 1014 }
1087 1015
1088 void QuotaManager::GetPersistentHostQuota(const std::string& host, 1016 void QuotaManager::GetPersistentHostQuota(const std::string& host,
1089 const QuotaCallback& callback) { 1017 const QuotaCallback& callback) {
1090 LazyInitialize(); 1018 LazyInitialize();
1091 if (host.empty()) { 1019 if (host.empty()) {
1092 // This could happen if we are called on file:///. 1020 // This could happen if we are called on file:///.
1093 // TODO(kinuko) We may want to respect --allow-file-access-from-files 1021 // TODO(kinuko) We may want to respect --allow-file-access-from-files
1094 // command line switch. 1022 // command line switch.
1095 callback.Run(kQuotaStatusOk, 0); 1023 callback.Run(kQuotaStatusOk, 0);
(...skipping 23 matching lines...) Expand all
1119 // This could happen if we are called on file:///. 1047 // This could happen if we are called on file:///.
1120 callback.Run(kQuotaErrorNotSupported, 0); 1048 callback.Run(kQuotaErrorNotSupported, 0);
1121 return; 1049 return;
1122 } 1050 }
1123 1051
1124 if (new_quota < 0) { 1052 if (new_quota < 0) {
1125 callback.Run(kQuotaErrorInvalidModification, -1); 1053 callback.Run(kQuotaErrorInvalidModification, -1);
1126 return; 1054 return;
1127 } 1055 }
1128 1056
1129 if (kPerHostPersistentQuotaLimit < new_quota) { 1057 // Cap the requested size at the per-host quota limit.
1130 // Cap the requested size at the per-host quota limit. 1058 new_quota = std::min(new_quota, kPerHostPersistentQuotaLimit);
1131 new_quota = kPerHostPersistentQuotaLimit;
1132 }
1133 1059
1134 if (db_disabled_) { 1060 if (db_disabled_) {
1135 callback.Run(kQuotaErrorInvalidAccess, -1); 1061 callback.Run(kQuotaErrorInvalidAccess, -1);
1136 return; 1062 return;
1137 } 1063 }
1138 1064
1139 int64_t* new_quota_ptr = new int64_t(new_quota); 1065 int64_t* new_quota_ptr = new int64_t(new_quota);
1140 PostTaskAndReplyWithResultForDBThread( 1066 PostTaskAndReplyWithResultForDBThread(
1141 FROM_HERE, 1067 FROM_HERE,
1142 base::Bind(&SetPersistentHostQuotaOnDBThread, 1068 base::Bind(&SetPersistentHostQuotaOnDBThread,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 QuotaManager::EvictionContext::EvictionContext() 1208 QuotaManager::EvictionContext::EvictionContext()
1283 : evicted_type(kStorageTypeUnknown) { 1209 : evicted_type(kStorageTypeUnknown) {
1284 } 1210 }
1285 1211
1286 QuotaManager::EvictionContext::~EvictionContext() { 1212 QuotaManager::EvictionContext::~EvictionContext() {
1287 } 1213 }
1288 1214
1289 void QuotaManager::LazyInitialize() { 1215 void QuotaManager::LazyInitialize() {
1290 DCHECK(io_thread_->BelongsToCurrentThread()); 1216 DCHECK(io_thread_->BelongsToCurrentThread());
1291 if (database_) { 1217 if (database_) {
1292 // Initialization seems to be done already. 1218 // Already initialized.
1293 return; 1219 return;
1294 } 1220 }
1295 1221
1296 // Use an empty path to open an in-memory only databse for incognito. 1222 // Use an empty path to open an in-memory only databse for incognito.
1297 database_.reset(new QuotaDatabase(is_incognito_ ? base::FilePath() : 1223 database_.reset(new QuotaDatabase(is_incognito_ ? base::FilePath() :
1298 profile_path_.AppendASCII(kDatabaseName))); 1224 profile_path_.AppendASCII(kDatabaseName)));
1299 1225
1300 temporary_usage_tracker_.reset(new UsageTracker( 1226 temporary_usage_tracker_.reset(new UsageTracker(
1301 clients_, kStorageTypeTemporary, special_storage_policy_.get(), 1227 clients_, kStorageTypeTemporary, special_storage_policy_.get(),
1302 storage_monitor_.get())); 1228 storage_monitor_.get()));
1303 persistent_usage_tracker_.reset(new UsageTracker( 1229 persistent_usage_tracker_.reset(new UsageTracker(
1304 clients_, kStorageTypePersistent, special_storage_policy_.get(), 1230 clients_, kStorageTypePersistent, special_storage_policy_.get(),
1305 storage_monitor_.get())); 1231 storage_monitor_.get()));
1306 syncable_usage_tracker_.reset(new UsageTracker( 1232 syncable_usage_tracker_.reset(new UsageTracker(
1307 clients_, kStorageTypeSyncable, special_storage_policy_.get(), 1233 clients_, kStorageTypeSyncable, special_storage_policy_.get(),
1308 storage_monitor_.get())); 1234 storage_monitor_.get()));
1309 1235
1310 int64_t* temporary_quota_override = new int64_t(-1); 1236 if (!is_incognito_) {
1311 int64_t* desired_available_space = new int64_t(-1); 1237 histogram_timer_.Start(FROM_HERE,
1312 PostTaskAndReplyWithResultForDBThread( 1238 base::TimeDelta::FromMilliseconds(
1313 FROM_HERE, 1239 kReportHistogramInterval),
1314 base::Bind(&InitializeOnDBThread, 1240 this, &QuotaManager::ReportHistogram);
1315 base::Unretained(temporary_quota_override), 1241 }
1316 base::Unretained(desired_available_space)), 1242
1317 base::Bind(&QuotaManager::DidInitialize, 1243 GetTemporaryGlobalQuota(
1318 weak_factory_.GetWeakPtr(), 1244 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
1319 base::Owned(temporary_quota_override), 1245 weak_factory_.GetWeakPtr(), base::TimeTicks::Now()));
1320 base::Owned(desired_available_space)));
1321 } 1246 }
1322 1247
1323 void QuotaManager::RegisterClient(QuotaClient* client) { 1248 void QuotaManager::RegisterClient(QuotaClient* client) {
1324 DCHECK(!database_.get()); 1249 DCHECK(!database_.get());
1325 clients_.push_back(client); 1250 clients_.push_back(client);
1326 } 1251 }
1327 1252
1328 UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const { 1253 UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const {
1329 switch (type) { 1254 switch (type) {
1330 case kStorageTypeTemporary: 1255 case kStorageTypeTemporary:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 base::Bind(&DumpOriginInfoTableHelper::DidDumpOriginInfoTable, 1332 base::Bind(&DumpOriginInfoTableHelper::DidDumpOriginInfoTable,
1408 base::Owned(helper), 1333 base::Owned(helper),
1409 weak_factory_.GetWeakPtr(), 1334 weak_factory_.GetWeakPtr(),
1410 callback)); 1335 callback));
1411 } 1336 }
1412 1337
1413 void QuotaManager::StartEviction() { 1338 void QuotaManager::StartEviction() {
1414 DCHECK(!temporary_storage_evictor_.get()); 1339 DCHECK(!temporary_storage_evictor_.get());
1415 temporary_storage_evictor_.reset(new QuotaTemporaryStorageEvictor( 1340 temporary_storage_evictor_.reset(new QuotaTemporaryStorageEvictor(
1416 this, kEvictionIntervalInMilliSeconds)); 1341 this, kEvictionIntervalInMilliSeconds));
1417 if (desired_available_space_ >= 0)
1418 temporary_storage_evictor_->set_min_available_disk_space_to_start_eviction(
1419 desired_available_space_);
1420 temporary_storage_evictor_->Start(); 1342 temporary_storage_evictor_->Start();
1421 } 1343 }
1422 1344
1423 void QuotaManager::DeleteOriginFromDatabase(const GURL& origin, 1345 void QuotaManager::DeleteOriginFromDatabase(const GURL& origin,
1424 StorageType type, 1346 StorageType type,
1425 bool is_eviction) { 1347 bool is_eviction) {
1426 LazyInitialize(); 1348 LazyInitialize();
1427 if (db_disabled_) 1349 if (db_disabled_)
1428 return; 1350 return;
1429 1351
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 eviction_context_.evicted_origin = origin; 1550 eviction_context_.evicted_origin = origin;
1629 eviction_context_.evicted_type = type; 1551 eviction_context_.evicted_type = type;
1630 eviction_context_.evict_origin_data_callback = callback; 1552 eviction_context_.evict_origin_data_callback = callback;
1631 1553
1632 DeleteOriginDataInternal(origin, type, QuotaClient::kAllClientsMask, true, 1554 DeleteOriginDataInternal(origin, type, QuotaClient::kAllClientsMask, true,
1633 base::Bind(&QuotaManager::DidOriginDataEvicted, 1555 base::Bind(&QuotaManager::DidOriginDataEvicted,
1634 weak_factory_.GetWeakPtr())); 1556 weak_factory_.GetWeakPtr()));
1635 } 1557 }
1636 1558
1637 void QuotaManager::GetUsageAndQuotaForEviction( 1559 void QuotaManager::GetUsageAndQuotaForEviction(
1638 const UsageAndQuotaCallback& callback) { 1560 const XUsageAndQuotaCallback& callback) {
1639 // crbug.com/349708 1561 // crbug.com/349708
1640 TRACE_EVENT0("io", "QuotaManager::GetUsageAndQuotaForEviction"); 1562 TRACE_EVENT0("io", "QuotaManager::GetUsageAndQuotaForEviction");
1641 1563
1642 DCHECK(io_thread_->BelongsToCurrentThread()); 1564 DCHECK(io_thread_->BelongsToCurrentThread());
1643 LazyInitialize(); 1565 LazyInitialize();
1644 1566
1645 UsageAndQuotaCallbackDispatcher* dispatcher = 1567 UsageAndQuotaCallbackDispatcher* dispatcher =
1646 new UsageAndQuotaCallbackDispatcher(this); 1568 new UsageAndQuotaCallbackDispatcher(this);
1647 GetUsageTracker(kStorageTypeTemporary) 1569 GetUsageTracker(kStorageTypeTemporary)
1648 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); 1570 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
1649 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); 1571 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback());
1650 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); 1572 xGetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
1651 dispatcher->WaitForResults(callback); 1573 dispatcher->WaitForResults(callback);
1652 } 1574 }
1653 1575
1654 void QuotaManager::AsyncGetVolumeInfo( 1576 void QuotaManager::AsyncGetVolumeInfo(
1655 const VolumeInfoCallback& callback) { 1577 const VolumeInfoCallback& callback) {
1656 DCHECK(io_thread_->BelongsToCurrentThread()); 1578 DCHECK(io_thread_->BelongsToCurrentThread());
1657 uint64_t* available_space = new uint64_t(0); 1579 uint64_t* available_space = new uint64_t(0);
1658 uint64_t* total_space = new uint64_t(0); 1580 uint64_t* total_space = new uint64_t(0);
1659 PostTaskAndReplyWithResult( 1581 base::PostTaskAndReplyWithResult(
1660 db_thread_.get(), 1582 db_thread_.get(),
1661 FROM_HERE, 1583 FROM_HERE,
1662 base::Bind(get_volume_info_fn_, 1584 base::Bind(get_volume_info_fn_,
1663 profile_path_, 1585 profile_path_,
1664 base::Unretained(available_space), 1586 base::Unretained(available_space),
1665 base::Unretained(total_space)), 1587 base::Unretained(total_space)),
1666 base::Bind(&QuotaManager::DidGetVolumeInfo, 1588 base::Bind(&QuotaManager::DidGetVolumeInfo,
1667 weak_factory_.GetWeakPtr(), 1589 weak_factory_.GetWeakPtr(),
1668 callback, 1590 callback,
1669 base::Owned(available_space), 1591 base::Owned(available_space),
(...skipping 22 matching lines...) Expand all
1692 GURL* url = new GURL; 1614 GURL* url = new GURL;
1693 PostTaskAndReplyWithResultForDBThread( 1615 PostTaskAndReplyWithResultForDBThread(
1694 FROM_HERE, base::Bind(&GetLRUOriginOnDBThread, type, 1616 FROM_HERE, base::Bind(&GetLRUOriginOnDBThread, type,
1695 GetEvictionOriginExceptions(std::set<GURL>()), 1617 GetEvictionOriginExceptions(std::set<GURL>()),
1696 base::RetainedRef(special_storage_policy_), 1618 base::RetainedRef(special_storage_policy_),
1697 base::Unretained(url)), 1619 base::Unretained(url)),
1698 base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(), 1620 base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(),
1699 base::Owned(url))); 1621 base::Owned(url)));
1700 } 1622 }
1701 1623
1702 void QuotaManager::DidSetTemporaryGlobalOverrideQuota(
1703 const QuotaCallback& callback,
1704 const int64_t* new_quota,
1705 bool success) {
1706 QuotaStatusCode status = kQuotaErrorInvalidAccess;
1707 DidDatabaseWork(success);
1708 if (success) {
1709 temporary_quota_override_ = *new_quota;
1710 status = kQuotaStatusOk;
1711 }
1712
1713 if (callback.is_null())
1714 return;
1715
1716 callback.Run(status, *new_quota);
1717 }
1718
1719 void QuotaManager::DidGetPersistentHostQuota(const std::string& host, 1624 void QuotaManager::DidGetPersistentHostQuota(const std::string& host,
1720 const int64_t* quota, 1625 const int64_t* quota,
1721 bool success) { 1626 bool success) {
1722 DidDatabaseWork(success); 1627 DidDatabaseWork(success);
1723 persistent_host_quota_callbacks_.Run(host, kQuotaStatusOk, *quota); 1628 persistent_host_quota_callbacks_.Run(
1629 host, kQuotaStatusOk,
1630 std::min(*quota, kPerHostPersistentQuotaLimit));
1724 } 1631 }
1725 1632
1726 void QuotaManager::DidSetPersistentHostQuota(const std::string& host, 1633 void QuotaManager::DidSetPersistentHostQuota(const std::string& host,
1727 const QuotaCallback& callback, 1634 const QuotaCallback& callback,
1728 const int64_t* new_quota, 1635 const int64_t* new_quota,
1729 bool success) { 1636 bool success) {
1730 DidDatabaseWork(success); 1637 DidDatabaseWork(success);
1731 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota); 1638 callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota);
1732 } 1639 }
1733 1640
1734 void QuotaManager::DidInitialize(int64_t* temporary_quota_override,
1735 int64_t* desired_available_space,
1736 bool success) {
1737 temporary_quota_override_ = *temporary_quota_override;
1738 desired_available_space_ = *desired_available_space;
1739 temporary_quota_initialized_ = true;
1740 DidDatabaseWork(success);
1741
1742 if (!is_incognito_) {
1743 histogram_timer_.Start(FROM_HERE,
1744 base::TimeDelta::FromMilliseconds(
1745 kReportHistogramInterval),
1746 this, &QuotaManager::ReportHistogram);
1747 }
1748
1749 db_initialization_callbacks_.Run();
1750 GetTemporaryGlobalQuota(
1751 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
1752 weak_factory_.GetWeakPtr(), base::TimeTicks::Now()));
1753 }
1754
1755 void QuotaManager::DidGetLRUOrigin(const GURL* origin, 1641 void QuotaManager::DidGetLRUOrigin(const GURL* origin,
1756 bool success) { 1642 bool success) {
1757 DidDatabaseWork(success); 1643 DidDatabaseWork(success);
1758 1644
1759 lru_origin_callback_.Run(*origin); 1645 lru_origin_callback_.Run(*origin);
1760 lru_origin_callback_.Reset(); 1646 lru_origin_callback_.Reset();
1761 } 1647 }
1762 1648
1763 void QuotaManager::DidGetInitialTemporaryGlobalQuota( 1649 void QuotaManager::DidGetInitialTemporaryGlobalQuota(
1764 base::TimeTicks start_ticks, 1650 base::TimeTicks start_ticks,
(...skipping 25 matching lines...) Expand all
1790 } 1676 }
1791 1677
1792 void QuotaManager::DidGetAvailableSpace(int64_t space) { 1678 void QuotaManager::DidGetAvailableSpace(int64_t space) {
1793 // crbug.com/349708 1679 // crbug.com/349708
1794 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace", 1680 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace",
1795 "n_callbacks", available_space_callbacks_.size()); 1681 "n_callbacks", available_space_callbacks_.size());
1796 1682
1797 available_space_callbacks_.Run(kQuotaStatusOk, space); 1683 available_space_callbacks_.Run(kQuotaStatusOk, space);
1798 } 1684 }
1799 1685
1686 namespace {
1687 void DidGetTempStorageConfigThreadAdapter(
1688 base::TaskRunner* task_runner,
1689 const TemporaryStorageConfigurationCallback& callback,
1690 const TemporaryStorageConfiguration& storage_config) {
1691 task_runner->PostTask(FROM_HERE, base::Bind(callback, storage_config));
1692 }
1693 } // namespace
1694
1695 void QuotaManager::GetTemporaryStorageConfig(
1696 const TemporaryStorageConfigurationCallback& callback) {
1697 if (base::TimeTicks::Now() - storage_config_timestamp_ <
1698 storage_config_.refresh_interval) {
1699 callback.Run(storage_config_);
1700 return;
1701 }
1702
1703 if (!storage_config_callbacks_.Add(callback))
1704 return;
1705
1706 // We invoke our clients GetTemporaryPoolConfigurationFunc on the
1707 // UI thread and plumb the resulting value back to this thread.
kinuko 2016/07/27 14:23:25 Could you help me understand why it needs to be ca
1708 get_config_task_runner_->PostTask(
1709 FROM_HERE,
1710 base::Bind(
1711 get_config_function_,
1712 profile_path_, is_incognito_,
1713 base::Bind(
1714 &DidGetTempStorageConfigThreadAdapter,
1715 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()),
1716 base::Bind(
1717 &QuotaManager::DidGetTemporaryStorageConfig,
1718 weak_factory_.GetWeakPtr()))));
1719 }
1720
1721 void QuotaManager::DidGetTemporaryStorageConfig(
1722 const TemporaryStorageConfiguration& config) {
1723 SetTemporaryStorageConfiguration(config);
1724 storage_config_callbacks_.Run(config);
1725 }
1726
1727
1800 void QuotaManager::DidDatabaseWork(bool success) { 1728 void QuotaManager::DidDatabaseWork(bool success) {
1801 db_disabled_ = !success; 1729 db_disabled_ = !success;
1802 } 1730 }
1803 1731
1804 void QuotaManager::DeleteOnCorrectThread() const { 1732 void QuotaManager::DeleteOnCorrectThread() const {
1805 if (!io_thread_->BelongsToCurrentThread() && 1733 if (!io_thread_->BelongsToCurrentThread() &&
1806 io_thread_->DeleteSoon(FROM_HERE, this)) { 1734 io_thread_->DeleteSoon(FROM_HERE, this)) {
1807 return; 1735 return;
1808 } 1736 }
1809 delete this; 1737 delete this;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(path); 1783 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(path);
1856 if (total < 0) 1784 if (total < 0)
1857 return false; 1785 return false;
1858 1786
1859 *available_space = static_cast<uint64_t>(available); 1787 *available_space = static_cast<uint64_t>(available);
1860 *total_size = static_cast<uint64_t>(total); 1788 *total_size = static_cast<uint64_t>(total);
1861 return true; 1789 return true;
1862 } 1790 }
1863 1791
1864 } // namespace storage 1792 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698