Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: webkit/appcache/appcache_storage_impl.cc

Issue 7031065: AppCache + Quota integration (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/appcache/appcache_storage_impl.h" 5 #include "webkit/appcache/appcache_storage_impl.h"
6 6
7 #include <set>
8
7 #include "app/sql/connection.h" 9 #include "app/sql/connection.h"
8 #include "app/sql/transaction.h" 10 #include "app/sql/transaction.h"
9 #include "base/file_util.h" 11 #include "base/file_util.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/message_loop.h" 13 #include "base/message_loop.h"
12 #include "base/stl_util-inl.h" 14 #include "base/stl_util-inl.h"
13 #include "base/string_util.h" 15 #include "base/string_util.h"
14 #include "net/base/cache_type.h" 16 #include "net/base/cache_type.h"
15 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
16 #include "webkit/appcache/appcache.h" 18 #include "webkit/appcache/appcache.h"
17 #include "webkit/appcache/appcache_database.h" 19 #include "webkit/appcache/appcache_database.h"
18 #include "webkit/appcache/appcache_entry.h" 20 #include "webkit/appcache/appcache_entry.h"
19 #include "webkit/appcache/appcache_group.h" 21 #include "webkit/appcache/appcache_group.h"
20 #include "webkit/appcache/appcache_histograms.h" 22 #include "webkit/appcache/appcache_histograms.h"
21 #include "webkit/appcache/appcache_policy.h" 23 #include "webkit/appcache/appcache_policy.h"
24 #include "webkit/appcache/appcache_quota_client.h"
22 #include "webkit/appcache/appcache_response.h" 25 #include "webkit/appcache/appcache_response.h"
23 #include "webkit/appcache/appcache_service.h" 26 #include "webkit/appcache/appcache_service.h"
24 #include "webkit/appcache/appcache_thread.h" 27 #include "webkit/appcache/appcache_thread.h"
28 #include "webkit/quota/quota_client.h"
29 #include "webkit/quota/quota_manager.h"
25 #include "webkit/quota/special_storage_policy.h" 30 #include "webkit/quota/special_storage_policy.h"
26 31
27 namespace { 32 namespace {
28 // Helper with no return value for use with NewRunnableFunction. 33 // Helper with no return value for use with NewRunnableFunction.
29 void DeleteDirectory(const FilePath& path) { 34 void DeleteDirectory(const FilePath& path) {
30 file_util::Delete(path, true); 35 file_util::Delete(path, true);
31 } 36 }
32 } 37 }
33 38
34 namespace appcache { 39 namespace appcache {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 last_cache_id_(0), last_response_id_(0), 144 last_cache_id_(0), last_response_id_(0),
140 last_deletable_response_rowid_(0) {} 145 last_deletable_response_rowid_(0) {}
141 146
142 virtual void Run(); 147 virtual void Run();
143 virtual void RunCompleted(); 148 virtual void RunCompleted();
144 149
145 int64 last_group_id_; 150 int64 last_group_id_;
146 int64 last_cache_id_; 151 int64 last_cache_id_;
147 int64 last_response_id_; 152 int64 last_response_id_;
148 int64 last_deletable_response_rowid_; 153 int64 last_deletable_response_rowid_;
149 std::set<GURL> origins_with_groups_; 154 std::map<GURL, int64> usage_map_;
150 }; 155 };
151 156
152 void AppCacheStorageImpl::InitTask::Run() { 157 void AppCacheStorageImpl::InitTask::Run() {
153 database_->FindLastStorageIds( 158 database_->FindLastStorageIds(
154 &last_group_id_, &last_cache_id_, &last_response_id_, 159 &last_group_id_, &last_cache_id_, &last_response_id_,
155 &last_deletable_response_rowid_); 160 &last_deletable_response_rowid_);
156 database_->FindOriginsWithGroups(&origins_with_groups_); 161 database_->GetAllOriginUsage(&usage_map_);
157 } 162 }
158 163
159 void AppCacheStorageImpl::InitTask::RunCompleted() { 164 void AppCacheStorageImpl::InitTask::RunCompleted() {
160 storage_->last_group_id_ = last_group_id_; 165 storage_->last_group_id_ = last_group_id_;
161 storage_->last_cache_id_ = last_cache_id_; 166 storage_->last_cache_id_ = last_cache_id_;
162 storage_->last_response_id_ = last_response_id_; 167 storage_->last_response_id_ = last_response_id_;
163 storage_->last_deletable_response_rowid_ = last_deletable_response_rowid_; 168 storage_->last_deletable_response_rowid_ = last_deletable_response_rowid_;
164 169
165 if (!storage_->is_disabled()) { 170 if (!storage_->is_disabled()) {
166 storage_->origins_with_groups_.swap(origins_with_groups_); 171 storage_->usage_map_.swap(usage_map_);
167
168 const int kDelayMillis = 5 * 60 * 1000; // Five minutes. 172 const int kDelayMillis = 5 * 60 * 1000; // Five minutes.
169 MessageLoop::current()->PostDelayedTask(FROM_HERE, 173 MessageLoop::current()->PostDelayedTask(FROM_HERE,
170 storage_->method_factory_.NewRunnableMethod( 174 storage_->method_factory_.NewRunnableMethod(
171 &AppCacheStorageImpl::DelayedStartDeletingUnusedResponses), 175 &AppCacheStorageImpl::DelayedStartDeletingUnusedResponses),
172 kDelayMillis); 176 kDelayMillis);
173 } 177 }
178
179 if (storage_->service()->quota_client())
180 storage_->service()->quota_client()->NotifyAppCacheReady();
174 } 181 }
175 182
176 // CloseConnectionTask ------- 183 // CloseConnectionTask -------
177 184
178 class AppCacheStorageImpl::CloseConnectionTask : public DatabaseTask { 185 class AppCacheStorageImpl::CloseConnectionTask : public DatabaseTask {
179 public: 186 public:
180 explicit CloseConnectionTask(AppCacheStorageImpl* storage) 187 explicit CloseConnectionTask(AppCacheStorageImpl* storage)
181 : DatabaseTask(storage) {} 188 : DatabaseTask(storage) {}
182 189
183 virtual void Run() { database_->CloseConnection(); } 190 virtual void Run() { database_->CloseConnection(); }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // We have to update foriegn entries if MarkEntryAsForeignTasks 302 // We have to update foriegn entries if MarkEntryAsForeignTasks
296 // are in flight. 303 // are in flight.
297 std::vector<GURL> urls; 304 std::vector<GURL> urls;
298 storage_->GetPendingForeignMarkingsForCache(cache->get()->cache_id(), &urls); 305 storage_->GetPendingForeignMarkingsForCache(cache->get()->cache_id(), &urls);
299 for (std::vector<GURL>::iterator iter = urls.begin(); 306 for (std::vector<GURL>::iterator iter = urls.begin();
300 iter != urls.end(); ++iter) { 307 iter != urls.end(); ++iter) {
301 DCHECK(cache->get()->GetEntry(*iter)); 308 DCHECK(cache->get()->GetEntry(*iter));
302 cache->get()->GetEntry(*iter)->add_types(AppCacheEntry::FOREIGN); 309 cache->get()->GetEntry(*iter)->add_types(AppCacheEntry::FOREIGN);
303 } 310 }
304 311
312 storage_->NotifyStorageAccessed(group_record_.origin);
313
305 // TODO(michaeln): Maybe verify that the responses we expect to exist 314 // TODO(michaeln): Maybe verify that the responses we expect to exist
306 // do actually exist in the disk_cache (and if not then what?) 315 // do actually exist in the disk_cache (and if not then what?)
307 } 316 }
308 317
309 // CacheLoadTask ------- 318 // CacheLoadTask -------
310 319
311 class AppCacheStorageImpl::CacheLoadTask : public StoreOrLoadTask { 320 class AppCacheStorageImpl::CacheLoadTask : public StoreOrLoadTask {
312 public: 321 public:
313 CacheLoadTask(int64 cache_id, AppCacheStorageImpl* storage) 322 CacheLoadTask(int64 cache_id, AppCacheStorageImpl* storage)
314 : StoreOrLoadTask(storage), cache_id_(cache_id), 323 : StoreOrLoadTask(storage), cache_id_(cache_id),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 406
398 virtual void Run(); 407 virtual void Run();
399 virtual void RunCompleted(); 408 virtual void RunCompleted();
400 virtual void CancelCompletion(); 409 virtual void CancelCompletion();
401 410
402 scoped_refptr<AppCacheGroup> group_; 411 scoped_refptr<AppCacheGroup> group_;
403 scoped_refptr<AppCache> cache_; 412 scoped_refptr<AppCache> cache_;
404 bool success_; 413 bool success_;
405 bool would_exceed_quota_; 414 bool would_exceed_quota_;
406 int64 quota_override_; 415 int64 quota_override_;
416 int64 new_origin_usage_;
407 std::vector<int64> newly_deletable_response_ids_; 417 std::vector<int64> newly_deletable_response_ids_;
408 }; 418 };
409 419
410 AppCacheStorageImpl::StoreGroupAndCacheTask::StoreGroupAndCacheTask( 420 AppCacheStorageImpl::StoreGroupAndCacheTask::StoreGroupAndCacheTask(
411 AppCacheStorageImpl* storage, AppCacheGroup* group, AppCache* newest_cache) 421 AppCacheStorageImpl* storage, AppCacheGroup* group, AppCache* newest_cache)
412 : StoreOrLoadTask(storage), group_(group), cache_(newest_cache), 422 : StoreOrLoadTask(storage), group_(group), cache_(newest_cache),
413 success_(false), would_exceed_quota_(false), 423 success_(false), would_exceed_quota_(false),
414 quota_override_(-1) { 424 quota_override_(-1), new_origin_usage_(-1) {
415 group_record_.group_id = group->group_id(); 425 group_record_.group_id = group->group_id();
416 group_record_.manifest_url = group->manifest_url(); 426 group_record_.manifest_url = group->manifest_url();
417 group_record_.origin = group_record_.manifest_url.GetOrigin(); 427 group_record_.origin = group_record_.manifest_url.GetOrigin();
418 newest_cache->ToDatabaseRecords( 428 newest_cache->ToDatabaseRecords(
419 group, 429 group,
420 &cache_record_, &entry_records_, &fallback_namespace_records_, 430 &cache_record_, &entry_records_, &fallback_namespace_records_,
421 &online_whitelist_records_); 431 &online_whitelist_records_);
422 432
423 if (storage->service()->special_storage_policy() && 433 if (storage->service()->special_storage_policy() &&
424 storage->service()->special_storage_policy()->IsStorageUnlimited( 434 storage->service()->special_storage_policy()->IsStorageUnlimited(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 database_->InsertFallbackNameSpaceRecords(fallback_namespace_records_)&& 501 database_->InsertFallbackNameSpaceRecords(fallback_namespace_records_)&&
492 database_->InsertOnlineWhiteListRecords(online_whitelist_records_); 502 database_->InsertOnlineWhiteListRecords(online_whitelist_records_);
493 503
494 if (!success_) 504 if (!success_)
495 return; 505 return;
496 506
497 int64 quota = (quota_override_ >= 0) ? 507 int64 quota = (quota_override_ >= 0) ?
498 quota_override_ : 508 quota_override_ :
499 database_->GetOriginQuota(group_record_.origin); 509 database_->GetOriginQuota(group_record_.origin);
500 510
501 if (database_->GetOriginUsage(group_record_.origin) > quota) { 511 new_origin_usage_ = database_->GetOriginUsage(group_record_.origin);
512 if (new_origin_usage_ > quota) {
502 would_exceed_quota_ = true; 513 would_exceed_quota_ = true;
503 success_ = false; 514 success_ = false;
504 return; 515 return;
505 } 516 }
506 517
507 success_ = transaction.Commit(); 518 success_ = transaction.Commit();
508 } 519 }
509 520
510 void AppCacheStorageImpl::StoreGroupAndCacheTask::RunCompleted() { 521 void AppCacheStorageImpl::StoreGroupAndCacheTask::RunCompleted() {
511 if (success_) { 522 if (success_) {
512 storage_->origins_with_groups_.insert(group_->manifest_url().GetOrigin()); 523 storage_->UpdateUsageMapAndNotify(
524 group_->manifest_url().GetOrigin(), new_origin_usage_);
513 if (cache_ != group_->newest_complete_cache()) { 525 if (cache_ != group_->newest_complete_cache()) {
514 cache_->set_complete(true); 526 cache_->set_complete(true);
515 group_->AddCache(cache_); 527 group_->AddCache(cache_);
516 } 528 }
517 if (group_->creation_time().is_null()) 529 if (group_->creation_time().is_null())
518 group_->set_creation_time(group_record_.creation_time); 530 group_->set_creation_time(group_record_.creation_time);
519 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); 531 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_);
520 } 532 }
521 FOR_EACH_DELEGATE(delegates_, 533 FOR_EACH_DELEGATE(delegates_,
522 OnGroupAndNewestCacheStored(group_, cache_, success_, 534 OnGroupAndNewestCacheStored(group_, cache_, success_,
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 class AppCacheStorageImpl::MakeGroupObsoleteTask : public DatabaseTask { 842 class AppCacheStorageImpl::MakeGroupObsoleteTask : public DatabaseTask {
831 public: 843 public:
832 MakeGroupObsoleteTask(AppCacheStorageImpl* storage, AppCacheGroup* group); 844 MakeGroupObsoleteTask(AppCacheStorageImpl* storage, AppCacheGroup* group);
833 845
834 virtual void Run(); 846 virtual void Run();
835 virtual void RunCompleted(); 847 virtual void RunCompleted();
836 virtual void CancelCompletion(); 848 virtual void CancelCompletion();
837 849
838 scoped_refptr<AppCacheGroup> group_; 850 scoped_refptr<AppCacheGroup> group_;
839 int64 group_id_; 851 int64 group_id_;
852 GURL origin_;
840 bool success_; 853 bool success_;
841 std::set<GURL> origins_with_groups_; 854 int64 new_origin_usage_;
842 std::vector<int64> newly_deletable_response_ids_; 855 std::vector<int64> newly_deletable_response_ids_;
843 }; 856 };
844 857
845 AppCacheStorageImpl::MakeGroupObsoleteTask::MakeGroupObsoleteTask( 858 AppCacheStorageImpl::MakeGroupObsoleteTask::MakeGroupObsoleteTask(
846 AppCacheStorageImpl* storage, AppCacheGroup* group) 859 AppCacheStorageImpl* storage, AppCacheGroup* group)
847 : DatabaseTask(storage), group_(group), group_id_(group->group_id()), 860 : DatabaseTask(storage), group_(group), group_id_(group->group_id()),
848 success_(false) { 861 origin_(group->manifest_url().GetOrigin()),
862 success_(false), new_origin_usage_(-1) {
849 } 863 }
850 864
851 void AppCacheStorageImpl::MakeGroupObsoleteTask::Run() { 865 void AppCacheStorageImpl::MakeGroupObsoleteTask::Run() {
852 DCHECK(!success_); 866 DCHECK(!success_);
853 sql::Connection* connection = database_->db_connection(); 867 sql::Connection* connection = database_->db_connection();
854 if (!connection) 868 if (!connection)
855 return; 869 return;
856 870
857 sql::Transaction transaction(connection); 871 sql::Transaction transaction(connection);
858 if (!transaction.Begin()) 872 if (!transaction.Begin())
859 return; 873 return;
860 874
861 AppCacheDatabase::GroupRecord group_record; 875 AppCacheDatabase::GroupRecord group_record;
862 if (!database_->FindGroup(group_id_, &group_record)) { 876 if (!database_->FindGroup(group_id_, &group_record)) {
863 // This group doesn't exists in the database, nothing todo here. 877 // This group doesn't exists in the database, nothing todo here.
878 new_origin_usage_ = database_->GetOriginUsage(origin_);
864 success_ = true; 879 success_ = true;
865 return; 880 return;
866 } 881 }
867 882
883 DCHECK_EQ(group_record.origin, origin_);
884
868 AppCacheDatabase::CacheRecord cache_record; 885 AppCacheDatabase::CacheRecord cache_record;
869 if (database_->FindCacheForGroup(group_id_, &cache_record)) { 886 if (database_->FindCacheForGroup(group_id_, &cache_record)) {
870 database_->FindResponseIdsForCacheAsVector(cache_record.cache_id, 887 database_->FindResponseIdsForCacheAsVector(cache_record.cache_id,
871 &newly_deletable_response_ids_); 888 &newly_deletable_response_ids_);
872 success_ = 889 success_ =
873 database_->DeleteGroup(group_id_) && 890 database_->DeleteGroup(group_id_) &&
874 database_->DeleteCache(cache_record.cache_id) && 891 database_->DeleteCache(cache_record.cache_id) &&
875 database_->DeleteEntriesForCache(cache_record.cache_id) && 892 database_->DeleteEntriesForCache(cache_record.cache_id) &&
876 database_->DeleteFallbackNameSpacesForCache(cache_record.cache_id) && 893 database_->DeleteFallbackNameSpacesForCache(cache_record.cache_id) &&
877 database_->DeleteOnlineWhiteListForCache(cache_record.cache_id) && 894 database_->DeleteOnlineWhiteListForCache(cache_record.cache_id) &&
878 database_->InsertDeletableResponseIds(newly_deletable_response_ids_); 895 database_->InsertDeletableResponseIds(newly_deletable_response_ids_);
879 } else { 896 } else {
880 NOTREACHED() << "A existing group without a cache is unexpected"; 897 NOTREACHED() << "A existing group without a cache is unexpected";
881 success_ = database_->DeleteGroup(group_id_); 898 success_ = database_->DeleteGroup(group_id_);
882 } 899 }
883 900
884 success_ = success_ && 901 new_origin_usage_ = database_->GetOriginUsage(origin_);
885 database_->FindOriginsWithGroups(&origins_with_groups_) && 902 success_ = success_ && transaction.Commit();
886 transaction.Commit();
887 } 903 }
888 904
889 void AppCacheStorageImpl::MakeGroupObsoleteTask::RunCompleted() { 905 void AppCacheStorageImpl::MakeGroupObsoleteTask::RunCompleted() {
890 if (success_) { 906 if (success_) {
891 group_->set_obsolete(true); 907 group_->set_obsolete(true);
892 if (!storage_->is_disabled()) { 908 if (!storage_->is_disabled()) {
893 storage_->origins_with_groups_.swap(origins_with_groups_); 909 storage_->UpdateUsageMapAndNotify(origin_, new_origin_usage_);
894 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_); 910 group_->AddNewlyDeletableResponseIds(&newly_deletable_response_ids_);
895 911
896 // Also remove from the working set, caches for an 'obsolete' group 912 // Also remove from the working set, caches for an 'obsolete' group
897 // may linger in use, but the group itself cannot be looked up by 913 // may linger in use, but the group itself cannot be looked up by
898 // 'manifest_url' in the working set any longer. 914 // 'manifest_url' in the working set any longer.
899 storage_->working_set()->RemoveGroup(group_); 915 storage_->working_set()->RemoveGroup(group_);
900 } 916 }
901 } 917 }
902 FOR_EACH_DELEGATE(delegates_, OnGroupMadeObsolete(group_, success_)); 918 FOR_EACH_DELEGATE(delegates_, OnGroupMadeObsolete(group_, success_));
903 group_ = NULL; 919 group_ = NULL;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 void AppCacheStorageImpl::DeleteDeletableResponseIdsTask::Run() { 979 void AppCacheStorageImpl::DeleteDeletableResponseIdsTask::Run() {
964 database_->DeleteDeletableResponseIds(response_ids_); 980 database_->DeleteDeletableResponseIds(response_ids_);
965 } 981 }
966 982
967 // UpdateGroupLastAccessTimeTask ------- 983 // UpdateGroupLastAccessTimeTask -------
968 984
969 class AppCacheStorageImpl::UpdateGroupLastAccessTimeTask 985 class AppCacheStorageImpl::UpdateGroupLastAccessTimeTask
970 : public DatabaseTask { 986 : public DatabaseTask {
971 public: 987 public:
972 UpdateGroupLastAccessTimeTask( 988 UpdateGroupLastAccessTimeTask(
973 AppCacheStorageImpl* storage, int64 group_id, base::Time time) 989 AppCacheStorageImpl* storage, AppCacheGroup* group, base::Time time)
974 : DatabaseTask(storage), group_id_(group_id), last_access_time_(time) {} 990 : DatabaseTask(storage), group_id_(group->group_id()),
991 last_access_time_(time) {
992 storage->NotifyStorageAccessed(group->manifest_url().GetOrigin());
993 }
975 994
976 virtual void Run(); 995 virtual void Run();
977 996
978 int64 group_id_; 997 int64 group_id_;
979 base::Time last_access_time_; 998 base::Time last_access_time_;
980 }; 999 };
981 1000
982 void AppCacheStorageImpl::UpdateGroupLastAccessTimeTask::Run() { 1001 void AppCacheStorageImpl::UpdateGroupLastAccessTimeTask::Run() {
983 database_->UpdateGroupLastAccessTime(group_id_, last_access_time_); 1002 database_->UpdateGroupLastAccessTime(group_id_, last_access_time_);
984 } 1003 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 1042
1024 scoped_refptr<InitTask> task(new InitTask(this)); 1043 scoped_refptr<InitTask> task(new InitTask(this));
1025 task->Schedule(); 1044 task->Schedule();
1026 } 1045 }
1027 1046
1028 void AppCacheStorageImpl::Disable() { 1047 void AppCacheStorageImpl::Disable() {
1029 if (is_disabled_) 1048 if (is_disabled_)
1030 return; 1049 return;
1031 VLOG(1) << "Disabling appcache storage."; 1050 VLOG(1) << "Disabling appcache storage.";
1032 is_disabled_ = true; 1051 is_disabled_ = true;
1033 origins_with_groups_.clear(); 1052 usage_map_.clear(); // TODO(michaeln): What to tell the QuotaManager?
kinuko 2011/06/02 08:38:06 hmm do we actually delete data when we disable th
michaeln 2011/06/02 22:46:55 Being disabled is being in an error condition. By
1034 working_set()->Disable(); 1053 working_set()->Disable();
1035 if (disk_cache_.get()) 1054 if (disk_cache_.get())
1036 disk_cache_->Disable(); 1055 disk_cache_->Disable();
1037 scoped_refptr<DisableDatabaseTask> task(new DisableDatabaseTask(this)); 1056 scoped_refptr<DisableDatabaseTask> task(new DisableDatabaseTask(this));
1038 task->Schedule(); 1057 task->Schedule();
1039 } 1058 }
1040 1059
1041 void AppCacheStorageImpl::GetAllInfo(Delegate* delegate) { 1060 void AppCacheStorageImpl::GetAllInfo(Delegate* delegate) {
1042 DCHECK(delegate); 1061 DCHECK(delegate);
1043 scoped_refptr<GetAllInfoTask> task(new GetAllInfoTask(this)); 1062 scoped_refptr<GetAllInfoTask> task(new GetAllInfoTask(this));
1044 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1063 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1045 task->Schedule(); 1064 task->Schedule();
1046 } 1065 }
1047 1066
1048 void AppCacheStorageImpl::LoadCache(int64 id, Delegate* delegate) { 1067 void AppCacheStorageImpl::LoadCache(int64 id, Delegate* delegate) {
1049 DCHECK(delegate); 1068 DCHECK(delegate);
1050 if (is_disabled_) { 1069 if (is_disabled_) {
1051 delegate->OnCacheLoaded(NULL, id); 1070 delegate->OnCacheLoaded(NULL, id);
1052 return; 1071 return;
1053 } 1072 }
1054 1073
1055 AppCache* cache = working_set_.GetCache(id); 1074 AppCache* cache = working_set_.GetCache(id);
1056 if (cache) { 1075 if (cache) {
1057 delegate->OnCacheLoaded(cache, id); 1076 delegate->OnCacheLoaded(cache, id);
1058 if (cache->owning_group()) { 1077 if (cache->owning_group()) {
1059 scoped_refptr<DatabaseTask> update_task( 1078 scoped_refptr<DatabaseTask> update_task(
1060 new UpdateGroupLastAccessTimeTask( 1079 new UpdateGroupLastAccessTimeTask(
1061 this, cache->owning_group()->group_id(), base::Time::Now())); 1080 this, cache->owning_group(), base::Time::Now()));
1062 update_task->Schedule(); 1081 update_task->Schedule();
1063 } 1082 }
1064 return; 1083 return;
1065 } 1084 }
1066 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id)); 1085 scoped_refptr<CacheLoadTask> task(GetPendingCacheLoadTask(id));
1067 if (task) { 1086 if (task) {
1068 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1087 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1069 return; 1088 return;
1070 } 1089 }
1071 task = new CacheLoadTask(id, this); 1090 task = new CacheLoadTask(id, this);
1072 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1091 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1073 task->Schedule(); 1092 task->Schedule();
1074 pending_cache_loads_[id] = task; 1093 pending_cache_loads_[id] = task;
1075 } 1094 }
1076 1095
1077 void AppCacheStorageImpl::LoadOrCreateGroup( 1096 void AppCacheStorageImpl::LoadOrCreateGroup(
1078 const GURL& manifest_url, Delegate* delegate) { 1097 const GURL& manifest_url, Delegate* delegate) {
1079 DCHECK(delegate); 1098 DCHECK(delegate);
1080 if (is_disabled_) { 1099 if (is_disabled_) {
1081 delegate->OnGroupLoaded(NULL, manifest_url); 1100 delegate->OnGroupLoaded(NULL, manifest_url);
1082 return; 1101 return;
1083 } 1102 }
1084 1103
1085 AppCacheGroup* group = working_set_.GetGroup(manifest_url); 1104 AppCacheGroup* group = working_set_.GetGroup(manifest_url);
1086 if (group) { 1105 if (group) {
1087 delegate->OnGroupLoaded(group, manifest_url); 1106 delegate->OnGroupLoaded(group, manifest_url);
1088 scoped_refptr<DatabaseTask> update_task( 1107 scoped_refptr<DatabaseTask> update_task(
1089 new UpdateGroupLastAccessTimeTask( 1108 new UpdateGroupLastAccessTimeTask(
1090 this, group->group_id(), base::Time::Now())); 1109 this, group, base::Time::Now()));
1091 update_task->Schedule(); 1110 update_task->Schedule();
1092 return; 1111 return;
1093 } 1112 }
1094 1113
1095 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url)); 1114 scoped_refptr<GroupLoadTask> task(GetPendingGroupLoadTask(manifest_url));
1096 if (task) { 1115 if (task) {
1097 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1116 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1098 return; 1117 return;
1099 } 1118 }
1100 1119
1101 if (origins_with_groups_.find(manifest_url.GetOrigin()) == 1120 if (usage_map_.find(manifest_url.GetOrigin()) == usage_map_.end()) {
1102 origins_with_groups_.end()) {
1103 // No need to query the database, return a new group immediately. 1121 // No need to query the database, return a new group immediately.
1104 scoped_refptr<AppCacheGroup> group(new AppCacheGroup( 1122 scoped_refptr<AppCacheGroup> group(new AppCacheGroup(
1105 service_, manifest_url, NewGroupId())); 1123 service_, manifest_url, NewGroupId()));
1106 delegate->OnGroupLoaded(group, manifest_url); 1124 delegate->OnGroupLoaded(group, manifest_url);
1107 return; 1125 return;
1108 } 1126 }
1109 1127
1110 task = new GroupLoadTask(manifest_url, this); 1128 task = new GroupLoadTask(manifest_url, this);
1111 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1129 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1112 task->Schedule(); 1130 task->Schedule();
1113 pending_group_loads_[manifest_url] = task.get(); 1131 pending_group_loads_[manifest_url] = task.get();
1114 } 1132 }
1115 1133
1116 void AppCacheStorageImpl::StoreGroupAndNewestCache( 1134 void AppCacheStorageImpl::StoreGroupAndNewestCache(
1117 AppCacheGroup* group, AppCache* newest_cache, Delegate* delegate) { 1135 AppCacheGroup* group, AppCache* newest_cache, Delegate* delegate) {
1136 // TODO: get quota from quotamanager, then continue.
1137
1118 // TODO(michaeln): distinguish between a simple update of an existing 1138 // TODO(michaeln): distinguish between a simple update of an existing
1119 // cache that just adds new master entry(s), and the insertion of a 1139 // cache that just adds new master entry(s), and the insertion of a
1120 // whole new cache. The StoreGroupAndCacheTask as written will handle 1140 // whole new cache. The StoreGroupAndCacheTask as written will handle
1121 // the simple update case in a very heavy weight way (delete all and 1141 // the simple update case in a very heavy weight way (delete all and
1122 // the reinsert all over again). 1142 // the reinsert all over again).
1123 DCHECK(group && delegate && newest_cache); 1143 DCHECK(group && delegate && newest_cache);
1124 scoped_refptr<StoreGroupAndCacheTask> task( 1144 scoped_refptr<StoreGroupAndCacheTask> task(
1125 new StoreGroupAndCacheTask(this, group, newest_cache)); 1145 new StoreGroupAndCacheTask(this, group, newest_cache));
1126 task->AddDelegate(GetOrCreateDelegateReference(delegate)); 1146 task->AddDelegate(GetOrCreateDelegateReference(delegate));
1127 task->Schedule(); 1147 task->Schedule();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 groups_in_use->begin(); 1181 groups_in_use->begin();
1162 it != groups_in_use->end(); ++it) { 1182 it != groups_in_use->end(); ++it) {
1163 if (FindResponseForMainRequestInGroup( 1183 if (FindResponseForMainRequestInGroup(
1164 it->second, *url_ptr, delegate)) { 1184 it->second, *url_ptr, delegate)) {
1165 return; 1185 return;
1166 } 1186 }
1167 } 1187 }
1168 } 1188 }
1169 } 1189 }
1170 1190
1171 if (IsInitTaskComplete() && 1191 if (IsInitTaskComplete() && usage_map_.find(origin) == usage_map_.end()) {
1172 origins_with_groups_.find(origin) == origins_with_groups_.end()) {
1173 // No need to query the database, return async'ly but without going thru 1192 // No need to query the database, return async'ly but without going thru
1174 // the DB thread. 1193 // the DB thread.
1175 scoped_refptr<AppCacheGroup> no_group; 1194 scoped_refptr<AppCacheGroup> no_group;
1176 scoped_refptr<AppCache> no_cache; 1195 scoped_refptr<AppCache> no_cache;
1177 ScheduleSimpleTask(method_factory_.NewRunnableMethod( 1196 ScheduleSimpleTask(method_factory_.NewRunnableMethod(
1178 &AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse, 1197 &AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse,
1179 url, AppCacheEntry(), no_group, no_cache, 1198 url, AppCacheEntry(), no_group, no_cache,
1180 make_scoped_refptr(GetOrCreateDelegateReference(delegate)))); 1199 make_scoped_refptr(GetOrCreateDelegateReference(delegate))));
1181 return; 1200 return;
1182 } 1201 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 Disable(); 1508 Disable();
1490 if (!is_incognito_) { 1509 if (!is_incognito_) {
1491 VLOG(1) << "Deleting existing appcache data and starting over."; 1510 VLOG(1) << "Deleting existing appcache data and starting over.";
1492 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, 1511 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE,
1493 NewRunnableFunction(DeleteDirectory, cache_directory_)); 1512 NewRunnableFunction(DeleteDirectory, cache_directory_));
1494 } 1513 }
1495 } 1514 }
1496 } 1515 }
1497 1516
1498 } // namespace appcache 1517 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698