diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:26:37 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 03:26:37 +0000 |
commit | ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f (patch) | |
tree | eca69245cafdb225f7ee2cf62ce88c7308b1d022 /mojo/examples/surfaces_app | |
parent | 633c60c341bb4c430c60b54492b74d1bdcff22f4 (diff) | |
download | chromium_src-ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f.zip chromium_src-ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f.tar.gz chromium_src-ffdb373a3e3fd523e78890fa8ab4ac1e8b49090f.tar.bz2 |
Mojo: Use InterfaceFactory<Interface> for service registration
This adds an InterfaceFactory<Interface> type and allows registering a
service through its provider. Using an InterfaceFactory allows the app
to be in control of the lifetime of the implementation of the interface
and hides all of the implementation details of the interface from the
application library code (i.e. no subclassing impl classes or anything
like that). The default binding behavior is to bind the lifetime of
the impl to the lifetime of the pipe, but the application
can also weakly bind to a service in cases where it needs to manage
the lifetime explicitly.
Review URL: https://codereview.chromium.org/380413003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285139 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples/surfaces_app')
-rw-r--r-- | mojo/examples/surfaces_app/child_app.cc | 19 | ||||
-rw-r--r-- | mojo/examples/surfaces_app/child_impl.cc | 32 | ||||
-rw-r--r-- | mojo/examples/surfaces_app/child_impl.h | 12 |
3 files changed, 25 insertions, 38 deletions
diff --git a/mojo/examples/surfaces_app/child_app.cc b/mojo/examples/surfaces_app/child_app.cc index 0a5c034..215f496 100644 --- a/mojo/examples/surfaces_app/child_app.cc +++ b/mojo/examples/surfaces_app/child_app.cc @@ -11,28 +11,31 @@ namespace mojo { namespace examples { -class ChildApp : public ApplicationDelegate, public ChildImpl::Context { +class ChildApp : public ApplicationDelegate, public InterfaceFactory<Child> { public: ChildApp() {} virtual ~ChildApp() {} - virtual void Initialize(ApplicationImpl* app) OVERRIDE { app_ = app; } + virtual void Initialize(ApplicationImpl* app) OVERRIDE { + surfaces_service_connection_ = + app->ConnectToApplication("mojo:mojo_surfaces_service"); + } // ApplicationDelegate implementation. virtual bool ConfigureIncomingConnection( ApplicationConnection* connection) OVERRIDE { - connection->AddService<ChildImpl, ChildImpl::Context>(this); + connection->AddService(this); return true; } - // ChildImpl::Context implementation. - virtual ApplicationConnection* ShellConnection( - const mojo::String& application_url) OVERRIDE { - return app_->ConnectToApplication(application_url); + // InterfaceFactory<Child> implementation. + virtual void Create(ApplicationConnection* connection, + InterfaceRequest<Child> request) OVERRIDE { + BindToRequest(new ChildImpl(surfaces_service_connection_), &request); } private: - ApplicationImpl* app_; + ApplicationConnection* surfaces_service_connection_; DISALLOW_COPY_AND_ASSIGN(ChildApp); }; diff --git a/mojo/examples/surfaces_app/child_impl.cc b/mojo/examples/surfaces_app/child_impl.cc index 2d5140a..e84e933 100644 --- a/mojo/examples/surfaces_app/child_impl.cc +++ b/mojo/examples/surfaces_app/child_impl.cc @@ -27,30 +27,9 @@ using cc::SolidColorDrawQuad; using cc::DelegatedFrameData; using cc::CompositorFrame; -class SurfaceClientImpl : public surfaces::SurfaceClient { - public: - explicit SurfaceClientImpl(ChildImpl* impl) : impl_(impl) {} - virtual ~SurfaceClientImpl() {} - - // surfaces::SurfaceClient implementation - virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE { - impl_->SetIdNamespace(id_namespace); - } - - virtual void ReturnResources( - Array<surfaces::ReturnedResourcePtr> resources) OVERRIDE { - DCHECK(!resources.size()); - } - - private: - ChildImpl* impl_; -}; - -ChildImpl::ChildImpl(ApplicationConnection* connection, Context* context) - : surface_client_(new SurfaceClientImpl(this)) { - context->ShellConnection("mojo:mojo_surfaces_service") - ->ConnectToService(&surface_); - surface_.set_client(surface_client_.get()); +ChildImpl::ChildImpl(ApplicationConnection* surfaces_service_connection) { + surfaces_service_connection->ConnectToService(&surface_); + surface_.set_client(this); } ChildImpl::~ChildImpl() { @@ -74,6 +53,11 @@ void ChildImpl::SetIdNamespace(uint32_t id_namespace) { Draw(); } +void ChildImpl::ReturnResources( + Array<surfaces::ReturnedResourcePtr> resources) { + DCHECK(!resources.size()); +} + void ChildImpl::Draw() { id_ = allocator_->GenerateId(); surface_->CreateSurface(mojo::surfaces::SurfaceId::From(id_), diff --git a/mojo/examples/surfaces_app/child_impl.h b/mojo/examples/surfaces_app/child_impl.h index 8770f61..cdd5263 100644 --- a/mojo/examples/surfaces_app/child_impl.h +++ b/mojo/examples/surfaces_app/child_impl.h @@ -29,20 +29,21 @@ class Surface; namespace examples { -class SurfaceClientImpl; - // Simple example of a child app using surfaces. -class ChildImpl : public InterfaceImpl<Child> { +class ChildImpl : public InterfaceImpl<Child>, public surfaces::SurfaceClient { public: class Context { public: virtual ApplicationConnection* ShellConnection( const mojo::String& application_url) = 0; }; - ChildImpl(ApplicationConnection* connection, Context* context); + explicit ChildImpl(ApplicationConnection* surfaces_service_connection); virtual ~ChildImpl(); - void SetIdNamespace(uint32_t id_namespace); + // surfaces::SurfaceClient implementation + virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE; + virtual void ReturnResources( + Array<surfaces::ReturnedResourcePtr> resources) OVERRIDE; private: // Child implementation. @@ -58,7 +59,6 @@ class ChildImpl : public InterfaceImpl<Child> { scoped_ptr<cc::SurfaceIdAllocator> allocator_; surfaces::SurfacePtr surface_; cc::SurfaceId id_; - scoped_ptr<SurfaceClientImpl> surface_client_; mojo::Callback<void(surfaces::SurfaceIdPtr id)> produce_callback_; DISALLOW_COPY_AND_ASSIGN(ChildImpl); |