Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/sql/connection.h" | 7 #include "app/sql/connection.h" |
| 8 #include "app/sql/transaction.h" | 8 #include "app/sql/transaction.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 } | 546 } |
| 547 } | 547 } |
| 548 | 548 |
| 549 virtual void Run(); | 549 virtual void Run(); |
| 550 virtual void RunCompleted(); | 550 virtual void RunCompleted(); |
| 551 | 551 |
| 552 GURL url_; | 552 GURL url_; |
| 553 std::set<int64> cache_ids_in_use_; | 553 std::set<int64> cache_ids_in_use_; |
| 554 AppCacheEntry entry_; | 554 AppCacheEntry entry_; |
| 555 AppCacheEntry fallback_entry_; | 555 AppCacheEntry fallback_entry_; |
| 556 GURL fallback_url_; | |
| 556 int64 cache_id_; | 557 int64 cache_id_; |
| 557 GURL manifest_url_; | 558 GURL manifest_url_; |
| 558 }; | 559 }; |
| 559 | 560 |
| 560 namespace { | 561 namespace { |
| 561 bool SortByLength( | 562 bool SortByLength( |
| 562 const AppCacheDatabase::FallbackNameSpaceRecord& lhs, | 563 const AppCacheDatabase::FallbackNameSpaceRecord& lhs, |
| 563 const AppCacheDatabase::FallbackNameSpaceRecord& rhs) { | 564 const AppCacheDatabase::FallbackNameSpaceRecord& rhs) { |
| 564 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); | 565 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); |
| 565 } | 566 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 | 630 |
| 630 AppCacheDatabase::EntryRecord entry_record; | 631 AppCacheDatabase::EntryRecord entry_record; |
| 631 if (take_new_candidate && | 632 if (take_new_candidate && |
| 632 database_->FindEntry(iter->cache_id, iter->fallback_entry_url, | 633 database_->FindEntry(iter->cache_id, iter->fallback_entry_url, |
| 633 &entry_record)) { | 634 &entry_record)) { |
| 634 AppCacheDatabase::GroupRecord group_record; | 635 AppCacheDatabase::GroupRecord group_record; |
| 635 if (!database_->FindGroupForCache(iter->cache_id, &group_record)) { | 636 if (!database_->FindGroupForCache(iter->cache_id, &group_record)) { |
| 636 NOTREACHED() << "A cache without a group is not expected."; | 637 NOTREACHED() << "A cache without a group is not expected."; |
| 637 continue; | 638 continue; |
| 638 } | 639 } |
| 640 if (entry_record.flags & AppCacheEntry::FOREIGN) | |
| 641 continue; | |
|
kinuko
2010/11/02 07:47:23
do we want to check this before looking up a group
michaeln
2010/11/02 20:25:36
Yes, thank you!
| |
| 639 cache_id_ = iter->cache_id; | 642 cache_id_ = iter->cache_id; |
| 643 fallback_url_ = iter->fallback_entry_url; | |
| 640 manifest_url_ = group_record.manifest_url; | 644 manifest_url_ = group_record.manifest_url; |
| 641 fallback_entry_ = AppCacheEntry( | 645 fallback_entry_ = AppCacheEntry( |
| 642 entry_record.flags, entry_record.response_id); | 646 entry_record.flags, entry_record.response_id); |
| 643 if (is_cache_in_use) | 647 if (is_cache_in_use) |
| 644 break; // Stop iterating since we favor hits from in-use caches. | 648 break; // Stop iterating since we favor hits from in-use caches. |
| 645 candidate_fallback_namespace = iter->namespace_url; | 649 candidate_fallback_namespace = iter->namespace_url; |
| 646 has_candidate = true; | 650 has_candidate = true; |
| 647 } | 651 } |
| 648 } | 652 } |
| 649 } | 653 } |
| 650 } | 654 } |
| 651 | 655 |
| 652 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { | 656 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { |
| 653 storage_->CheckPolicyAndCallOnMainResponseFound( | 657 storage_->CheckPolicyAndCallOnMainResponseFound( |
| 654 &delegates_, url_, entry_, fallback_entry_, cache_id_, manifest_url_); | 658 &delegates_, url_, entry_, fallback_url_, fallback_entry_, |
| 659 cache_id_, manifest_url_); | |
| 655 } | 660 } |
| 656 | 661 |
| 657 // MarkEntryAsForeignTask ------- | 662 // MarkEntryAsForeignTask ------- |
| 658 | 663 |
| 659 class AppCacheStorageImpl::MarkEntryAsForeignTask : public DatabaseTask { | 664 class AppCacheStorageImpl::MarkEntryAsForeignTask : public DatabaseTask { |
| 660 public: | 665 public: |
| 661 MarkEntryAsForeignTask( | 666 MarkEntryAsForeignTask( |
| 662 AppCacheStorageImpl* storage, const GURL& url, int64 cache_id) | 667 AppCacheStorageImpl* storage, const GURL& url, int64 cache_id) |
| 663 : DatabaseTask(storage), cache_id_(cache_id), entry_url_(url) {} | 668 : DatabaseTask(storage), cache_id_(cache_id), entry_url_(url) {} |
| 664 | 669 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 task->Schedule(); | 1045 task->Schedule(); |
| 1041 } | 1046 } |
| 1042 | 1047 |
| 1043 void AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse( | 1048 void AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse( |
| 1044 const GURL& url, AppCacheEntry found_entry, | 1049 const GURL& url, AppCacheEntry found_entry, |
| 1045 scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> cache, | 1050 scoped_refptr<AppCacheGroup> group, scoped_refptr<AppCache> cache, |
| 1046 scoped_refptr<DelegateReference> delegate_ref) { | 1051 scoped_refptr<DelegateReference> delegate_ref) { |
| 1047 if (delegate_ref->delegate) { | 1052 if (delegate_ref->delegate) { |
| 1048 DelegateReferenceVector delegates(1, delegate_ref); | 1053 DelegateReferenceVector delegates(1, delegate_ref); |
| 1049 CheckPolicyAndCallOnMainResponseFound( | 1054 CheckPolicyAndCallOnMainResponseFound( |
| 1050 &delegates, url, found_entry, AppCacheEntry(), | 1055 &delegates, url, found_entry, |
| 1056 GURL(), AppCacheEntry(), | |
| 1051 cache.get() ? cache->cache_id() : kNoCacheId, | 1057 cache.get() ? cache->cache_id() : kNoCacheId, |
| 1052 group.get() ? group->manifest_url() : GURL()); | 1058 group.get() ? group->manifest_url() : GURL()); |
| 1053 } | 1059 } |
| 1054 } | 1060 } |
| 1055 | 1061 |
| 1056 void AppCacheStorageImpl::CheckPolicyAndCallOnMainResponseFound( | 1062 void AppCacheStorageImpl::CheckPolicyAndCallOnMainResponseFound( |
| 1057 DelegateReferenceVector* delegates, const GURL& url, | 1063 DelegateReferenceVector* delegates, |
| 1058 const AppCacheEntry& entry, const AppCacheEntry& fallback_entry, | 1064 const GURL& url, const AppCacheEntry& entry, |
| 1065 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | |
| 1059 int64 cache_id, const GURL& manifest_url) { | 1066 int64 cache_id, const GURL& manifest_url) { |
| 1060 if (!manifest_url.is_empty()) { | 1067 if (!manifest_url.is_empty()) { |
| 1061 // Check the policy prior to returning a main resource from the appcache. | 1068 // Check the policy prior to returning a main resource from the appcache. |
| 1062 AppCachePolicy* policy = service()->appcache_policy(); | 1069 AppCachePolicy* policy = service()->appcache_policy(); |
| 1063 if (policy && !policy->CanLoadAppCache(manifest_url)) { | 1070 if (policy && !policy->CanLoadAppCache(manifest_url)) { |
| 1064 FOR_EACH_DELEGATE( | 1071 FOR_EACH_DELEGATE( |
| 1065 (*delegates), | 1072 (*delegates), |
| 1066 OnMainResponseFound(url, AppCacheEntry(), AppCacheEntry(), | 1073 OnMainResponseFound(url, AppCacheEntry(), |
| 1074 GURL(), AppCacheEntry(), | |
| 1067 kNoCacheId, manifest_url, true)); | 1075 kNoCacheId, manifest_url, true)); |
| 1068 return; | 1076 return; |
| 1069 } | 1077 } |
| 1070 } | 1078 } |
| 1071 | 1079 |
| 1072 FOR_EACH_DELEGATE( | 1080 FOR_EACH_DELEGATE( |
| 1073 (*delegates), | 1081 (*delegates), |
| 1074 OnMainResponseFound(url, entry, fallback_entry, | 1082 OnMainResponseFound(url, entry, |
| 1083 fallback_url, fallback_entry, | |
| 1075 cache_id, manifest_url, false)); | 1084 cache_id, manifest_url, false)); |
| 1076 } | 1085 } |
| 1077 | 1086 |
| 1078 void AppCacheStorageImpl::FindResponseForSubRequest( | 1087 void AppCacheStorageImpl::FindResponseForSubRequest( |
| 1079 AppCache* cache, const GURL& url, | 1088 AppCache* cache, const GURL& url, |
| 1080 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, | 1089 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, |
| 1081 bool* found_network_namespace) { | 1090 bool* found_network_namespace) { |
| 1082 DCHECK(cache && cache->is_complete()); | 1091 DCHECK(cache && cache->is_complete()); |
| 1083 | 1092 |
| 1084 // When a group is forcibly deleted, all subresource loads for pages | 1093 // When a group is forcibly deleted, all subresource loads for pages |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1319 Disable(); | 1328 Disable(); |
| 1320 if (!is_incognito_) { | 1329 if (!is_incognito_) { |
| 1321 VLOG(1) << "Deleting existing appcache data and starting over."; | 1330 VLOG(1) << "Deleting existing appcache data and starting over."; |
| 1322 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, | 1331 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, |
| 1323 NewRunnableFunction(DeleteDirectory, cache_directory_)); | 1332 NewRunnableFunction(DeleteDirectory, cache_directory_)); |
| 1324 } | 1333 } |
| 1325 } | 1334 } |
| 1326 } | 1335 } |
| 1327 | 1336 |
| 1328 } // namespace appcache | 1337 } // namespace appcache |
| OLD | NEW |