OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/cert_net/cert_net_fetcher_impl.h" | 5 #include "net/cert_net/cert_net_fetcher_impl.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
10 #include "base/containers/linked_list.h" | 11 #include "base/containers/linked_list.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/numerics/safe_math.h" | 14 #include "base/numerics/safe_math.h" |
14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
16 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
17 #include "net/url_request/redirect_info.h" | 18 #include "net/url_request/redirect_info.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 DISALLOW_COPY_AND_ASSIGN(Job); | 225 DISALLOW_COPY_AND_ASSIGN(Job); |
225 }; | 226 }; |
226 | 227 |
227 CertNetFetcherImpl::RequestImpl::~RequestImpl() { | 228 CertNetFetcherImpl::RequestImpl::~RequestImpl() { |
228 if (job_) | 229 if (job_) |
229 job_->DetachRequest(this); | 230 job_->DetachRequest(this); |
230 } | 231 } |
231 | 232 |
232 CertNetFetcherImpl::Job::Job(scoped_ptr<RequestParams> request_params, | 233 CertNetFetcherImpl::Job::Job(scoped_ptr<RequestParams> request_params, |
233 CertNetFetcherImpl* parent) | 234 CertNetFetcherImpl* parent) |
234 : request_params_(request_params.Pass()), | 235 : request_params_(std::move(request_params)), |
235 result_net_error_(ERR_IO_PENDING), | 236 result_net_error_(ERR_IO_PENDING), |
236 parent_(parent) { | 237 parent_(parent) {} |
237 } | |
238 | 238 |
239 CertNetFetcherImpl::Job::~Job() { | 239 CertNetFetcherImpl::Job::~Job() { |
240 Cancel(); | 240 Cancel(); |
241 } | 241 } |
242 | 242 |
243 void CertNetFetcherImpl::Job::Cancel() { | 243 void CertNetFetcherImpl::Job::Cancel() { |
244 parent_ = nullptr; | 244 parent_ = nullptr; |
245 | 245 |
246 // Notify each request of cancellation and remove it from the list. | 246 // Notify each request of cancellation and remove it from the list. |
247 for (base::LinkNode<RequestImpl>* current = requests_.head(); | 247 for (base::LinkNode<RequestImpl>* current = requests_.head(); |
248 current != requests_.end();) { | 248 current != requests_.end();) { |
249 base::LinkNode<RequestImpl>* next = current->next(); | 249 base::LinkNode<RequestImpl>* next = current->next(); |
250 current->value()->OnJobCancelled(this); | 250 current->value()->OnJobCancelled(this); |
251 current->RemoveFromList(); | 251 current->RemoveFromList(); |
252 current = next; | 252 current = next; |
253 } | 253 } |
254 | 254 |
255 DCHECK(requests_.empty()); | 255 DCHECK(requests_.empty()); |
256 | 256 |
257 Stop(); | 257 Stop(); |
258 } | 258 } |
259 | 259 |
260 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::Job::CreateRequest( | 260 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::Job::CreateRequest( |
261 const FetchCallback& callback) { | 261 const FetchCallback& callback) { |
262 scoped_ptr<RequestImpl> request(new RequestImpl(this, callback)); | 262 scoped_ptr<RequestImpl> request(new RequestImpl(this, callback)); |
263 requests_.Append(request.get()); | 263 requests_.Append(request.get()); |
264 return request.Pass(); | 264 return std::move(request); |
265 } | 265 } |
266 | 266 |
267 void CertNetFetcherImpl::Job::DetachRequest(RequestImpl* request) { | 267 void CertNetFetcherImpl::Job::DetachRequest(RequestImpl* request) { |
268 scoped_ptr<Job> delete_this; | 268 scoped_ptr<Job> delete_this; |
269 | 269 |
270 request->RemoveFromList(); | 270 request->RemoveFromList(); |
271 | 271 |
272 // If there are no longer any requests attached to the job then | 272 // If there are no longer any requests attached to the job then |
273 // cancel and delete it. | 273 // cancel and delete it. |
274 if (requests_.empty() && !parent_->IsCurrentlyCompletingJob(this)) | 274 if (requests_.empty() && !parent_->IsCurrentlyCompletingJob(this)) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 int max_response_bytes, | 443 int max_response_bytes, |
444 const FetchCallback& callback) { | 444 const FetchCallback& callback) { |
445 scoped_ptr<RequestParams> request_params(new RequestParams); | 445 scoped_ptr<RequestParams> request_params(new RequestParams); |
446 | 446 |
447 request_params->url = url; | 447 request_params->url = url; |
448 request_params->http_method = HTTP_METHOD_GET; | 448 request_params->http_method = HTTP_METHOD_GET; |
449 request_params->timeout = GetTimeout(timeout_milliseconds); | 449 request_params->timeout = GetTimeout(timeout_milliseconds); |
450 request_params->max_response_bytes = | 450 request_params->max_response_bytes = |
451 GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); | 451 GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); |
452 | 452 |
453 return Fetch(request_params.Pass(), callback); | 453 return Fetch(std::move(request_params), callback); |
454 } | 454 } |
455 | 455 |
456 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchCrl( | 456 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchCrl( |
457 const GURL& url, | 457 const GURL& url, |
458 int timeout_milliseconds, | 458 int timeout_milliseconds, |
459 int max_response_bytes, | 459 int max_response_bytes, |
460 const FetchCallback& callback) { | 460 const FetchCallback& callback) { |
461 scoped_ptr<RequestParams> request_params(new RequestParams); | 461 scoped_ptr<RequestParams> request_params(new RequestParams); |
462 | 462 |
463 request_params->url = url; | 463 request_params->url = url; |
464 request_params->http_method = HTTP_METHOD_GET; | 464 request_params->http_method = HTTP_METHOD_GET; |
465 request_params->timeout = GetTimeout(timeout_milliseconds); | 465 request_params->timeout = GetTimeout(timeout_milliseconds); |
466 request_params->max_response_bytes = | 466 request_params->max_response_bytes = |
467 GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForCrl); | 467 GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForCrl); |
468 | 468 |
469 return Fetch(request_params.Pass(), callback); | 469 return Fetch(std::move(request_params), callback); |
470 } | 470 } |
471 | 471 |
472 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchOcsp( | 472 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchOcsp( |
473 const GURL& url, | 473 const GURL& url, |
474 int timeout_milliseconds, | 474 int timeout_milliseconds, |
475 int max_response_bytes, | 475 int max_response_bytes, |
476 const FetchCallback& callback) { | 476 const FetchCallback& callback) { |
477 scoped_ptr<RequestParams> request_params(new RequestParams); | 477 scoped_ptr<RequestParams> request_params(new RequestParams); |
478 | 478 |
479 request_params->url = url; | 479 request_params->url = url; |
480 request_params->http_method = HTTP_METHOD_GET; | 480 request_params->http_method = HTTP_METHOD_GET; |
481 request_params->timeout = GetTimeout(timeout_milliseconds); | 481 request_params->timeout = GetTimeout(timeout_milliseconds); |
482 request_params->max_response_bytes = | 482 request_params->max_response_bytes = |
483 GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); | 483 GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); |
484 | 484 |
485 return Fetch(request_params.Pass(), callback); | 485 return Fetch(std::move(request_params), callback); |
486 } | 486 } |
487 | 487 |
488 bool CertNetFetcherImpl::JobComparator::operator()(const Job* job1, | 488 bool CertNetFetcherImpl::JobComparator::operator()(const Job* job1, |
489 const Job* job2) const { | 489 const Job* job2) const { |
490 return job1->request_params() < job2->request_params(); | 490 return job1->request_params() < job2->request_params(); |
491 } | 491 } |
492 | 492 |
493 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::Fetch( | 493 scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::Fetch( |
494 scoped_ptr<RequestParams> request_params, | 494 scoped_ptr<RequestParams> request_params, |
495 const FetchCallback& callback) { | 495 const FetchCallback& callback) { |
496 DCHECK(thread_checker_.CalledOnValidThread()); | 496 DCHECK(thread_checker_.CalledOnValidThread()); |
497 | 497 |
498 // If there is an in-progress job that matches the request parameters use it. | 498 // If there is an in-progress job that matches the request parameters use it. |
499 // Otherwise start a new job. | 499 // Otherwise start a new job. |
500 Job* job = FindJob(*request_params); | 500 Job* job = FindJob(*request_params); |
501 | 501 |
502 if (!job) { | 502 if (!job) { |
503 job = new Job(request_params.Pass(), this); | 503 job = new Job(std::move(request_params), this); |
504 jobs_.insert(job); | 504 jobs_.insert(job); |
505 job->StartURLRequest(context_); | 505 job->StartURLRequest(context_); |
506 } | 506 } |
507 | 507 |
508 return job->CreateRequest(callback); | 508 return job->CreateRequest(callback); |
509 } | 509 } |
510 | 510 |
511 struct CertNetFetcherImpl::JobToRequestParamsComparator { | 511 struct CertNetFetcherImpl::JobToRequestParamsComparator { |
512 bool operator()(const Job* job, | 512 bool operator()(const Job* job, |
513 const CertNetFetcherImpl::RequestParams& value) const { | 513 const CertNetFetcherImpl::RequestParams& value) const { |
(...skipping 30 matching lines...) Expand all Loading... |
544 void CertNetFetcherImpl::ClearCurrentlyCompletingJob(Job* job) { | 544 void CertNetFetcherImpl::ClearCurrentlyCompletingJob(Job* job) { |
545 DCHECK_EQ(currently_completing_job_, job); | 545 DCHECK_EQ(currently_completing_job_, job); |
546 currently_completing_job_ = nullptr; | 546 currently_completing_job_ = nullptr; |
547 } | 547 } |
548 | 548 |
549 bool CertNetFetcherImpl::IsCurrentlyCompletingJob(Job* job) { | 549 bool CertNetFetcherImpl::IsCurrentlyCompletingJob(Job* job) { |
550 return job == currently_completing_job_; | 550 return job == currently_completing_job_; |
551 } | 551 } |
552 | 552 |
553 } // namespace net | 553 } // namespace net |
OLD | NEW |