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

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 refptr due windows error 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
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..ba876d8a83e1811c2423ee4971449aebc44636c8 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:
+ RequestImpl(scoped_ptr<Job> job);
eroman 2016/02/24 03:08:06 explicit
+
+ ~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();
-
+ bool IsCallback();
+ void PacScriptTerminated();
// Returns the LoadState of this job.
LoadState GetLoadState();
+ ProxyResolverMojo* GetResolver();
eroman 2016/02/24 03:08:06 resolver()
+
private:
+ friend class base::RefCounted<Job>;
// Mojo error handler.
void OnConnectionError();
@@ -183,6 +197,21 @@ class ProxyResolverMojo::Job
mojo::Binding<interfaces::ProxyResolverRequestClient> binding_;
};
+ProxyResolverMojo::RequestImpl::RequestImpl(scoped_ptr<Job> job)
+ : job_(std::move(job)) {}
+
+ProxyResolverMojo::RequestImpl::~RequestImpl() {
+ ProxyResolverMojo* resolver = job_->GetResolver();
+ if (resolver) {
+ resolver->RemoveJob(job_.get());
+ }
+}
+
+LoadState ProxyResolverMojo::RequestImpl::GetLoadState() {
+ CHECK_EQ(1u, job_->GetResolver()->pending_jobs_.count(job_.get()));
+ return job_->GetLoadState();
+}
+
ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
const GURL& url,
ProxyInfo* results,
@@ -204,16 +233,18 @@ ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
&ProxyResolverMojo::Job::OnConnectionError, base::Unretained(this)));
}
-ProxyResolverMojo::Job::~Job() {
+void ProxyResolverMojo::Job::PacScriptTerminated() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!callback_.is_null())
callback_.Run(ERR_PAC_SCRIPT_TERMINATED);
+ callback_.Reset();
+ resolver_ = nullptr;
}
-void ProxyResolverMojo::Job::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(!callback_.is_null());
- callback_.Reset();
+ProxyResolverMojo::Job::~Job() {}
+
+bool ProxyResolverMojo::Job::IsCallback() {
eroman 2016/02/24 03:08:06 Is this used anywhere? I believe you can delete.
+ return !callback_.is_null();
}
LoadState ProxyResolverMojo::Job::GetLoadState() {
@@ -221,10 +252,15 @@ LoadState ProxyResolverMojo::Job::GetLoadState() {
: LOAD_STATE_RESOLVING_PROXY_FOR_URL;
}
+ProxyResolverMojo* ProxyResolverMojo::Job::GetResolver() {
+ return resolver_;
+};
+
void ProxyResolverMojo::Job::OnConnectionError() {
DCHECK(thread_checker_.CalledOnValidThread());
DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError";
- resolver_->RemoveJob(this);
+ if (resolver_)
eroman 2016/02/24 03:08:06 Your refactor here looks correct (good job reading
+ resolver_->RemoveJob(this);
eroman 2016/02/24 03:08:06 Based on suggestion above, this would become:
}
void ProxyResolverMojo::Job::ReportResult(
@@ -275,42 +311,29 @@ 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);
+ job->PacScriptTerminated();
}
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

Powered by Google App Engine
This is Rietveld 408576698