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