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

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

Issue 2919313004: Get rid of URLLoaderFactory in browser-side case (Closed)
Patch Set: . Created 3 years, 6 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
« no previous file with comments | « no previous file | content/browser/loader/url_loader_request_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (!frame_tree_node) 52 if (!frame_tree_node)
53 return nullptr; 53 return nullptr;
54 54
55 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); 55 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 // Kept around during the lifetime of the navigation request, and is 60 // Kept around during the lifetime of the navigation request, and is
61 // responsible for dispatching a ResourceRequest to the appropriate 61 // responsible for dispatching a ResourceRequest to the appropriate
62 // URLLoaderFactory. In order to get the right URLLoaderFactory it 62 // URLLoader. In order to get the right URLLoader it builds a vector
63 // builds a vector of URLLoaderRequestHandler's and successively calls 63 // of URLLoaderRequestHandler's and successively calls MaybeCreateLoader
64 // MaybeCreateLoaderFactory on each until the request is successfully 64 // on each until the request is successfully handled. The same sequence
65 // handled. The same sequence may be performed multiple times when 65 // may be performed multiple times when redirects happen.
66 // redirects happen.
67 class NavigationURLLoaderNetworkService::URLLoaderRequestController { 66 class NavigationURLLoaderNetworkService::URLLoaderRequestController {
68 public: 67 public:
69 URLLoaderRequestController( 68 URLLoaderRequestController(
70 std::unique_ptr<ResourceRequest> resource_request, 69 std::unique_ptr<ResourceRequest> resource_request,
71 ResourceContext* resource_context, 70 ResourceContext* resource_context,
72 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter) 71 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter)
73 : resource_request_(std::move(resource_request)), 72 : resource_request_(std::move(resource_request)),
74 resource_context_(resource_context), 73 resource_context_(resource_context),
75 url_loader_factory_getter_(url_loader_factory_getter) {} 74 url_loader_factory_getter_(url_loader_factory_getter) {}
76 75
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 135
137 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr_)); 136 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr_));
138 } 137 }
139 138
140 // This could be called multiple times. 139 // This could be called multiple times.
141 void Restart(mojom::URLLoaderAssociatedRequest url_loader_request, 140 void Restart(mojom::URLLoaderAssociatedRequest url_loader_request,
142 mojom::URLLoaderClientPtr url_loader_client_ptr) { 141 mojom::URLLoaderClientPtr url_loader_client_ptr) {
143 url_loader_request_ = std::move(url_loader_request); 142 url_loader_request_ = std::move(url_loader_request);
144 url_loader_client_ptr_ = std::move(url_loader_client_ptr); 143 url_loader_client_ptr_ = std::move(url_loader_client_ptr);
145 handler_index_ = 0; 144 handler_index_ = 0;
146 MaybeStartLoader(nullptr); 145 MaybeStartLoader(StartLoaderCallback());
147 } 146 }
148 147
149 void MaybeStartLoader(mojom::URLLoaderFactory* factory) { 148 void MaybeStartLoader(StartLoaderCallback start_loader_callback) {
150 DCHECK(url_loader_client_ptr_.is_bound()); 149 DCHECK(url_loader_client_ptr_.is_bound());
151 150
152 if (factory) { 151 if (start_loader_callback) {
153 factory->CreateLoaderAndStart( 152 std::move(start_loader_callback)
154 std::move(url_loader_request_), 0 /* routing_id? */, 153 .Run(std::move(url_loader_request_),
yzshen1 2017/06/07 23:28:25 I noticed that this still uses associated URLLoade
155 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, 154 std::move(url_loader_client_ptr_));
156 *resource_request_, std::move(url_loader_client_ptr_));
157 return; 155 return;
158 } 156 }
159 157
160 if (handler_index_ < handlers_.size()) { 158 if (handler_index_ < handlers_.size()) {
161 handlers_[handler_index_++]->MaybeCreateLoaderFactory( 159 handlers_[handler_index_++]->MaybeCreateLoader(
162 *resource_request_, resource_context_, 160 *resource_request_, resource_context_,
163 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader, 161 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader,
164 base::Unretained(this))); 162 base::Unretained(this)));
165 return; 163 return;
166 } 164 }
167 165
166 mojom::URLLoaderFactory* factory = nullptr;
168 DCHECK_EQ(handlers_.size(), handler_index_); 167 DCHECK_EQ(handlers_.size(), handler_index_);
169 if (resource_request_->url.SchemeIs(url::kBlobScheme)) { 168 if (resource_request_->url.SchemeIs(url::kBlobScheme)) {
170 factory = url_loader_factory_getter_->GetBlobFactory()->get(); 169 factory = url_loader_factory_getter_->GetBlobFactory()->get();
171 } else { 170 } else {
172 factory = url_loader_factory_getter_->GetNetworkFactory()->get(); 171 factory = url_loader_factory_getter_->GetNetworkFactory()->get();
173 } 172 }
174 MaybeStartLoader(factory); 173 factory->CreateLoaderAndStart(
174 std::move(url_loader_request_), 0 /* routing_id? */,
175 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo,
176 *resource_request_, std::move(url_loader_client_ptr_));
175 } 177 }
176 178
177 private: 179 private:
178 std::vector<std::unique_ptr<URLLoaderRequestHandler>> handlers_; 180 std::vector<std::unique_ptr<URLLoaderRequestHandler>> handlers_;
179 size_t handler_index_ = 0; 181 size_t handler_index_ = 0;
180 182
181 std::unique_ptr<ResourceRequest> resource_request_; 183 std::unique_ptr<ResourceRequest> resource_request_;
182 ResourceContext* resource_context_; 184 ResourceContext* resource_context_;
183 185
184 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_; 186 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", 354 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted",
353 this, "&NavigationURLLoaderNetworkService", this, 355 this, "&NavigationURLLoaderNetworkService", this,
354 "success", false); 356 "success", false);
355 357
356 delegate_->OnRequestFailed(completion_status.exists_in_cache, 358 delegate_->OnRequestFailed(completion_status.exists_in_cache,
357 completion_status.error_code); 359 completion_status.error_code);
358 } 360 }
359 } 361 }
360 362
361 } // namespace content 363 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/url_loader_request_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698