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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "net/base/cache_type.h" | 14 #include "net/base/cache_type.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "sql/connection.h" | 16 #include "sql/connection.h" |
17 #include "sql/transaction.h" | 17 #include "sql/transaction.h" |
18 #include "webkit/appcache/appcache.h" | 18 #include "webkit/appcache/appcache.h" |
19 #include "webkit/appcache/appcache_database.h" | 19 #include "webkit/appcache/appcache_database.h" |
20 #include "webkit/appcache/appcache_entry.h" | 20 #include "webkit/appcache/appcache_entry.h" |
21 #include "webkit/appcache/appcache_group.h" | 21 #include "webkit/appcache/appcache_group.h" |
22 #include "webkit/appcache/appcache_histograms.h" | 22 #include "webkit/appcache/appcache_histograms.h" |
23 #include "webkit/appcache/appcache_policy.h" | |
24 #include "webkit/appcache/appcache_quota_client.h" | 23 #include "webkit/appcache/appcache_quota_client.h" |
25 #include "webkit/appcache/appcache_response.h" | 24 #include "webkit/appcache/appcache_response.h" |
26 #include "webkit/appcache/appcache_service.h" | 25 #include "webkit/appcache/appcache_service.h" |
27 #include "webkit/appcache/appcache_thread.h" | 26 #include "webkit/appcache/appcache_thread.h" |
28 #include "webkit/quota/quota_client.h" | 27 #include "webkit/quota/quota_client.h" |
29 #include "webkit/quota/quota_manager.h" | 28 #include "webkit/quota/quota_manager.h" |
30 #include "webkit/quota/special_storage_policy.h" | 29 #include "webkit/quota/special_storage_policy.h" |
31 | 30 |
32 namespace appcache { | 31 namespace appcache { |
33 | 32 |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 fallback_url_ = (*iter)->fallback_entry_url; | 931 fallback_url_ = (*iter)->fallback_entry_url; |
933 fallback_entry_ = AppCacheEntry( | 932 fallback_entry_ = AppCacheEntry( |
934 entry_record.flags, entry_record.response_id); | 933 entry_record.flags, entry_record.response_id); |
935 return true; // We found one. | 934 return true; // We found one. |
936 } | 935 } |
937 } | 936 } |
938 return false; // We didn't find a match. | 937 return false; // We didn't find a match. |
939 } | 938 } |
940 | 939 |
941 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { | 940 void AppCacheStorageImpl::FindMainResponseTask::RunCompleted() { |
942 storage_->CheckPolicyAndCallOnMainResponseFound( | 941 storage_->CallOnMainResponseFound( |
943 &delegates_, url_, entry_, fallback_url_, fallback_entry_, | 942 &delegates_, url_, entry_, fallback_url_, fallback_entry_, |
944 cache_id_, manifest_url_); | 943 cache_id_, manifest_url_); |
945 } | 944 } |
946 | 945 |
947 // MarkEntryAsForeignTask ------- | 946 // MarkEntryAsForeignTask ------- |
948 | 947 |
949 class AppCacheStorageImpl::MarkEntryAsForeignTask : public DatabaseTask { | 948 class AppCacheStorageImpl::MarkEntryAsForeignTask : public DatabaseTask { |
950 public: | 949 public: |
951 MarkEntryAsForeignTask( | 950 MarkEntryAsForeignTask( |
952 AppCacheStorageImpl* storage, const GURL& url, int64 cache_id) | 951 AppCacheStorageImpl* storage, const GURL& url, int64 cache_id) |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 } | 1355 } |
1357 | 1356 |
1358 void AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse( | 1357 void AppCacheStorageImpl::DeliverShortCircuitedFindMainResponse( |
1359 const GURL& url, | 1358 const GURL& url, |
1360 const AppCacheEntry& found_entry, | 1359 const AppCacheEntry& found_entry, |
1361 scoped_refptr<AppCacheGroup> group, | 1360 scoped_refptr<AppCacheGroup> group, |
1362 scoped_refptr<AppCache> cache, | 1361 scoped_refptr<AppCache> cache, |
1363 scoped_refptr<DelegateReference> delegate_ref) { | 1362 scoped_refptr<DelegateReference> delegate_ref) { |
1364 if (delegate_ref->delegate) { | 1363 if (delegate_ref->delegate) { |
1365 DelegateReferenceVector delegates(1, delegate_ref); | 1364 DelegateReferenceVector delegates(1, delegate_ref); |
1366 CheckPolicyAndCallOnMainResponseFound( | 1365 CallOnMainResponseFound( |
1367 &delegates, url, found_entry, | 1366 &delegates, url, found_entry, |
1368 GURL(), AppCacheEntry(), | 1367 GURL(), AppCacheEntry(), |
1369 cache.get() ? cache->cache_id() : kNoCacheId, | 1368 cache.get() ? cache->cache_id() : kNoCacheId, |
1370 group.get() ? group->manifest_url() : GURL()); | 1369 group.get() ? group->manifest_url() : GURL()); |
1371 } | 1370 } |
1372 } | 1371 } |
1373 | 1372 |
1374 void AppCacheStorageImpl::CheckPolicyAndCallOnMainResponseFound( | 1373 void AppCacheStorageImpl::CallOnMainResponseFound( |
1375 DelegateReferenceVector* delegates, | 1374 DelegateReferenceVector* delegates, |
1376 const GURL& url, const AppCacheEntry& entry, | 1375 const GURL& url, const AppCacheEntry& entry, |
1377 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 1376 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
1378 int64 cache_id, const GURL& manifest_url) { | 1377 int64 cache_id, const GURL& manifest_url) { |
1379 if (!manifest_url.is_empty()) { | |
1380 // Check the policy prior to returning a main resource from the appcache. | |
1381 AppCachePolicy* policy = service()->appcache_policy(); | |
1382 if (policy && !policy->CanLoadAppCache(manifest_url)) { | |
1383 FOR_EACH_DELEGATE( | |
1384 (*delegates), | |
1385 OnMainResponseFound(url, AppCacheEntry(), | |
1386 GURL(), AppCacheEntry(), | |
1387 kNoCacheId, manifest_url, true)); | |
1388 return; | |
1389 } | |
1390 } | |
1391 | |
1392 FOR_EACH_DELEGATE( | 1378 FOR_EACH_DELEGATE( |
1393 (*delegates), | 1379 (*delegates), |
1394 OnMainResponseFound(url, entry, | 1380 OnMainResponseFound(url, entry, |
1395 fallback_url, fallback_entry, | 1381 fallback_url, fallback_entry, |
1396 cache_id, manifest_url, false)); | 1382 cache_id, manifest_url)); |
1397 } | 1383 } |
1398 | 1384 |
1399 void AppCacheStorageImpl::FindResponseForSubRequest( | 1385 void AppCacheStorageImpl::FindResponseForSubRequest( |
1400 AppCache* cache, const GURL& url, | 1386 AppCache* cache, const GURL& url, |
1401 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, | 1387 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, |
1402 bool* found_network_namespace) { | 1388 bool* found_network_namespace) { |
1403 DCHECK(cache && cache->is_complete()); | 1389 DCHECK(cache && cache->is_complete()); |
1404 | 1390 |
1405 // When a group is forcibly deleted, all subresource loads for pages | 1391 // When a group is forcibly deleted, all subresource loads for pages |
1406 // using caches in the group will result in a synthesized network errors. | 1392 // using caches in the group will result in a synthesized network errors. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 Disable(); | 1626 Disable(); |
1641 if (!is_incognito_) { | 1627 if (!is_incognito_) { |
1642 VLOG(1) << "Deleting existing appcache data and starting over."; | 1628 VLOG(1) << "Deleting existing appcache data and starting over."; |
1643 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, | 1629 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, |
1644 NewRunnableFunction(DeleteDirectory, cache_directory_)); | 1630 NewRunnableFunction(DeleteDirectory, cache_directory_)); |
1645 } | 1631 } |
1646 } | 1632 } |
1647 } | 1633 } |
1648 | 1634 |
1649 } // namespace appcache | 1635 } // namespace appcache |
OLD | NEW |