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

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

Issue 2847003003: Fix SitePerProcessBrowserTest.ProcessTransferAfterError to not requiring modifying the mock HostRes… (Closed)
Patch Set: remove unnecessary include 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"
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 11 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
11 #include "content/browser/frame_host/navigation_request_info.h" 12 #include "content/browser/frame_host/navigation_request_info.h"
12 #include "content/browser/loader/navigation_resource_handler.h" 13 #include "content/browser/loader/navigation_resource_handler.h"
13 #include "content/browser/loader/navigation_resource_throttle.h" 14 #include "content/browser/loader/navigation_resource_throttle.h"
14 #include "content/browser/loader/navigation_url_loader_delegate.h" 15 #include "content/browser/loader/navigation_url_loader_delegate.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/global_request_id.h" 17 #include "content/public/browser/global_request_id.h"
17 #include "content/public/browser/navigation_data.h" 18 #include "content/public/browser/navigation_data.h"
18 #include "content/public/browser/navigation_ui_data.h" 19 #include "content/public/browser/navigation_ui_data.h"
19 #include "content/public/browser/ssl_status.h" 20 #include "content/public/browser/ssl_status.h"
20 #include "content/public/browser/stream_handle.h" 21 #include "content/public/browser/stream_handle.h"
21 #include "content/public/common/referrer.h" 22 #include "content/public/common/referrer.h"
22 #include "content/public/common/service_manager_connection.h" 23 #include "content/public/common/service_manager_connection.h"
23 #include "content/public/common/service_names.mojom.h" 24 #include "content/public/common/service_names.mojom.h"
24 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
25 #include "net/url_request/url_request_context.h" 26 #include "net/url_request/url_request_context.h"
26 #include "services/service_manager/public/cpp/connector.h" 27 #include "services/service_manager/public/cpp/connector.h"
27 28
28 namespace content { 29 namespace content {
29 30
31 namespace {
32 static base::LazyInstance<mojom::URLLoaderFactoryPtr>::Leaky
33 g_url_loader_factory = LAZY_INSTANCE_INITIALIZER;
34 }
35
30 // This function is called on the IO thread for POST/PUT requests for 36 // This function is called on the IO thread for POST/PUT requests for
31 // attaching blob information to the request body. 37 // attaching blob information to the request body.
32 void HandleRequestsWithBody( 38 void HandleRequestsWithBody(
33 std::unique_ptr<ResourceRequest> request, 39 std::unique_ptr<ResourceRequest> request,
34 ResourceContext* resource_context, 40 ResourceContext* resource_context,
35 base::WeakPtr<NavigationURLLoaderNetworkService> url_loader) { 41 base::WeakPtr<NavigationURLLoaderNetworkService> url_loader) {
36 DCHECK_CURRENTLY_ON(BrowserThread::IO); 42 DCHECK_CURRENTLY_ON(BrowserThread::IO);
37 DCHECK(request->request_body.get()); 43 DCHECK(request->request_body.get());
38 44
39 AttachRequestBodyBlobDataHandles(request->request_body.get(), 45 AttachRequestBodyBlobDataHandles(request->request_body.get(),
(...skipping 10 matching lines...) Expand all
50 std::unique_ptr<NavigationRequestInfo> request_info, 56 std::unique_ptr<NavigationRequestInfo> request_info,
51 std::unique_ptr<NavigationUIData> navigation_ui_data, 57 std::unique_ptr<NavigationUIData> navigation_ui_data,
52 ServiceWorkerNavigationHandle* service_worker_handle, 58 ServiceWorkerNavigationHandle* service_worker_handle,
53 AppCacheNavigationHandle* appcache_handle, 59 AppCacheNavigationHandle* appcache_handle,
54 NavigationURLLoaderDelegate* delegate) 60 NavigationURLLoaderDelegate* delegate)
55 : delegate_(delegate), binding_(this), weak_factory_(this) { 61 : delegate_(delegate), binding_(this), weak_factory_(this) {
56 DCHECK_CURRENTLY_ON(BrowserThread::UI); 62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
57 63
58 // TODO(scottmg): Maybe some of this setup should be done only once, instead 64 // TODO(scottmg): Maybe some of this setup should be done only once, instead
59 // of every time. 65 // of every time.
60 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( 66 if (g_url_loader_factory.Get().get()) {
61 mojom::kNetworkServiceName, &url_loader_factory_); 67 url_loader_factory_ = std::move(g_url_loader_factory.Get());
68 } else {
69 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface(
70 mojom::kNetworkServiceName, &url_loader_factory_);
71 }
62 72
63 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. 73 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here.
64 auto new_request = base::MakeUnique<ResourceRequest>(); 74 auto new_request = base::MakeUnique<ResourceRequest>();
65 75
66 new_request->method = request_info->common_params.method; 76 new_request->method = request_info->common_params.method;
67 new_request->url = request_info->common_params.url; 77 new_request->url = request_info->common_params.url;
68 new_request->first_party_for_cookies = request_info->first_party_for_cookies; 78 new_request->first_party_for_cookies = request_info->first_party_for_cookies;
69 new_request->priority = net::HIGHEST; 79 new_request->priority = net::HIGHEST;
70 80
71 // The code below to set fields like request_initiator, referrer, etc has 81 // The code below to set fields like request_initiator, referrer, etc has
(...skipping 27 matching lines...) Expand all
99 resource_context, 109 resource_context,
100 weak_factory_.GetWeakPtr())); 110 weak_factory_.GetWeakPtr()));
101 return; 111 return;
102 } 112 }
103 113
104 StartURLRequest(std::move(new_request)); 114 StartURLRequest(std::move(new_request));
105 } 115 }
106 116
107 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() {} 117 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() {}
108 118
119 void NavigationURLLoaderNetworkService::OverrideURLLoaderFactoryForTesting(
120 mojom::URLLoaderFactoryPtr url_loader_factory) {
121 g_url_loader_factory.Get() = std::move(url_loader_factory);
122 }
123
109 void NavigationURLLoaderNetworkService::FollowRedirect() { 124 void NavigationURLLoaderNetworkService::FollowRedirect() {
110 url_loader_associated_ptr_->FollowRedirect(); 125 url_loader_associated_ptr_->FollowRedirect();
111 } 126 }
112 127
113 void NavigationURLLoaderNetworkService::ProceedWithResponse() {} 128 void NavigationURLLoaderNetworkService::ProceedWithResponse() {}
114 129
115 void NavigationURLLoaderNetworkService::OnReceiveResponse( 130 void NavigationURLLoaderNetworkService::OnReceiveResponse(
116 const ResourceResponseHead& head, 131 const ResourceResponseHead& head,
117 const base::Optional<net::SSLInfo>& ssl_info, 132 const base::Optional<net::SSLInfo>& ssl_info,
118 mojom::DownloadedTempFilePtr downloaded_file) { 133 mojom::DownloadedTempFilePtr downloaded_file) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; 191 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass;
177 binding_.Bind(&url_loader_client_ptr_to_pass); 192 binding_.Bind(&url_loader_client_ptr_to_pass);
178 193
179 url_loader_factory_->CreateLoaderAndStart( 194 url_loader_factory_->CreateLoaderAndStart(
180 mojo::MakeRequest(&url_loader_associated_ptr_), 0 /* routing_id? */, 195 mojo::MakeRequest(&url_loader_associated_ptr_), 0 /* routing_id? */,
181 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, *request, 196 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, *request,
182 std::move(url_loader_client_ptr_to_pass)); 197 std::move(url_loader_client_ptr_to_pass));
183 } 198 }
184 199
185 } // namespace content 200 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698