| 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/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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 : context_(context), | 163 : context_(context), |
| 164 options_(options), | 164 options_(options), |
| 165 connected_(true), | 165 connected_(true), |
| 166 binding_(this, std::move(url_loader_request)), | 166 binding_(this, std::move(url_loader_request)), |
| 167 url_loader_client_(std::move(url_loader_client)), | 167 url_loader_client_(std::move(url_loader_client)), |
| 168 writable_handle_watcher_(FROM_HERE, | 168 writable_handle_watcher_(FROM_HERE, |
| 169 mojo::SimpleWatcher::ArmingPolicy::MANUAL), | 169 mojo::SimpleWatcher::ArmingPolicy::MANUAL), |
| 170 peer_closed_handle_watcher_(FROM_HERE, | 170 peer_closed_handle_watcher_(FROM_HERE, |
| 171 mojo::SimpleWatcher::ArmingPolicy::MANUAL), | 171 mojo::SimpleWatcher::ArmingPolicy::MANUAL), |
| 172 weak_ptr_factory_(this) { | 172 weak_ptr_factory_(this) { |
| 173 context_->RegisterURLLoader(this); |
| 173 binding_.set_connection_error_handler( | 174 binding_.set_connection_error_handler( |
| 174 base::Bind(&URLLoaderImpl::OnConnectionError, base::Unretained(this))); | 175 base::Bind(&URLLoaderImpl::OnConnectionError, base::Unretained(this))); |
| 175 | 176 |
| 176 url_request_ = context_->url_request_context()->CreateRequest( | 177 url_request_ = context_->url_request_context()->CreateRequest( |
| 177 GURL(request.url), net::DEFAULT_PRIORITY, this, traffic_annotation); | 178 GURL(request.url), net::DEFAULT_PRIORITY, this, traffic_annotation); |
| 178 url_request_->set_method(request.method); | 179 url_request_->set_method(request.method); |
| 179 | 180 |
| 180 url_request_->set_first_party_for_cookies(request.first_party_for_cookies); | 181 url_request_->set_first_party_for_cookies(request.first_party_for_cookies); |
| 181 | 182 |
| 182 const Referrer referrer(request.referrer, request.referrer_policy); | 183 const Referrer referrer(request.referrer, request.referrer_policy); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 url_request_->set_upload( | 195 url_request_->set_upload( |
| 195 CreateUploadDataStream(request.request_body.get(), task_runner.get())); | 196 CreateUploadDataStream(request.request_body.get(), task_runner.get())); |
| 196 } | 197 } |
| 197 | 198 |
| 198 int load_flags = BuildLoadFlagsForRequest(request, false); | 199 int load_flags = BuildLoadFlagsForRequest(request, false); |
| 199 url_request_->SetLoadFlags(load_flags); | 200 url_request_->SetLoadFlags(load_flags); |
| 200 | 201 |
| 201 url_request_->Start(); | 202 url_request_->Start(); |
| 202 } | 203 } |
| 203 | 204 |
| 204 URLLoaderImpl::~URLLoaderImpl() {} | 205 URLLoaderImpl::~URLLoaderImpl() { |
| 206 context_->DeregisterURLLoader(this); |
| 207 } |
| 205 | 208 |
| 206 void URLLoaderImpl::Cleanup() { | 209 void URLLoaderImpl::Cleanup() { |
| 207 // The associated network context is going away and we have to destroy | 210 // The associated network context is going away and we have to destroy |
| 208 // net::URLRequest hold by this loader. | 211 // net::URLRequest held by this loader. |
| 209 delete this; | 212 delete this; |
| 210 } | 213 } |
| 211 | 214 |
| 212 void URLLoaderImpl::FollowRedirect() { | 215 void URLLoaderImpl::FollowRedirect() { |
| 213 if (!url_request_) { | 216 if (!url_request_) { |
| 214 NotifyCompleted(net::ERR_UNEXPECTED); | 217 NotifyCompleted(net::ERR_UNEXPECTED); |
| 215 return; | 218 return; |
| 216 } | 219 } |
| 217 | 220 |
| 218 url_request_->FollowDeferredRedirect(); | 221 url_request_->FollowDeferredRedirect(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 if (!url_request->status().is_success()) { | 350 if (!url_request->status().is_success()) { |
| 348 writable_handle_watcher_.Cancel(); | 351 writable_handle_watcher_.Cancel(); |
| 349 pending_write_ = nullptr; // This closes the data pipe. | 352 pending_write_ = nullptr; // This closes the data pipe. |
| 350 DeleteIfNeeded(); | 353 DeleteIfNeeded(); |
| 351 return; | 354 return; |
| 352 } | 355 } |
| 353 | 356 |
| 354 DidRead(static_cast<uint32_t>(bytes_read), false); | 357 DidRead(static_cast<uint32_t>(bytes_read), false); |
| 355 } | 358 } |
| 356 | 359 |
| 360 base::WeakPtr<URLLoaderImpl> URLLoaderImpl::GetWeakPtrForTests() { |
| 361 return weak_ptr_factory_.GetWeakPtr(); |
| 362 } |
| 363 |
| 357 void URLLoaderImpl::NotifyCompleted(int error_code) { | 364 void URLLoaderImpl::NotifyCompleted(int error_code) { |
| 358 ResourceRequestCompletionStatus request_complete_data; | 365 ResourceRequestCompletionStatus request_complete_data; |
| 359 request_complete_data.error_code = error_code; | 366 request_complete_data.error_code = error_code; |
| 360 request_complete_data.exists_in_cache = | 367 request_complete_data.exists_in_cache = |
| 361 url_request_->response_info().was_cached; | 368 url_request_->response_info().was_cached; |
| 362 request_complete_data.completion_time = base::TimeTicks::Now(); | 369 request_complete_data.completion_time = base::TimeTicks::Now(); |
| 363 request_complete_data.encoded_data_length = | 370 request_complete_data.encoded_data_length = |
| 364 url_request_->GetTotalReceivedBytes(); | 371 url_request_->GetTotalReceivedBytes(); |
| 365 request_complete_data.encoded_body_length = url_request_->GetRawBodyBytes(); | 372 request_complete_data.encoded_body_length = url_request_->GetRawBodyBytes(); |
| 366 | 373 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 386 ReadMore(); | 393 ReadMore(); |
| 387 } | 394 } |
| 388 | 395 |
| 389 void URLLoaderImpl::DeleteIfNeeded() { | 396 void URLLoaderImpl::DeleteIfNeeded() { |
| 390 bool has_data_pipe = pending_write_.get() || response_body_stream_.is_valid(); | 397 bool has_data_pipe = pending_write_.get() || response_body_stream_.is_valid(); |
| 391 if (!connected_ && !has_data_pipe) | 398 if (!connected_ && !has_data_pipe) |
| 392 delete this; | 399 delete this; |
| 393 } | 400 } |
| 394 | 401 |
| 395 } // namespace content | 402 } // namespace content |
| OLD | NEW |