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

Side by Side Diff: content/browser/appcache/appcache_subresource_url_factory.cc

Issue 2991443002: The Appcache subresource URL factory needs to inform the URLLoaderClient if there is a failure. (Closed)
Patch Set: Provide a way to turn off certain errors like missing host etc in the factory for tests. Created 3 years, 5 months 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "content/browser/appcache/appcache_subresource_url_factory.h" 5 #include "content/browser/appcache/appcache_subresource_url_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/appcache/appcache_host.h" 9 #include "content/browser/appcache/appcache_host.h"
10 #include "content/browser/appcache/appcache_request_handler.h" 10 #include "content/browser/appcache/appcache_request_handler.h"
11 #include "content/browser/appcache/appcache_url_loader_job.h" 11 #include "content/browser/appcache/appcache_url_loader_job.h"
12 #include "content/browser/appcache/appcache_url_loader_request.h" 12 #include "content/browser/appcache/appcache_url_loader_request.h"
13 #include "content/browser/url_loader_factory_getter.h" 13 #include "content/browser/url_loader_factory_getter.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/common/resource_request.h" 15 #include "content/public/common/resource_request.h"
16 #include "content/public/common/url_loader_factory.mojom.h" 16 #include "content/public/common/url_loader_factory.mojom.h"
17 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/binding_set.h" 18 #include "mojo/public/cpp/bindings/binding_set.h"
19 #include "mojo/public/cpp/bindings/interface_ptr.h" 19 #include "mojo/public/cpp/bindings/interface_ptr.h"
20 #include "net/traffic_annotation/network_traffic_annotation.h" 20 #include "net/traffic_annotation/network_traffic_annotation.h"
21 21
22 namespace content { 22 namespace content {
23 23
24 namespace {
25
26 // Set to true if we are running as part of tests.
27 bool g_for_testing = false;
28
29 } // namespace.
30
24 // Implements the URLLoaderFactory mojom for AppCache requests. 31 // Implements the URLLoaderFactory mojom for AppCache requests.
25 AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory( 32 AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory(
26 mojom::URLLoaderFactoryRequest request, 33 mojom::URLLoaderFactoryRequest request,
27 URLLoaderFactoryGetter* default_url_loader_factory_getter, 34 URLLoaderFactoryGetter* default_url_loader_factory_getter,
28 base::WeakPtr<AppCacheHost> host) 35 base::WeakPtr<AppCacheHost> host)
29 : binding_(this, std::move(request)), 36 : binding_(this, std::move(request)),
30 default_url_loader_factory_getter_(default_url_loader_factory_getter), 37 default_url_loader_factory_getter_(default_url_loader_factory_getter),
31 appcache_host_(host) { 38 appcache_host_(host) {
32 binding_.set_connection_error_handler( 39 binding_.set_connection_error_handler(
33 base::Bind(&AppCacheSubresourceURLFactory::OnConnectionError, 40 base::Bind(&AppCacheSubresourceURLFactory::OnConnectionError,
(...skipping 22 matching lines...) Expand all
56 int32_t request_id, 63 int32_t request_id,
57 uint32_t options, 64 uint32_t options,
58 const ResourceRequest& request, 65 const ResourceRequest& request,
59 mojom::URLLoaderClientPtr client, 66 mojom::URLLoaderClientPtr client,
60 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { 67 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
61 DCHECK_CURRENTLY_ON(BrowserThread::IO); 68 DCHECK_CURRENTLY_ON(BrowserThread::IO);
62 DLOG(WARNING) << "Received request for loading : " << request.url.spec(); 69 DLOG(WARNING) << "Received request for loading : " << request.url.spec();
63 70
64 // If the host is invalid, it means that the renderer has probably died. 71 // If the host is invalid, it means that the renderer has probably died.
65 // (Frame has navigated elsewhere?) 72 // (Frame has navigated elsewhere?)
66 if (!appcache_host_.get()) 73 if (!appcache_host_.get() && !g_for_testing) {
74 NotifyError(std::move(client), net::ERR_FAILED);
67 return; 75 return;
76 }
68 77
69 std::unique_ptr<AppCacheRequestHandler> handler = 78 std::unique_ptr<AppCacheRequestHandler> handler =
70 appcache_host_->CreateRequestHandler( 79 appcache_host_->CreateRequestHandler(
71 AppCacheURLLoaderRequest::Create(request), request.resource_type, 80 AppCacheURLLoaderRequest::Create(request), request.resource_type,
72 request.should_reset_appcache); 81 request.should_reset_appcache);
73 if (!handler) { 82 if (!handler) {
74 ResourceRequestCompletionStatus request_result; 83 NotifyError(std::move(client), net::ERR_FAILED);
75 request_result.error_code = net::ERR_FAILED;
76 client->OnComplete(request_result);
77 return; 84 return;
78 } 85 }
79 86
80 handler->set_network_url_loader_factory_getter( 87 handler->set_network_url_loader_factory_getter(
81 default_url_loader_factory_getter_.get()); 88 default_url_loader_factory_getter_.get());
82 89
83 std::unique_ptr<SubresourceLoadInfo> load_info(new SubresourceLoadInfo()); 90 std::unique_ptr<SubresourceLoadInfo> load_info(new SubresourceLoadInfo());
84 load_info->url_loader_request = std::move(url_loader_request); 91 load_info->url_loader_request = std::move(url_loader_request);
85 load_info->routing_id = routing_id; 92 load_info->routing_id = routing_id;
86 load_info->request_id = request_id; 93 load_info->request_id = request_id;
(...skipping 15 matching lines...) Expand all
102 int32_t request_id, 109 int32_t request_id,
103 const ResourceRequest& request, 110 const ResourceRequest& request,
104 SyncLoadCallback callback) { 111 SyncLoadCallback callback) {
105 NOTREACHED(); 112 NOTREACHED();
106 } 113 }
107 114
108 void AppCacheSubresourceURLFactory::OnConnectionError() { 115 void AppCacheSubresourceURLFactory::OnConnectionError() {
109 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 116 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
110 } 117 }
111 118
119 void AppCacheSubresourceURLFactory::NotifyError(
120 mojom::URLLoaderClientPtr client,
121 int error_code) {
122 ResourceRequestCompletionStatus request_result;
123 request_result.error_code = error_code;
124 client->OnComplete(request_result);
125 }
126
127 // static
128 void AppCacheSubresourceURLFactory::SetForTesting(bool for_testing) {
129 g_for_testing = for_testing;
130 }
131
112 } // namespace content 132 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698