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

Unified Diff: net/proxy/proxy_resolver_factory_mojo.cc

Issue 1439053002: 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: Restore scoped_ptr to mock and nits 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 2070cf9bef250d0927712c09e91ab47505ccbf26..0412217502e310a7a715f004190618f68a184da8 100644
--- a/net/proxy/proxy_resolver_factory_mojo.cc
+++ b/net/proxy/proxy_resolver_factory_mojo.cc
@@ -118,13 +118,14 @@ class ProxyResolverMojo : public ProxyResolver {
int GetProxyForURL(const GURL& url,
ProxyInfo* results,
const net::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 Job;
+ class RequestImpl;
+
+ base::ThreadChecker thread_checker_;
// Mojo error handler.
void OnConnectionError();
@@ -142,13 +143,24 @@ class ProxyResolverMojo : public ProxyResolver {
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
: public ClientMixin<interfaces::ProxyResolverRequestClient> {
public:
@@ -159,13 +171,15 @@ class ProxyResolverMojo::Job
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();
@@ -183,6 +197,18 @@ class ProxyResolverMojo::Job
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,
ProxyInfo* results,
@@ -204,27 +230,31 @@ ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
&ProxyResolverMojo::Job::OnConnectionError, base::Unretained(this)));
}
-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();
-}
+ProxyResolverMojo::Job::~Job() {}
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";
- resolver_->RemoveJob(this);
+ 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);
}
void ProxyResolverMojo::Job::ReportResult(
@@ -238,10 +268,7 @@ void ProxyResolverMojo::Job::ReportResult(
DVLOG(1) << "Servers: " << results_->ToPacString();
}
- CompletionCallback callback = callback_;
- callback_.Reset();
- resolver_->RemoveJob(this);
- callback.Run(error);
+ CompleteRequest(error);
}
ProxyResolverMojo::ProxyResolverMojo(
@@ -275,42 +302,28 @@ void ProxyResolverMojo::OnConnectionError() {
void ProxyResolverMojo::RemoveJob(Job* job) {
DCHECK(thread_checker_.CalledOnValidThread());
- size_t num_erased = pending_jobs_.erase(job);
- DCHECK(num_erased);
- delete job;
+ pending_jobs_.erase(job);
}
int ProxyResolverMojo::GetProxyForURL(const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
- RequestHandle* request,
+ scoped_ptr<Request>* request,
const BoundNetLog& net_log) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!mojo_proxy_resolver_ptr_)
return ERR_PAC_SCRIPT_TERMINATED;
- Job* job = new Job(this, url, results, callback, net_log);
- bool inserted = pending_jobs_.insert(job).second;
+ scoped_ptr<Job> job(new Job(this, url, results, callback, net_log));
+ bool inserted = pending_jobs_.insert(job.get()).second;
DCHECK(inserted);
- *request = job;
+ request->reset(new RequestImpl(std::move(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