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

Side by Side Diff: content/browser/loader/navigation_url_loader_network_service.cc

Issue 2891773002: Add a stub implementation of the URLLoaderFactory for AppCache. (Closed)
Patch Set: Address final round of comments Created 3 years, 7 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/loader/navigation_url_loader_network_service.h" 5 #include "content/browser/loader/navigation_url_loader_network_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "content/browser/appcache/appcache_navigation_handle.h" 11 #include "content/browser/appcache/appcache_navigation_handle.h"
12 #include "content/browser/appcache/appcache_navigation_handle_core.h"
13 #include "content/browser/appcache/appcache_request_handler.h"
14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
15 #include "content/browser/frame_host/frame_tree_node.h" 13 #include "content/browser/frame_host/frame_tree_node.h"
16 #include "content/browser/frame_host/navigation_request_info.h" 14 #include "content/browser/frame_host/navigation_request_info.h"
17 #include "content/browser/loader/navigation_resource_handler.h" 15 #include "content/browser/loader/navigation_resource_handler.h"
18 #include "content/browser/loader/navigation_resource_throttle.h" 16 #include "content/browser/loader/navigation_resource_throttle.h"
19 #include "content/browser/loader/navigation_url_loader_delegate.h" 17 #include "content/browser/loader/navigation_url_loader_delegate.h"
20 #include "content/browser/resource_context_impl.h" 18 #include "content/browser/resource_context_impl.h"
21 #include "content/browser/service_worker/service_worker_navigation_handle.h" 19 #include "content/browser/service_worker/service_worker_navigation_handle.h"
22 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " 20 #include "content/browser/service_worker/service_worker_navigation_handle_core.h "
23 #include "content/browser/service_worker/service_worker_request_handler.h" 21 #include "content/browser/service_worker/service_worker_request_handler.h"
(...skipping 11 matching lines...) Expand all
35 #include "content/public/browser/stream_handle.h" 33 #include "content/public/browser/stream_handle.h"
36 #include "content/public/common/referrer.h" 34 #include "content/public/common/referrer.h"
37 #include "content/public/common/url_constants.h" 35 #include "content/public/common/url_constants.h"
38 #include "net/base/load_flags.h" 36 #include "net/base/load_flags.h"
39 #include "net/url_request/url_request_context.h" 37 #include "net/url_request/url_request_context.h"
40 38
41 namespace content { 39 namespace content {
42 40
43 namespace { 41 namespace {
44 42
43 // Request ID for browser initiated requests. We start at -2 on the same lines
44 // as ResourceDispatcherHostImpl.
45 int g_next_request_id = -2;
46
45 WebContents* GetWebContentsFromFrameTreeNodeID(int frame_tree_node_id) { 47 WebContents* GetWebContentsFromFrameTreeNodeID(int frame_tree_node_id) {
46 DCHECK_CURRENTLY_ON(BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(BrowserThread::UI);
47 FrameTreeNode* frame_tree_node = 49 FrameTreeNode* frame_tree_node =
48 FrameTreeNode::GloballyFindByID(frame_tree_node_id); 50 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
49 if (!frame_tree_node) 51 if (!frame_tree_node)
50 return nullptr; 52 return nullptr;
51 53
52 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); 54 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
53 } 55 }
54 56
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 url_loader_factory_ptr = 88 url_loader_factory_ptr =
87 ServiceWorkerRequestHandler::InitializeForNavigationNetworkService( 89 ServiceWorkerRequestHandler::InitializeForNavigationNetworkService(
88 *resource_request, resource_context, 90 *resource_request, resource_context,
89 service_worker_navigation_handle_core, blob_storage_context, 91 service_worker_navigation_handle_core, blob_storage_context,
90 request_info->begin_params.skip_service_worker, resource_type, 92 request_info->begin_params.skip_service_worker, resource_type,
91 request_info->begin_params.request_context_type, frame_type, 93 request_info->begin_params.request_context_type, frame_type,
92 request_info->are_ancestors_secure, 94 request_info->are_ancestors_secure,
93 request_info->common_params.post_data, web_contents_getter); 95 request_info->common_params.post_data, web_contents_getter);
94 } 96 }
95 97
96 // TODO(scottmg): We need to rework AppCache to have it return a
97 // URLLoaderFactoryPtr[Info] here. We should also try to have it return
98 // synchronously in as many cases as possible (especially when there's no
99 // AppCache) to simplify and speed the common case.
100 if (false /*appcache_handle_core*/) {
101 AppCacheRequestHandler::InitializeForNavigationNetworkService(
102 std::move(resource_request), resource_context, appcache_handle_core,
103 resource_type,
104 base::Callback<void(
105 mojom::URLLoaderFactoryPtrInfo,
106 std::unique_ptr<ResourceRequest>)>() /* TODO(ananta) */);
107 return;
108 }
109
110 // If we haven't gotten one from the above, then use the one the UI thread 98 // If we haven't gotten one from the above, then use the one the UI thread
111 // gave us, or otherwise fallback to the default. 99 // gave us, or otherwise fallback to the default.
112 mojom::URLLoaderFactory* factory; 100 mojom::URLLoaderFactory* factory;
113 if (url_loader_factory_ptr) { 101 if (url_loader_factory_ptr) {
114 factory = url_loader_factory_ptr.get(); 102 factory = url_loader_factory_ptr.get();
115 } else { 103 } else {
116 if (factory_from_ui.is_valid()) { 104 if (factory_from_ui.is_valid()) {
117 url_loader_factory_ptr.Bind(std::move(factory_from_ui)); 105 url_loader_factory_ptr.Bind(std::move(factory_from_ui));
118 factory = url_loader_factory_ptr.get(); 106 factory = url_loader_factory_ptr.get();
119 } else { 107 } else {
120 factory = url_loader_factory_getter->GetNetworkFactory()->get(); 108 if (appcache_handle_core) {
109 factory = url_loader_factory_getter->GetAppCacheFactory()->get();
110 } else {
111 factory = url_loader_factory_getter->GetNetworkFactory()->get();
112 }
121 } 113 }
122 } 114 }
123 115
124 factory->CreateLoaderAndStart( 116 factory->CreateLoaderAndStart(
125 std::move(url_loader_request), 0 /* routing_id? */, 0 /* request_id? */, 117 std::move(url_loader_request), 0 /* routing_id? */, 0 /* request_id? */,
126 mojom::kURLLoadOptionSendSSLInfo, *resource_request, 118 mojom::kURLLoadOptionSendSSLInfo, *resource_request,
127 std::move(url_loader_client_to_pass)); 119 std::move(url_loader_client_to_pass));
128 } 120 }
129 121
130 } // namespace 122 } // namespace
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 mojom::URLLoaderFactoryPtrInfo factory_ptr_info; 178 mojom::URLLoaderFactoryPtrInfo factory_ptr_info;
187 179
188 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); 180 const auto& schemes = URLDataManagerBackend::GetWebUISchemes();
189 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) != 181 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) !=
190 schemes.end()) { 182 schemes.end()) {
191 FrameTreeNode* frame_tree_node = 183 FrameTreeNode* frame_tree_node =
192 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id); 184 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id);
193 factory_ptr_info = GetWebUIURLLoader(frame_tree_node).PassInterface(); 185 factory_ptr_info = GetWebUIURLLoader(frame_tree_node).PassInterface();
194 } 186 }
195 187
188 g_next_request_id--;
189
196 BrowserThread::PostTask( 190 BrowserThread::PostTask(
197 BrowserThread::IO, FROM_HERE, 191 BrowserThread::IO, FROM_HERE,
198 base::Bind(&PrepareNavigationStartOnIO, 192 base::Bind(&PrepareNavigationStartOnIO,
199 base::Passed(std::move(new_request)), resource_context, 193 base::Passed(std::move(new_request)), resource_context,
200 service_worker_navigation_handle 194 service_worker_navigation_handle
201 ? service_worker_navigation_handle->core() 195 ? service_worker_navigation_handle->core()
202 : nullptr, 196 : nullptr,
203 appcache_handle ? appcache_handle->core() : nullptr, 197 appcache_handle ? appcache_handle->core() : nullptr,
204 request_info_.get(), base::Passed(std::move(factory_ptr_info)), 198 request_info_.get(), base::Passed(std::move(factory_ptr_info)),
205 static_cast<StoragePartitionImpl*>(storage_partition) 199 static_cast<StoragePartitionImpl*>(storage_partition)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 258
265 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, 259 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this,
266 "&NavigationURLLoaderNetworkService", this, "success", 260 "&NavigationURLLoaderNetworkService", this, "success",
267 true); 261 true);
268 262
269 // Temporarily, we pass both a stream (null) and the data pipe to the 263 // Temporarily, we pass both a stream (null) and the data pipe to the
270 // delegate until PlzNavigate has shipped and we can be comfortable fully 264 // delegate until PlzNavigate has shipped and we can be comfortable fully
271 // switching to the data pipe. 265 // switching to the data pipe.
272 delegate_->OnResponseStarted(response_, nullptr, std::move(body), ssl_status_, 266 delegate_->OnResponseStarted(response_, nullptr, std::move(body), ssl_status_,
273 std::unique_ptr<NavigationData>(), 267 std::unique_ptr<NavigationData>(),
274 GlobalRequestID() /* request_id? */, 268 GlobalRequestID(-1, g_next_request_id),
275 false /* is_download? */, false /* is_stream */); 269 false /* is_download? */, false /* is_stream */);
276 } 270 }
277 271
278 void NavigationURLLoaderNetworkService::OnComplete( 272 void NavigationURLLoaderNetworkService::OnComplete(
279 const ResourceRequestCompletionStatus& completion_status) { 273 const ResourceRequestCompletionStatus& completion_status) {
280 if (completion_status.error_code != net::OK) { 274 if (completion_status.error_code != net::OK) {
281 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", 275 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted",
282 this, "&NavigationURLLoaderNetworkService", this, 276 this, "&NavigationURLLoaderNetworkService", this,
283 "success", false); 277 "success", false);
284 278
285 delegate_->OnRequestFailed(completion_status.exists_in_cache, 279 delegate_->OnRequestFailed(completion_status.exists_in_cache,
286 completion_status.error_code); 280 completion_status.error_code);
287 } 281 }
288 } 282 }
289 283
290 } // namespace content 284 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_url_loader_factory.cc ('k') | content/browser/storage_partition_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698