| 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/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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 int64 preferred_cache_id, | 844 int64 preferred_cache_id, |
| 845 AppCacheDatabase::NamespaceRecordVector* namespaces, | 845 AppCacheDatabase::NamespaceRecordVector* namespaces, |
| 846 NetworkNamespaceHelper* network_namespace_helper); | 846 NetworkNamespaceHelper* network_namespace_helper); |
| 847 bool FindFirstValidNamespace(const NamespaceRecordPtrVector& namespaces); | 847 bool FindFirstValidNamespace(const NamespaceRecordPtrVector& namespaces); |
| 848 | 848 |
| 849 GURL url_; | 849 GURL url_; |
| 850 GURL preferred_manifest_url_; | 850 GURL preferred_manifest_url_; |
| 851 std::set<int64> cache_ids_in_use_; | 851 std::set<int64> cache_ids_in_use_; |
| 852 AppCacheEntry entry_; | 852 AppCacheEntry entry_; |
| 853 AppCacheEntry fallback_entry_; | 853 AppCacheEntry fallback_entry_; |
| 854 GURL fallback_url_; | 854 GURL namespace_entry_url_; |
| 855 int64 cache_id_; | 855 int64 cache_id_; |
| 856 int64 group_id_; | 856 int64 group_id_; |
| 857 GURL manifest_url_; | 857 GURL manifest_url_; |
| 858 }; | 858 }; |
| 859 | 859 |
| 860 | 860 |
| 861 | 861 |
| 862 void AppCacheStorageImpl::FindMainResponseTask::Run() { | 862 void AppCacheStorageImpl::FindMainResponseTask::Run() { |
| 863 // NOTE: The heuristics around choosing amoungst multiple candidates | 863 // NOTE: The heuristics around choosing amoungst multiple candidates |
| 864 // is underspecified, and just plain not fully understood. This needs | 864 // is underspecified, and just plain not fully understood. This needs |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 if (database_->FindEntry((*iter)->cache_id, (*iter)->target_url, | 997 if (database_->FindEntry((*iter)->cache_id, (*iter)->target_url, |
| 998 &entry_record)) { | 998 &entry_record)) { |
| 999 AppCacheDatabase::GroupRecord group_record; | 999 AppCacheDatabase::GroupRecord group_record; |
| 1000 if ((entry_record.flags & AppCacheEntry::FOREIGN) || | 1000 if ((entry_record.flags & AppCacheEntry::FOREIGN) || |
| 1001 !database_->FindGroupForCache(entry_record.cache_id, &group_record)) { | 1001 !database_->FindGroupForCache(entry_record.cache_id, &group_record)) { |
| 1002 continue; | 1002 continue; |
| 1003 } | 1003 } |
| 1004 manifest_url_ = group_record.manifest_url; | 1004 manifest_url_ = group_record.manifest_url; |
| 1005 group_id_ = group_record.group_id; | 1005 group_id_ = group_record.group_id; |
| 1006 cache_id_ = (*iter)->cache_id; | 1006 cache_id_ = (*iter)->cache_id; |
| 1007 if ((*iter)->type == FALLBACK_NAMESPACE) { | 1007 namespace_entry_url_ = (*iter)->target_url; |
| 1008 fallback_url_ = (*iter)->target_url; | 1008 if ((*iter)->type == FALLBACK_NAMESPACE) |
| 1009 fallback_entry_ = AppCacheEntry( | 1009 fallback_entry_ = AppCacheEntry(entry_record.flags, |
| 1010 entry_record.flags, entry_record.response_id); | 1010 entry_record.response_id); |
| 1011 } else { | 1011 else |
| 1012 entry_ = AppCacheEntry(entry_record.flags, entry_record.response_id); | 1012 entry_ = AppCacheEntry(entry_record.flags, entry_record.response_id); |
| 1013 } | |
| 1014 return true; // We found one. | 1013 return true; // We found one. |
| 1015 } | 1014 } |
| 1016 } | 1015 } |
| 1017 return false; // We didn't find a match. | 1016 return false; // We didn't find a match. |
| 1018 } | 1017 } |
| 1019 | 1018 |
| 1020 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { | 1019 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { |
| 1021 storage_->CallOnMainResponseFound( | 1020 storage_->CallOnMainResponseFound( |
| 1022 &delegates_, url_, entry_, fallback_url_, fallback_entry_, | 1021 &delegates_, url_, entry_, namespace_entry_url_, fallback_entry_, |
| 1023 cache_id_, group_id_, manifest_url_); | 1022 cache_id_, group_id_, manifest_url_); |
| 1024 } | 1023 } |
| 1025 | 1024 |
| 1026 // MarkEntryAsForeignTask ------- | 1025 // MarkEntryAsForeignTask ------- |
| 1027 | 1026 |
| 1028 class AppCacheStorageImpl::MarkEntryAsForeignTask : public DatabaseTask { | 1027 class AppCacheStorageImpl::MarkEntryAsForeignTask : public DatabaseTask { |
| 1029 public: | 1028 public: |
| 1030 MarkEntryAsForeignTask( | 1029 MarkEntryAsForeignTask( |
| 1031 AppCacheStorageImpl* storage, const GURL& url, int64 cache_id) | 1030 AppCacheStorageImpl* storage, const GURL& url, int64 cache_id) |
| 1032 : DatabaseTask(storage), cache_id_(cache_id), entry_url_(url) {} | 1031 : DatabaseTask(storage), cache_id_(cache_id), entry_url_(url) {} |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 GURL(), AppCacheEntry(), | 1445 GURL(), AppCacheEntry(), |
| 1447 cache.get() ? cache->cache_id() : kNoCacheId, | 1446 cache.get() ? cache->cache_id() : kNoCacheId, |
| 1448 group.get() ? group->group_id() : kNoCacheId, | 1447 group.get() ? group->group_id() : kNoCacheId, |
| 1449 group.get() ? group->manifest_url() : GURL()); | 1448 group.get() ? group->manifest_url() : GURL()); |
| 1450 } | 1449 } |
| 1451 } | 1450 } |
| 1452 | 1451 |
| 1453 void AppCacheStorageImpl::CallOnMainResponseFound( | 1452 void AppCacheStorageImpl::CallOnMainResponseFound( |
| 1454 DelegateReferenceVector* delegates, | 1453 DelegateReferenceVector* delegates, |
| 1455 const GURL& url, const AppCacheEntry& entry, | 1454 const GURL& url, const AppCacheEntry& entry, |
| 1456 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 1455 const GURL& namespace_entry_url, const AppCacheEntry& fallback_entry, |
| 1457 int64 cache_id, int64 group_id, const GURL& manifest_url) { | 1456 int64 cache_id, int64 group_id, const GURL& manifest_url) { |
| 1458 FOR_EACH_DELEGATE( | 1457 FOR_EACH_DELEGATE( |
| 1459 (*delegates), | 1458 (*delegates), |
| 1460 OnMainResponseFound(url, entry, | 1459 OnMainResponseFound(url, entry, |
| 1461 fallback_url, fallback_entry, | 1460 namespace_entry_url, fallback_entry, |
| 1462 cache_id, group_id, manifest_url)); | 1461 cache_id, group_id, manifest_url)); |
| 1463 } | 1462 } |
| 1464 | 1463 |
| 1465 void AppCacheStorageImpl::FindResponseForSubRequest( | 1464 void AppCacheStorageImpl::FindResponseForSubRequest( |
| 1466 AppCache* cache, const GURL& url, | 1465 AppCache* cache, const GURL& url, |
| 1467 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, | 1466 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, |
| 1468 bool* found_network_namespace) { | 1467 bool* found_network_namespace) { |
| 1469 DCHECK(cache && cache->is_complete()); | 1468 DCHECK(cache && cache->is_complete()); |
| 1470 | 1469 |
| 1471 // When a group is forcibly deleted, all subresource loads for pages | 1470 // When a group is forcibly deleted, all subresource loads for pages |
| 1472 // using caches in the group will result in a synthesized network errors. | 1471 // using caches in the group will result in a synthesized network errors. |
| 1473 // Forcible deletion is not a function that is covered by the HTML5 spec. | 1472 // Forcible deletion is not a function that is covered by the HTML5 spec. |
| 1474 if (cache->owning_group()->is_being_deleted()) { | 1473 if (cache->owning_group()->is_being_deleted()) { |
| 1475 *found_entry = AppCacheEntry(); | 1474 *found_entry = AppCacheEntry(); |
| 1476 *found_fallback_entry = AppCacheEntry(); | 1475 *found_fallback_entry = AppCacheEntry(); |
| 1477 *found_network_namespace = false; | 1476 *found_network_namespace = false; |
| 1478 return; | 1477 return; |
| 1479 } | 1478 } |
| 1480 | 1479 |
| 1481 GURL fallback_namespace_not_used; | 1480 GURL fallback_namespace_not_used; |
| 1481 GURL intercept_namespace_not_used; |
| 1482 cache->FindResponseForRequest( | 1482 cache->FindResponseForRequest( |
| 1483 url, found_entry, found_fallback_entry, | 1483 url, found_entry, &intercept_namespace_not_used, |
| 1484 &fallback_namespace_not_used, found_network_namespace); | 1484 found_fallback_entry, &fallback_namespace_not_used, |
| 1485 found_network_namespace); |
| 1485 } | 1486 } |
| 1486 | 1487 |
| 1487 void AppCacheStorageImpl::MarkEntryAsForeign( | 1488 void AppCacheStorageImpl::MarkEntryAsForeign( |
| 1488 const GURL& entry_url, int64 cache_id) { | 1489 const GURL& entry_url, int64 cache_id) { |
| 1489 AppCache* cache = working_set_.GetCache(cache_id); | 1490 AppCache* cache = working_set_.GetCache(cache_id); |
| 1490 if (cache) { | 1491 if (cache) { |
| 1491 AppCacheEntry* entry = cache->GetEntry(entry_url); | 1492 AppCacheEntry* entry = cache->GetEntry(entry_url); |
| 1492 DCHECK(entry); | 1493 DCHECK(entry); |
| 1493 if (entry) | 1494 if (entry) |
| 1494 entry->add_types(AppCacheEntry::FOREIGN); | 1495 entry->add_types(AppCacheEntry::FOREIGN); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 Disable(); | 1715 Disable(); |
| 1715 if (!is_incognito_) { | 1716 if (!is_incognito_) { |
| 1716 VLOG(1) << "Deleting existing appcache data and starting over."; | 1717 VLOG(1) << "Deleting existing appcache data and starting over."; |
| 1717 db_thread_->PostTask( | 1718 db_thread_->PostTask( |
| 1718 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); | 1719 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); |
| 1719 } | 1720 } |
| 1720 } | 1721 } |
| 1721 } | 1722 } |
| 1722 | 1723 |
| 1723 } // namespace appcache | 1724 } // namespace appcache |
| OLD | NEW |