diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-07 22:41:53 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-07 22:41:53 +0000 |
commit | c8826725c7d1fe6a5cf8d46eae51b226ec4a2359 (patch) | |
tree | 4f27fb6424541152472b9b10e6a010d1fe87649c | |
parent | 37ae8a4ebc0593bc0fb8704f5b070b6686f61f02 (diff) | |
download | chromium_src-c8826725c7d1fe6a5cf8d46eae51b226ec4a2359.zip chromium_src-c8826725c7d1fe6a5cf8d46eae51b226ec4a2359.tar.gz chromium_src-c8826725c7d1fe6a5cf8d46eae51b226ec4a2359.tar.bz2 |
Mojo: abstract interface implementation from generated Stub classes
Remove RemotePtr<S>::SetPeer method in favor of an optionally NULL second constructor argument. (The reset method also gains an optionally NULL second argument.)
R=davemoore@chromium.org
Review URL: https://codereview.chromium.org/109103003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243416 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 70 insertions, 82 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc index 4ed3bd7..2ac77cd 100644 --- a/mojo/examples/aura_demo/aura_demo.cc +++ b/mojo/examples/aura_demo/aura_demo.cc @@ -116,12 +116,10 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient { DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); }; -class AuraDemo : public ShellClientStub { +class AuraDemo : public ShellClient { public: explicit AuraDemo(ScopedMessagePipeHandle shell_handle) - : shell_(shell_handle.Pass()) { - shell_.SetPeer(this); - + : shell_(shell_handle.Pass(), this) { screen_.reset(DemoScreen::Create()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); diff --git a/mojo/examples/aura_demo/root_window_host_mojo.cc b/mojo/examples/aura_demo/root_window_host_mojo.cc index db3e13d..95d1ff0 100644 --- a/mojo/examples/aura_demo/root_window_host_mojo.cc +++ b/mojo/examples/aura_demo/root_window_host_mojo.cc @@ -26,9 +26,8 @@ ui::ContextFactory* RootWindowHostMojo::context_factory_ = NULL; RootWindowHostMojo::RootWindowHostMojo( ScopedMessagePipeHandle viewport_handle, const base::Callback<void()>& compositor_created_callback) - : native_viewport_(viewport_handle.Pass()), + : native_viewport_(viewport_handle.Pass(), this), compositor_created_callback_(compositor_created_callback) { - native_viewport_.SetPeer(this); native_viewport_->Open(); ScopedMessagePipeHandle gles2_handle; @@ -147,7 +146,7 @@ void RootWindowHostMojo::PrepareForShutdown() { } //////////////////////////////////////////////////////////////////////////////// -// RootWindowHostMojo, NativeViewportClientStub implementation: +// RootWindowHostMojo, NativeViewportClient implementation: void RootWindowHostMojo::OnCreated() { } diff --git a/mojo/examples/aura_demo/root_window_host_mojo.h b/mojo/examples/aura_demo/root_window_host_mojo.h index 4f74c1f..3391ce3 100644 --- a/mojo/examples/aura_demo/root_window_host_mojo.h +++ b/mojo/examples/aura_demo/root_window_host_mojo.h @@ -20,7 +20,7 @@ namespace examples { class GLES2ClientImpl; class RootWindowHostMojo : public aura::RootWindowHost, - public NativeViewportClientStub { + public NativeViewportClient { public: RootWindowHostMojo(ScopedMessagePipeHandle viewport_handle, const base::Callback<void()>& compositor_created_callback); @@ -52,7 +52,7 @@ class RootWindowHostMojo : public aura::RootWindowHost, virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void PrepareForShutdown() OVERRIDE; - // Overridden from NativeViewportClientStub: + // Overridden from NativeViewportClient: virtual void OnCreated() OVERRIDE; virtual void OnDestroyed() OVERRIDE; virtual void OnEvent(const Event& event) OVERRIDE; diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc index 172e4c0..2865fb9 100644 --- a/mojo/examples/compositor_app/compositor_app.cc +++ b/mojo/examples/compositor_app/compositor_app.cc @@ -30,11 +30,10 @@ namespace mojo { namespace examples { -class SampleApp : public ShellClientStub { +class SampleApp : public ShellClient { public: explicit SampleApp(ScopedMessagePipeHandle shell_handle) - : shell_(shell_handle.Pass()) { - shell_.SetPeer(this); + : shell_(shell_handle.Pass(), this) { mojo::ScopedMessagePipeHandle client_handle, native_viewport_handle; CreateMessagePipe(&client_handle, &native_viewport_handle); native_viewport_client_.reset( @@ -48,11 +47,10 @@ class SampleApp : public ShellClientStub { } private: - class NativeViewportClientImpl : public mojo::NativeViewportClientStub { + class NativeViewportClientImpl : public mojo::NativeViewportClient { public: explicit NativeViewportClientImpl(ScopedMessagePipeHandle viewport_handle) - : viewport_(viewport_handle.Pass()) { - viewport_.SetPeer(this); + : viewport_(viewport_handle.Pass(), this) { viewport_->Open(); ScopedMessagePipeHandle gles2_handle; ScopedMessagePipeHandle gles2_client_handle; diff --git a/mojo/examples/compositor_app/gles2_client_impl.cc b/mojo/examples/compositor_app/gles2_client_impl.cc index fecb42d..f6849fd 100644 --- a/mojo/examples/compositor_app/gles2_client_impl.cc +++ b/mojo/examples/compositor_app/gles2_client_impl.cc @@ -16,8 +16,7 @@ GLES2ClientImpl::GLES2ClientImpl( const base::Callback<void(gfx::Size)>& context_created_callback) : context_created_callback_(context_created_callback), impl_(NULL), - service_(pipe.Pass()) { - service_.SetPeer(this); + service_(pipe.Pass(), this) { } GLES2ClientImpl::~GLES2ClientImpl() { service_->Destroy(); } diff --git a/mojo/examples/compositor_app/gles2_client_impl.h b/mojo/examples/compositor_app/gles2_client_impl.h index b5e4e7e..38d80b5 100644 --- a/mojo/examples/compositor_app/gles2_client_impl.h +++ b/mojo/examples/compositor_app/gles2_client_impl.h @@ -23,7 +23,7 @@ class GLES2Implementation; namespace mojo { namespace examples { -class GLES2ClientImpl : public GLES2ClientStub { +class GLES2ClientImpl : public GLES2Client { public: GLES2ClientImpl( ScopedMessagePipeHandle pipe, diff --git a/mojo/examples/sample_app/gles2_client_impl.cc b/mojo/examples/sample_app/gles2_client_impl.cc index c03531b..3dd943d 100644 --- a/mojo/examples/sample_app/gles2_client_impl.cc +++ b/mojo/examples/sample_app/gles2_client_impl.cc @@ -22,8 +22,7 @@ float CalculateDragDistance(const gfx::PointF& start, const Point& end) { } GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) - : service_(pipe.Pass()) { - service_.SetPeer(this); + : service_(pipe.Pass(), this) { } GLES2ClientImpl::~GLES2ClientImpl() { diff --git a/mojo/examples/sample_app/gles2_client_impl.h b/mojo/examples/sample_app/gles2_client_impl.h index 300557a..8dbc91d 100644 --- a/mojo/examples/sample_app/gles2_client_impl.h +++ b/mojo/examples/sample_app/gles2_client_impl.h @@ -16,7 +16,7 @@ namespace mojo { namespace examples { -class GLES2ClientImpl : public GLES2ClientStub { +class GLES2ClientImpl : public GLES2Client { public: explicit GLES2ClientImpl(ScopedMessagePipeHandle pipe); virtual ~GLES2ClientImpl(); diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc index 4d6ea83..b3bd71f 100644 --- a/mojo/examples/sample_app/sample_app.cc +++ b/mojo/examples/sample_app/sample_app.cc @@ -29,11 +29,10 @@ namespace mojo { namespace examples { -class SampleApp : public ShellClientStub { +class SampleApp : public ShellClient { public: explicit SampleApp(ScopedMessagePipeHandle shell_handle) - : shell_(shell_handle.Pass()) { - shell_.SetPeer(this); + : shell_(shell_handle.Pass(), this) { MessagePipe pipe; native_viewport_client_.reset( @@ -47,11 +46,10 @@ class SampleApp : public ShellClientStub { } private: - class NativeViewportClientImpl : public mojo::NativeViewportClientStub { + class NativeViewportClientImpl : public mojo::NativeViewportClient { public: explicit NativeViewportClientImpl(ScopedMessagePipeHandle viewport_handle) - : viewport_(viewport_handle.Pass()) { - viewport_.SetPeer(this); + : viewport_(viewport_handle.Pass(), this) { viewport_->Open(); MessagePipe pipe; diff --git a/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl b/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl index 3ca8b46..9885a36 100644 --- a/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl +++ b/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl @@ -55,6 +55,10 @@ void {{proxy_name}}::{{method.name}}({{params_list(method)}}) { } {%- endfor %} +{{class_name}}Stub::{{class_name}}Stub({{class_name}}* sink) + : sink_(sink) { +} + {#--- Stub definition #} {%- macro params(method) %} {%- for param in method.parameters %} @@ -79,7 +83,7 @@ bool {{class_name}}Stub::Accept(mojo::Message* message) { if (!mojo::internal::DecodePointersAndHandles(params, message)) return false; - {{method.name}}({{params(method)}}); + sink_->{{method.name}}({{params(method)}}); mojo::internal::CloseHandles(params); break; } diff --git a/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl b/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl index c4e3d1f..a01c5f4 100644 --- a/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl +++ b/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl @@ -1,4 +1,9 @@ -class {{interface.name}}Stub : public {{interface.name}}, public mojo::MessageReceiver { +class {{interface.name}}Stub : public mojo::MessageReceiver { public: + explicit {{interface.name}}Stub({{interface.name}}* sink); + virtual bool Accept(mojo::Message* message) MOJO_OVERRIDE; + + private: + {{interface.name}}* sink_; }; diff --git a/mojo/public/bindings/lib/remote_ptr.h b/mojo/public/bindings/lib/remote_ptr.h index 3b57594..a0c42e3 100644 --- a/mojo/public/bindings/lib/remote_ptr.h +++ b/mojo/public/bindings/lib/remote_ptr.h @@ -22,8 +22,7 @@ namespace mojo { // class FooClientImpl : public FooClientStub { // public: // explicit FooClientImpl(const mojo::MessagePipeHandle& message_pipe) -// : foo_(message_pipe) { -// foo_.SetPeer(this); +// : foo_(message_pipe, this) { // foo_.Ping(); // } // virtual void Pong() { @@ -38,8 +37,7 @@ namespace mojo { // class FooImpl : public FooStub { // public: // explicit FooImpl(const mojo::MessagePipeHandle& message_pipe) -// : client_(message_pipe) { -// client_.SetPeer(this); +// : client_(message_pipe, this) { // } // virtual void Ping() { // client_->Pong(); @@ -54,8 +52,9 @@ class RemotePtr { public: RemotePtr() : state_(NULL) {} - explicit RemotePtr(ScopedMessagePipeHandle message_pipe) - : state_(new State(message_pipe.Pass())) { + explicit RemotePtr(ScopedMessagePipeHandle message_pipe, + typename S::_Peer* peer = NULL) + : state_(new State(message_pipe.Pass(), peer)) { } // Move-only constructor and operator=. @@ -87,9 +86,10 @@ class RemotePtr { state_ = NULL; } - void reset(ScopedMessagePipeHandle message_pipe) { + void reset(ScopedMessagePipeHandle message_pipe, + typename S::_Peer* peer = NULL) { delete state_; - state_ = new State(message_pipe.Pass()); + state_ = new State(message_pipe.Pass(), peer); } bool encountered_error() const { @@ -97,19 +97,18 @@ class RemotePtr { return state_->connector.encountered_error(); } - void SetPeer(typename S::_Peer::_Stub* peer) { - assert(state_); - state_->connector.SetIncomingReceiver(peer); - } - private: struct State { - State(ScopedMessagePipeHandle message_pipe) + State(ScopedMessagePipeHandle message_pipe, typename S::_Peer* peer) : connector(message_pipe.Pass()), - proxy(&connector) { + proxy(&connector), + stub(peer) { + if (peer) + connector.SetIncomingReceiver(&stub); } internal::Connector connector; typename S::_Proxy proxy; + typename S::_Peer::_Stub stub; }; State* release() { diff --git a/mojo/public/bindings/sample/sample_service_unittests.cc b/mojo/public/bindings/sample/sample_service_unittests.cc index 0588a11..8670441 100644 --- a/mojo/public/bindings/sample/sample_service_unittests.cc +++ b/mojo/public/bindings/sample/sample_service_unittests.cc @@ -238,7 +238,7 @@ static void DumpHex(const uint8_t* bytes, uint32_t num_bytes) { } } -class ServiceImpl : public ServiceStub { +class ServiceImpl : public Service { public: virtual void Frobinate(const Foo& foo, int32_t baz, mojo::ScopedMessagePipeHandle port) @@ -273,8 +273,8 @@ class SimpleMessageReceiver : public mojo::MessageReceiver { // the system. It receives the incoming message. ServiceImpl impl; - ServiceStub* stub = &impl; - return stub->Accept(message); + ServiceStub stub(&impl); + return stub.Accept(message); } }; diff --git a/mojo/public/tests/bindings_handle_passing_unittest.cc b/mojo/public/tests/bindings_handle_passing_unittest.cc index df27359..2f687de 100644 --- a/mojo/public/tests/bindings_handle_passing_unittest.cc +++ b/mojo/public/tests/bindings_handle_passing_unittest.cc @@ -15,11 +15,10 @@ namespace { const char kText1[] = "hello"; const char kText2[] = "world"; -class SampleFactoryImpl : public sample::FactoryStub { +class SampleFactoryImpl : public sample::Factory { public: explicit SampleFactoryImpl(ScopedMessagePipeHandle pipe) - : client_(pipe.Pass()) { - client_.SetPeer(this); + : client_(pipe.Pass(), this) { } virtual void DoStuff(const sample::Request& request, @@ -54,12 +53,11 @@ class SampleFactoryImpl : public sample::FactoryStub { ScopedMessagePipeHandle pipe1_; }; -class SampleFactoryClientImpl : public sample::FactoryClientStub { +class SampleFactoryClientImpl : public sample::FactoryClient { public: explicit SampleFactoryClientImpl(ScopedMessagePipeHandle pipe) - : factory_(pipe.Pass()), + : factory_(pipe.Pass(), this), got_response_(false) { - factory_.SetPeer(this); } void Start() { diff --git a/mojo/public/tests/bindings_remote_ptr_unittest.cc b/mojo/public/tests/bindings_remote_ptr_unittest.cc index beada47..0d52224 100644 --- a/mojo/public/tests/bindings_remote_ptr_unittest.cc +++ b/mojo/public/tests/bindings_remote_ptr_unittest.cc @@ -10,14 +10,13 @@ namespace mojo { namespace test { -class MathCalculatorImpl : public math::CalculatorStub { +class MathCalculatorImpl : public math::Calculator { public: virtual ~MathCalculatorImpl() {} explicit MathCalculatorImpl(ScopedMessagePipeHandle pipe) - : ui_(pipe.Pass()), + : ui_(pipe.Pass(), this), total_(0.0) { - ui_.SetPeer(this); } virtual void Clear() MOJO_OVERRIDE { @@ -39,12 +38,11 @@ class MathCalculatorImpl : public math::CalculatorStub { double total_; }; -class MathCalculatorUIImpl : public math::CalculatorUIStub { +class MathCalculatorUIImpl : public math::CalculatorUI { public: explicit MathCalculatorUIImpl(ScopedMessagePipeHandle pipe) - : calculator_(pipe.Pass()), + : calculator_(pipe.Pass(), this), output_(0.0) { - calculator_.SetPeer(this); } bool encountered_error() const { @@ -119,7 +117,7 @@ TEST_F(BindingsRemotePtrTest, EndToEnd) { TEST_F(BindingsRemotePtrTest, Movable) { RemotePtr<math::Calculator> a; - RemotePtr<math::Calculator> b(pipe0_.Pass()); + RemotePtr<math::Calculator> b(pipe0_.Pass(), NULL); EXPECT_TRUE(a.is_null()); EXPECT_FALSE(b.is_null()); @@ -137,7 +135,7 @@ TEST_F(BindingsRemotePtrTest, Resettable) { MessagePipeHandle handle = pipe0_.get(); - a.reset(pipe0_.Pass()); + a.reset(pipe0_.Pass(), NULL); EXPECT_FALSE(a.is_null()); diff --git a/mojo/services/gles2/gles2_impl.cc b/mojo/services/gles2/gles2_impl.cc index d63fd3f..b80d3d7 100644 --- a/mojo/services/gles2/gles2_impl.cc +++ b/mojo/services/gles2/gles2_impl.cc @@ -13,8 +13,7 @@ namespace mojo { namespace services { GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client) - : client_(client.Pass()) { - client_.SetPeer(this); + : client_(client.Pass(), this) { } GLES2Impl::~GLES2Impl() { diff --git a/mojo/services/gles2/gles2_impl.h b/mojo/services/gles2/gles2_impl.h index 50ca456..63b6980 100644 --- a/mojo/services/gles2/gles2_impl.h +++ b/mojo/services/gles2/gles2_impl.h @@ -19,7 +19,7 @@ class GLInProcessContext; namespace mojo { namespace services { -class GLES2Impl : public GLES2Stub { +class GLES2Impl : public GLES2 { public: explicit GLES2Impl(ScopedMessagePipeHandle client); virtual ~GLES2Impl(); diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc index af7ce8d..0352ddf 100644 --- a/mojo/services/native_viewport/native_viewport_service.cc +++ b/mojo/services/native_viewport/native_viewport_service.cc @@ -25,7 +25,7 @@ bool IsRateLimitedEventType(ui::Event* event) { } class NativeViewportService::NativeViewportImpl - : public NativeViewportStub, + : public mojo::NativeViewport, public NativeViewportDelegate { public: NativeViewportImpl(NativeViewportService* service, @@ -34,8 +34,7 @@ class NativeViewportService::NativeViewportImpl widget_(gfx::kNullAcceleratedWidget), waiting_for_event_ack_(false), pending_event_timestamp_(0), - client_(client_handle.Pass()) { - client_.SetPeer(this); + client_(client_handle.Pass(), this) { } virtual ~NativeViewportImpl() {} @@ -155,9 +154,8 @@ class NativeViewportService::NativeViewportImpl NativeViewportService::NativeViewportService( ScopedMessagePipeHandle shell_handle) - : shell_(shell_handle.Pass()), + : shell_(shell_handle.Pass(), this), context_(NULL) { - shell_.SetPeer(this); } NativeViewportService::~NativeViewportService() {} diff --git a/mojo/services/native_viewport/native_viewport_service.h b/mojo/services/native_viewport/native_viewport_service.h index 638a127..85b734a 100644 --- a/mojo/services/native_viewport/native_viewport_service.h +++ b/mojo/services/native_viewport/native_viewport_service.h @@ -18,7 +18,7 @@ class Context; namespace services { -class NativeViewportService : public ShellClientStub { +class NativeViewportService : public ShellClient { public: NativeViewportService(ScopedMessagePipeHandle shell_handle); virtual ~NativeViewportService(); diff --git a/mojo/shell/service_manager.cc b/mojo/shell/service_manager.cc index cea78da..55fd41f 100644 --- a/mojo/shell/service_manager.cc +++ b/mojo/shell/service_manager.cc @@ -11,14 +11,13 @@ namespace mojo { namespace shell { -class ServiceManager::Service : public ShellStub { +class ServiceManager::Service : public Shell { public: Service(ServiceManager* manager, const GURL& url) : manager_(manager), url_(url) { MessagePipe pipe; - shell_client_.reset(pipe.handle0.Pass()); - shell_client_.SetPeer(this); + shell_client_.reset(pipe.handle0.Pass(), this); manager_->GetLoaderForURL(url)->Load(url, pipe.handle1.Pass()); } virtual ~Service() {} diff --git a/mojo/shell/service_manager_unittest.cc b/mojo/shell/service_manager_unittest.cc index d3545d5..9573694 100644 --- a/mojo/shell/service_manager_unittest.cc +++ b/mojo/shell/service_manager_unittest.cc @@ -14,11 +14,10 @@ namespace mojo { namespace shell { namespace { -class TestApp : public ShellClientStub { +class TestApp : public ShellClient { public: TestApp(ScopedMessagePipeHandle shell_handle) - : shell_(shell_handle.Pass()) { - shell_.SetPeer(this); + : shell_(shell_handle.Pass(), this) { } virtual ~TestApp() { } @@ -31,12 +30,11 @@ class TestApp : public ShellClientStub { } private: - class TestServiceImpl : public TestServiceStub { + class TestServiceImpl : public TestService { public: TestServiceImpl(TestApp* service, ScopedMessagePipeHandle client_handle) : service_(service), - client_(client_handle.Pass()) { - client_.SetPeer(this); + client_(client_handle.Pass(), this) { } virtual ~TestServiceImpl() { } @@ -52,12 +50,11 @@ class TestApp : public ShellClientStub { scoped_ptr<TestServiceImpl> service_; }; -class TestClientImpl : public TestClientStub { +class TestClientImpl : public TestClient { public: explicit TestClientImpl(ScopedMessagePipeHandle service_handle) - : service_(service_handle.Pass()), + : service_(service_handle.Pass(), this), quit_after_ack_(false) { - service_.SetPeer(this); } virtual ~TestClientImpl() { } |