Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/appcache/appcache_network_service_handler.h" | |
| 6 #include "base/bind.h" | |
| 7 #include "base/logging.h" | |
| 8 #include "content/browser/appcache/appcache_entry.h" | |
| 9 #include "content/browser/appcache/appcache_host.h" | |
| 10 #include "content/browser/appcache/appcache_navigation_handle_core.h" | |
| 11 #include "content/browser/appcache/appcache_policy.h" | |
| 12 #include "content/browser/appcache/appcache_request.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 AppCacheNetworkServiceHandler::AppCacheNetworkServiceHandler( | |
| 18 std::unique_ptr<ResourceRequest> resource_request, | |
| 19 ResourceContext* resource_context, | |
| 20 AppCacheNavigationHandleCore* navigation_handle_core, | |
| 21 ResourceType resource_type, | |
| 22 base::Callback<void(mojom::URLLoaderFactoryPtrInfo, | |
| 23 std::unique_ptr<ResourceRequest>)> callback) | |
| 24 : resource_request_(std::move(resource_request)), | |
| 25 resource_context_(resource_context), | |
| 26 resource_type_(resource_type), | |
| 27 callback_(callback), | |
| 28 storage_(navigation_handle_core->host()->storage()), | |
| 29 host_(navigation_handle_core->host()) {} | |
| 30 | |
| 31 AppCacheNetworkServiceHandler::~AppCacheNetworkServiceHandler() {} | |
| 32 | |
| 33 void AppCacheNetworkServiceHandler::Start() { | |
| 34 storage_->FindResponseForMainRequest(resource_request_->url, GURL(), this); | |
| 35 } | |
| 36 | |
| 37 void AppCacheNetworkServiceHandler::OnMainResponseFound( | |
| 38 const GURL& url, | |
| 39 const AppCacheEntry& entry, | |
| 40 const GURL& fallback_url, | |
| 41 const AppCacheEntry& fallback_entry, | |
| 42 int64_t cache_id, | |
| 43 int64_t group_id, | |
| 44 const GURL& manifest_url) { | |
| 45 AppCachePolicy* policy = host_->service()->appcache_policy(); | |
| 46 bool was_blocked_by_policy = | |
| 47 !manifest_url.is_empty() && policy && | |
| 48 !policy->CanLoadAppCache(manifest_url, host_->first_party_url()); | |
| 49 | |
| 50 if (was_blocked_by_policy || !entry.has_response_id() || | |
| 51 cache_id == kAppCacheNoCacheId) { | |
| 52 BrowserThread::PostTask( | |
| 53 BrowserThread::UI, FROM_HERE, | |
| 54 base::Bind(callback_, | |
| 55 base::Passed(std::move(mojom::URLLoaderFactoryPtrInfo())), | |
| 56 base::Passed(std::move(resource_request_)))); | |
| 57 } else { | |
| 58 DLOG(WARNING) << "AppCache found for url " << url | |
| 59 << " falling back to network for now\n"; | |
| 60 // TODO(ananta) | |
| 61 // Pass a URLLoaderFactory pointer which supports serving URL requests from | |
|
jam
2017/05/11 01:42:13
similar to my comment to scott on the other cl for
ananta
2017/05/11 02:12:31
Noted
kinuko
2017/05/11 02:14:14
Yeah, maybe that's better.
jam
2017/05/11 14:50:43
Just to make sure I understand what you mean: do y
| |
| 62 // the cache. | |
| 63 BrowserThread::PostTask( | |
| 64 BrowserThread::UI, FROM_HERE, | |
| 65 base::Bind(callback_, | |
| 66 base::Passed(std::move(mojom::URLLoaderFactoryPtrInfo())), | |
| 67 base::Passed(std::move(resource_request_)))); | |
| 68 } | |
| 69 delete this; | |
| 70 } | |
| 71 | |
| 72 } // namespace content | |
| OLD | NEW |