| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/browser/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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 500 |
| 501 private: | 501 private: |
| 502 void AddEntries(StorageType type, UsageTracker* tracker) { | 502 void AddEntries(StorageType type, UsageTracker* tracker) { |
| 503 std::map<std::string, int64> host_usage; | 503 std::map<std::string, int64> host_usage; |
| 504 tracker->GetCachedHostsUsage(&host_usage); | 504 tracker->GetCachedHostsUsage(&host_usage); |
| 505 for (std::map<std::string, int64>::const_iterator iter = host_usage.begin(); | 505 for (std::map<std::string, int64>::const_iterator iter = host_usage.begin(); |
| 506 iter != host_usage.end(); | 506 iter != host_usage.end(); |
| 507 ++iter) { | 507 ++iter) { |
| 508 entries_.push_back(UsageInfo(iter->first, type, iter->second)); | 508 entries_.push_back(UsageInfo(iter->first, type, iter->second)); |
| 509 } | 509 } |
| 510 |
| 510 if (--remaining_trackers_ == 0) | 511 if (--remaining_trackers_ == 0) |
| 511 CallCompleted(); | 512 CallCompleted(); |
| 512 } | 513 } |
| 513 | 514 |
| 514 void DidGetGlobalUsage(StorageType type, int64, int64) { | 515 void DidGetGlobalUsage(StorageType type, int64, int64) { |
| 515 DCHECK(manager()->GetUsageTracker(type)); | 516 DCHECK(manager()->GetUsageTracker(type)); |
| 516 AddEntries(type, manager()->GetUsageTracker(type)); | 517 AddEntries(type, manager()->GetUsageTracker(type)); |
| 517 } | 518 } |
| 518 | 519 |
| 519 QuotaManager* manager() const { | 520 QuotaManager* manager() const { |
| 520 return static_cast<QuotaManager*>(observer()); | 521 return static_cast<QuotaManager*>(observer()); |
| 521 } | 522 } |
| 522 | 523 |
| 523 GetUsageInfoCallback callback_; | 524 GetUsageInfoCallback callback_; |
| 524 UsageInfoEntries entries_; | 525 UsageInfoEntries entries_; |
| 525 int remaining_trackers_; | 526 int remaining_trackers_; |
| 526 base::WeakPtrFactory<GetUsageInfoTask> weak_factory_; | 527 base::WeakPtrFactory<GetUsageInfoTask> weak_factory_; |
| 527 | 528 |
| 528 DISALLOW_COPY_AND_ASSIGN(GetUsageInfoTask); | 529 DISALLOW_COPY_AND_ASSIGN(GetUsageInfoTask); |
| 529 }; | 530 }; |
| 530 | 531 |
| 532 class QuotaManager::GetTemporaryEvictionOriginTask : public QuotaTask { |
| 533 public: |
| 534 GetTemporaryEvictionOriginTask( |
| 535 QuotaManager* manager, |
| 536 scoped_refptr<SpecialStoragePolicy> special_storage_policy, |
| 537 QuotaEvictionPolicy* eviction_policy, |
| 538 const GetOriginCallback& callback) |
| 539 : QuotaTask(manager), |
| 540 special_storage_policy_(special_storage_policy), |
| 541 eviction_policy_(eviction_policy), |
| 542 callback_(callback), |
| 543 weak_factory_(this) {} |
| 544 |
| 545 protected: |
| 546 void Run() override { |
| 547 remaining_tasks_ = 2; |
| 548 // This will populate cached hosts and usage info. |
| 549 manager() |
| 550 ->GetUsageTracker(kStorageTypeTemporary) |
| 551 ->GetGlobalUsage( |
| 552 base::Bind(&GetTemporaryEvictionOriginTask::DidGetGlobalUsage, |
| 553 weak_factory_.GetWeakPtr(), kStorageTypeTemporary)); |
| 554 manager()->GetTemporaryGlobalQuota( |
| 555 base::Bind(&GetTemporaryEvictionOriginTask::DidGetTemporaryGlobalQuota, |
| 556 weak_factory_.GetWeakPtr())); |
| 557 } |
| 558 |
| 559 void Completed() override { |
| 560 eviction_policy_->GetEvictionOrigin(special_storage_policy_.get(), |
| 561 usage_map_, global_quota_, callback_); |
| 562 DeleteSoon(); |
| 563 } |
| 564 |
| 565 void Aborted() override { |
| 566 callback_.Run(GURL()); |
| 567 DeleteSoon(); |
| 568 } |
| 569 |
| 570 private: |
| 571 void DidGetGlobalUsage(StorageType type, int64, int64) { |
| 572 DCHECK(manager()->GetUsageTracker(type)); |
| 573 manager()->GetUsageTracker(type)->GetCachedOriginsUsage(&usage_map_); |
| 574 if (--remaining_tasks_ == 0) |
| 575 CallCompleted(); |
| 576 } |
| 577 |
| 578 void DidGetTemporaryGlobalQuota(QuotaStatusCode status, int64 quota) { |
| 579 if (status == kQuotaStatusOk) |
| 580 global_quota_ = quota; |
| 581 |
| 582 if (--remaining_tasks_ == 0) |
| 583 CallCompleted(); |
| 584 } |
| 585 |
| 586 QuotaManager* manager() const { |
| 587 return static_cast<QuotaManager*>(observer()); |
| 588 } |
| 589 |
| 590 int64 global_quota_; |
| 591 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
| 592 QuotaEvictionPolicy* eviction_policy_; |
| 593 GetOriginCallback callback_; |
| 594 std::map<GURL, int64> usage_map_; |
| 595 int remaining_tasks_; |
| 596 base::WeakPtrFactory<GetTemporaryEvictionOriginTask> weak_factory_; |
| 597 |
| 598 DISALLOW_COPY_AND_ASSIGN(GetTemporaryEvictionOriginTask); |
| 599 }; |
| 600 |
| 531 class QuotaManager::OriginDataDeleter : public QuotaTask { | 601 class QuotaManager::OriginDataDeleter : public QuotaTask { |
| 532 public: | 602 public: |
| 533 OriginDataDeleter(QuotaManager* manager, | 603 OriginDataDeleter(QuotaManager* manager, |
| 534 const GURL& origin, | 604 const GURL& origin, |
| 535 StorageType type, | 605 StorageType type, |
| 536 int quota_client_mask, | 606 int quota_client_mask, |
| 537 const StatusCallback& callback) | 607 const StatusCallback& callback) |
| 538 : QuotaTask(manager), | 608 : QuotaTask(manager), |
| 539 origin_(origin), | 609 origin_(origin), |
| 540 type_(type), | 610 type_(type), |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 OriginInfoTableEntries entries_; | 862 OriginInfoTableEntries entries_; |
| 793 }; | 863 }; |
| 794 | 864 |
| 795 // QuotaManager --------------------------------------------------------------- | 865 // QuotaManager --------------------------------------------------------------- |
| 796 | 866 |
| 797 QuotaManager::QuotaManager( | 867 QuotaManager::QuotaManager( |
| 798 bool is_incognito, | 868 bool is_incognito, |
| 799 const base::FilePath& profile_path, | 869 const base::FilePath& profile_path, |
| 800 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, | 870 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, |
| 801 const scoped_refptr<base::SequencedTaskRunner>& db_thread, | 871 const scoped_refptr<base::SequencedTaskRunner>& db_thread, |
| 802 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy) | 872 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy, |
| 873 QuotaEvictionPolicy* temporary_storage_eviction_policy) |
| 803 : is_incognito_(is_incognito), | 874 : is_incognito_(is_incognito), |
| 804 profile_path_(profile_path), | 875 profile_path_(profile_path), |
| 805 proxy_(new QuotaManagerProxy(this, io_thread)), | 876 proxy_(new QuotaManagerProxy(this, io_thread)), |
| 806 db_disabled_(false), | 877 db_disabled_(false), |
| 807 eviction_disabled_(false), | 878 eviction_disabled_(false), |
| 808 io_thread_(io_thread), | 879 io_thread_(io_thread), |
| 809 db_thread_(db_thread), | 880 db_thread_(db_thread), |
| 881 temporary_storage_eviction_policy_(temporary_storage_eviction_policy), |
| 810 temporary_quota_initialized_(false), | 882 temporary_quota_initialized_(false), |
| 811 temporary_quota_override_(-1), | 883 temporary_quota_override_(-1), |
| 812 desired_available_space_(-1), | 884 desired_available_space_(-1), |
| 813 special_storage_policy_(special_storage_policy), | 885 special_storage_policy_(special_storage_policy), |
| 814 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), | 886 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), |
| 815 storage_monitor_(new StorageMonitor(this)), | 887 storage_monitor_(new StorageMonitor(this)), |
| 816 weak_factory_(this) { | 888 weak_factory_(this) {} |
| 817 } | |
| 818 | 889 |
| 819 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { | 890 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { |
| 820 LazyInitialize(); | 891 LazyInitialize(); |
| 821 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); | 892 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); |
| 822 get_usage_info->Start(); | 893 get_usage_info->Start(); |
| 823 } | 894 } |
| 824 | 895 |
| 825 void QuotaManager::GetUsageAndQuotaForWebApps( | 896 void QuotaManager::GetUsageAndQuotaForWebApps( |
| 826 const GURL& origin, | 897 const GURL& origin, |
| 827 StorageType type, | 898 StorageType type, |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", | 1506 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", |
| 1436 num_origins); | 1507 num_origins); |
| 1437 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", | 1508 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", |
| 1438 protected_origins); | 1509 protected_origins); |
| 1439 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", | 1510 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", |
| 1440 unlimited_origins); | 1511 unlimited_origins); |
| 1441 } | 1512 } |
| 1442 | 1513 |
| 1443 void QuotaManager::GetEvictionOrigin(StorageType type, | 1514 void QuotaManager::GetEvictionOrigin(StorageType type, |
| 1444 const GetOriginCallback& callback) { | 1515 const GetOriginCallback& callback) { |
| 1516 LazyInitialize(); |
| 1517 if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) { |
| 1518 GetTemporaryEvictionOriginTask* task = new GetTemporaryEvictionOriginTask( |
| 1519 this, special_storage_policy_, temporary_storage_eviction_policy_, |
| 1520 callback); |
| 1521 task->Start(); |
| 1522 return; |
| 1523 } |
| 1524 |
| 1445 GetLRUOrigin(type, callback); | 1525 GetLRUOrigin(type, callback); |
| 1446 } | 1526 } |
| 1447 | 1527 |
| 1448 void QuotaManager::EvictOriginData(const GURL& origin, | 1528 void QuotaManager::EvictOriginData(const GURL& origin, |
| 1449 StorageType type, | 1529 StorageType type, |
| 1450 const EvictOriginDataCallback& callback) { | 1530 const EvictOriginDataCallback& callback) { |
| 1451 DCHECK(io_thread_->BelongsToCurrentThread()); | 1531 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1452 DCHECK_EQ(type, kStorageTypeTemporary); | 1532 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1453 | 1533 |
| 1454 eviction_context_.evicted_origin = origin; | 1534 eviction_context_.evicted_origin = origin; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1625 // |database_|, therefore we can be sure that database_ is alive when this | 1705 // |database_|, therefore we can be sure that database_ is alive when this |
| 1626 // task runs. | 1706 // task runs. |
| 1627 base::PostTaskAndReplyWithResult( | 1707 base::PostTaskAndReplyWithResult( |
| 1628 db_thread_.get(), | 1708 db_thread_.get(), |
| 1629 from_here, | 1709 from_here, |
| 1630 base::Bind(task, base::Unretained(database_.get())), | 1710 base::Bind(task, base::Unretained(database_.get())), |
| 1631 reply); | 1711 reply); |
| 1632 } | 1712 } |
| 1633 | 1713 |
| 1634 } // namespace storage | 1714 } // namespace storage |
| OLD | NEW |