Chromium Code Reviews| 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 // Overview | 5 // Overview |
| 6 // | 6 // |
| 7 // The main entry point is CertNetFetcherImpl. This is an implementation of | 7 // The main entry point is CertNetFetcherImpl. This is an implementation of |
| 8 // CertNetFetcher that provides a service for fetching network requests. | 8 // CertNetFetcher that provides a service for fetching network requests. |
| 9 // | 9 // |
| 10 // The interface for CertNetFetcher is synchronous, however allows | 10 // The interface for CertNetFetcher is synchronous, however allows |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 // RequestCore tracks an outstanding call to Fetch(). It is | 198 // RequestCore tracks an outstanding call to Fetch(). It is |
| 199 // reference-counted for ease of sharing between threads. | 199 // reference-counted for ease of sharing between threads. |
| 200 class RequestCore : public base::RefCountedThreadSafe<RequestCore> { | 200 class RequestCore : public base::RefCountedThreadSafe<RequestCore> { |
| 201 public: | 201 public: |
| 202 explicit RequestCore(scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 202 explicit RequestCore(scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 203 : completion_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 203 : completion_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 204 base::WaitableEvent::InitialState::NOT_SIGNALED), | 204 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 205 task_runner_(std::move(task_runner)) {} | 205 task_runner_(std::move(task_runner)) {} |
| 206 | 206 |
| 207 void AttachedToJob(Job* job) { | 207 void AttachedToJob(Job* job) { |
| 208 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 208 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 209 DCHECK(!job_); | 209 DCHECK(!job_); |
| 210 // Requests should not be attached to jobs after they have been signalled | 210 // Requests should not be attached to jobs after they have been signalled |
| 211 // with a cancellation error (which happens via either Cancel() or | 211 // with a cancellation error (which happens via either Cancel() or |
| 212 // SignalImmediateError()). | 212 // SignalImmediateError()). |
| 213 DCHECK_NE(error_, ERR_ABORTED); | 213 DCHECK_NE(error_, ERR_ABORTED); |
| 214 job_ = job; | 214 job_ = job; |
| 215 } | 215 } |
| 216 | 216 |
| 217 void OnJobCompleted(Job* job, | 217 void OnJobCompleted(Job* job, |
| 218 Error error, | 218 Error error, |
| 219 const std::vector<uint8_t>& response_body) { | 219 const std::vector<uint8_t>& response_body) { |
| 220 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 220 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 221 | 221 |
| 222 DCHECK_EQ(job_, job); | 222 DCHECK_EQ(job_, job); |
| 223 job_ = nullptr; | 223 job_ = nullptr; |
| 224 | 224 |
| 225 error_ = error; | 225 error_ = error; |
| 226 bytes_ = response_body; | 226 bytes_ = response_body; |
| 227 completion_event_.Signal(); | 227 completion_event_.Signal(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Detaches this request from its job (if it is attached to any) and | 230 // Detaches this request from its job (if it is attached to any) and |
| 231 // signals completion with ERR_ABORTED. Can be called from any thread. | 231 // signals completion with ERR_ABORTED. Can be called from any thread. |
| 232 void CancelJob(); | 232 void CancelJob(); |
| 233 | 233 |
| 234 // Can be used to signal that an error was encountered before the request was | 234 // Can be used to signal that an error was encountered before the request was |
| 235 // attached to a job. Can be called from any thread. | 235 // attached to a job. Can be called from any thread. |
| 236 void SignalImmediateError(); | 236 void SignalImmediateError(); |
| 237 | 237 |
| 238 // Should only be called once. | 238 // Should only be called once. |
| 239 void WaitForResult(Error* error, std::vector<uint8_t>* bytes) { | 239 void WaitForResult(Error* error, std::vector<uint8_t>* bytes) { |
| 240 DCHECK(!task_runner_->RunsTasksOnCurrentThread()); | 240 DCHECK(!task_runner_->RunsTasksInCurrentSequence()); |
| 241 | 241 |
| 242 completion_event_.Wait(); | 242 completion_event_.Wait(); |
| 243 *bytes = std::move(bytes_); | 243 *bytes = std::move(bytes_); |
| 244 *error = error_; | 244 *error = error_; |
| 245 | 245 |
| 246 error_ = ERR_UNEXPECTED; | 246 error_ = ERR_UNEXPECTED; |
| 247 } | 247 } |
| 248 | 248 |
| 249 private: | 249 private: |
| 250 friend class base::RefCountedThreadSafe<RequestCore>; | 250 friend class base::RefCountedThreadSafe<RequestCore>; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 // also used for notifying a failure to start the URLRequest. | 377 // also used for notifying a failure to start the URLRequest. |
| 378 base::OneShotTimer timer_; | 378 base::OneShotTimer timer_; |
| 379 | 379 |
| 380 // Non-owned pointer to the AsyncCertNetFetcherImpl that created this job. | 380 // Non-owned pointer to the AsyncCertNetFetcherImpl that created this job. |
| 381 AsyncCertNetFetcherImpl* parent_; | 381 AsyncCertNetFetcherImpl* parent_; |
| 382 | 382 |
| 383 DISALLOW_COPY_AND_ASSIGN(Job); | 383 DISALLOW_COPY_AND_ASSIGN(Job); |
| 384 }; | 384 }; |
| 385 | 385 |
| 386 void RequestCore::CancelJob() { | 386 void RequestCore::CancelJob() { |
| 387 if (!task_runner_->RunsTasksOnCurrentThread()) { | 387 if (!task_runner_->RunsTasksInCurrentSequence()) { |
| 388 task_runner_->PostTask(FROM_HERE, | 388 task_runner_->PostTask(FROM_HERE, |
| 389 base::Bind(&RequestCore::CancelJob, this)); | 389 base::Bind(&RequestCore::CancelJob, this)); |
| 390 return; | 390 return; |
| 391 } | 391 } |
| 392 | 392 |
| 393 if (job_) { | 393 if (job_) { |
| 394 auto* job = job_; | 394 auto* job = job_; |
| 395 job_ = nullptr; | 395 job_ = nullptr; |
| 396 job->DetachRequest(this); | 396 job->DetachRequest(this); |
| 397 } | 397 } |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 private: | 704 private: |
| 705 scoped_refptr<RequestCore> core_; | 705 scoped_refptr<RequestCore> core_; |
| 706 }; | 706 }; |
| 707 | 707 |
| 708 class CertNetFetcherImpl : public CertNetFetcher { | 708 class CertNetFetcherImpl : public CertNetFetcher { |
| 709 public: | 709 public: |
| 710 explicit CertNetFetcherImpl(URLRequestContext* context) | 710 explicit CertNetFetcherImpl(URLRequestContext* context) |
| 711 : task_runner_(base::ThreadTaskRunnerHandle::Get()), context_(context) {} | 711 : task_runner_(base::ThreadTaskRunnerHandle::Get()), context_(context) {} |
| 712 | 712 |
| 713 void Shutdown() override { | 713 void Shutdown() override { |
| 714 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 714 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 715 if (impl_) { | 715 if (impl_) { |
| 716 impl_->Shutdown(); | 716 impl_->Shutdown(); |
| 717 impl_.reset(); | 717 impl_.reset(); |
| 718 } | 718 } |
| 719 context_ = nullptr; | 719 context_ = nullptr; |
| 720 } | 720 } |
| 721 | 721 |
| 722 std::unique_ptr<Request> FetchCaIssuers(const GURL& url, | 722 std::unique_ptr<Request> FetchCaIssuers(const GURL& url, |
| 723 int timeout_milliseconds, | 723 int timeout_milliseconds, |
| 724 int max_response_bytes) override { | 724 int max_response_bytes) override { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 return DoFetch(std::move(request_params)); | 762 return DoFetch(std::move(request_params)); |
| 763 } | 763 } |
| 764 | 764 |
| 765 private: | 765 private: |
| 766 ~CertNetFetcherImpl() override { | 766 ~CertNetFetcherImpl() override { |
| 767 // The fetcher must be shutdown (at which point |context_| will be set to | 767 // The fetcher must be shutdown (at which point |context_| will be set to |
| 768 // null) before destruction. | 768 // null) before destruction. |
| 769 DCHECK(!context_); | 769 DCHECK(!context_); |
| 770 } | 770 } |
| 771 | 771 |
| 772 void DoFetchOnNetworkThread(std::unique_ptr<RequestParams> request_params, | 772 void DoFetchOnNetworkThread(std::unique_ptr<RequestParams> request_params, |
|
Ryan Sleevi
2017/05/22 17:22:13
DoFetchOnNetworkSequence
Yeol Park
2017/05/23 05:26:33
Done.
| |
| 773 scoped_refptr<RequestCore> request) { | 773 scoped_refptr<RequestCore> request) { |
| 774 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 774 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
| 775 | 775 |
| 776 if (!context_) { | 776 if (!context_) { |
| 777 // The fetcher might have been shutdown between when this task was posted | 777 // The fetcher might have been shutdown between when this task was posted |
| 778 // and when it is running. In this case, signal the request and do not | 778 // and when it is running. In this case, signal the request and do not |
| 779 // start a network request. | 779 // start a network request. |
| 780 request->SignalImmediateError(); | 780 request->SignalImmediateError(); |
| 781 return; | 781 return; |
| 782 } | 782 } |
| 783 | 783 |
| 784 if (!impl_) { | 784 if (!impl_) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 813 std::unique_ptr<AsyncCertNetFetcherImpl> impl_; | 813 std::unique_ptr<AsyncCertNetFetcherImpl> impl_; |
| 814 }; | 814 }; |
| 815 | 815 |
| 816 } // namespace | 816 } // namespace |
| 817 | 817 |
| 818 scoped_refptr<CertNetFetcher> CreateCertNetFetcher(URLRequestContext* context) { | 818 scoped_refptr<CertNetFetcher> CreateCertNetFetcher(URLRequestContext* context) { |
| 819 return make_scoped_refptr(new CertNetFetcherImpl(context)); | 819 return make_scoped_refptr(new CertNetFetcherImpl(context)); |
| 820 } | 820 } |
| 821 | 821 |
| 822 } // namespace net | 822 } // namespace net |
| OLD | NEW |