Commit 07ed1e38 authored by darin@chromium.org's avatar darin@chromium.org

Mojo: Make overriding OnConnectionError optional

Using mojo::Application::AddService<ServiceImpl> results in the system taking care of error handling for you. There's no need to force ServiceImpl to override OnConnectionError in this case.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271287 0039d316-1c4b-4281-b951-d872f2087c98
parent 2d6a14f3
...@@ -206,9 +206,6 @@ class LauncherImpl : public InterfaceImpl<Launcher>, ...@@ -206,9 +206,6 @@ class LauncherImpl : public InterfaceImpl<Launcher>,
base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this)))); base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this))));
} }
// Overridden from InterfaceImpl:
virtual void OnConnectionError() OVERRIDE {}
private: private:
// Overridden from Launcher: // Overridden from Launcher:
virtual void Show() OVERRIDE { virtual void Show() OVERRIDE {
......
...@@ -21,17 +21,19 @@ class InterfaceImpl : public internal::InterfaceImplBase<Interface> { ...@@ -21,17 +21,19 @@ class InterfaceImpl : public internal::InterfaceImplBase<Interface> {
InterfaceImpl() : internal_state_(this) {} InterfaceImpl() : internal_state_(this) {}
virtual ~InterfaceImpl() {} virtual ~InterfaceImpl() {}
// Subclasses can override this to handle post connection initialization. // Returns a proxy to the client interface. This is null upon construction,
virtual void OnConnectionEstablished() {} // and becomes non-null after OnClientConnected. NOTE: It remains non-null
// until this instance is deleted.
Client* client() { return internal_state_.client(); }
// Subclasses must handle connection errors. // Called when the client has connected to this instance.
virtual void OnConnectionError() = 0; virtual void OnConnectionEstablished() {}
// We override SetClient here so subclasses don't each have to. // Called when the client is no longer connected to this instance. NOTE: The
virtual void SetClient(Client* client) MOJO_OVERRIDE { // client() method continues to return a non-null pointer after this method
internal_state_.set_client(client); // is called. After this method is called, any method calls made on client()
} // will be silently ignored.
Client* client() { return internal_state_.client(); } virtual void OnConnectionError() {}
// DO NOT USE. Exposed only for internal use and for testing. // DO NOT USE. Exposed only for internal use and for testing.
internal::InterfaceImplState<Interface>* internal_state() { internal::InterfaceImplState<Interface>* internal_state() {
...@@ -39,6 +41,9 @@ class InterfaceImpl : public internal::InterfaceImplBase<Interface> { ...@@ -39,6 +41,9 @@ class InterfaceImpl : public internal::InterfaceImplBase<Interface> {
} }
private: private:
virtual void SetClient(Client* client) MOJO_OVERRIDE {
internal_state_.set_client(client);
}
internal::InterfaceImplState<Interface> internal_state_; internal::InterfaceImplState<Interface> internal_state_;
MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImpl); MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImpl);
}; };
......
...@@ -34,10 +34,6 @@ class TestServiceImpl : public InterfaceImpl<TestService> { ...@@ -34,10 +34,6 @@ class TestServiceImpl : public InterfaceImpl<TestService> {
--context_->num_impls; --context_->num_impls;
} }
// InterfaceImpl<TestService> implementation.
virtual void OnConnectionError() OVERRIDE {
}
// TestService implementation: // TestService implementation:
virtual void Test(const mojo::String& test_string) OVERRIDE { virtual void Test(const mojo::String& test_string) OVERRIDE {
context_->last_test_string = test_string.To<std::string>(); context_->last_test_string = test_string.To<std::string>();
......
...@@ -21,8 +21,6 @@ class EchoServiceImpl : public mojo::InterfaceImpl<mojo::EchoService> { ...@@ -21,8 +21,6 @@ class EchoServiceImpl : public mojo::InterfaceImpl<mojo::EchoService> {
EchoServiceImpl() {} EchoServiceImpl() {}
virtual ~EchoServiceImpl() {} virtual ~EchoServiceImpl() {}
virtual void OnConnectionError() OVERRIDE {}
protected: protected:
virtual void Echo( virtual void Echo(
const mojo::String& in_to_echo, const mojo::String& in_to_echo,
......
...@@ -41,8 +41,6 @@ class NativeViewportImpl ...@@ -41,8 +41,6 @@ class NativeViewportImpl
native_viewport_.reset(); native_viewport_.reset();
} }
virtual void OnConnectionError() OVERRIDE {}
virtual void Create(const Rect& bounds) OVERRIDE { virtual void Create(const Rect& bounds) OVERRIDE {
native_viewport_ = native_viewport_ =
services::NativeViewport::Create(context_, this); services::NativeViewport::Create(context_, this);
......
...@@ -70,8 +70,6 @@ void ViewManagerConnection::OnConnectionEstablished() { ...@@ -70,8 +70,6 @@ void ViewManagerConnection::OnConnectionEstablished() {
Array<INode>::From(to_send)); Array<INode>::From(to_send));
} }
void ViewManagerConnection::OnConnectionError() {}
const Node* ViewManagerConnection::GetNode(const NodeId& id) const { const Node* ViewManagerConnection::GetNode(const NodeId& id) const {
if (id_ == id.connection_id) { if (id_ == id.connection_id) {
NodeMap::const_iterator i = node_map_.find(id.node_id); NodeMap::const_iterator i = node_map_.find(id.node_id);
......
...@@ -40,7 +40,6 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection ...@@ -40,7 +40,6 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
virtual ~ViewManagerConnection(); virtual ~ViewManagerConnection();
virtual void OnConnectionEstablished() MOJO_OVERRIDE; virtual void OnConnectionEstablished() MOJO_OVERRIDE;
virtual void OnConnectionError() MOJO_OVERRIDE;
TransportConnectionId id() const { return id_; } TransportConnectionId id() const { return id_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment