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

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

Issue 8396013: AppCache INTERCEPT namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 std::vector<int64>* deletable_response_ids) { 55 std::vector<int64>* deletable_response_ids) {
56 AppCacheDatabase::CacheRecord cache_record; 56 AppCacheDatabase::CacheRecord cache_record;
57 bool success = false; 57 bool success = false;
58 if (database->FindCacheForGroup(group_id, &cache_record)) { 58 if (database->FindCacheForGroup(group_id, &cache_record)) {
59 database->FindResponseIdsForCacheAsVector(cache_record.cache_id, 59 database->FindResponseIdsForCacheAsVector(cache_record.cache_id,
60 deletable_response_ids); 60 deletable_response_ids);
61 success = 61 success =
62 database->DeleteGroup(group_id) && 62 database->DeleteGroup(group_id) &&
63 database->DeleteCache(cache_record.cache_id) && 63 database->DeleteCache(cache_record.cache_id) &&
64 database->DeleteEntriesForCache(cache_record.cache_id) && 64 database->DeleteEntriesForCache(cache_record.cache_id) &&
65 database->DeleteFallbackNameSpacesForCache(cache_record.cache_id) && 65 database->DeleteNamespacesForCache(cache_record.cache_id) &&
66 database->DeleteOnlineWhiteListForCache(cache_record.cache_id) && 66 database->DeleteOnlineWhiteListForCache(cache_record.cache_id) &&
67 database->InsertDeletableResponseIds(*deletable_response_ids); 67 database->InsertDeletableResponseIds(*deletable_response_ids);
68 } else { 68 } else {
69 NOTREACHED() << "A existing group without a cache is unexpected"; 69 NOTREACHED() << "A existing group without a cache is unexpected";
70 success = database->DeleteGroup(group_id); 70 success = database->DeleteGroup(group_id);
71 } 71 }
72 return success; 72 return success;
73 } 73 }
74 74
75 // Deletes all appcache data (if clear_all_data is true), or session-only 75 // Deletes all appcache data (if clear_all_data is true), or session-only
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 explicit StoreOrLoadTask(AppCacheStorageImpl* storage) 362 explicit StoreOrLoadTask(AppCacheStorageImpl* storage)
363 : DatabaseTask(storage) {} 363 : DatabaseTask(storage) {}
364 364
365 bool FindRelatedCacheRecords(int64 cache_id); 365 bool FindRelatedCacheRecords(int64 cache_id);
366 void CreateCacheAndGroupFromRecords( 366 void CreateCacheAndGroupFromRecords(
367 scoped_refptr<AppCache>* cache, scoped_refptr<AppCacheGroup>* group); 367 scoped_refptr<AppCache>* cache, scoped_refptr<AppCacheGroup>* group);
368 368
369 AppCacheDatabase::GroupRecord group_record_; 369 AppCacheDatabase::GroupRecord group_record_;
370 AppCacheDatabase::CacheRecord cache_record_; 370 AppCacheDatabase::CacheRecord cache_record_;
371 std::vector<AppCacheDatabase::EntryRecord> entry_records_; 371 std::vector<AppCacheDatabase::EntryRecord> entry_records_;
372 std::vector<AppCacheDatabase::FallbackNameSpaceRecord> 372 std::vector<AppCacheDatabase::NamespaceRecord>
373 intercept_namespace_records_;
374 std::vector<AppCacheDatabase::NamespaceRecord>
373 fallback_namespace_records_; 375 fallback_namespace_records_;
374 std::vector<AppCacheDatabase::OnlineWhiteListRecord> 376 std::vector<AppCacheDatabase::OnlineWhiteListRecord>
375 online_whitelist_records_; 377 online_whitelist_records_;
376 }; 378 };
377 379
378 bool AppCacheStorageImpl::StoreOrLoadTask::FindRelatedCacheRecords( 380 bool AppCacheStorageImpl::StoreOrLoadTask::FindRelatedCacheRecords(
379 int64 cache_id) { 381 int64 cache_id) {
380 return database_->FindEntriesForCache(cache_id, &entry_records_) && 382 return database_->FindEntriesForCache(cache_id, &entry_records_) &&
381 database_->FindFallbackNameSpacesForCache( 383 database_->FindNamespacesForCache(
382 cache_id, &fallback_namespace_records_) && 384 cache_id, &intercept_namespace_records_,
385 &fallback_namespace_records_) &&
383 database_->FindOnlineWhiteListForCache( 386 database_->FindOnlineWhiteListForCache(
384 cache_id, &online_whitelist_records_); 387 cache_id, &online_whitelist_records_);
385 } 388 }
386 389
387 void AppCacheStorageImpl::StoreOrLoadTask::CreateCacheAndGroupFromRecords( 390 void AppCacheStorageImpl::StoreOrLoadTask::CreateCacheAndGroupFromRecords(
388 scoped_refptr<AppCache>* cache, scoped_refptr<AppCacheGroup>* group) { 391 scoped_refptr<AppCache>* cache, scoped_refptr<AppCacheGroup>* group) {
389 DCHECK(storage_ && cache && group); 392 DCHECK(storage_ && cache && group);
390 393
391 (*cache) = storage_->working_set_.GetCache(cache_record_.cache_id); 394 (*cache) = storage_->working_set_.GetCache(cache_record_.cache_id);
392 if (cache->get()) { 395 if (cache->get()) {
393 (*group) = cache->get()->owning_group(); 396 (*group) = cache->get()->owning_group();
394 DCHECK(group->get()); 397 DCHECK(group->get());
395 DCHECK_EQ(group_record_.group_id, group->get()->group_id()); 398 DCHECK_EQ(group_record_.group_id, group->get()->group_id());
396 storage_->NotifyStorageAccessed(group_record_.origin); 399 storage_->NotifyStorageAccessed(group_record_.origin);
397 return; 400 return;
398 } 401 }
399 402
400 (*cache) = new AppCache(storage_->service_, cache_record_.cache_id); 403 (*cache) = new AppCache(storage_->service_, cache_record_.cache_id);
401 cache->get()->InitializeWithDatabaseRecords( 404 cache->get()->InitializeWithDatabaseRecords(
402 cache_record_, entry_records_, fallback_namespace_records_, 405 cache_record_, entry_records_,
406 intercept_namespace_records_,
407 fallback_namespace_records_,
403 online_whitelist_records_); 408 online_whitelist_records_);
404 cache->get()->set_complete(true); 409 cache->get()->set_complete(true);
405 410
406 (*group) = storage_->working_set_.GetGroup(group_record_.manifest_url); 411 (*group) = storage_->working_set_.GetGroup(group_record_.manifest_url);
407 if (group->get()) { 412 if (group->get()) {
408 DCHECK(group_record_.group_id == group->get()->group_id()); 413 DCHECK(group_record_.group_id == group->get()->group_id());
409 group->get()->AddCache(cache->get()); 414 group->get()->AddCache(cache->get());
410 } else { 415 } else {
411 (*group) = new AppCacheGroup( 416 (*group) = new AppCacheGroup(
412 storage_->service_, group_record_.manifest_url, 417 storage_->service_, group_record_.manifest_url,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 AppCacheStorageImpl::StoreGroupAndCacheTask::StoreGroupAndCacheTask( 546 AppCacheStorageImpl::StoreGroupAndCacheTask::StoreGroupAndCacheTask(
542 AppCacheStorageImpl* storage, AppCacheGroup* group, AppCache* newest_cache) 547 AppCacheStorageImpl* storage, AppCacheGroup* group, AppCache* newest_cache)
543 : StoreOrLoadTask(storage), group_(group), cache_(newest_cache), 548 : StoreOrLoadTask(storage), group_(group), cache_(newest_cache),
544 success_(false), would_exceed_quota_(false), 549 success_(false), would_exceed_quota_(false),
545 space_available_(-1), new_origin_usage_(-1) { 550 space_available_(-1), new_origin_usage_(-1) {
546 group_record_.group_id = group->group_id(); 551 group_record_.group_id = group->group_id();
547 group_record_.manifest_url = group->manifest_url(); 552 group_record_.manifest_url = group->manifest_url();
548 group_record_.origin = group_record_.manifest_url.GetOrigin(); 553 group_record_.origin = group_record_.manifest_url.GetOrigin();
549 newest_cache->ToDatabaseRecords( 554 newest_cache->ToDatabaseRecords(
550 group, 555 group,
551 &cache_record_, &entry_records_, &fallback_namespace_records_, 556 &cache_record_, &entry_records_,
557 &intercept_namespace_records_,
558 &fallback_namespace_records_,
552 &online_whitelist_records_); 559 &online_whitelist_records_);
553 } 560 }
554 561
555 void AppCacheStorageImpl::StoreGroupAndCacheTask::GetQuotaThenSchedule() { 562 void AppCacheStorageImpl::StoreGroupAndCacheTask::GetQuotaThenSchedule() {
556 quota::QuotaManager* quota_manager = NULL; 563 quota::QuotaManager* quota_manager = NULL;
557 if (storage_->service()->quota_manager_proxy()) { 564 if (storage_->service()->quota_manager_proxy()) {
558 quota_manager = 565 quota_manager =
559 storage_->service()->quota_manager_proxy()->quota_manager(); 566 storage_->service()->quota_manager_proxy()->quota_manager();
560 } 567 }
561 568
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 // The rest are deletable. 638 // The rest are deletable.
632 std::set<int64>::const_iterator id_iter = existing_response_ids.begin(); 639 std::set<int64>::const_iterator id_iter = existing_response_ids.begin();
633 while (id_iter != existing_response_ids.end()) { 640 while (id_iter != existing_response_ids.end()) {
634 newly_deletable_response_ids_.push_back(*id_iter); 641 newly_deletable_response_ids_.push_back(*id_iter);
635 ++id_iter; 642 ++id_iter;
636 } 643 }
637 644
638 success_ = 645 success_ =
639 database_->DeleteCache(cache.cache_id) && 646 database_->DeleteCache(cache.cache_id) &&
640 database_->DeleteEntriesForCache(cache.cache_id) && 647 database_->DeleteEntriesForCache(cache.cache_id) &&
641 database_->DeleteFallbackNameSpacesForCache(cache.cache_id) && 648 database_->DeleteNamespacesForCache(cache.cache_id) &&
642 database_->DeleteOnlineWhiteListForCache(cache.cache_id) && 649 database_->DeleteOnlineWhiteListForCache(cache.cache_id) &&
643 database_->InsertDeletableResponseIds(newly_deletable_response_ids_); 650 database_->InsertDeletableResponseIds(newly_deletable_response_ids_);
644 // TODO(michaeln): store group_id too with deletable ids 651 // TODO(michaeln): store group_id too with deletable ids
645 } else { 652 } else {
646 NOTREACHED() << "A existing group without a cache is unexpected"; 653 NOTREACHED() << "A existing group without a cache is unexpected";
647 } 654 }
648 } 655 }
649 656
650 success_ = 657 success_ =
651 success_ && 658 success_ &&
652 database_->InsertCache(&cache_record_) && 659 database_->InsertCache(&cache_record_) &&
653 database_->InsertEntryRecords(entry_records_) && 660 database_->InsertEntryRecords(entry_records_) &&
654 database_->InsertFallbackNameSpaceRecords(fallback_namespace_records_)&& 661 database_->InsertNamespaceRecords(intercept_namespace_records_) &&
662 database_->InsertNamespaceRecords(fallback_namespace_records_) &&
655 database_->InsertOnlineWhiteListRecords(online_whitelist_records_); 663 database_->InsertOnlineWhiteListRecords(online_whitelist_records_);
656 664
657 if (!success_) 665 if (!success_)
658 return; 666 return;
659 667
660 new_origin_usage_ = database_->GetOriginUsage(group_record_.origin); 668 new_origin_usage_ = database_->GetOriginUsage(group_record_.origin);
661 669
662 // Only check quota when the new usage exceeds the old usage. 670 // Only check quota when the new usage exceeds the old usage.
663 if (new_origin_usage_ <= old_origin_usage) { 671 if (new_origin_usage_ <= old_origin_usage) {
664 success_ = transaction.Commit(); 672 success_ = transaction.Commit();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 void AppCacheStorageImpl::StoreGroupAndCacheTask::CancelCompletion() { 721 void AppCacheStorageImpl::StoreGroupAndCacheTask::CancelCompletion() {
714 // Overriden to safely drop our reference to the group and cache 722 // Overriden to safely drop our reference to the group and cache
715 // which are not thread safe refcounted. 723 // which are not thread safe refcounted.
716 DatabaseTask::CancelCompletion(); 724 DatabaseTask::CancelCompletion();
717 group_ = NULL; 725 group_ = NULL;
718 cache_ = NULL; 726 cache_ = NULL;
719 } 727 }
720 728
721 // FindMainResponseTask ------- 729 // FindMainResponseTask -------
722 730
723 class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask {
724 public:
725 FindMainResponseTask(AppCacheStorageImpl* storage,
726 const GURL& url,
727 const GURL& preferred_manifest_url,
728 const AppCacheWorkingSet::GroupMap* groups_in_use)
729 : DatabaseTask(storage), url_(url),
730 preferred_manifest_url_(preferred_manifest_url),
731 cache_id_(kNoCacheId), group_id_(0) {
732 if (groups_in_use) {
733 for (AppCacheWorkingSet::GroupMap::const_iterator it =
734 groups_in_use->begin();
735 it != groups_in_use->end(); ++it) {
736 AppCacheGroup* group = it->second;
737 AppCache* cache = group->newest_complete_cache();
738 if (group->is_obsolete() || !cache)
739 continue;
740 cache_ids_in_use_.insert(cache->cache_id());
741 }
742 }
743 }
744
745 virtual void Run();
746 virtual void RunCompleted();
747
748 private:
749 typedef std::vector<AppCacheDatabase::FallbackNameSpaceRecord*>
750 FallbackNameSpaceVector;
751 bool FindExactMatch(int64 preferred_id);
752 bool FindFallback(int64 preferred_id);
753 bool FindFirstValidFallback(const FallbackNameSpaceVector& fallbacks);
754
755 GURL url_;
756 GURL preferred_manifest_url_;
757 std::set<int64> cache_ids_in_use_;
758 AppCacheEntry entry_;
759 AppCacheEntry fallback_entry_;
760 GURL fallback_url_;
761 int64 cache_id_;
762 int64 group_id_;
763 GURL manifest_url_;
764 };
765
766 // Helpers for FindMainResponseTask::Run() 731 // Helpers for FindMainResponseTask::Run()
767 namespace { 732 namespace {
768 class SortByCachePreference 733 class SortByCachePreference
769 : public std::binary_function< 734 : public std::binary_function<
770 AppCacheDatabase::EntryRecord, 735 AppCacheDatabase::EntryRecord,
771 AppCacheDatabase::EntryRecord, 736 AppCacheDatabase::EntryRecord,
772 bool> { 737 bool> {
773 public: 738 public:
774 SortByCachePreference(int64 preferred_id, const std::set<int64>& in_use_ids) 739 SortByCachePreference(int64 preferred_id, const std::set<int64>& in_use_ids)
775 : preferred_id_(preferred_id), in_use_ids_(in_use_ids) { 740 : preferred_id_(preferred_id), in_use_ids_(in_use_ids) {
776 } 741 }
777 bool operator()( 742 bool operator()(
778 const AppCacheDatabase::EntryRecord& lhs, 743 const AppCacheDatabase::EntryRecord& lhs,
779 const AppCacheDatabase::EntryRecord& rhs) { 744 const AppCacheDatabase::EntryRecord& rhs) {
780 return compute_value(lhs) > compute_value(rhs); 745 return compute_value(lhs) > compute_value(rhs);
781 } 746 }
782 private: 747 private:
783 int compute_value(const AppCacheDatabase::EntryRecord& entry) { 748 int compute_value(const AppCacheDatabase::EntryRecord& entry) {
784 if (entry.cache_id == preferred_id_) 749 if (entry.cache_id == preferred_id_)
785 return 100; 750 return 100;
786 else if (in_use_ids_.find(entry.cache_id) != in_use_ids_.end()) 751 else if (in_use_ids_.find(entry.cache_id) != in_use_ids_.end())
787 return 50; 752 return 50;
788 return 0; 753 return 0;
789 } 754 }
790 int64 preferred_id_; 755 int64 preferred_id_;
791 const std::set<int64>& in_use_ids_; 756 const std::set<int64>& in_use_ids_;
792 }; 757 };
793 758
794 bool SortByLength( 759 bool SortByLength(
795 const AppCacheDatabase::FallbackNameSpaceRecord& lhs, 760 const AppCacheDatabase::NamespaceRecord& lhs,
796 const AppCacheDatabase::FallbackNameSpaceRecord& rhs) { 761 const AppCacheDatabase::NamespaceRecord& rhs) {
797 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); 762 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length();
798 } 763 }
799 764
800 class NetworkNamespaceHelper { 765 class NetworkNamespaceHelper {
801 public: 766 public:
802 explicit NetworkNamespaceHelper(AppCacheDatabase* database) 767 explicit NetworkNamespaceHelper(AppCacheDatabase* database)
803 : database_(database) { 768 : database_(database) {
804 } 769 }
805 770
806 bool IsInNetworkNamespace(const GURL& url, int64 cache_id) { 771 bool IsInNetworkNamespace(const GURL& url, int64 cache_id) {
(...skipping 23 matching lines...) Expand all
830 } 795 }
831 796
832 // Key is cache id 797 // Key is cache id
833 typedef std::map<int64, std::vector<GURL> > WhiteListMap; 798 typedef std::map<int64, std::vector<GURL> > WhiteListMap;
834 WhiteListMap namespaces_map_; 799 WhiteListMap namespaces_map_;
835 AppCacheDatabase* database_; 800 AppCacheDatabase* database_;
836 }; 801 };
837 802
838 } // namespace 803 } // namespace
839 804
805 class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask {
806 public:
807 FindMainResponseTask(AppCacheStorageImpl* storage,
808 const GURL& url,
809 const GURL& preferred_manifest_url,
810 const AppCacheWorkingSet::GroupMap* groups_in_use)
811 : DatabaseTask(storage), url_(url),
812 preferred_manifest_url_(preferred_manifest_url),
813 cache_id_(kNoCacheId), group_id_(0) {
814 if (groups_in_use) {
815 for (AppCacheWorkingSet::GroupMap::const_iterator it =
816 groups_in_use->begin();
817 it != groups_in_use->end(); ++it) {
818 AppCacheGroup* group = it->second;
819 AppCache* cache = group->newest_complete_cache();
820 if (group->is_obsolete() || !cache)
821 continue;
822 cache_ids_in_use_.insert(cache->cache_id());
823 }
824 }
825 }
826
827 virtual void Run();
828 virtual void RunCompleted();
829
830 private:
831 typedef std::vector<AppCacheDatabase::NamespaceRecord*>
832 NamespaceRecordPtrVector;
833 bool FindExactMatch(int64 preferred_id);
834 bool FindNamespaceMatch(int64 preferred_id);
835 bool FindNamespaceHelper(
836 int64 preferred_cache_id,
837 AppCacheDatabase::NamespaceRecordVector* namespaces,
838 NetworkNamespaceHelper* network_namespace_helper);
839 bool FindFirstValidNamespace(const NamespaceRecordPtrVector& namespaces);
840
841 GURL url_;
842 GURL preferred_manifest_url_;
843 std::set<int64> cache_ids_in_use_;
844 AppCacheEntry entry_;
845 AppCacheEntry fallback_entry_;
846 GURL fallback_url_;
847 int64 cache_id_;
848 int64 group_id_;
849 GURL manifest_url_;
850 };
851
852
853
840 void AppCacheStorageImpl::FindMainResponseTask::Run() { 854 void AppCacheStorageImpl::FindMainResponseTask::Run() {
841 // NOTE: The heuristics around choosing amoungst multiple candidates 855 // NOTE: The heuristics around choosing amoungst multiple candidates
842 // is underspecified, and just plain not fully understood. This needs 856 // is underspecified, and just plain not fully understood. This needs
843 // to be refined. 857 // to be refined.
844 858
845 // The 'preferred_manifest_url' is the url of the manifest associated 859 // The 'preferred_manifest_url' is the url of the manifest associated
846 // with the page that opened or embedded the page being loaded now. 860 // with the page that opened or embedded the page being loaded now.
847 // We have a strong preference to use resources from that cache. 861 // We have a strong preference to use resources from that cache.
848 // We also have a lesser bias to use resources from caches that are currently 862 // We also have a lesser bias to use resources from caches that are currently
849 // being used by other unrelated pages. 863 // being used by other unrelated pages.
850 // TODO(michaeln): come up with a 'preferred_manifest_url' in more cases 864 // TODO(michaeln): come up with a 'preferred_manifest_url' in more cases
851 // - when navigating a frame whose current contents are from an appcache 865 // - when navigating a frame whose current contents are from an appcache
852 // - when clicking an href in a frame that is appcached 866 // - when clicking an href in a frame that is appcached
853 int64 preferred_cache_id = kNoCacheId; 867 int64 preferred_cache_id = kNoCacheId;
854 if (!preferred_manifest_url_.is_empty()) { 868 if (!preferred_manifest_url_.is_empty()) {
855 AppCacheDatabase::GroupRecord preferred_group; 869 AppCacheDatabase::GroupRecord preferred_group;
856 AppCacheDatabase::CacheRecord preferred_cache; 870 AppCacheDatabase::CacheRecord preferred_cache;
857 if (database_->FindGroupForManifestUrl( 871 if (database_->FindGroupForManifestUrl(
858 preferred_manifest_url_, &preferred_group) && 872 preferred_manifest_url_, &preferred_group) &&
859 database_->FindCacheForGroup( 873 database_->FindCacheForGroup(
860 preferred_group.group_id, &preferred_cache)) { 874 preferred_group.group_id, &preferred_cache)) {
861 preferred_cache_id = preferred_cache.cache_id; 875 preferred_cache_id = preferred_cache.cache_id;
862 } 876 }
863 } 877 }
864 878
865 // TODO(michaeln): Also lookup matches in intercept namespaces.
866 // http://code.google.com/p/chromium/issues/detail?id=101565
867 if (FindExactMatch(preferred_cache_id) || 879 if (FindExactMatch(preferred_cache_id) ||
868 FindFallback(preferred_cache_id)) { 880 FindNamespaceMatch(preferred_cache_id)) {
869 // We found something. 881 // We found something.
870 DCHECK(cache_id_ != kNoCacheId && !manifest_url_.is_empty() && 882 DCHECK(cache_id_ != kNoCacheId && !manifest_url_.is_empty() &&
871 group_id_ != 0); 883 group_id_ != 0);
872 return; 884 return;
873 } 885 }
874 886
875 // We didn't find anything. 887 // We didn't find anything.
876 DCHECK(cache_id_ == kNoCacheId && manifest_url_.is_empty() && 888 DCHECK(cache_id_ == kNoCacheId && manifest_url_.is_empty() &&
877 group_id_ == 0); 889 group_id_ == 0);
878 } 890 }
(...skipping 19 matching lines...) Expand all
898 group_id_ = group_record.group_id; 910 group_id_ = group_record.group_id;
899 entry_ = AppCacheEntry(iter->flags, iter->response_id); 911 entry_ = AppCacheEntry(iter->flags, iter->response_id);
900 cache_id_ = iter->cache_id; 912 cache_id_ = iter->cache_id;
901 return true; // We found an exact match. 913 return true; // We found an exact match.
902 } 914 }
903 } 915 }
904 return false; 916 return false;
905 } 917 }
906 918
907 bool AppCacheStorageImpl:: 919 bool AppCacheStorageImpl::
908 FindMainResponseTask::FindFallback(int64 preferred_cache_id) { 920 FindMainResponseTask::FindNamespaceMatch(int64 preferred_cache_id) {
909 std::vector<AppCacheDatabase::FallbackNameSpaceRecord> all_fallbacks; 921 AppCacheDatabase::NamespaceRecordVector all_intercepts;
910 if (!database_->FindFallbackNameSpacesForOrigin( 922 AppCacheDatabase::NamespaceRecordVector all_fallbacks;
911 url_.GetOrigin(), &all_fallbacks) 923 if (!database_->FindNamespacesForOrigin(
912 || all_fallbacks.empty()) { 924 url_.GetOrigin(), &all_intercepts, &all_fallbacks)
925 || (all_intercepts.empty() && all_fallbacks.empty())) {
913 return false; 926 return false;
914 } 927 }
915 928
929 NetworkNamespaceHelper network_namespace_helper(database_);
930 if (FindNamespaceHelper(preferred_cache_id,
931 &all_intercepts,
932 &network_namespace_helper) ||
933 FindNamespaceHelper(preferred_cache_id,
934 &all_fallbacks,
935 &network_namespace_helper)) {
936 return true;
937 }
938 return false;
939 }
940
941 bool AppCacheStorageImpl::
942 FindMainResponseTask::FindNamespaceHelper(
943 int64 preferred_cache_id,
944 AppCacheDatabase::NamespaceRecordVector* namespaces,
945 NetworkNamespaceHelper* network_namespace_helper) {
916 // Sort them by length, longer matches within the same cache/bucket take 946 // Sort them by length, longer matches within the same cache/bucket take
917 // precedence. 947 // precedence.
918 std::sort(all_fallbacks.begin(), all_fallbacks.end(), SortByLength); 948 std::sort(namespaces->begin(), namespaces->end(), SortByLength);
919 949
920 // Filter the list and bin them into buckets. 950 NamespaceRecordPtrVector preferred_namespaces;
921 NetworkNamespaceHelper network_namespace_helper(database_); 951 NamespaceRecordPtrVector inuse_namespaces;
922 FallbackNameSpaceVector preferred_fallbacks; 952 NamespaceRecordPtrVector other_namespaces;
923 FallbackNameSpaceVector inuse_fallbacks; 953 std::vector<AppCacheDatabase::NamespaceRecord>::iterator iter;
924 FallbackNameSpaceVector other_fallbacks; 954 for (iter = namespaces->begin(); iter < namespaces->end(); ++iter) {
925 std::vector<AppCacheDatabase::FallbackNameSpaceRecord>::iterator iter;
926 for (iter = all_fallbacks.begin(); iter < all_fallbacks.end(); ++iter) {
927 // Skip those that aren't a prefix match. 955 // Skip those that aren't a prefix match.
928 if (!StartsWithASCII(url_.spec(), iter->namespace_url.spec(), true)) 956 if (!StartsWithASCII(url_.spec(), iter->namespace_url.spec(), true))
929 continue; 957 continue;
930 958
931 // Skip fallback namespaces where the requested url falls into a network 959 // Skip namespaces where the requested url falls into a network
932 // namespace of its containing appcache. 960 // namespace of its containing appcache.
933 if (network_namespace_helper.IsInNetworkNamespace(url_, iter->cache_id)) 961 if (network_namespace_helper->IsInNetworkNamespace(url_, iter->cache_id))
934 continue; 962 continue;
935 963
936 // Bin them into one of our three buckets. 964 // Bin them into one of our three buckets.
937 if (iter->cache_id == preferred_cache_id) 965 if (iter->cache_id == preferred_cache_id)
938 preferred_fallbacks.push_back(&(*iter)); 966 preferred_namespaces.push_back(&(*iter));
939 else if (cache_ids_in_use_.find(iter->cache_id) != cache_ids_in_use_.end()) 967 else if (cache_ids_in_use_.find(iter->cache_id) != cache_ids_in_use_.end())
940 inuse_fallbacks.push_back(&(*iter)); 968 inuse_namespaces.push_back(&(*iter));
941 else 969 else
942 other_fallbacks.push_back(&(*iter)); 970 other_namespaces.push_back(&(*iter));
943 } 971 }
944 972
945 if (FindFirstValidFallback(preferred_fallbacks) || 973 if (FindFirstValidNamespace(preferred_namespaces) ||
946 FindFirstValidFallback(inuse_fallbacks) || 974 FindFirstValidNamespace(inuse_namespaces) ||
947 FindFirstValidFallback(other_fallbacks)) 975 FindFirstValidNamespace(other_namespaces))
948 return true; // We found one. 976 return true; // We found one.
949 977
950 // We didn't find anything. 978 // We didn't find anything.
951 return false; 979 return false;
952 } 980 }
953 981
954 bool AppCacheStorageImpl:: 982 bool AppCacheStorageImpl::
955 FindMainResponseTask::FindFirstValidFallback( 983 FindMainResponseTask::FindFirstValidNamespace(
956 const FallbackNameSpaceVector& fallbacks) { 984 const NamespaceRecordPtrVector& namespaces) {
957 // Take the first with a valid, non-foreign entry. 985 // Take the first with a valid, non-foreign entry.
958 FallbackNameSpaceVector::const_iterator iter; 986 NamespaceRecordPtrVector::const_iterator iter;
959 for (iter = fallbacks.begin(); iter < fallbacks.end(); ++iter) { 987 for (iter = namespaces.begin(); iter < namespaces.end(); ++iter) {
960 AppCacheDatabase::EntryRecord entry_record; 988 AppCacheDatabase::EntryRecord entry_record;
961 if (database_->FindEntry((*iter)->cache_id, (*iter)->fallback_entry_url, 989 if (database_->FindEntry((*iter)->cache_id, (*iter)->target_url,
962 &entry_record)) { 990 &entry_record)) {
963 AppCacheDatabase::GroupRecord group_record; 991 AppCacheDatabase::GroupRecord group_record;
964 if ((entry_record.flags & AppCacheEntry::FOREIGN) || 992 if ((entry_record.flags & AppCacheEntry::FOREIGN) ||
965 !database_->FindGroupForCache(entry_record.cache_id, &group_record)) { 993 !database_->FindGroupForCache(entry_record.cache_id, &group_record)) {
966 continue; 994 continue;
967 } 995 }
968 manifest_url_ = group_record.manifest_url; 996 manifest_url_ = group_record.manifest_url;
969 group_id_ = group_record.group_id; 997 group_id_ = group_record.group_id;
970 cache_id_ = (*iter)->cache_id; 998 cache_id_ = (*iter)->cache_id;
971 fallback_url_ = (*iter)->fallback_entry_url; 999 if ((*iter)->type == FALLBACK_NAMESPACE) {
972 fallback_entry_ = AppCacheEntry( 1000 fallback_url_ = (*iter)->target_url;
973 entry_record.flags, entry_record.response_id); 1001 fallback_entry_ = AppCacheEntry(
1002 entry_record.flags, entry_record.response_id);
1003 } else {
1004 entry_ = AppCacheEntry(entry_record.flags, entry_record.response_id);
1005 }
974 return true; // We found one. 1006 return true; // We found one.
975 } 1007 }
976 } 1008 }
977 return false; // We didn't find a match. 1009 return false; // We didn't find a match.
978 } 1010 }
979 1011
980 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { 1012 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() {
981 storage_->CallOnMainResponseFound( 1013 storage_->CallOnMainResponseFound(
982 &delegates_, url_, entry_, fallback_url_, fallback_entry_, 1014 &delegates_, url_, entry_, fallback_url_, fallback_entry_,
983 cache_id_, group_id_, manifest_url_); 1015 cache_id_, group_id_, manifest_url_);
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 Disable(); 1703 Disable();
1672 if (!is_incognito_) { 1704 if (!is_incognito_) {
1673 VLOG(1) << "Deleting existing appcache data and starting over."; 1705 VLOG(1) << "Deleting existing appcache data and starting over.";
1674 db_thread_->PostTask( 1706 db_thread_->PostTask(
1675 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); 1707 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_));
1676 } 1708 }
1677 } 1709 }
1678 } 1710 }
1679 1711
1680 } // namespace appcache 1712 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698