Skip to content

Commit

Permalink
Always set the error handler closure of Binding<> after binding to a …
Browse files Browse the repository at this point in the history
…message pipe.

This change only modifies users of Binding<>, and not the bindings code
itself.  The intention is to bring the behaviour of Binding<> closer to
that of InterfacePtr<>, which already has this restriction.

BUG=569694

Review URL: https://codereview.chromium.org/1525033004

Cr-Commit-Position: refs/heads/master@{#365710}
  • Loading branch information
akmistry authored and Commit bot committed Dec 17, 2015
1 parent 39e3c00 commit d8ee03d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
8 changes: 3 additions & 5 deletions content/common/mojo/service_registry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
namespace content {

ServiceRegistryImpl::ServiceRegistryImpl()
: binding_(this), weak_factory_(this) {
binding_.set_connection_error_handler(
base::Bind(&ServiceRegistryImpl::OnConnectionError,
base::Unretained(this)));
}
: binding_(this), weak_factory_(this) {}

ServiceRegistryImpl::~ServiceRegistryImpl() {
while (!pending_connects_.empty()) {
Expand All @@ -25,6 +21,8 @@ ServiceRegistryImpl::~ServiceRegistryImpl() {
void ServiceRegistryImpl::Bind(
mojo::InterfaceRequest<mojo::ServiceProvider> request) {
binding_.Bind(request.Pass());
binding_.set_connection_error_handler(base::Bind(
&ServiceRegistryImpl::OnConnectionError, base::Unretained(this)));
}

void ServiceRegistryImpl::BindRemoteServiceProvider(
Expand Down
9 changes: 5 additions & 4 deletions mojo/runner/child/runner_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ class ChildControllerImpl : public ChildController {
connection->set_controller(impl.Pass());
}

void Bind(ScopedMessagePipeHandle handle) { binding_.Bind(handle.Pass()); }
void Bind(ScopedMessagePipeHandle handle) {
binding_.Bind(handle.Pass());
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}

void OnConnectionError() {
// A connection error means the connection to the shell is lost. This is not
Expand Down Expand Up @@ -184,9 +187,7 @@ class ChildControllerImpl : public ChildController {
callback_(callback),
unblocker_(unblocker),
channel_info_(nullptr),
binding_(this) {
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}
binding_(this) {}

static void ReturnApplicationRequestOnMainThread(
const GotApplicationRequestCallback& callback,
Expand Down
9 changes: 5 additions & 4 deletions mojo/runner/host/child_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ class ChildControllerImpl : public ChildController {
app_context->set_controller(impl.Pass());
}

void Bind(ScopedMessagePipeHandle handle) { binding_.Bind(handle.Pass()); }
void Bind(ScopedMessagePipeHandle handle) {
binding_.Bind(handle.Pass());
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}

void OnConnectionError() {
// A connection error means the connection to the shell is lost. This is not
Expand Down Expand Up @@ -251,9 +254,7 @@ class ChildControllerImpl : public ChildController {
app_library_(app_library),
unblocker_(unblocker),
channel_info_(nullptr),
binding_(this) {
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}
binding_(this) {}

static void StartAppOnMainThread(
base::NativeLibrary app_library,
Expand Down
2 changes: 1 addition & 1 deletion mojo/shell/application_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ ApplicationInstance::ApplicationInstance(
queue_requests_(false),
native_runner_(nullptr),
pid_(base::kNullProcessId) {
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}

ApplicationInstance::~ApplicationInstance() {
Expand All @@ -43,6 +42,7 @@ ApplicationInstance::~ApplicationInstance() {
void ApplicationInstance::InitializeApplication() {
ShellPtr shell;
binding_.Bind(GetProxy(&shell));
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
application_->Initialize(shell.Pass(), identity_.url().spec());
}

Expand Down
5 changes: 2 additions & 3 deletions net/proxy/proxy_resolver_factory_mojo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,10 @@ ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver,
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));
binding_.set_connection_error_handler(base::Bind(
&ProxyResolverMojo::Job::OnConnectionError, base::Unretained(this)));
resolver_->mojo_proxy_resolver_ptr_->GetProxyForUrl(mojo::String::From(url_),
client_ptr.Pass());
}
Expand Down

0 comments on commit d8ee03d

Please sign in to comment.