OLD | NEW |
---|---|
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" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "content/public/common/referrer.h" | 23 #include "content/public/common/referrer.h" |
24 #include "content/public/common/service_manager_connection.h" | 24 #include "content/public/common/service_manager_connection.h" |
25 #include "content/public/common/service_names.mojom.h" | 25 #include "content/public/common/service_names.mojom.h" |
26 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
27 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
28 #include "services/service_manager/public/cpp/connector.h" | 28 #include "services/service_manager/public/cpp/connector.h" |
29 | 29 |
30 namespace content { | 30 namespace content { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | |
33 static base::LazyInstance<mojom::URLLoaderFactoryPtr>::Leaky | 34 static base::LazyInstance<mojom::URLLoaderFactoryPtr>::Leaky |
34 g_url_loader_factory = LAZY_INSTANCE_INITIALIZER; | 35 g_url_loader_factory = LAZY_INSTANCE_INITIALIZER; |
35 } | |
36 | 36 |
37 // This function is called on the IO thread for POST/PUT requests for | 37 // This function is called on the IO thread for POST/PUT requests for |
38 // attaching blob information to the request body. | 38 // attaching blob information to the request body. |
39 void HandleRequestsWithBody( | 39 void HandleRequestsWithBody( |
40 std::unique_ptr<ResourceRequest> request, | 40 std::unique_ptr<ResourceRequest> request, |
41 ResourceContext* resource_context, | 41 ResourceContext* resource_context, |
42 base::WeakPtr<NavigationURLLoaderNetworkService> url_loader) { | 42 base::WeakPtr<NavigationURLLoaderNetworkService> url_loader) { |
43 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
44 DCHECK(request->request_body.get()); | 44 DCHECK(request->request_body.get()); |
45 | 45 |
46 AttachRequestBodyBlobDataHandles(request->request_body.get(), | 46 AttachRequestBodyBlobDataHandles(request->request_body.get(), |
47 resource_context); | 47 resource_context); |
48 BrowserThread::PostTask( | 48 BrowserThread::PostTask( |
49 BrowserThread::UI, FROM_HERE, | 49 BrowserThread::UI, FROM_HERE, |
50 base::Bind(&NavigationURLLoaderNetworkService::StartURLRequest, | 50 base::Bind(&NavigationURLLoaderNetworkService::StartURLRequest, |
51 url_loader, base::Passed(&request))); | 51 url_loader, base::Passed(&request))); |
52 } | 52 } |
53 | 53 |
54 } // namespace | |
55 | |
54 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( | 56 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( |
55 ResourceContext* resource_context, | 57 ResourceContext* resource_context, |
56 StoragePartition* storage_partition, | 58 StoragePartition* storage_partition, |
57 std::unique_ptr<NavigationRequestInfo> request_info, | 59 std::unique_ptr<NavigationRequestInfo> request_info, |
58 std::unique_ptr<NavigationUIData> navigation_ui_data, | 60 std::unique_ptr<NavigationUIData> navigation_ui_data, |
59 ServiceWorkerNavigationHandle* service_worker_handle, | 61 ServiceWorkerNavigationHandle* service_worker_handle, |
60 AppCacheNavigationHandle* appcache_handle, | 62 AppCacheNavigationHandle* appcache_handle, |
61 NavigationURLLoaderDelegate* delegate) | 63 NavigationURLLoaderDelegate* delegate) |
62 : delegate_(delegate), binding_(this), weak_factory_(this) { | 64 : delegate_(delegate), binding_(this), weak_factory_(this) { |
63 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
64 | 66 |
65 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( | 67 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( |
66 "navigation", "Navigation timeToResponseStarted", this, | 68 "navigation", "Navigation timeToResponseStarted", this, |
67 request_info->common_params.navigation_start, "FrameTreeNode id", | 69 request_info->common_params.navigation_start, "FrameTreeNode id", |
68 request_info->frame_tree_node_id); | 70 request_info->frame_tree_node_id); |
69 | 71 |
70 // TODO(scottmg): Maybe some of this setup should be done only once, instead | |
71 // of every time. | |
72 if (g_url_loader_factory.Get().get()) { | |
73 url_loader_factory_ = std::move(g_url_loader_factory.Get()); | |
74 } else { | |
75 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( | |
76 mojom::kNetworkServiceName, &url_loader_factory_); | |
77 } | |
78 | |
79 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. | 72 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. |
80 auto new_request = base::MakeUnique<ResourceRequest>(); | 73 auto new_request = base::MakeUnique<ResourceRequest>(); |
81 | 74 |
82 new_request->method = request_info->common_params.method; | 75 new_request->method = request_info->common_params.method; |
83 new_request->url = request_info->common_params.url; | 76 new_request->url = request_info->common_params.url; |
84 new_request->first_party_for_cookies = request_info->first_party_for_cookies; | 77 new_request->first_party_for_cookies = request_info->first_party_for_cookies; |
85 new_request->priority = net::HIGHEST; | 78 new_request->priority = net::HIGHEST; |
86 | 79 |
87 // The code below to set fields like request_initiator, referrer, etc has | 80 // The code below to set fields like request_initiator, referrer, etc has |
88 // been copied from ResourceDispatcherHostImpl. We did not refactor the | 81 // been copied from ResourceDispatcherHostImpl. We did not refactor the |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 } | 192 } |
200 } | 193 } |
201 | 194 |
202 void NavigationURLLoaderNetworkService::StartURLRequest( | 195 void NavigationURLLoaderNetworkService::StartURLRequest( |
203 std::unique_ptr<ResourceRequest> request) { | 196 std::unique_ptr<ResourceRequest> request) { |
204 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 197 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
205 | 198 |
206 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; | 199 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; |
207 binding_.Bind(&url_loader_client_ptr_to_pass); | 200 binding_.Bind(&url_loader_client_ptr_to_pass); |
208 | 201 |
209 url_loader_factory_->CreateLoaderAndStart( | 202 GetURLLoaderFactory()->CreateLoaderAndStart( |
210 mojo::MakeRequest(&url_loader_associated_ptr_), 0 /* routing_id? */, | 203 mojo::MakeRequest(&url_loader_associated_ptr_), 0 /* routing_id? */, |
211 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, *request, | 204 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, *request, |
212 std::move(url_loader_client_ptr_to_pass)); | 205 std::move(url_loader_client_ptr_to_pass)); |
213 } | 206 } |
214 | 207 |
208 mojom::URLLoaderFactory* | |
scottmg
2017/05/02 18:00:56
nit; maybe make this return a & instead of a point
yzshen1
2017/05/02 20:20:14
Done.
| |
209 NavigationURLLoaderNetworkService::GetURLLoaderFactory() { | |
210 // TODO(yzshen): We will need the ability to customize the factory per frame | |
211 // e.g., for appacache or service worker. | |
scottmg
2017/05/02 18:00:56
"appcache"
yzshen1
2017/05/02 20:20:14
Done.
| |
212 if (!g_url_loader_factory.Get()) { | |
213 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( | |
214 mojom::kNetworkServiceName, &g_url_loader_factory.Get()); | |
215 } | |
216 | |
217 return g_url_loader_factory.Get().get(); | |
218 } | |
219 | |
215 } // namespace content | 220 } // namespace content |
OLD | NEW |