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 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 } | 681 } |
682 } | 682 } |
683 virtual void DatabaseTaskCompleted() OVERRIDE {} | 683 virtual void DatabaseTaskCompleted() OVERRIDE {} |
684 | 684 |
685 private: | 685 private: |
686 GURL origin_; | 686 GURL origin_; |
687 StorageType type_; | 687 StorageType type_; |
688 base::Time accessed_time_; | 688 base::Time accessed_time_; |
689 }; | 689 }; |
690 | 690 |
| 691 class QuotaManager::OriginModifyRecordDatabaseTask |
| 692 : public QuotaManager::DatabaseTaskBase { |
| 693 public: |
| 694 OriginModifyRecordDatabaseTask( |
| 695 QuotaManager* manager, |
| 696 const GURL& origin, |
| 697 StorageType type, |
| 698 base::Time modified_time) |
| 699 : DatabaseTaskBase(manager), |
| 700 origin_(origin), |
| 701 type_(type), |
| 702 modified_time_(modified_time) {} |
| 703 |
| 704 protected: |
| 705 virtual void RunOnTargetThread() OVERRIDE { |
| 706 if (!database()->SetOriginLastModifiedTime( |
| 707 origin_, type_, modified_time_)) { |
| 708 set_db_disabled(true); |
| 709 } |
| 710 } |
| 711 virtual void DatabaseTaskCompleted() OVERRIDE {} |
| 712 |
| 713 private: |
| 714 GURL origin_; |
| 715 StorageType type_; |
| 716 base::Time modified_time_; |
| 717 }; |
| 718 |
| 719 class QuotaManager::OriginsModifiedSinceRetrieveTask |
| 720 : public QuotaManager::DatabaseTaskBase { |
| 721 public: |
| 722 OriginsModifiedSinceRetrieveTask( |
| 723 QuotaManager* manager, |
| 724 StorageType type, |
| 725 base::Time modified_since, |
| 726 GetOriginsCallback* callback) |
| 727 : DatabaseTaskBase(manager), |
| 728 type_(type), |
| 729 modified_since_(modified_since), |
| 730 callback_(callback) {} |
| 731 |
| 732 protected: |
| 733 virtual void RunOnTargetThread() OVERRIDE { |
| 734 if (!database()->GetOriginsModifiedSince( |
| 735 type_, &origins_, modified_since_)) { |
| 736 set_db_disabled(true); |
| 737 } |
| 738 } |
| 739 |
| 740 virtual void DatabaseTaskCompleted() OVERRIDE { |
| 741 callback_->Run(origins_); |
| 742 } |
| 743 |
| 744 virtual void Aborted() OVERRIDE { |
| 745 callback_->Run(origins_); |
| 746 } |
| 747 |
| 748 private: |
| 749 StorageType type_; |
| 750 base::Time modified_since_; |
| 751 std::set<GURL> origins_; |
| 752 scoped_ptr<GetOriginsCallback> callback_; |
| 753 }; |
| 754 |
691 class QuotaManager::DumpQuotaTableTask | 755 class QuotaManager::DumpQuotaTableTask |
692 : public QuotaManager::DatabaseTaskBase { | 756 : public QuotaManager::DatabaseTaskBase { |
693 private: | 757 private: |
694 typedef QuotaManager::DumpQuotaTableTask self_type; | 758 typedef QuotaManager::DumpQuotaTableTask self_type; |
695 typedef QuotaManager::DumpQuotaTableCallback Callback; | 759 typedef QuotaManager::DumpQuotaTableCallback Callback; |
696 typedef QuotaManager::QuotaTableEntry TableEntry; | 760 typedef QuotaManager::QuotaTableEntry TableEntry; |
697 typedef QuotaManager::QuotaTableEntries TableEntries; | 761 typedef QuotaManager::QuotaTableEntries TableEntries; |
698 typedef QuotaDatabase::QuotaTableCallback TableCallback; | 762 typedef QuotaDatabase::QuotaTableCallback TableCallback; |
699 | 763 |
700 public: | 764 public: |
(...skipping 22 matching lines...) Expand all Loading... |
723 private: | 787 private: |
724 bool AppendEntry(const TableEntry& entry) { | 788 bool AppendEntry(const TableEntry& entry) { |
725 entries_.push_back(entry); | 789 entries_.push_back(entry); |
726 return true; | 790 return true; |
727 } | 791 } |
728 | 792 |
729 scoped_ptr<Callback> callback_; | 793 scoped_ptr<Callback> callback_; |
730 TableEntries entries_; | 794 TableEntries entries_; |
731 }; | 795 }; |
732 | 796 |
733 class QuotaManager::DumpLastAccessTimeTableTask | 797 class QuotaManager::DumpOriginInfoTableTask |
734 : public QuotaManager::DatabaseTaskBase { | 798 : public QuotaManager::DatabaseTaskBase { |
735 private: | 799 private: |
736 typedef QuotaManager::DumpLastAccessTimeTableTask self_type; | 800 typedef QuotaManager::DumpOriginInfoTableTask self_type; |
737 typedef QuotaManager::DumpLastAccessTimeTableCallback Callback; | 801 typedef QuotaManager::DumpOriginInfoTableCallback Callback; |
738 typedef QuotaManager::LastAccessTimeTableEntry TableEntry; | 802 typedef QuotaManager::OriginInfoTableEntry TableEntry; |
739 typedef QuotaManager::LastAccessTimeTableEntries TableEntries; | 803 typedef QuotaManager::OriginInfoTableEntries TableEntries; |
740 typedef QuotaDatabase::LastAccessTimeTableCallback TableCallback; | 804 typedef QuotaDatabase::OriginInfoTableCallback TableCallback; |
741 | 805 |
742 public: | 806 public: |
743 DumpLastAccessTimeTableTask( | 807 DumpOriginInfoTableTask( |
744 QuotaManager* manager, | 808 QuotaManager* manager, |
745 Callback* callback) | 809 Callback* callback) |
746 : DatabaseTaskBase(manager), | 810 : DatabaseTaskBase(manager), |
747 callback_(callback) { | 811 callback_(callback) { |
748 } | 812 } |
749 protected: | 813 protected: |
750 virtual void RunOnTargetThread() OVERRIDE { | 814 virtual void RunOnTargetThread() OVERRIDE { |
751 if (!database()->DumpLastAccessTimeTable( | 815 if (!database()->DumpOriginInfoTable( |
752 new TableCallback( | 816 new TableCallback( |
753 base::Bind(&self_type::AppendEntry, this)))) | 817 base::Bind(&self_type::AppendEntry, this)))) |
754 set_db_disabled(true); | 818 set_db_disabled(true); |
755 } | 819 } |
756 | 820 |
757 virtual void Aborted() OVERRIDE { | 821 virtual void Aborted() OVERRIDE { |
758 callback_->Run(entries_); | 822 callback_->Run(entries_); |
759 } | 823 } |
760 | 824 |
761 virtual void DatabaseTaskCompleted() OVERRIDE { | 825 virtual void DatabaseTaskCompleted() OVERRIDE { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 | 1034 |
971 void QuotaManager::NotifyStorageAccessed( | 1035 void QuotaManager::NotifyStorageAccessed( |
972 QuotaClient::ID client_id, | 1036 QuotaClient::ID client_id, |
973 const GURL& origin, StorageType type) { | 1037 const GURL& origin, StorageType type) { |
974 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); | 1038 NotifyStorageAccessedInternal(client_id, origin, type, base::Time::Now()); |
975 } | 1039 } |
976 | 1040 |
977 void QuotaManager::NotifyStorageModified( | 1041 void QuotaManager::NotifyStorageModified( |
978 QuotaClient::ID client_id, | 1042 QuotaClient::ID client_id, |
979 const GURL& origin, StorageType type, int64 delta) { | 1043 const GURL& origin, StorageType type, int64 delta) { |
980 LazyInitialize(); | 1044 NotifyStorageModifiedInternal(client_id, origin, type, delta, |
981 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); | 1045 base::Time::Now()); |
982 } | 1046 } |
983 | 1047 |
984 void QuotaManager::NotifyOriginInUse(const GURL& origin) { | 1048 void QuotaManager::NotifyOriginInUse(const GURL& origin) { |
985 DCHECK(io_thread_->BelongsToCurrentThread()); | 1049 DCHECK(io_thread_->BelongsToCurrentThread()); |
986 origins_in_use_[origin]++; | 1050 origins_in_use_[origin]++; |
987 } | 1051 } |
988 | 1052 |
989 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { | 1053 void QuotaManager::NotifyOriginNoLongerInUse(const GURL& origin) { |
990 DCHECK(io_thread_->BelongsToCurrentThread()); | 1054 DCHECK(io_thread_->BelongsToCurrentThread()); |
991 DCHECK(IsOriginInUse(origin)); | 1055 DCHECK(IsOriginInUse(origin)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 base::Time accessed_time) { | 1094 base::Time accessed_time) { |
1031 LazyInitialize(); | 1095 LazyInitialize(); |
1032 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { | 1096 if (type == kStorageTypeTemporary && lru_origin_callback_.get()) { |
1033 // Record the accessed origins while GetLRUOrigin task is runing | 1097 // Record the accessed origins while GetLRUOrigin task is runing |
1034 // to filter out them from eviction. | 1098 // to filter out them from eviction. |
1035 access_notified_origins_.insert(origin); | 1099 access_notified_origins_.insert(origin); |
1036 } | 1100 } |
1037 | 1101 |
1038 if (db_disabled_) | 1102 if (db_disabled_) |
1039 return; | 1103 return; |
1040 scoped_refptr<OriginAccessRecordDatabaseTask> task( | 1104 make_scoped_refptr(new OriginAccessRecordDatabaseTask( |
1041 new OriginAccessRecordDatabaseTask(this, origin, type, accessed_time)); | 1105 this, origin, type, accessed_time))->Start(); |
1042 task->Start(); | 1106 } |
| 1107 |
| 1108 void QuotaManager::NotifyStorageModifiedInternal( |
| 1109 QuotaClient::ID client_id, |
| 1110 const GURL& origin, |
| 1111 StorageType type, |
| 1112 int64 delta, |
| 1113 base::Time modified_time) { |
| 1114 LazyInitialize(); |
| 1115 GetUsageTracker(type)->UpdateUsageCache(client_id, origin, delta); |
| 1116 make_scoped_refptr(new OriginModifyRecordDatabaseTask( |
| 1117 this, origin, type, modified_time))->Start(); |
| 1118 } |
| 1119 |
| 1120 void QuotaManager::GetOriginsModifiedSince( |
| 1121 StorageType type, |
| 1122 base::Time modified_since, |
| 1123 GetOriginsCallback* callback) { |
| 1124 LazyInitialize(); |
| 1125 make_scoped_refptr(new OriginsModifiedSinceRetrieveTask( |
| 1126 this, type, modified_since, callback))->Start(); |
1043 } | 1127 } |
1044 | 1128 |
1045 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { | 1129 void QuotaManager::DumpQuotaTable(DumpQuotaTableCallback* callback) { |
1046 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); | 1130 make_scoped_refptr(new DumpQuotaTableTask(this, callback))->Start(); |
1047 } | 1131 } |
1048 | 1132 |
1049 void QuotaManager::DumpLastAccessTimeTable( | 1133 void QuotaManager::DumpOriginInfoTable( |
1050 DumpLastAccessTimeTableCallback* callback) { | 1134 DumpOriginInfoTableCallback* callback) { |
1051 make_scoped_refptr(new DumpLastAccessTimeTableTask(this, callback))->Start(); | 1135 make_scoped_refptr(new DumpOriginInfoTableTask(this, callback))->Start(); |
1052 } | 1136 } |
1053 | 1137 |
1054 | 1138 |
1055 void QuotaManager::DeleteOriginFromDatabase( | 1139 void QuotaManager::DeleteOriginFromDatabase( |
1056 const GURL& origin, StorageType type) { | 1140 const GURL& origin, StorageType type) { |
1057 LazyInitialize(); | 1141 LazyInitialize(); |
1058 if (db_disabled_) | 1142 if (db_disabled_) |
1059 return; | 1143 return; |
1060 scoped_refptr<OriginDeletionDatabaseTask> task = | 1144 scoped_refptr<OriginDeletionDatabaseTask> task = |
1061 new OriginDeletionDatabaseTask(this, origin, type); | 1145 new OriginDeletionDatabaseTask(this, origin, type); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 | 1406 |
1323 QuotaManagerProxy::QuotaManagerProxy( | 1407 QuotaManagerProxy::QuotaManagerProxy( |
1324 QuotaManager* manager, base::MessageLoopProxy* io_thread) | 1408 QuotaManager* manager, base::MessageLoopProxy* io_thread) |
1325 : manager_(manager), io_thread_(io_thread) { | 1409 : manager_(manager), io_thread_(io_thread) { |
1326 } | 1410 } |
1327 | 1411 |
1328 QuotaManagerProxy::~QuotaManagerProxy() { | 1412 QuotaManagerProxy::~QuotaManagerProxy() { |
1329 } | 1413 } |
1330 | 1414 |
1331 } // namespace quota | 1415 } // namespace quota |
OLD | NEW |