| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/quota/quota_manager.h" | 5 #include "webkit/quota/quota_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 manager()->DidInitializeTemporaryGlobalQuota(temporary_storage_quota_); | 478 manager()->DidInitializeTemporaryGlobalQuota(temporary_storage_quota_); |
| 479 } | 479 } |
| 480 | 480 |
| 481 private: | 481 private: |
| 482 FilePath profile_path_; | 482 FilePath profile_path_; |
| 483 bool is_incognito_; | 483 bool is_incognito_; |
| 484 bool need_initialize_origins_; | 484 bool need_initialize_origins_; |
| 485 int64 temporary_storage_quota_; | 485 int64 temporary_storage_quota_; |
| 486 }; | 486 }; |
| 487 | 487 |
| 488 class QuotaManager::TemporaryGlobalQuotaUpdateTask | 488 class QuotaManager::UpdateTemporaryGlobalQuotaTask |
| 489 : public QuotaManager::DatabaseTaskBase { | 489 : public QuotaManager::DatabaseTaskBase { |
| 490 public: | 490 public: |
| 491 TemporaryGlobalQuotaUpdateTask( | 491 UpdateTemporaryGlobalQuotaTask( |
| 492 QuotaManager* manager, | 492 QuotaManager* manager, |
| 493 int64 new_quota, | 493 int64 new_quota, |
| 494 QuotaCallback* callback) | 494 QuotaCallback* callback) |
| 495 : DatabaseTaskBase(manager), | 495 : DatabaseTaskBase(manager), |
| 496 new_quota_(new_quota), | 496 new_quota_(new_quota), |
| 497 callback_(callback) { | 497 callback_(callback) { |
| 498 DCHECK_GE(new_quota, 0); | 498 DCHECK_GE(new_quota, 0); |
| 499 } | 499 } |
| 500 | 500 |
| 501 protected: | 501 protected: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 512 if (!db_disabled()) { | 512 if (!db_disabled()) { |
| 513 manager()->temporary_global_quota_ = new_quota_; | 513 manager()->temporary_global_quota_ = new_quota_; |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 | 516 |
| 517 private: | 517 private: |
| 518 int64 new_quota_; | 518 int64 new_quota_; |
| 519 scoped_ptr<QuotaCallback> callback_; | 519 scoped_ptr<QuotaCallback> callback_; |
| 520 }; | 520 }; |
| 521 | 521 |
| 522 class QuotaManager::PersistentHostQuotaQueryTask | 522 class QuotaManager::GetPersistentHostQuotaTask |
| 523 : public QuotaManager::DatabaseTaskBase { | 523 : public QuotaManager::DatabaseTaskBase { |
| 524 public: | 524 public: |
| 525 PersistentHostQuotaQueryTask( | 525 GetPersistentHostQuotaTask( |
| 526 QuotaManager* manager, | 526 QuotaManager* manager, |
| 527 const std::string& host, | 527 const std::string& host, |
| 528 HostQuotaCallback* callback) | 528 HostQuotaCallback* callback) |
| 529 : DatabaseTaskBase(manager), | 529 : DatabaseTaskBase(manager), |
| 530 host_(host), | 530 host_(host), |
| 531 quota_(-1), | 531 quota_(-1), |
| 532 callback_(callback) { | 532 callback_(callback) { |
| 533 } | 533 } |
| 534 protected: | 534 protected: |
| 535 virtual void RunOnTargetThread() OVERRIDE { | 535 virtual void RunOnTargetThread() OVERRIDE { |
| 536 if (!database()->GetHostQuota(host_, kStorageTypePersistent, "a_)) | 536 if (!database()->GetHostQuota(host_, kStorageTypePersistent, "a_)) |
| 537 quota_ = 0; | 537 quota_ = 0; |
| 538 } | 538 } |
| 539 virtual void DatabaseTaskCompleted() OVERRIDE { | 539 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 540 callback_->Run(kQuotaStatusOk, | 540 callback_->Run(kQuotaStatusOk, |
| 541 host_, kStorageTypePersistent, quota_); | 541 host_, kStorageTypePersistent, quota_); |
| 542 } | 542 } |
| 543 private: | 543 private: |
| 544 std::string host_; | 544 std::string host_; |
| 545 int64 quota_; | 545 int64 quota_; |
| 546 scoped_ptr<HostQuotaCallback> callback_; | 546 scoped_ptr<HostQuotaCallback> callback_; |
| 547 }; | 547 }; |
| 548 | 548 |
| 549 class QuotaManager::PersistentHostQuotaUpdateTask | 549 class QuotaManager::UpdatePersistentHostQuotaTask |
| 550 : public QuotaManager::DatabaseTaskBase { | 550 : public QuotaManager::DatabaseTaskBase { |
| 551 public: | 551 public: |
| 552 PersistentHostQuotaUpdateTask( | 552 UpdatePersistentHostQuotaTask( |
| 553 QuotaManager* manager, | 553 QuotaManager* manager, |
| 554 const std::string& host, | 554 const std::string& host, |
| 555 int new_quota, | 555 int new_quota, |
| 556 HostQuotaCallback* callback) | 556 HostQuotaCallback* callback) |
| 557 : DatabaseTaskBase(manager), | 557 : DatabaseTaskBase(manager), |
| 558 host_(host), | 558 host_(host), |
| 559 new_quota_(new_quota), | 559 new_quota_(new_quota), |
| 560 callback_(callback) { | 560 callback_(callback) { |
| 561 DCHECK_GE(new_quota_, 0); | 561 DCHECK_GE(new_quota_, 0); |
| 562 } | 562 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 } | 626 } |
| 627 | 627 |
| 628 private: | 628 private: |
| 629 StorageType type_; | 629 StorageType type_; |
| 630 std::set<GURL> exceptions_; | 630 std::set<GURL> exceptions_; |
| 631 scoped_ptr<GetLRUOriginCallback> callback_; | 631 scoped_ptr<GetLRUOriginCallback> callback_; |
| 632 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; | 632 scoped_refptr<SpecialStoragePolicy> special_storage_policy_; |
| 633 GURL url_; | 633 GURL url_; |
| 634 }; | 634 }; |
| 635 | 635 |
| 636 class QuotaManager::OriginDeletionDatabaseTask | 636 class QuotaManager::DeleteOriginInfo |
| 637 : public QuotaManager::DatabaseTaskBase { | 637 : public QuotaManager::DatabaseTaskBase { |
| 638 public: | 638 public: |
| 639 OriginDeletionDatabaseTask( | 639 DeleteOriginInfo( |
| 640 QuotaManager* manager, | 640 QuotaManager* manager, |
| 641 const GURL& origin, | 641 const GURL& origin, |
| 642 StorageType type) | 642 StorageType type) |
| 643 : DatabaseTaskBase(manager), | 643 : DatabaseTaskBase(manager), |
| 644 origin_(origin), | 644 origin_(origin), |
| 645 type_(type) {} | 645 type_(type) {} |
| 646 | 646 |
| 647 protected: | 647 protected: |
| 648 virtual void RunOnTargetThread() OVERRIDE { | 648 virtual void RunOnTargetThread() OVERRIDE { |
| 649 if (!database()->DeleteOriginLastAccessTime(origin_, type_)) { | 649 if (!database()->DeleteOriginInfo(origin_, type_)) { |
| 650 set_db_disabled(true); | 650 set_db_disabled(true); |
| 651 } | 651 } |
| 652 } | 652 } |
| 653 virtual void DatabaseTaskCompleted() OVERRIDE {} | 653 virtual void DatabaseTaskCompleted() OVERRIDE {} |
| 654 | 654 |
| 655 private: | 655 private: |
| 656 GURL origin_; | 656 GURL origin_; |
| 657 StorageType type_; | 657 StorageType type_; |
| 658 }; | 658 }; |
| 659 | 659 |
| 660 class QuotaManager::TemporaryOriginsRegistrationTask | 660 class QuotaManager::InitializeTemporaryOriginsInfoTask |
| 661 : public QuotaManager::DatabaseTaskBase { | 661 : public QuotaManager::DatabaseTaskBase { |
| 662 public: | 662 public: |
| 663 TemporaryOriginsRegistrationTask( | 663 InitializeTemporaryOriginsInfoTask( |
| 664 QuotaManager* manager, | 664 QuotaManager* manager, |
| 665 UsageTracker* temporary_usage_tracker) | 665 UsageTracker* temporary_usage_tracker) |
| 666 : DatabaseTaskBase(manager), | 666 : DatabaseTaskBase(manager), |
| 667 has_registered_origins_(false) { | 667 has_registered_origins_(false) { |
| 668 DCHECK(temporary_usage_tracker); | 668 DCHECK(temporary_usage_tracker); |
| 669 temporary_usage_tracker->GetCachedOrigins(&origins_); | 669 temporary_usage_tracker->GetCachedOrigins(&origins_); |
| 670 } | 670 } |
| 671 | 671 |
| 672 protected: | 672 protected: |
| 673 virtual void RunOnTargetThread() OVERRIDE { | 673 virtual void RunOnTargetThread() OVERRIDE { |
| 674 if (!database()->IsOriginDatabaseBootstrapped()) { | 674 if (!database()->IsOriginDatabaseBootstrapped()) { |
| 675 // Register existing origins with 0 last time access. | 675 // Register existing origins with 0 last time access. |
| 676 if (!database()->RegisterOrigins(origins_, | 676 if (!database()->RegisterInitialOriginInfo( |
| 677 kStorageTypeTemporary, | 677 origins_, kStorageTypeTemporary)) { |
| 678 base::Time::FromInternalValue(0))) { | |
| 679 set_db_disabled(true); | 678 set_db_disabled(true); |
| 680 } else { | 679 } else { |
| 681 has_registered_origins_ = true; | 680 has_registered_origins_ = true; |
| 682 database()->SetOriginDatabaseBootstrapped(true); | 681 database()->SetOriginDatabaseBootstrapped(true); |
| 683 } | 682 } |
| 684 } | 683 } |
| 685 } | 684 } |
| 686 virtual void DatabaseTaskCompleted() OVERRIDE { | 685 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 687 if (has_registered_origins_) | 686 if (has_registered_origins_) |
| 688 manager()->StartEviction(); | 687 manager()->StartEviction(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 705 space_(-1), | 704 space_(-1), |
| 706 callback_(callback) {} | 705 callback_(callback) {} |
| 707 virtual ~AvailableSpaceQueryTask() {} | 706 virtual ~AvailableSpaceQueryTask() {} |
| 708 | 707 |
| 709 protected: | 708 protected: |
| 710 virtual void RunOnTargetThread() OVERRIDE { | 709 virtual void RunOnTargetThread() OVERRIDE { |
| 711 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); | 710 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); |
| 712 } | 711 } |
| 713 | 712 |
| 714 virtual void Aborted() OVERRIDE { | 713 virtual void Aborted() OVERRIDE { |
| 715 callback_->Run(kQuotaErrorAbort, space_); | 714 callback_->Run(kQuotaErrorAbort, -1); |
| 716 } | 715 } |
| 717 | 716 |
| 718 virtual void Completed() OVERRIDE { | 717 virtual void Completed() OVERRIDE { |
| 719 callback_->Run(kQuotaStatusOk, space_); | 718 callback_->Run(kQuotaStatusOk, space_); |
| 720 } | 719 } |
| 721 | 720 |
| 722 private: | 721 private: |
| 723 FilePath profile_path_; | 722 FilePath profile_path_; |
| 724 int64 space_; | 723 int64 space_; |
| 725 scoped_ptr<AvailableSpaceCallback> callback_; | 724 scoped_ptr<AvailableSpaceCallback> callback_; |
| 726 }; | 725 }; |
| 727 | 726 |
| 728 class QuotaManager::OriginAccessRecordDatabaseTask | 727 class QuotaManager::UpdateAccesTimeTask |
| 729 : public QuotaManager::DatabaseTaskBase { | 728 : public QuotaManager::DatabaseTaskBase { |
| 730 public: | 729 public: |
| 731 OriginAccessRecordDatabaseTask( | 730 UpdateAccesTimeTask( |
| 732 QuotaManager* manager, | 731 QuotaManager* manager, |
| 733 const GURL& origin, | 732 const GURL& origin, |
| 734 StorageType type, | 733 StorageType type, |
| 735 base::Time accessed_time) | 734 base::Time accessed_time) |
| 736 : DatabaseTaskBase(manager), | 735 : DatabaseTaskBase(manager), |
| 737 origin_(origin), | 736 origin_(origin), |
| 738 type_(type), | 737 type_(type), |
| 739 accessed_time_(accessed_time) {} | 738 accessed_time_(accessed_time) {} |
| 740 | 739 |
| 741 protected: | 740 protected: |
| 742 virtual void RunOnTargetThread() OVERRIDE { | 741 virtual void RunOnTargetThread() OVERRIDE { |
| 743 if (!database()->SetOriginLastAccessTime(origin_, type_, accessed_time_)) { | 742 if (!database()->SetOriginLastAccessTime(origin_, type_, accessed_time_)) { |
| 744 set_db_disabled(true); | 743 set_db_disabled(true); |
| 745 } | 744 } |
| 746 } | 745 } |
| 747 virtual void DatabaseTaskCompleted() OVERRIDE {} | 746 virtual void DatabaseTaskCompleted() OVERRIDE {} |
| 748 | 747 |
| 749 private: | 748 private: |
| 750 GURL origin_; | 749 GURL origin_; |
| 751 StorageType type_; | 750 StorageType type_; |
| 752 base::Time accessed_time_; | 751 base::Time accessed_time_; |
| 753 }; | 752 }; |
| 754 | 753 |
| 754 class QuotaManager::UpdateModifiedTimeTask |
| 755 : public QuotaManager::DatabaseTaskBase { |
| 756 public: |
| 757 UpdateModifiedTimeTask( |
| 758 QuotaManager* manager, |
| 759 const GURL& origin, |
| 760 StorageType type, |
| 761 base::Time modified_time) |
| 762 : DatabaseTaskBase(manager), |
| 763 origin_(origin), |
| 764 type_(type), |
| 765 modified_time_(modified_time) {} |
| 766 |
| 767 protected: |
| 768 virtual void RunOnTargetThread() OVERRIDE { |
| 769 if (!database()->SetOriginLastModifiedTime( |
| 770 origin_, type_, modified_time_)) { |
| 771 set_db_disabled(true); |
| 772 } |
| 773 } |
| 774 virtual void DatabaseTaskCompleted() OVERRIDE {} |
| 775 |
| 776 private: |
| 777 GURL origin_; |
| 778 StorageType type_; |
| 779 base::Time modified_time_; |
| 780 }; |
| 781 |
| 782 class QuotaManager::GetModifiedSinceTask |
| 783 : public QuotaManager::DatabaseTaskBase { |
| 784 public: |
| 785 GetModifiedSinceTask( |
| 786 QuotaManager* manager, |
| 787 StorageType type, |
| 788 base::Time modified_since, |
| 789 GetOriginsCallback* callback) |
| 790 : DatabaseTaskBase(manager), |
| 791 type_(type), |
| 792 modified_since_(modified_since), |
| 793 callback_(callback) {} |
| 794 |
| 795 protected: |
| 796 virtual void RunOnTargetThread() OVERRIDE { |
| 797 if (!database()->GetOriginsModifiedSince( |
| 798 type_, &origins_, modified_since_)) { |
| 799 set_db_disabled(true); |
| 800 } |
| 801 } |
| 802 |
| 803 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 804 callback_->Run(origins_); |
| 805 } |
| 806 |
| 807 virtual void Aborted() OVERRIDE { |
| 808 callback_->Run(std::set<GURL>()); |
| 809 } |
| 810 |
| 811 private: |
| 812 StorageType type_; |
| 813 base::Time modified_since_; |
| 814 std::set<GURL> origins_; |
| 815 scoped_ptr<GetOriginsCallback> callback_; |
| 816 }; |
| 817 |
| 755 class QuotaManager::DumpQuotaTableTask | 818 class QuotaManager::DumpQuotaTableTask |
| 756 : public QuotaManager::DatabaseTaskBase { | 819 : public QuotaManager::DatabaseTaskBase { |
| 757 private: | 820 private: |
| 758 typedef QuotaManager::DumpQuotaTableTask self_type; | 821 typedef QuotaManager::DumpQuotaTableTask self_type; |
| 759 typedef QuotaManager::DumpQuotaTableCallback Callback; | 822 typedef QuotaManager::DumpQuotaTableCallback Callback; |
| 760 typedef QuotaManager::QuotaTableEntry TableEntry; | 823 typedef QuotaManager::QuotaTableEntry TableEntry; |
| 761 typedef QuotaManager::QuotaTableEntries TableEntries; | 824 typedef QuotaManager::QuotaTableEntries TableEntries; |
| 762 typedef QuotaDatabase::QuotaTableCallback TableCallback; | 825 typedef QuotaDatabase::QuotaTableCallback TableCallback; |
| 763 | 826 |
| 764 public: | 827 public: |
| 765 DumpQuotaTableTask( | 828 DumpQuotaTableTask( |
| 766 QuotaManager* manager, | 829 QuotaManager* manager, |
| 767 Callback* callback) | 830 Callback* callback) |
| 768 : DatabaseTaskBase(manager), | 831 : DatabaseTaskBase(manager), |
| 769 callback_(callback) { | 832 callback_(callback) { |
| 770 } | 833 } |
| 771 protected: | 834 protected: |
| 772 virtual void RunOnTargetThread() OVERRIDE { | 835 virtual void RunOnTargetThread() OVERRIDE { |
| 773 if (!database()->DumpQuotaTable( | 836 if (!database()->DumpQuotaTable( |
| 774 new TableCallback( | 837 new TableCallback( |
| 775 base::Bind(&self_type::AppendEntry, this)))) | 838 base::Bind(&self_type::AppendEntry, this)))) |
| 776 set_db_disabled(true); | 839 set_db_disabled(true); |
| 777 } | 840 } |
| 778 | 841 |
| 779 virtual void Aborted() OVERRIDE { | 842 virtual void Aborted() OVERRIDE { |
| 780 callback_->Run(entries_); | 843 callback_->Run(TableEntries()); |
| 781 } | 844 } |
| 782 | 845 |
| 783 virtual void DatabaseTaskCompleted() OVERRIDE { | 846 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 784 callback_->Run(entries_); | 847 callback_->Run(entries_); |
| 785 } | 848 } |
| 786 | 849 |
| 787 private: | 850 private: |
| 788 bool AppendEntry(const TableEntry& entry) { | 851 bool AppendEntry(const TableEntry& entry) { |
| 789 entries_.push_back(entry); | 852 entries_.push_back(entry); |
| 790 return true; | 853 return true; |
| 791 } | 854 } |
| 792 | 855 |
| 793 scoped_ptr<Callback> callback_; | 856 scoped_ptr<Callback> callback_; |
| 794 TableEntries entries_; | 857 TableEntries entries_; |
| 795 }; | 858 }; |
| 796 | 859 |
| 797 class QuotaManager::DumpLastAccessTimeTableTask | 860 class QuotaManager::DumpOriginInfoTableTask |
| 798 : public QuotaManager::DatabaseTaskBase { | 861 : public QuotaManager::DatabaseTaskBase { |
| 799 private: | 862 private: |
| 800 typedef QuotaManager::DumpLastAccessTimeTableTask self_type; | 863 typedef QuotaManager::DumpOriginInfoTableTask self_type; |
| 801 typedef QuotaManager::DumpLastAccessTimeTableCallback Callback; | 864 typedef QuotaManager::DumpOriginInfoTableCallback Callback; |
| 802 typedef QuotaManager::LastAccessTimeTableEntry TableEntry; | 865 typedef QuotaManager::OriginInfoTableEntry TableEntry; |
| 803 typedef QuotaManager::LastAccessTimeTableEntries TableEntries; | 866 typedef QuotaManager::OriginInfoTableEntries TableEntries; |
| 804 typedef QuotaDatabase::LastAccessTimeTableCallback TableCallback; | 867 typedef QuotaDatabase::OriginInfoTableCallback TableCallback; |
| 805 | 868 |
| 806 public: | 869 public: |
| 807 DumpLastAccessTimeTableTask( | 870 DumpOriginInfoTableTask( |
| 808 QuotaManager* manager, | 871 QuotaManager* manager, |
| 809 Callback* callback) | 872 Callback* callback) |
| 810 : DatabaseTaskBase(manager), | 873 : DatabaseTaskBase(manager), |
| 811 callback_(callback) { | 874 callback_(callback) { |
| 812 } | 875 } |
| 813 protected: | 876 protected: |
| 814 virtual void RunOnTargetThread() OVERRIDE { | 877 virtual void RunOnTargetThread() OVERRIDE { |
| 815 if (!database()->DumpLastAccessTimeTable( | 878 if (!database()->DumpOriginInfoTable( |
| 816 new TableCallback( | 879 new TableCallback( |
| 817 base::Bind(&self_type::AppendEntry, this)))) | 880 base::Bind(&self_type::AppendEntry, this)))) |
| 818 set_db_disabled(true); | 881 set_db_disabled(true); |
| 819 } | 882 } |
| 820 | 883 |
| 821 virtual void Aborted() OVERRIDE { | 884 virtual void Aborted() OVERRIDE { |
| 822 callback_->Run(entries_); | 885 callback_->Run(TableEntries()); |
| 823 } | 886 } |
| 824 | 887 |
| 825 virtual void DatabaseTaskCompleted() OVERRIDE { | 888 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 826 callback_->Run(entries_); | 889 callback_->Run(entries_); |
| 827 } | 890 } |
| 828 | 891 |
| 829 private: | 892 private: |
| 830 bool AppendEntry(const TableEntry& entry) { | 893 bool AppendEntry(const TableEntry& entry) { |
| 831 entries_.push_back(entry); | 894 entries_.push_back(entry); |
| 832 return true; | 895 return true; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 QuotaCallback* callback) { | 980 QuotaCallback* callback) { |
| 918 LazyInitialize(); | 981 LazyInitialize(); |
| 919 if (new_quota < 0) { | 982 if (new_quota < 0) { |
| 920 callback->Run(kQuotaErrorInvalidModification, | 983 callback->Run(kQuotaErrorInvalidModification, |
| 921 kStorageTypeTemporary, -1); | 984 kStorageTypeTemporary, -1); |
| 922 delete callback; | 985 delete callback; |
| 923 return; | 986 return; |
| 924 } | 987 } |
| 925 | 988 |
| 926 if (!db_disabled_) { | 989 if (!db_disabled_) { |
| 927 scoped_refptr<TemporaryGlobalQuotaUpdateTask> task( | 990 scoped_refptr<UpdateTemporaryGlobalQuotaTask> task( |
| 928 new TemporaryGlobalQuotaUpdateTask(this, new_quota, callback)); | 991 new UpdateTemporaryGlobalQuotaTask(this, new_quota, callback)); |
| 929 task->Start(); | 992 task->Start(); |
| 930 } else { | 993 } else { |
| 931 callback->Run(kQuotaErrorInvalidAccess, | 994 callback->Run(kQuotaErrorInvalidAccess, |
| 932 kStorageTypeTemporary, -1); | 995 kStorageTypeTemporary, -1); |
| 933 delete callback; | 996 delete callback; |
| 934 } | 997 } |
| 935 } | 998 } |
| 936 | 999 |
| 937 void QuotaManager::GetPersistentHostQuota(const std::string& host, | 1000 void QuotaManager::GetPersistentHostQuota(const std::string& host, |
| 938 HostQuotaCallback* callback_ptr) { | 1001 HostQuotaCallback* callback_ptr) { |
| 939 scoped_ptr<HostQuotaCallback> callback(callback_ptr); | 1002 scoped_ptr<HostQuotaCallback> callback(callback_ptr); |
| 940 LazyInitialize(); | 1003 LazyInitialize(); |
| 941 if (host.empty()) { | 1004 if (host.empty()) { |
| 942 // This could happen if we are called on file:///. | 1005 // This could happen if we are called on file:///. |
| 943 // TODO(kinuko) We may want to respect --allow-file-access-from-files | 1006 // TODO(kinuko) We may want to respect --allow-file-access-from-files |
| 944 // command line switch. | 1007 // command line switch. |
| 945 callback->Run(kQuotaStatusOk, host, kStorageTypePersistent, 0); | 1008 callback->Run(kQuotaStatusOk, host, kStorageTypePersistent, 0); |
| 946 return; | 1009 return; |
| 947 } | 1010 } |
| 948 scoped_refptr<PersistentHostQuotaQueryTask> task( | 1011 scoped_refptr<GetPersistentHostQuotaTask> task( |
| 949 new PersistentHostQuotaQueryTask(this, host, callback.release())); | 1012 new GetPersistentHostQuotaTask(this, host, callback.release())); |
| 950 task->Start(); | 1013 task->Start(); |
| 951 } | 1014 } |
| 952 | 1015 |
| 953 void QuotaManager::SetPersistentHostQuota(const std::string& host, | 1016 void QuotaManager::SetPersistentHostQuota(const std::string& host, |
| 954 int64 new_quota, | 1017 int64 new_quota, |
| 955 HostQuotaCallback* callback_ptr) { | 1018 HostQuotaCallback* callback_ptr) { |
| 956 scoped_ptr<HostQuotaCallback> callback(callback_ptr); | 1019 scoped_ptr<HostQuotaCallback> callback(callback_ptr); |
| 957 LazyInitialize(); | 1020 LazyInitialize(); |
| 958 if (host.empty()) { | 1021 if (host.empty()) { |
| 959 // This could happen if we are called on file:///. | 1022 // This could happen if we are called on file:///. |
| 960 callback->Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0); | 1023 callback->Run(kQuotaErrorNotSupported, host, kStorageTypePersistent, 0); |
| 961 return; | 1024 return; |
| 962 } | 1025 } |
| 963 if (new_quota < 0) { | 1026 if (new_quota < 0) { |
| 964 callback->Run(kQuotaErrorInvalidModification, | 1027 callback->Run(kQuotaErrorInvalidModification, |
| 965 host, kStorageTypePersistent, -1); | 1028 host, kStorageTypePersistent, -1); |
| 966 return; | 1029 return; |
| 967 } | 1030 } |
| 968 | 1031 |
| 969 if (!db_disabled_) { | 1032 if (!db_disabled_) { |
| 970 scoped_refptr<PersistentHostQuotaUpdateTask> task( | 1033 scoped_refptr<UpdatePersistentHostQuotaTask> task( |
| 971 new PersistentHostQuotaUpdateTask( | 1034 new UpdatePersistentHostQuotaTask( |
| 972 this, host, new_quota, callback.release())); | 1035 this, host, new_quota, callback.release())); |
| 973 task->Start(); | 1036 task->Start(); |
| 974 } else { | 1037 } else { |
| 975 callback->Run(kQuotaErrorInvalidAccess, | 1038 callback->Run(kQuotaErrorInvalidAccess, |
| 976 host, kStorageTypePersistent, -1); | 1039 host, kStorageTypePersistent, -1); |
| 977 } | 1040 } |
| 978 } | 1041 } |
| 979 | 1042 |
| 980 void QuotaManager::GetGlobalUsage( | 1043 void QuotaManager::GetGlobalUsage( |
| 981 StorageType type, | 1044 StorageType type, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 996 if (temporary_storage_evictor_.get()) { | 1059 if (temporary_storage_evictor_.get()) { |
| 997 std::map<std::string, int64> stats; | 1060 std::map<std::string, int64> stats; |
| 998 temporary_storage_evictor_->GetStatistics(&stats); | 1061 temporary_storage_evictor_->GetStatistics(&stats); |
| 999 for (std::map<std::string, int64>::iterator p = stats.begin(); | 1062 for (std::map<std::string, int64>::iterator p = stats.begin(); |
| 1000 p != stats.end(); | 1063 p != stats.end(); |
| 1001 ++p) | 1064 ++p) |
| 1002 (*statistics)[p->first] = base::Int64ToString(p->second); | 1065 (*statistics)[p->first] = base::Int64ToString(p->second); |
| 1003 } | 1066 } |
| 1004 } | 1067 } |
| 1005 | 1068 |
| 1069 void QuotaManager::GetOriginsModifiedSince( |
| 1070 StorageType type, |
| 1071 base::Time modified_since, |
| 1072 GetOriginsCallback* callback) { |
| 1073 LazyInitialize(); |
| 1074 make_scoped_refptr(new GetModifiedSinceTask( |
| 1075 this, type, modified_since, callback))->Start(); |
| 1076 } |
| 1077 |
| 1006 void QuotaManager::LazyInitialize() { | 1078 void QuotaManager::LazyInitialize() { |
| 1007 DCHECK(io_thread_->BelongsToCurrentThread()); | 1079 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1008 if (database_.get()) { | 1080 if (database_.get()) { |
| 1009 // Initialization seems to be done already. | 1081 // Initialization seems to be done already. |
| 1010 return; | 1082 return; |
| 1011 } | 1083 } |
| 1012 | 1084 |
| 1013 // Use an empty path to open an in-memory only databse for incognito. | 1085 // Use an empty path to open an in-memory only databse for incognito. |
| 1014 database_.reset(new QuotaDatabase(is_incognito_ ? FilePath() : | 1086 database_.reset(new QuotaDatabase(is_incognito_ ? FilePath() : |
| 1015 profile_path_.AppendASCII(kDatabaseName))); | 1087 profile_path_.AppendASCII(kDatabaseName))); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1034 | 1106 |
| 1035 void QuotaManager::NotifyStorageAccessed( | 1107 void QuotaManager::NotifyStorageAccessed( |
| 1036 QuotaClient::ID client_id, | 1108 QuotaClient::ID client_id, |
| 1037 const GURL& origin, StorageType type) { | 1109 const GURL& origin, StorageType type) { |
| 1038 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); | 1110 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); |
| 1039 } | 1111 } |
| 1040 | 1112 |
| 1041 void QuotaManager::NotifyStorageModified( | 1113 void QuotaManager::NotifyStorageModified( |
| 1042 QuotaClient::ID client_id, | 1114 QuotaClient::ID client_id, |
| 1043 const GURL& origin, StorageType type, int64 delta) { | 1115 const GURL& origin, StorageType type, int64 delta) { |
| 1044 LazyInitialize(); | 1116 NotifyStorageModifiedInternal(client_id, origin, type, delta, |
| 1045 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); | 1117 base::Time::Now()); |
| 1046 } | 1118 } |
| 1047 | 1119 |
| 1048 void QuotaManager::NotifyOriginInUse(const GURL& origin) { | 1120 void QuotaManager::NotifyOriginInUse(const GURL& origin) { |
| 1049 DCHECK(io_thread_->BelongsToCurrentThread()); | 1121 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1050 origins_in_use_[origin]++; | 1122 origins_in_use_[origin]++; |
| 1051 } | 1123 } |
| 1052 | 1124 |
| 1053 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { | 1125 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { |
| 1054 DCHECK(io_thread_->BelongsToCurrentThread()); | 1126 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1055 DCHECK(IsOriginInUse(origin)); | 1127 DCHECK(IsOriginInUse(origin)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 base::Time accessed_time) { | 1181 base::Time accessed_time) { |
| 1110 LazyInitialize(); | 1182 LazyInitialize(); |
| 1111 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { | 1183 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { |
| 1112 // Record the accessed origins while GetLRUOrigin task is runing | 1184 // Record the accessed origins while GetLRUOrigin task is runing |
| 1113 // to filter out them from eviction. | 1185 // to filter out them from eviction. |
| 1114 access_notified_origins_.insert(origin); | 1186 access_notified_origins_.insert(origin); |
| 1115 } | 1187 } |
| 1116 | 1188 |
| 1117 if (db_disabled_) | 1189 if (db_disabled_) |
| 1118 return; | 1190 return; |
| 1119 scoped_refptr<OriginAccessRecordDatabaseTask> task( | 1191 make_scoped_refptr(new UpdateAccesTimeTask( |
| 1120 new OriginAccessRecordDatabaseTask(this, origin, type, accessed_time)); | 1192 this, origin, type, accessed_time))->Start(); |
| 1121 task->Start(); | 1193 } |
| 1194 |
| 1195 void QuotaManager::NotifyStorageModifiedInternal( |
| 1196 QuotaClient::ID client_id, |
| 1197 const GURL& origin, |
| 1198 StorageType type, |
| 1199 int64 delta, |
| 1200 base::Time modified_time) { |
| 1201 LazyInitialize(); |
| 1202 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); |
| 1203 make_scoped_refptr(new UpdateModifiedTimeTask( |
| 1204 this, origin, type, modified_time))->Start(); |
| 1122 } | 1205 } |
| 1123 | 1206 |
| 1124 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { | 1207 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { |
| 1125 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); | 1208 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); |
| 1126 } | 1209 } |
| 1127 | 1210 |
| 1128 void QuotaManager::DumpLastAccessTimeTable( | 1211 void QuotaManager::DumpOriginInfoTable( |
| 1129 DumpLastAccessTimeTableCallback* callback) { | 1212 DumpOriginInfoTableCallback* callback) { |
| 1130 make_scoped_refptr(new DumpLastAccessTimeTableTask(this, callback))->Start(); | 1213 make_scoped_refptr(new DumpOriginInfoTableTask(this, callback))->Start(); |
| 1131 } | 1214 } |
| 1132 | 1215 |
| 1133 | 1216 |
| 1134 void QuotaManager::DeleteOriginFromDatabase( | 1217 void QuotaManager::DeleteOriginFromDatabase( |
| 1135 const GURL& origin, StorageType type) { | 1218 const GURL& origin, StorageType type) { |
| 1136 LazyInitialize(); | 1219 LazyInitialize(); |
| 1137 if (db_disabled_) | 1220 if (db_disabled_) |
| 1138 return; | 1221 return; |
| 1139 scoped_refptr<OriginDeletionDatabaseTask> task = | 1222 scoped_refptr<DeleteOriginInfo> task = |
| 1140 new OriginDeletionDatabaseTask(this, origin, type); | 1223 new DeleteOriginInfo(this, origin, type); |
| 1141 task->Start(); | 1224 task->Start(); |
| 1142 } | 1225 } |
| 1143 | 1226 |
| 1144 void QuotaManager::GetLRUOrigin( | 1227 void QuotaManager::GetLRUOrigin( |
| 1145 StorageType type, | 1228 StorageType type, |
| 1146 GetLRUOriginCallback* callback) { | 1229 GetLRUOriginCallback* callback) { |
| 1147 LazyInitialize(); | 1230 LazyInitialize(); |
| 1148 // This must not be called while there's an in-flight task. | 1231 // This must not be called while there's an in-flight task. |
| 1149 DCHECK(!lru_origin_callback_.get()); | 1232 DCHECK(!lru_origin_callback_.get()); |
| 1150 lru_origin_callback_.reset(callback); | 1233 lru_origin_callback_.reset(callback); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 // for eviction later.) | 1349 // for eviction later.) |
| 1267 temporary_usage_tracker_->GetGlobalUsage(callback_factory_.NewCallback( | 1350 temporary_usage_tracker_->GetGlobalUsage(callback_factory_.NewCallback( |
| 1268 &QuotaManager::DidRunInitialGetTemporaryGlobalUsage)); | 1351 &QuotaManager::DidRunInitialGetTemporaryGlobalUsage)); |
| 1269 } | 1352 } |
| 1270 | 1353 |
| 1271 void QuotaManager::DidRunInitialGetTemporaryGlobalUsage( | 1354 void QuotaManager::DidRunInitialGetTemporaryGlobalUsage( |
| 1272 StorageType type, int64 usage_unused, int64 unlimited_usage_unused) { | 1355 StorageType type, int64 usage_unused, int64 unlimited_usage_unused) { |
| 1273 DCHECK_EQ(type, kStorageTypeTemporary); | 1356 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1274 // This will call the StartEviction() when initial origin registration | 1357 // This will call the StartEviction() when initial origin registration |
| 1275 // is completed. | 1358 // is completed. |
| 1276 scoped_refptr<TemporaryOriginsRegistrationTask> task( | 1359 scoped_refptr<InitializeTemporaryOriginsInfoTask> task( |
| 1277 new TemporaryOriginsRegistrationTask( | 1360 new InitializeTemporaryOriginsInfoTask( |
| 1278 this, temporary_usage_tracker_.get())); | 1361 this, temporary_usage_tracker_.get())); |
| 1279 task->Start(); | 1362 task->Start(); |
| 1280 } | 1363 } |
| 1281 | 1364 |
| 1282 void QuotaManager::DidGetDatabaseLRUOrigin(const GURL& origin) { | 1365 void QuotaManager::DidGetDatabaseLRUOrigin(const GURL& origin) { |
| 1283 // Make sure the returned origin is (still) not in the origin_in_use_ set | 1366 // Make sure the returned origin is (still) not in the origin_in_use_ set |
| 1284 // and has not been accessed since we posted the task. | 1367 // and has not been accessed since we posted the task. |
| 1285 if (origins_in_use_.find(origin) != origins_in_use_.end() || | 1368 if (origins_in_use_.find(origin) != origins_in_use_.end() || |
| 1286 access_notified_origins_.find(origin) != access_notified_origins_.end()) | 1369 access_notified_origins_.find(origin) != access_notified_origins_.end()) |
| 1287 lru_origin_callback_->Run(GURL()); | 1370 lru_origin_callback_->Run(GURL()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 | 1454 |
| 1372 QuotaManagerProxy::QuotaManagerProxy( | 1455 QuotaManagerProxy::QuotaManagerProxy( |
| 1373 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1456 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
| 1374 : manager_(manager), io_thread_(io_thread) { | 1457 : manager_(manager), io_thread_(io_thread) { |
| 1375 } | 1458 } |
| 1376 | 1459 |
| 1377 QuotaManagerProxy::~QuotaManagerProxy() { | 1460 QuotaManagerProxy::~QuotaManagerProxy() { |
| 1378 } | 1461 } |
| 1379 | 1462 |
| 1380 } // namespace quota | 1463 } // namespace quota |
| OLD | NEW |