Chromium Code Reviews| Index: net/proxy/multi_threaded_proxy_resolver.cc |
| diff --git a/net/proxy/multi_threaded_proxy_resolver.cc b/net/proxy/multi_threaded_proxy_resolver.cc |
| index 5eae4f744e8d7d79915c8afe3f157da5161fcdf7..b464029d2b021af543d44f5ecbe7a4f62ecb8076 100644 |
| --- a/net/proxy/multi_threaded_proxy_resolver.cc |
| +++ b/net/proxy/multi_threaded_proxy_resolver.cc |
| @@ -117,13 +117,12 @@ class MultiThreadedProxyResolver : public ProxyResolver, |
| int GetProxyForURL(const GURL& url, |
| ProxyInfo* results, |
| const CompletionCallback& callback, |
| - RequestHandle* request, |
| + scoped_ptr<Request>* request, |
| const BoundNetLog& net_log) override; |
| - void CancelRequest(RequestHandle request) override; |
| - LoadState GetLoadState(RequestHandle request) const override; |
| private: |
| class GetProxyForURLJob; |
| + class RequestImpl; |
| // FIFO queue of pending jobs waiting to be started. |
| // TODO(eroman): Make this priority queue. |
| typedef std::deque<scoped_refptr<Job>> PendingJobsQueue; |
| @@ -231,6 +230,20 @@ class Job : public base::RefCountedThreadSafe<Job> { |
| bool was_cancelled_; |
| }; |
| +class MultiThreadedProxyResolver::RequestImpl : public ProxyResolver::Request { |
| + public: |
| + RequestImpl(scoped_refptr<Job> job) : job_(job) {} |
|
eroman
2016/02/24 03:08:06
You can do: job_(std::move(job)) to avoid a spurio
|
| + |
| + ~RequestImpl() override { job_->Cancel(); } |
| + |
| + LoadState GetLoadState() override { |
| + return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
| + } |
| + |
| + private: |
| + scoped_refptr<Job> job_; |
| +}; |
| + |
| // CreateResolverJob ----------------------------------------------------------- |
| // Runs on the worker thread to call ProxyResolverFactory::CreateProxyResolver. |
| @@ -442,8 +455,11 @@ MultiThreadedProxyResolver::~MultiThreadedProxyResolver() { |
| } |
| int MultiThreadedProxyResolver::GetProxyForURL( |
| - const GURL& url, ProxyInfo* results, const CompletionCallback& callback, |
| - RequestHandle* request, const BoundNetLog& net_log) { |
| + const GURL& url, |
| + ProxyInfo* results, |
| + const CompletionCallback& callback, |
| + scoped_ptr<Request>* request, |
| + const BoundNetLog& net_log) { |
| DCHECK(CalledOnValidThread()); |
| DCHECK(!callback.is_null()); |
| @@ -453,7 +469,7 @@ int MultiThreadedProxyResolver::GetProxyForURL( |
| // Completion will be notified through |callback|, unless the caller cancels |
| // the request using |request|. |
| if (request) |
| - *request = reinterpret_cast<RequestHandle>(job.get()); |
| + request->reset(new RequestImpl(job)); |
| // If there is an executor that is ready to run this request, submit it! |
| Executor* executor = FindIdleExecutor(); |
| @@ -476,31 +492,6 @@ int MultiThreadedProxyResolver::GetProxyForURL( |
| return ERR_IO_PENDING; |
| } |
| -void MultiThreadedProxyResolver::CancelRequest(RequestHandle req) { |
| - DCHECK(CalledOnValidThread()); |
| - DCHECK(req); |
| - |
| - Job* job = reinterpret_cast<Job*>(req); |
| - DCHECK_EQ(Job::TYPE_GET_PROXY_FOR_URL, job->type()); |
| - |
| - if (job->executor()) { |
| - // If the job was already submitted to the executor, just mark it |
| - // as cancelled so the user callback isn't run on completion. |
| - job->Cancel(); |
| - } else { |
| - // Otherwise the job is just sitting in a queue. |
| - PendingJobsQueue::iterator it = |
| - std::find(pending_jobs_.begin(), pending_jobs_.end(), job); |
| - DCHECK(it != pending_jobs_.end()); |
| - pending_jobs_.erase(it); |
| - } |
| -} |
| - |
| -LoadState MultiThreadedProxyResolver::GetLoadState(RequestHandle req) const { |
| - DCHECK(CalledOnValidThread()); |
| - DCHECK(req); |
| - return LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
| -} |
| Executor* MultiThreadedProxyResolver::FindIdleExecutor() { |
| DCHECK(CalledOnValidThread()); |
| @@ -526,14 +517,14 @@ void MultiThreadedProxyResolver::AddNewExecutor() { |
| void MultiThreadedProxyResolver::OnExecutorReady(Executor* executor) { |
| DCHECK(CalledOnValidThread()); |
| - if (pending_jobs_.empty()) |
| - return; |
| - |
| - // Get the next job to process (FIFO). Transfer it from the pending queue |
| - // to the executor. |
| - scoped_refptr<Job> job = pending_jobs_.front(); |
| - pending_jobs_.pop_front(); |
| - executor->StartJob(job.get()); |
| + while (!pending_jobs_.empty()) { |
| + scoped_refptr<Job> job = pending_jobs_.front(); |
| + pending_jobs_.pop_front(); |
| + if (!job->was_cancelled()) { |
| + executor->StartJob(job.get()); |
| + return; |
| + } |
| + } |
| } |
| } // namespace |