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

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

Issue 2874163004: Add support in the network service for different contexts. (Closed)
Patch Set: review comment and clang fixes 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/lazy_instance.h"
10 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
11 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
12 #include "content/browser/appcache/appcache_navigation_handle.h" 11 #include "content/browser/appcache/appcache_navigation_handle.h"
13 #include "content/browser/appcache/appcache_navigation_handle_core.h" 12 #include "content/browser/appcache/appcache_navigation_handle_core.h"
14 #include "content/browser/appcache/appcache_request_handler.h" 13 #include "content/browser/appcache/appcache_request_handler.h"
15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 14 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
16 #include "content/browser/frame_host/frame_tree_node.h" 15 #include "content/browser/frame_host/frame_tree_node.h"
17 #include "content/browser/frame_host/navigation_request_info.h" 16 #include "content/browser/frame_host/navigation_request_info.h"
18 #include "content/browser/loader/navigation_resource_handler.h" 17 #include "content/browser/loader/navigation_resource_handler.h"
19 #include "content/browser/loader/navigation_resource_throttle.h" 18 #include "content/browser/loader/navigation_resource_throttle.h"
20 #include "content/browser/loader/navigation_url_loader_delegate.h" 19 #include "content/browser/loader/navigation_url_loader_delegate.h"
21 #include "content/browser/resource_context_impl.h" 20 #include "content/browser/resource_context_impl.h"
22 #include "content/browser/service_worker/service_worker_navigation_handle.h" 21 #include "content/browser/service_worker/service_worker_navigation_handle.h"
23 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " 22 #include "content/browser/service_worker/service_worker_navigation_handle_core.h "
24 #include "content/browser/service_worker/service_worker_request_handler.h" 23 #include "content/browser/service_worker/service_worker_request_handler.h"
24 #include "content/browser/storage_partition_impl.h"
25 #include "content/browser/url_loader_factory_getter.h"
25 #include "content/browser/web_contents/web_contents_impl.h" 26 #include "content/browser/web_contents/web_contents_impl.h"
26 #include "content/browser/webui/url_data_manager_backend.h" 27 #include "content/browser/webui/url_data_manager_backend.h"
27 #include "content/browser/webui/web_ui_url_loader_factory.h" 28 #include "content/browser/webui/web_ui_url_loader_factory.h"
29 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/global_request_id.h" 31 #include "content/public/browser/global_request_id.h"
30 #include "content/public/browser/navigation_data.h" 32 #include "content/public/browser/navigation_data.h"
31 #include "content/public/browser/navigation_ui_data.h" 33 #include "content/public/browser/navigation_ui_data.h"
32 #include "content/public/browser/ssl_status.h" 34 #include "content/public/browser/ssl_status.h"
33 #include "content/public/browser/stream_handle.h" 35 #include "content/public/browser/stream_handle.h"
34 #include "content/public/common/referrer.h" 36 #include "content/public/common/referrer.h"
35 #include "content/public/common/service_manager_connection.h"
36 #include "content/public/common/service_names.mojom.h"
37 #include "content/public/common/url_constants.h" 37 #include "content/public/common/url_constants.h"
38 #include "net/base/load_flags.h" 38 #include "net/base/load_flags.h"
39 #include "net/url_request/url_request_context.h" 39 #include "net/url_request/url_request_context.h"
40 #include "services/service_manager/public/cpp/connector.h"
41 40
42 namespace content { 41 namespace content {
43 42
44 namespace { 43 namespace {
45 44
46 static base::LazyInstance<mojom::URLLoaderFactoryPtr>::Leaky
47 g_url_loader_factory;
48 #if DCHECK_IS_ON()
49 static bool g_url_loader_factory_retrieved;
50 #endif // DCHECK_IS_ON()
51
52 WebContents* GetWebContentsFromFrameTreeNodeID(int frame_tree_node_id) { 45 WebContents* GetWebContentsFromFrameTreeNodeID(int frame_tree_node_id) {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI); 46 DCHECK_CURRENTLY_ON(BrowserThread::UI);
54 FrameTreeNode* frame_tree_node = 47 FrameTreeNode* frame_tree_node =
55 FrameTreeNode::GloballyFindByID(frame_tree_node_id); 48 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
56 if (!frame_tree_node) 49 if (!frame_tree_node)
57 return nullptr; 50 return nullptr;
58 51
59 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); 52 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
60 } 53 }
61 54
62 void PrepareNavigationStartOnIO( 55 void PrepareNavigationStartOnIO(
63 std::unique_ptr<ResourceRequest> resource_request, 56 std::unique_ptr<ResourceRequest> resource_request,
64 ResourceContext* resource_context, 57 ResourceContext* resource_context,
65 ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core, 58 ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core,
66 AppCacheNavigationHandleCore* appcache_handle_core, 59 AppCacheNavigationHandleCore* appcache_handle_core,
67 NavigationRequestInfo* request_info, 60 NavigationRequestInfo* request_info,
68 mojom::URLLoaderFactoryPtrInfo factory_from_ui, 61 mojom::URLLoaderFactoryPtrInfo factory_from_ui,
62 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter,
69 const base::Callback<WebContents*(void)>& web_contents_getter, 63 const base::Callback<WebContents*(void)>& web_contents_getter,
70 mojom::URLLoaderAssociatedRequest url_loader_request, 64 mojom::URLLoaderAssociatedRequest url_loader_request,
71 mojom::URLLoaderClientPtr url_loader_client_to_pass, 65 mojom::URLLoaderClientPtr url_loader_client_to_pass,
72 std::unique_ptr<service_manager::Connector> connector) { 66 std::unique_ptr<service_manager::Connector> connector) {
73 DCHECK_CURRENTLY_ON(BrowserThread::IO); 67 DCHECK_CURRENTLY_ON(BrowserThread::IO);
74 68
75 const ResourceType resource_type = request_info->is_main_frame 69 const ResourceType resource_type = request_info->is_main_frame
76 ? RESOURCE_TYPE_MAIN_FRAME 70 ? RESOURCE_TYPE_MAIN_FRAME
77 : RESOURCE_TYPE_SUB_FRAME; 71 : RESOURCE_TYPE_SUB_FRAME;
78 72
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // If we haven't gotten one from the above, then use the one the UI thread 110 // If we haven't gotten one from the above, then use the one the UI thread
117 // gave us, or otherwise fallback to the default. 111 // gave us, or otherwise fallback to the default.
118 mojom::URLLoaderFactory* factory; 112 mojom::URLLoaderFactory* factory;
119 if (url_loader_factory_ptr) { 113 if (url_loader_factory_ptr) {
120 factory = url_loader_factory_ptr.get(); 114 factory = url_loader_factory_ptr.get();
121 } else { 115 } else {
122 if (factory_from_ui.is_valid()) { 116 if (factory_from_ui.is_valid()) {
123 url_loader_factory_ptr.Bind(std::move(factory_from_ui)); 117 url_loader_factory_ptr.Bind(std::move(factory_from_ui));
124 factory = url_loader_factory_ptr.get(); 118 factory = url_loader_factory_ptr.get();
125 } else { 119 } else {
126 if (!g_url_loader_factory.Get()) { 120 factory = url_loader_factory_getter->GetNetworkFactory()->get();
127 #if DCHECK_IS_ON()
128 DCHECK(!g_url_loader_factory_retrieved);
129 #endif // DCHECK_IS_ON()
130 connector->BindInterface(mojom::kNetworkServiceName,
131 &g_url_loader_factory.Get());
132 #if DCHECK_IS_ON()
133 g_url_loader_factory_retrieved = true;
134 #endif // DCHECK_IS_ON()
135 }
136 factory = g_url_loader_factory.Get().get();
137 } 121 }
138 } 122 }
139 123
140 factory->CreateLoaderAndStart( 124 factory->CreateLoaderAndStart(
141 std::move(url_loader_request), 0 /* routing_id? */, 0 /* request_id? */, 125 std::move(url_loader_request), 0 /* routing_id? */, 0 /* request_id? */,
142 mojom::kURLLoadOptionSendSSLInfo, *resource_request, 126 mojom::kURLLoadOptionSendSSLInfo, *resource_request,
143 std::move(url_loader_client_to_pass)); 127 std::move(url_loader_client_to_pass));
144 } 128 }
145 129
146 } // namespace 130 } // namespace
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 195
212 BrowserThread::PostTask( 196 BrowserThread::PostTask(
213 BrowserThread::IO, FROM_HERE, 197 BrowserThread::IO, FROM_HERE,
214 base::Bind(&PrepareNavigationStartOnIO, 198 base::Bind(&PrepareNavigationStartOnIO,
215 base::Passed(std::move(new_request)), resource_context, 199 base::Passed(std::move(new_request)), resource_context,
216 service_worker_navigation_handle 200 service_worker_navigation_handle
217 ? service_worker_navigation_handle->core() 201 ? service_worker_navigation_handle->core()
218 : nullptr, 202 : nullptr,
219 appcache_handle ? appcache_handle->core() : nullptr, 203 appcache_handle ? appcache_handle->core() : nullptr,
220 request_info_.get(), base::Passed(std::move(factory_ptr_info)), 204 request_info_.get(), base::Passed(std::move(factory_ptr_info)),
205 static_cast<StoragePartitionImpl*>(storage_partition)
206 ->url_loader_factory_getter(),
221 base::Bind(&GetWebContentsFromFrameTreeNodeID, 207 base::Bind(&GetWebContentsFromFrameTreeNodeID,
222 request_info_->frame_tree_node_id), 208 request_info_->frame_tree_node_id),
223 base::Passed(std::move(loader_associated_request)), 209 base::Passed(std::move(loader_associated_request)),
224 base::Passed(std::move(url_loader_client_ptr_to_pass)), 210 base::Passed(std::move(url_loader_client_ptr_to_pass)),
225 base::Passed(ServiceManagerConnection::GetForProcess() 211 base::Passed(ServiceManagerConnection::GetForProcess()
226 ->GetConnector() 212 ->GetConnector()
227 ->Clone()))); 213 ->Clone())));
228 } 214 }
229 215
230 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() {} 216 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() {}
231 217
232 void NavigationURLLoaderNetworkService::OverrideURLLoaderFactoryForTesting(
233 mojom::URLLoaderFactoryPtr url_loader_factory) {
234 g_url_loader_factory.Get() = std::move(url_loader_factory);
235 }
236
237 void NavigationURLLoaderNetworkService::FollowRedirect() { 218 void NavigationURLLoaderNetworkService::FollowRedirect() {
238 url_loader_associated_ptr_->FollowRedirect(); 219 url_loader_associated_ptr_->FollowRedirect();
239 } 220 }
240 221
241 void NavigationURLLoaderNetworkService::ProceedWithResponse() {} 222 void NavigationURLLoaderNetworkService::ProceedWithResponse() {}
242 223
243 void NavigationURLLoaderNetworkService::OnReceiveResponse( 224 void NavigationURLLoaderNetworkService::OnReceiveResponse(
244 const ResourceResponseHead& head, 225 const ResourceResponseHead& head,
245 const base::Optional<net::SSLInfo>& ssl_info, 226 const base::Optional<net::SSLInfo>& ssl_info,
246 mojom::DownloadedTempFilePtr downloaded_file) { 227 mojom::DownloadedTempFilePtr downloaded_file) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", 281 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted",
301 this, "&NavigationURLLoaderNetworkService", this, 282 this, "&NavigationURLLoaderNetworkService", this,
302 "success", false); 283 "success", false);
303 284
304 delegate_->OnRequestFailed(completion_status.exists_in_cache, 285 delegate_->OnRequestFailed(completion_status.exists_in_cache,
305 completion_status.error_code); 286 completion_status.error_code);
306 } 287 }
307 } 288 }
308 289
309 } // namespace content 290 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698