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 98455930fa7287f7f8571e6dc836ef0c9f7c8d85..5eae4f744e8d7d79915c8afe3f157da5161fcdf7 100644 |
--- a/net/proxy/multi_threaded_proxy_resolver.cc |
+++ b/net/proxy/multi_threaded_proxy_resolver.cc |
@@ -117,12 +117,13 @@ |
int GetProxyForURL(const GURL& url, |
ProxyInfo* results, |
const CompletionCallback& callback, |
- scoped_ptr<Request>* request, |
+ RequestHandle* 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; |
@@ -228,20 +229,6 @@ |
CompletionCallback callback_; |
Executor* executor_; |
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 ----------------------------------------------------------- |
@@ -455,11 +442,8 @@ |
} |
int MultiThreadedProxyResolver::GetProxyForURL( |
- const GURL& url, |
- ProxyInfo* results, |
- const CompletionCallback& callback, |
- scoped_ptr<Request>* request, |
- const BoundNetLog& net_log) { |
+ const GURL& url, ProxyInfo* results, const CompletionCallback& callback, |
+ RequestHandle* request, const BoundNetLog& net_log) { |
DCHECK(CalledOnValidThread()); |
DCHECK(!callback.is_null()); |
@@ -469,7 +453,7 @@ |
// Completion will be notified through |callback|, unless the caller cancels |
// the request using |request|. |
if (request) |
- request->reset(new RequestImpl(job)); |
+ *request = reinterpret_cast<RequestHandle>(job.get()); |
// If there is an executor that is ready to run this request, submit it! |
Executor* executor = FindIdleExecutor(); |
@@ -492,6 +476,31 @@ |
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()); |
@@ -517,14 +526,14 @@ |
void MultiThreadedProxyResolver::OnExecutorReady(Executor* executor) { |
DCHECK(CalledOnValidThread()); |
- while (!pending_jobs_.empty()) { |
- scoped_refptr<Job> job = pending_jobs_.front(); |
- pending_jobs_.pop_front(); |
- if (!job->was_cancelled()) { |
- executor->StartJob(job.get()); |
- return; |
- } |
- } |
+ 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()); |
} |
} // namespace |