Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Unified Diff: net/proxy/proxy_resolver_factory_mojo.cc

Issue 1745133002: Revert of Change ProxyResolver::GetProxyForURL() to take a scoped_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/proxy/proxy_resolver.h ('k') | net/proxy/proxy_resolver_factory_mojo_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_resolver_factory_mojo.cc
diff --git a/net/proxy/proxy_resolver_factory_mojo.cc b/net/proxy/proxy_resolver_factory_mojo.cc
index 0412217502e310a7a715f004190618f68a184da8..2070cf9bef250d0927712c09e91ab47505ccbf26 100644
--- a/net/proxy/proxy_resolver_factory_mojo.cc
+++ b/net/proxy/proxy_resolver_factory_mojo.cc
@@ -118,14 +118,13 @@
int GetProxyForURL(const GURL& url,
ProxyInfo* results,
const net::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 Job;
- class RequestImpl;
-
- base::ThreadChecker thread_checker_;
// Mojo error handler.
void OnConnectionError();
@@ -143,22 +142,11 @@
std::set<Job*> pending_jobs_;
+ base::ThreadChecker thread_checker_;
scoped_ptr<base::ScopedClosureRunner> on_delete_callback_runner_;
DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo);
-};
-
-class ProxyResolverMojo::RequestImpl : public ProxyResolver::Request {
- public:
- explicit RequestImpl(scoped_ptr<Job> job);
-
- ~RequestImpl() override;
-
- LoadState GetLoadState() override;
-
- private:
- scoped_ptr<Job> job_;
};
class ProxyResolverMojo::Job
@@ -171,15 +159,13 @@
const BoundNetLog& net_log);
~Job() override;
+ // Cancels the job and prevents the callback from being run.
+ void Cancel();
+
// Returns the LoadState of this job.
LoadState GetLoadState();
- ProxyResolverMojo* resolver();
-
- void CompleteRequest(int result);
-
private:
- friend class base::RefCounted<Job>;
// Mojo error handler.
void OnConnectionError();
@@ -196,18 +182,6 @@
base::ThreadChecker thread_checker_;
mojo::Binding<interfaces::ProxyResolverRequestClient> binding_;
};
-
-ProxyResolverMojo::RequestImpl::RequestImpl(scoped_ptr<Job> job)
- : job_(std::move(job)) {}
-
-ProxyResolverMojo::RequestImpl::~RequestImpl() {
- job_->CompleteRequest(ERR_PAC_SCRIPT_TERMINATED);
-}
-
-LoadState ProxyResolverMojo::RequestImpl::GetLoadState() {
- CHECK_EQ(1u, job_->resolver()->pending_jobs_.count(job_.get()));
- return job_->GetLoadState();
-}
ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
const GURL& url,
@@ -230,31 +204,27 @@
&ProxyResolverMojo::Job::OnConnectionError, base::Unretained(this)));
}
-ProxyResolverMojo::Job::~Job() {}
+ProxyResolverMojo::Job::~Job() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!callback_.is_null())
+ callback_.Run(ERR_PAC_SCRIPT_TERMINATED);
+}
+
+void ProxyResolverMojo::Job::Cancel() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!callback_.is_null());
+ callback_.Reset();
+}
LoadState ProxyResolverMojo::Job::GetLoadState() {
return dns_request_in_progress() ? LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT
: LOAD_STATE_RESOLVING_PROXY_FOR_URL;
}
-ProxyResolverMojo* ProxyResolverMojo::Job::resolver() {
- return resolver_;
-};
-
void ProxyResolverMojo::Job::OnConnectionError() {
DCHECK(thread_checker_.CalledOnValidThread());
DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError";
- CompleteRequest(ERR_PAC_SCRIPT_TERMINATED);
-}
-
-void ProxyResolverMojo::Job::CompleteRequest(int result) {
- CompletionCallback callback = callback_;
- callback_.Reset();
- if (resolver_)
- resolver_->RemoveJob(this);
- resolver_ = nullptr;
- if (!callback.is_null())
- callback.Run(result);
+ resolver_->RemoveJob(this);
}
void ProxyResolverMojo::Job::ReportResult(
@@ -268,7 +238,10 @@
DVLOG(1) << "Servers: " << results_->ToPacString();
}
- CompleteRequest(error);
+ CompletionCallback callback = callback_;
+ callback_.Reset();
+ resolver_->RemoveJob(this);
+ callback.Run(error);
}
ProxyResolverMojo::ProxyResolverMojo(
@@ -302,28 +275,42 @@
void ProxyResolverMojo::RemoveJob(Job* job) {
DCHECK(thread_checker_.CalledOnValidThread());
- pending_jobs_.erase(job);
+ size_t num_erased = pending_jobs_.erase(job);
+ DCHECK(num_erased);
+ delete job;
}
int ProxyResolverMojo::GetProxyForURL(const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
- scoped_ptr<Request>* request,
+ RequestHandle* request,
const BoundNetLog& net_log) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!mojo_proxy_resolver_ptr_)
return ERR_PAC_SCRIPT_TERMINATED;
- scoped_ptr<Job> job(new Job(this, url, results, callback, net_log));
- bool inserted = pending_jobs_.insert(job.get()).second;
+ Job* job = new Job(this, url, results, callback, net_log);
+ bool inserted = pending_jobs_.insert(job).second;
DCHECK(inserted);
- request->reset(new RequestImpl(std::move(job)));
+ *request = job;
return ERR_IO_PENDING;
}
-
+void ProxyResolverMojo::CancelRequest(RequestHandle request) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ Job* job = static_cast<Job*>(request);
+ DCHECK(job);
+ job->Cancel();
+ RemoveJob(job);
+}
+
+LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const {
+ Job* job = static_cast<Job*>(request);
+ CHECK_EQ(1u, pending_jobs_.count(job));
+ return job->GetLoadState();
+}
} // namespace
« no previous file with comments | « net/proxy/proxy_resolver.h ('k') | net/proxy/proxy_resolver_factory_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698