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

Unified Diff: net/proxy/proxy_resolver_factory_mojo.cc

Issue 1516493003: Change ProxyResolverMojo::Job to use mojo::StrongBindingSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-geolocation-untangle
Patch Set: Created 5 years 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 | « no previous file | no next file » | 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 592e7489f127b0d97e7d2bde8c68f3725f788183..9ba83daee90a8a22dbc2b7f8002738c457e19c62 100644
--- a/net/proxy/proxy_resolver_factory_mojo.cc
+++ b/net/proxy/proxy_resolver_factory_mojo.cc
@@ -12,6 +12,7 @@
#include "base/threading/thread_checker.h"
#include "base/values.h"
#include "mojo/common/common_type_converters.h"
+#include "mojo/common/strong_binding_set.h"
#include "mojo/common/url_type_converters.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "net/base/load_states.h"
@@ -122,13 +123,36 @@ class ProxyResolverMojo : public ProxyResolver {
LoadState GetLoadState(RequestHandle request) const override;
private:
- class Job;
+ class Job : public ClientMixin<interfaces::ProxyResolverRequestClient> {
+ public:
+ Job(ProxyResolverMojo* resolver,
+ ProxyInfo* results,
+ const CompletionCallback& callback,
+ 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();
+
+ private:
+ // Overridden from interfaces::ProxyResolverRequestClient:
+ void ReportResult(
+ int32_t error,
+ mojo::Array<interfaces::ProxyServerPtr> proxy_servers) override;
+
+ ProxyResolverMojo* resolver_;
+ ProxyInfo* results_;
+ CompletionCallback callback_;
+
+ base::ThreadChecker thread_checker_;
+ };
// Mojo error handler.
void OnConnectionError();
- void RemoveJob(Job* job);
-
// Connection to the Mojo proxy resolver.
interfaces::ProxyResolverPtr mojo_proxy_resolver_ptr_;
@@ -138,7 +162,7 @@ class ProxyResolverMojo : public ProxyResolver {
NetLog* net_log_;
- std::set<Job*> pending_jobs_;
+ mojo::StrongBindingSet<Job> pending_jobs_;
base::ThreadChecker thread_checker_;
@@ -147,42 +171,7 @@ class ProxyResolverMojo : public ProxyResolver {
DISALLOW_COPY_AND_ASSIGN(ProxyResolverMojo);
};
-class ProxyResolverMojo::Job
- : public ClientMixin<interfaces::ProxyResolverRequestClient> {
- public:
- Job(ProxyResolverMojo* resolver,
- const GURL& url,
- ProxyInfo* results,
- const CompletionCallback& callback,
- 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();
-
- private:
- // Mojo error handler.
- void OnConnectionError();
-
- // Overridden from interfaces::ProxyResolverRequestClient:
- void ReportResult(
- int32_t error,
- mojo::Array<interfaces::ProxyServerPtr> proxy_servers) override;
-
- ProxyResolverMojo* resolver_;
- const GURL url_;
- ProxyInfo* results_;
- CompletionCallback callback_;
-
- base::ThreadChecker thread_checker_;
- mojo::Binding<interfaces::ProxyResolverRequestClient> binding_;
-};
-
ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
- const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
const BoundNetLog& net_log)
@@ -192,18 +181,8 @@ ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
resolver->net_log_,
net_log),
resolver_(resolver),
- url_(url),
results_(results),
- callback_(callback),
- binding_(this) {
- binding_.set_connection_error_handler(base::Bind(
- &ProxyResolverMojo::Job::OnConnectionError, base::Unretained(this)));
-
- interfaces::ProxyResolverRequestClientPtr client_ptr;
- binding_.Bind(mojo::GetProxy(&client_ptr));
- resolver_->mojo_proxy_resolver_ptr_->GetProxyForUrl(mojo::String::From(url_),
- client_ptr.Pass());
-}
+ callback_(callback) {}
ProxyResolverMojo::Job::~Job() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -222,12 +201,6 @@ LoadState ProxyResolverMojo::Job::GetLoadState() {
: LOAD_STATE_RESOLVING_PROXY_FOR_URL;
}
-void ProxyResolverMojo::Job::OnConnectionError() {
- DCHECK(thread_checker_.CalledOnValidThread());
- DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError";
- resolver_->RemoveJob(this);
-}
-
void ProxyResolverMojo::Job::ReportResult(
int32_t error,
mojo::Array<interfaces::ProxyServerPtr> proxy_servers) {
@@ -241,7 +214,7 @@ void ProxyResolverMojo::Job::ReportResult(
CompletionCallback callback = callback_;
callback_.Reset();
- resolver_->RemoveJob(this);
+ resolver_->pending_jobs_.DestroyService(this);
callback.Run(error);
}
@@ -274,13 +247,6 @@ void ProxyResolverMojo::OnConnectionError() {
mojo_proxy_resolver_ptr_.reset();
}
-void ProxyResolverMojo::RemoveJob(Job* job) {
- DCHECK(thread_checker_.CalledOnValidThread());
- size_t num_erased = pending_jobs_.erase(job);
- DCHECK(num_erased);
- delete job;
-}
-
int ProxyResolverMojo::GetProxyForURL(const GURL& url,
ProxyInfo* results,
const CompletionCallback& callback,
@@ -291,25 +257,21 @@ int ProxyResolverMojo::GetProxyForURL(const GURL& url,
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;
- DCHECK(inserted);
- *request = job;
-
+ interfaces::ProxyResolverRequestClientPtr client_ptr;
+ *request = pending_jobs_.EmplaceService(mojo::GetProxy(&client_ptr), this,
+ results, callback, net_log);
+ mojo_proxy_resolver_ptr_->GetProxyForUrl(mojo::String::From(url),
+ client_ptr.Pass());
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);
+ pending_jobs_.DestroyService(static_cast<Job*>(request));
}
LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const {
Job* job = static_cast<Job*>(request);
- CHECK_EQ(1u, pending_jobs_.count(job));
return job->GetLoadState();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698