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 70f5023ba54a38f95da255ceca1eb4ca7c7f3842..d2c722a61be32aaabbeebe94d15c0d1b9ab81650 100644 |
--- a/net/proxy/multi_threaded_proxy_resolver.cc |
+++ b/net/proxy/multi_threaded_proxy_resolver.cc |
@@ -119,13 +119,12 @@ class MultiThreadedProxyResolver : public ProxyResolver, |
int GetProxyForURL(const GURL& url, |
ProxyInfo* results, |
const CompletionCallback& callback, |
- RequestHandle* request, |
+ std::unique_ptr<Request>* request, |
const NetLogWithSource& 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; |
@@ -233,6 +232,20 @@ class Job : public base::RefCountedThreadSafe<Job> { |
bool was_cancelled_; |
}; |
+class MultiThreadedProxyResolver::RequestImpl : public ProxyResolver::Request { |
+ public: |
+ explicit RequestImpl(scoped_refptr<Job> job) : job_(std::move(job)) {} |
+ |
+ ~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. |
@@ -447,7 +460,7 @@ int MultiThreadedProxyResolver::GetProxyForURL( |
const GURL& url, |
ProxyInfo* results, |
const CompletionCallback& callback, |
- RequestHandle* request, |
+ std::unique_ptr<Request>* request, |
const NetLogWithSource& net_log) { |
DCHECK(CalledOnValidThread()); |
DCHECK(!callback.is_null()); |
@@ -458,7 +471,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(); |
@@ -481,32 +494,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()); |
for (ExecutorList::iterator it = executors_.begin(); |
@@ -531,14 +518,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 |