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

Side by Side Diff: content/network/url_loader_impl.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
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/network/url_loader_impl.h" 5 #include "content/network/url_loader_impl.h"
6 6
7 #include "base/task_scheduler/post_task.h" 7 #include "base/task_scheduler/post_task.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/common/net_adapters.h" 10 #include "content/common/net_adapters.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 break; 146 break;
147 } 147 }
148 } 148 }
149 149
150 return base::MakeUnique<net::ElementsUploadDataStream>( 150 return base::MakeUnique<net::ElementsUploadDataStream>(
151 std::move(element_readers), body->identifier()); 151 std::move(element_readers), body->identifier());
152 } 152 }
153 153
154 } // namespace 154 } // namespace
155 155
156 URLLoaderImpl::URLLoaderImpl( 156 URLLoaderImpl::URLLoaderImpl(NetworkContext* context,
157 NetworkContext* context, 157 int32_t options,
158 mojom::URLLoaderAssociatedRequest url_loader_request, 158 const ResourceRequest& request)
159 int32_t options,
160 const ResourceRequest& request,
161 mojom::URLLoaderClientPtr url_loader_client)
162 : context_(context), 159 : context_(context),
163 options_(options), 160 options_(options),
164 connected_(true), 161 connected_(true),
165 binding_(this, std::move(url_loader_request)), 162 binding_(this),
166 url_loader_client_(std::move(url_loader_client)),
167 writable_handle_watcher_(FROM_HERE, 163 writable_handle_watcher_(FROM_HERE,
168 mojo::SimpleWatcher::ArmingPolicy::MANUAL), 164 mojo::SimpleWatcher::ArmingPolicy::MANUAL),
169 peer_closed_handle_watcher_(FROM_HERE, 165 peer_closed_handle_watcher_(FROM_HERE,
170 mojo::SimpleWatcher::ArmingPolicy::MANUAL), 166 mojo::SimpleWatcher::ArmingPolicy::MANUAL),
171 weak_ptr_factory_(this) { 167 weak_ptr_factory_(this) {
172 binding_.set_connection_error_handler(
173 base::Bind(&URLLoaderImpl::OnConnectionError, base::Unretained(this)));
174
175 url_request_ = context_->url_request_context()->CreateRequest( 168 url_request_ = context_->url_request_context()->CreateRequest(
176 GURL(request.url), net::DEFAULT_PRIORITY, this); 169 GURL(request.url), net::DEFAULT_PRIORITY, this);
177 url_request_->set_method(request.method); 170 url_request_->set_method(request.method);
178 171
179 url_request_->set_first_party_for_cookies(request.first_party_for_cookies); 172 url_request_->set_first_party_for_cookies(request.first_party_for_cookies);
180 173
181 const Referrer referrer(request.referrer, request.referrer_policy); 174 const Referrer referrer(request.referrer, request.referrer_policy);
182 Referrer::SetReferrerForRequest(url_request_.get(), referrer); 175 Referrer::SetReferrerForRequest(url_request_.get(), referrer);
183 176
184 net::HttpRequestHeaders headers; 177 net::HttpRequestHeaders headers;
185 headers.AddHeadersFromString(request.headers); 178 headers.AddHeadersFromString(request.headers);
186 url_request_->SetExtraRequestHeaders(headers); 179 url_request_->SetExtraRequestHeaders(headers);
187 180
188 // Resolve elements from request_body and prepare upload data. 181 // Resolve elements from request_body and prepare upload data.
189 if (request.request_body.get()) { 182 if (request.request_body.get()) {
190 scoped_refptr<base::SequencedTaskRunner> task_runner = 183 scoped_refptr<base::SequencedTaskRunner> task_runner =
191 base::CreateSequencedTaskRunnerWithTraits( 184 base::CreateSequencedTaskRunnerWithTraits(
192 {base::MayBlock(), base::TaskPriority::USER_VISIBLE}); 185 {base::MayBlock(), base::TaskPriority::USER_VISIBLE});
193 url_request_->set_upload( 186 url_request_->set_upload(
194 CreateUploadDataStream(request.request_body.get(), task_runner.get())); 187 CreateUploadDataStream(request.request_body.get(), task_runner.get()));
195 } 188 }
196 189
197 int load_flags = BuildLoadFlagsForRequest(request, false); 190 int load_flags = BuildLoadFlagsForRequest(request, false);
198 url_request_->SetLoadFlags(load_flags); 191 url_request_->SetLoadFlags(load_flags);
199
200 url_request_->Start();
201 } 192 }
202 193
203 URLLoaderImpl::~URLLoaderImpl() {} 194 URLLoaderImpl::~URLLoaderImpl() {}
204 195
205 void URLLoaderImpl::Cleanup() { 196 void URLLoaderImpl::Cleanup() {
206 // The associated network context is going away and we have to destroy 197 // The associated network context is going away and we have to destroy
207 // net::URLRequest hold by this loader. 198 // net::URLRequest hold by this loader.
208 delete this; 199 delete this;
209 } 200 }
210 201
202 void URLLoaderImpl::Start(mojom::URLLoaderAssociatedRequest url_loader_request,
203 mojom::URLLoaderClientPtr url_loader_client) {
204 DCHECK(!url_loader_client_);
205 DCHECK(!binding_.is_bound());
206 DCHECK(url_request_);
207
208 binding_.Bind(std::move(url_loader_request));
209 binding_.set_connection_error_handler(
210 base::Bind(&URLLoaderImpl::OnConnectionError, base::Unretained(this)));
211
212 url_loader_client_ = std::move(url_loader_client);
213
214 url_request_->Start();
215 }
216
211 void URLLoaderImpl::FollowRedirect() { 217 void URLLoaderImpl::FollowRedirect() {
212 if (!url_request_) { 218 if (!url_request_) {
213 NotifyCompleted(net::ERR_UNEXPECTED); 219 NotifyCompleted(net::ERR_UNEXPECTED);
214 return; 220 return;
215 } 221 }
216 222
217 url_request_->FollowDeferredRedirect(); 223 url_request_->FollowDeferredRedirect();
218 } 224 }
219 225
220 void URLLoaderImpl::SetPriority(net::RequestPriority priority, 226 void URLLoaderImpl::SetPriority(net::RequestPriority priority,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 ReadMore(); 401 ReadMore();
396 } 402 }
397 403
398 void URLLoaderImpl::DeleteIfNeeded() { 404 void URLLoaderImpl::DeleteIfNeeded() {
399 bool has_data_pipe = pending_write_.get() || response_body_stream_.is_valid(); 405 bool has_data_pipe = pending_write_.get() || response_body_stream_.is_valid();
400 if (!connected_ && !has_data_pipe) 406 if (!connected_ && !has_data_pipe)
401 delete this; 407 delete this;
402 } 408 }
403 409
404 } // namespace content 410 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698