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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 return new UsageAndQuotaDispatcherTaskForPersistent( | 340 return new UsageAndQuotaDispatcherTaskForPersistent( |
341 manager, host); | 341 manager, host); |
342 default: | 342 default: |
343 NOTREACHED(); | 343 NOTREACHED(); |
344 } | 344 } |
345 return NULL; | 345 return NULL; |
346 } | 346 } |
347 | 347 |
348 class QuotaManager::DatabaseTaskBase : public QuotaThreadTask { | 348 class QuotaManager::DatabaseTaskBase : public QuotaThreadTask { |
349 public: | 349 public: |
350 DatabaseTaskBase(QuotaManager* manager) | 350 explicit DatabaseTaskBase(QuotaManager* manager) |
351 : QuotaThreadTask(manager, manager->db_thread_), | 351 : QuotaThreadTask(manager, manager->db_thread_), |
352 manager_(manager), | 352 manager_(manager), |
353 database_(manager->database_.get()), | 353 database_(manager->database_.get()), |
354 db_disabled_(false) { | 354 db_disabled_(false) { |
355 DCHECK(manager_); | 355 DCHECK(manager_); |
356 DCHECK(database_); | 356 DCHECK(database_); |
357 } | 357 } |
358 | 358 |
359 protected: | 359 protected: |
360 virtual void DatabaseTaskCompleted() = 0; | 360 virtual void DatabaseTaskCompleted() = 0; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 OriginDeletionDatabaseTask( | 575 OriginDeletionDatabaseTask( |
576 QuotaManager* manager, | 576 QuotaManager* manager, |
577 const GURL& origin, | 577 const GURL& origin, |
578 StorageType type) | 578 StorageType type) |
579 : DatabaseTaskBase(manager), | 579 : DatabaseTaskBase(manager), |
580 origin_(origin), | 580 origin_(origin), |
581 type_(type) {} | 581 type_(type) {} |
582 | 582 |
583 protected: | 583 protected: |
584 virtual void RunOnTargetThread() OVERRIDE { | 584 virtual void RunOnTargetThread() OVERRIDE { |
585 if (!database()->DeleteOriginLastAccessTime(origin_, type_)) { | 585 if (!database()->DeleteOriginInfo(origin_, type_)) { |
586 set_db_disabled(true); | 586 set_db_disabled(true); |
587 } | 587 } |
588 } | 588 } |
589 virtual void DatabaseTaskCompleted() OVERRIDE {} | 589 virtual void DatabaseTaskCompleted() OVERRIDE {} |
590 | 590 |
591 private: | 591 private: |
592 GURL origin_; | 592 GURL origin_; |
593 StorageType type_; | 593 StorageType type_; |
594 }; | 594 }; |
595 | 595 |
596 class QuotaManager::TemporaryOriginsRegistrationTask | 596 class QuotaManager::TemporaryOriginsRegistrationTask |
597 : public QuotaManager::DatabaseTaskBase { | 597 : public QuotaManager::DatabaseTaskBase { |
598 public: | 598 public: |
599 TemporaryOriginsRegistrationTask( | 599 TemporaryOriginsRegistrationTask( |
600 QuotaManager* manager, | 600 QuotaManager* manager, |
601 UsageTracker* temporary_usage_tracker) | 601 UsageTracker* temporary_usage_tracker) |
602 : DatabaseTaskBase(manager), | 602 : DatabaseTaskBase(manager), |
603 has_registered_origins_(false) { | 603 has_registered_origins_(false) { |
604 DCHECK(temporary_usage_tracker); | 604 DCHECK(temporary_usage_tracker); |
605 temporary_usage_tracker->GetCachedOrigins(&origins_); | 605 temporary_usage_tracker->GetCachedOrigins(&origins_); |
606 } | 606 } |
607 | 607 |
608 protected: | 608 protected: |
609 virtual void RunOnTargetThread() OVERRIDE { | 609 virtual void RunOnTargetThread() OVERRIDE { |
610 if (!database()->IsOriginDatabaseBootstrapped()) { | 610 if (!database()->IsOriginDatabaseBootstrapped()) { |
611 // Register existing origins with 0 last time access. | 611 // Register existing origins with 0 last time access. |
612 if (!database()->RegisterOrigins(origins_, | 612 if (!database()->RegisterInitialOriginInfo( |
613 kStorageTypeTemporary, | 613 origins_, kStorageTypeTemporary)) { |
614 base::Time::FromInternalValue(0))) { | |
615 set_db_disabled(true); | 614 set_db_disabled(true); |
616 } else { | 615 } else { |
617 has_registered_origins_ = true; | 616 has_registered_origins_ = true; |
618 database()->SetOriginDatabaseBootstrapped(true); | 617 database()->SetOriginDatabaseBootstrapped(true); |
619 } | 618 } |
620 } | 619 } |
621 } | 620 } |
622 virtual void DatabaseTaskCompleted() OVERRIDE { | 621 virtual void DatabaseTaskCompleted() OVERRIDE { |
623 if (has_registered_origins_) | 622 if (has_registered_origins_) |
624 manager()->StartEviction(); | 623 manager()->StartEviction(); |
(...skipping 16 matching lines...) Expand all Loading... | |
641 space_(-1), | 640 space_(-1), |
642 callback_(callback) {} | 641 callback_(callback) {} |
643 virtual ~AvailableSpaceQueryTask() {} | 642 virtual ~AvailableSpaceQueryTask() {} |
644 | 643 |
645 protected: | 644 protected: |
646 virtual void RunOnTargetThread() OVERRIDE { | 645 virtual void RunOnTargetThread() OVERRIDE { |
647 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); | 646 space_ = base::SysInfo::AmountOfFreeDiskSpace(profile_path_); |
648 } | 647 } |
649 | 648 |
650 virtual void Aborted() OVERRIDE { | 649 virtual void Aborted() OVERRIDE { |
651 callback_->Run(kQuotaErrorAbort, space_); | 650 callback_->Run(kQuotaErrorAbort, -1); |
652 } | 651 } |
653 | 652 |
654 virtual void Completed() OVERRIDE { | 653 virtual void Completed() OVERRIDE { |
655 callback_->Run(kQuotaStatusOk, space_); | 654 callback_->Run(kQuotaStatusOk, space_); |
656 } | 655 } |
657 | 656 |
658 private: | 657 private: |
659 FilePath profile_path_; | 658 FilePath profile_path_; |
660 int64 space_; | 659 int64 space_; |
661 scoped_ptr<AvailableSpaceCallback> callback_; | 660 scoped_ptr<AvailableSpaceCallback> callback_; |
(...skipping 19 matching lines...) Expand all Loading... | |
681 } | 680 } |
682 } | 681 } |
683 virtual void DatabaseTaskCompleted() OVERRIDE {} | 682 virtual void DatabaseTaskCompleted() OVERRIDE {} |
684 | 683 |
685 private: | 684 private: |
686 GURL origin_; | 685 GURL origin_; |
687 StorageType type_; | 686 StorageType type_; |
688 base::Time accessed_time_; | 687 base::Time accessed_time_; |
689 }; | 688 }; |
690 | 689 |
690 class QuotaManager::OriginModifyRecordDatabaseTask | |
michaeln
2011/07/01 00:17:39
naming nit: these names are awkward to me, too man
kinuko
2011/07/04 07:43:52
They are named like that in order to make them dis
| |
691 : public QuotaManager::DatabaseTaskBase { | |
692 public: | |
693 OriginModifyRecordDatabaseTask( | |
694 QuotaManager* manager, | |
695 const GURL& origin, | |
696 StorageType type, | |
697 base::Time modified_time) | |
698 : DatabaseTaskBase(manager), | |
699 origin_(origin), | |
700 type_(type), | |
701 modified_time_(modified_time) {} | |
702 | |
703 protected: | |
704 virtual void RunOnTargetThread() OVERRIDE { | |
705 if (!database()->SetOriginLastModifiedTime( | |
706 origin_, type_, modified_time_)) { | |
707 set_db_disabled(true); | |
708 } | |
709 } | |
710 virtual void DatabaseTaskCompleted() OVERRIDE {} | |
711 | |
712 private: | |
713 GURL origin_; | |
714 StorageType type_; | |
715 base::Time modified_time_; | |
716 }; | |
717 | |
718 class QuotaManager::OriginsModifiedSinceRetrieveTask | |
719 : public QuotaManager::DatabaseTaskBase { | |
720 public: | |
721 OriginsModifiedSinceRetrieveTask( | |
722 QuotaManager* manager, | |
723 StorageType type, | |
724 base::Time modified_since, | |
725 GetOriginsCallback* callback) | |
726 : DatabaseTaskBase(manager), | |
727 type_(type), | |
728 modified_since_(modified_since), | |
729 callback_(callback) {} | |
730 | |
731 protected: | |
732 virtual void RunOnTargetThread() OVERRIDE { | |
733 if (!database()->GetOriginsModifiedSince( | |
734 type_, &origins_, modified_since_)) { | |
735 set_db_disabled(true); | |
736 } | |
737 } | |
738 | |
739 virtual void DatabaseTaskCompleted() OVERRIDE { | |
740 callback_->Run(origins_); | |
741 } | |
742 | |
743 virtual void Aborted() OVERRIDE { | |
744 callback_->Run(std::set<GURL>()); | |
745 } | |
746 | |
747 private: | |
748 StorageType type_; | |
749 base::Time modified_since_; | |
750 std::set<GURL> origins_; | |
751 scoped_ptr<GetOriginsCallback> callback_; | |
752 }; | |
753 | |
691 class QuotaManager::DumpQuotaTableTask | 754 class QuotaManager::DumpQuotaTableTask |
692 : public QuotaManager::DatabaseTaskBase { | 755 : public QuotaManager::DatabaseTaskBase { |
693 private: | 756 private: |
694 typedef QuotaManager::DumpQuotaTableTask self_type; | 757 typedef QuotaManager::DumpQuotaTableTask self_type; |
695 typedef QuotaManager::DumpQuotaTableCallback Callback; | 758 typedef QuotaManager::DumpQuotaTableCallback Callback; |
696 typedef QuotaManager::QuotaTableEntry TableEntry; | 759 typedef QuotaManager::QuotaTableEntry TableEntry; |
697 typedef QuotaManager::QuotaTableEntries TableEntries; | 760 typedef QuotaManager::QuotaTableEntries TableEntries; |
698 typedef QuotaDatabase::QuotaTableCallback TableCallback; | 761 typedef QuotaDatabase::QuotaTableCallback TableCallback; |
699 | 762 |
700 public: | 763 public: |
701 DumpQuotaTableTask( | 764 DumpQuotaTableTask( |
702 QuotaManager* manager, | 765 QuotaManager* manager, |
703 Callback* callback) | 766 Callback* callback) |
704 : DatabaseTaskBase(manager), | 767 : DatabaseTaskBase(manager), |
705 callback_(callback) { | 768 callback_(callback) { |
706 } | 769 } |
707 protected: | 770 protected: |
708 virtual void RunOnTargetThread() OVERRIDE { | 771 virtual void RunOnTargetThread() OVERRIDE { |
709 if (!database()->DumpQuotaTable( | 772 if (!database()->DumpQuotaTable( |
710 new TableCallback( | 773 new TableCallback( |
711 base::Bind(&self_type::AppendEntry, this)))) | 774 base::Bind(&self_type::AppendEntry, this)))) |
712 set_db_disabled(true); | 775 set_db_disabled(true); |
713 } | 776 } |
714 | 777 |
715 virtual void Aborted() OVERRIDE { | 778 virtual void Aborted() OVERRIDE { |
716 callback_->Run(entries_); | 779 callback_->Run(TableEntries()); |
717 } | 780 } |
718 | 781 |
719 virtual void DatabaseTaskCompleted() OVERRIDE { | 782 virtual void DatabaseTaskCompleted() OVERRIDE { |
720 callback_->Run(entries_); | 783 callback_->Run(entries_); |
721 } | 784 } |
722 | 785 |
723 private: | 786 private: |
724 bool AppendEntry(const TableEntry& entry) { | 787 bool AppendEntry(const TableEntry& entry) { |
725 entries_.push_back(entry); | 788 entries_.push_back(entry); |
726 return true; | 789 return true; |
727 } | 790 } |
728 | 791 |
729 scoped_ptr<Callback> callback_; | 792 scoped_ptr<Callback> callback_; |
730 TableEntries entries_; | 793 TableEntries entries_; |
731 }; | 794 }; |
732 | 795 |
733 class QuotaManager::DumpLastAccessTimeTableTask | 796 class QuotaManager::DumpOriginInfoTableTask |
734 : public QuotaManager::DatabaseTaskBase { | 797 : public QuotaManager::DatabaseTaskBase { |
735 private: | 798 private: |
736 typedef QuotaManager::DumpLastAccessTimeTableTask self_type; | 799 typedef QuotaManager::DumpOriginInfoTableTask self_type; |
737 typedef QuotaManager::DumpLastAccessTimeTableCallback Callback; | 800 typedef QuotaManager::DumpOriginInfoTableCallback Callback; |
738 typedef QuotaManager::LastAccessTimeTableEntry TableEntry; | 801 typedef QuotaManager::OriginInfoTableEntry TableEntry; |
739 typedef QuotaManager::LastAccessTimeTableEntries TableEntries; | 802 typedef QuotaManager::OriginInfoTableEntries TableEntries; |
740 typedef QuotaDatabase::LastAccessTimeTableCallback TableCallback; | 803 typedef QuotaDatabase::OriginInfoTableCallback TableCallback; |
741 | 804 |
742 public: | 805 public: |
743 DumpLastAccessTimeTableTask( | 806 DumpOriginInfoTableTask( |
744 QuotaManager* manager, | 807 QuotaManager* manager, |
745 Callback* callback) | 808 Callback* callback) |
746 : DatabaseTaskBase(manager), | 809 : DatabaseTaskBase(manager), |
747 callback_(callback) { | 810 callback_(callback) { |
748 } | 811 } |
749 protected: | 812 protected: |
750 virtual void RunOnTargetThread() OVERRIDE { | 813 virtual void RunOnTargetThread() OVERRIDE { |
751 if (!database()->DumpLastAccessTimeTable( | 814 if (!database()->DumpOriginInfoTable( |
752 new TableCallback( | 815 new TableCallback( |
753 base::Bind(&self_type::AppendEntry, this)))) | 816 base::Bind(&self_type::AppendEntry, this)))) |
754 set_db_disabled(true); | 817 set_db_disabled(true); |
755 } | 818 } |
756 | 819 |
757 virtual void Aborted() OVERRIDE { | 820 virtual void Aborted() OVERRIDE { |
758 callback_->Run(entries_); | 821 callback_->Run(TableEntries()); |
759 } | 822 } |
760 | 823 |
761 virtual void DatabaseTaskCompleted() OVERRIDE { | 824 virtual void DatabaseTaskCompleted() OVERRIDE { |
762 callback_->Run(entries_); | 825 callback_->Run(entries_); |
763 } | 826 } |
764 | 827 |
765 private: | 828 private: |
766 bool AppendEntry(const TableEntry& entry) { | 829 bool AppendEntry(const TableEntry& entry) { |
767 entries_.push_back(entry); | 830 entries_.push_back(entry); |
768 return true; | 831 return true; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 if (temporary_storage_evictor_.get()) { | 995 if (temporary_storage_evictor_.get()) { |
933 std::map<std::string, int64> stats; | 996 std::map<std::string, int64> stats; |
934 temporary_storage_evictor_->GetStatistics(&stats); | 997 temporary_storage_evictor_->GetStatistics(&stats); |
935 for (std::map<std::string, int64>::iterator p = stats.begin(); | 998 for (std::map<std::string, int64>::iterator p = stats.begin(); |
936 p != stats.end(); | 999 p != stats.end(); |
937 ++p) | 1000 ++p) |
938 (*statistics)[p->first] = base::Int64ToString(p->second); | 1001 (*statistics)[p->first] = base::Int64ToString(p->second); |
939 } | 1002 } |
940 } | 1003 } |
941 | 1004 |
1005 void QuotaManager::GetOriginsModifiedSince( | |
1006 StorageType type, | |
1007 base::Time modified_since, | |
1008 GetOriginsCallback* callback) { | |
1009 LazyInitialize(); | |
1010 make_scoped_refptr(new OriginsModifiedSinceRetrieveTask( | |
1011 this, type, modified_since, callback))->Start(); | |
1012 } | |
1013 | |
942 void QuotaManager::LazyInitialize() { | 1014 void QuotaManager::LazyInitialize() { |
943 DCHECK(io_thread_->BelongsToCurrentThread()); | 1015 DCHECK(io_thread_->BelongsToCurrentThread()); |
944 if (database_.get()) { | 1016 if (database_.get()) { |
945 // Initialization seems to be done already. | 1017 // Initialization seems to be done already. |
946 return; | 1018 return; |
947 } | 1019 } |
948 | 1020 |
949 // Use an empty path to open an in-memory only databse for incognito. | 1021 // Use an empty path to open an in-memory only databse for incognito. |
950 database_.reset(new QuotaDatabase(is_incognito_ ? FilePath() : | 1022 database_.reset(new QuotaDatabase(is_incognito_ ? FilePath() : |
951 profile_path_.AppendASCII(kDatabaseName))); | 1023 profile_path_.AppendASCII(kDatabaseName))); |
(...skipping 18 matching lines...) Expand all Loading... | |
970 | 1042 |
971 void QuotaManager::NotifyStorageAccessed( | 1043 void QuotaManager::NotifyStorageAccessed( |
972 QuotaClient::ID client_id, | 1044 QuotaClient::ID client_id, |
973 const GURL& origin, StorageType type) { | 1045 const GURL& origin, StorageType type) { |
974 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); | 1046 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); |
975 } | 1047 } |
976 | 1048 |
977 void QuotaManager::NotifyStorageModified( | 1049 void QuotaManager::NotifyStorageModified( |
978 QuotaClient::ID client_id, | 1050 QuotaClient::ID client_id, |
979 const GURL& origin, StorageType type, int64 delta) { | 1051 const GURL& origin, StorageType type, int64 delta) { |
980 LazyInitialize(); | 1052 NotifyStorageModifiedInternal(client_id, origin, type, delta, |
981 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); | 1053 base::Time::Now()); |
982 } | 1054 } |
983 | 1055 |
984 void QuotaManager::NotifyOriginInUse(const GURL& origin) { | 1056 void QuotaManager::NotifyOriginInUse(const GURL& origin) { |
985 DCHECK(io_thread_->BelongsToCurrentThread()); | 1057 DCHECK(io_thread_->BelongsToCurrentThread()); |
986 origins_in_use_[origin]++; | 1058 origins_in_use_[origin]++; |
987 } | 1059 } |
988 | 1060 |
989 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { | 1061 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { |
990 DCHECK(io_thread_->BelongsToCurrentThread()); | 1062 DCHECK(io_thread_->BelongsToCurrentThread()); |
991 DCHECK(IsOriginInUse(origin)); | 1063 DCHECK(IsOriginInUse(origin)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1030 base::Time accessed_time) { | 1102 base::Time accessed_time) { |
1031 LazyInitialize(); | 1103 LazyInitialize(); |
1032 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { | 1104 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { |
1033 // Record the accessed origins while GetLRUOrigin task is runing | 1105 // Record the accessed origins while GetLRUOrigin task is runing |
1034 // to filter out them from eviction. | 1106 // to filter out them from eviction. |
1035 access_notified_origins_.insert(origin); | 1107 access_notified_origins_.insert(origin); |
1036 } | 1108 } |
1037 | 1109 |
1038 if (db_disabled_) | 1110 if (db_disabled_) |
1039 return; | 1111 return; |
1040 scoped_refptr<OriginAccessRecordDatabaseTask> task( | 1112 make_scoped_refptr(new OriginAccessRecordDatabaseTask( |
1041 new OriginAccessRecordDatabaseTask(this, origin, type, accessed_time)); | 1113 this, origin, type, accessed_time))->Start(); |
1042 task->Start(); | 1114 } |
1115 | |
1116 void QuotaManager::NotifyStorageModifiedInternal( | |
1117 QuotaClient::ID client_id, | |
1118 const GURL& origin, | |
1119 StorageType type, | |
1120 int64 delta, | |
1121 base::Time modified_time) { | |
1122 LazyInitialize(); | |
1123 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); | |
1124 make_scoped_refptr(new OriginModifyRecordDatabaseTask( | |
1125 this, origin, type, modified_time))->Start(); | |
1043 } | 1126 } |
1044 | 1127 |
1045 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { | 1128 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { |
1046 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); | 1129 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); |
1047 } | 1130 } |
1048 | 1131 |
1049 void QuotaManager::DumpLastAccessTimeTable( | 1132 void QuotaManager::DumpOriginInfoTable( |
1050 DumpLastAccessTimeTableCallback* callback) { | 1133 DumpOriginInfoTableCallback* callback) { |
1051 make_scoped_refptr(new DumpLastAccessTimeTableTask(this, callback))->Start(); | 1134 make_scoped_refptr(new DumpOriginInfoTableTask(this, callback))->Start(); |
1052 } | 1135 } |
1053 | 1136 |
1054 | 1137 |
1055 void QuotaManager::DeleteOriginFromDatabase( | 1138 void QuotaManager::DeleteOriginFromDatabase( |
1056 const GURL& origin, StorageType type) { | 1139 const GURL& origin, StorageType type) { |
1057 LazyInitialize(); | 1140 LazyInitialize(); |
1058 if (db_disabled_) | 1141 if (db_disabled_) |
1059 return; | 1142 return; |
1060 scoped_refptr<OriginDeletionDatabaseTask> task = | 1143 scoped_refptr<OriginDeletionDatabaseTask> task = |
1061 new OriginDeletionDatabaseTask(this, origin, type); | 1144 new OriginDeletionDatabaseTask(this, origin, type); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1322 | 1405 |
1323 QuotaManagerProxy::QuotaManagerProxy( | 1406 QuotaManagerProxy::QuotaManagerProxy( |
1324 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1407 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
1325 : manager_(manager), io_thread_(io_thread) { | 1408 : manager_(manager), io_thread_(io_thread) { |
1326 } | 1409 } |
1327 | 1410 |
1328 QuotaManagerProxy::~QuotaManagerProxy() { | 1411 QuotaManagerProxy::~QuotaManagerProxy() { |
1329 } | 1412 } |
1330 | 1413 |
1331 } // namespace quota | 1414 } // namespace quota |
OLD | NEW |