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/window_manager | |
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/window_manager')
-rw-r--r-- | mojo/examples/window_manager/window_manager.cc | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc index 1ef062c..1f4e597 100644 --- a/mojo/examples/window_manager/window_manager.cc +++ b/mojo/examples/window_manager/window_manager.cc @@ -10,12 +10,14 @@ #include "mojo/public/cpp/application/application_connection.h" #include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_impl.h" +#include "mojo/public/cpp/application/interface_factory_with_context.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "mojo/services/public/cpp/view_manager/node.h" #include "mojo/services/public/cpp/view_manager/node_observer.h" #include "mojo/services/public/cpp/view_manager/view.h" #include "mojo/services/public/cpp/view_manager/view_manager.h" +#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" @@ -35,6 +37,7 @@ using mojo::view_manager::Node; using mojo::view_manager::NodeObserver; using mojo::view_manager::View; using mojo::view_manager::ViewManager; +using mojo::view_manager::ViewManagerClientFactory; using mojo::view_manager::ViewManagerDelegate; using mojo::view_manager::ViewObserver; using mojo::view_manager::WindowManagerDelegate; @@ -54,8 +57,7 @@ const int kTextfieldHeight = 25; class WindowManagerConnection : public InterfaceImpl<IWindowManager> { public: - explicit WindowManagerConnection(ApplicationConnection* connection, - WindowManager* window_manager) + explicit WindowManagerConnection(WindowManager* window_manager) : window_manager_(window_manager) {} virtual ~WindowManagerConnection() {} @@ -72,10 +74,8 @@ class WindowManagerConnection : public InterfaceImpl<IWindowManager> { class NavigatorHost : public InterfaceImpl<navigation::NavigatorHost> { public: - explicit NavigatorHost(ApplicationConnection* connection, - WindowManager* window_manager) - : window_manager_(window_manager) { - } + explicit NavigatorHost(WindowManager* window_manager) + : window_manager_(window_manager) {} virtual ~NavigatorHost() { } @@ -249,16 +249,23 @@ class RootLayoutManager : public NodeObserver { DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); }; -class WindowManager : public ApplicationDelegate, - public DebugPanel::Delegate, - public ViewManagerDelegate, - public WindowManagerDelegate { +class WindowManager + : public ApplicationDelegate, + public DebugPanel::Delegate, + public ViewManagerDelegate, + public WindowManagerDelegate, + public InterfaceFactoryWithContext<WindowManagerConnection, + WindowManager>, + public InterfaceFactoryWithContext<NavigatorHost, WindowManager> { public: WindowManager() - : launcher_ui_(NULL), + : InterfaceFactoryWithContext<WindowManagerConnection, WindowManager>( + this), + InterfaceFactoryWithContext<NavigatorHost, WindowManager>(this), + launcher_ui_(NULL), view_manager_(NULL), - app_(NULL) { - } + view_manager_client_factory_(this), + app_(NULL) {} virtual ~WindowManager() {} @@ -329,9 +336,9 @@ class WindowManager : public ApplicationDelegate, virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) MOJO_OVERRIDE { - connection->AddService<WindowManagerConnection>(this); - connection->AddService<NavigatorHost>(this); - ViewManager::ConfigureIncomingConnection(connection, this); + connection->AddService<IWindowManager>(this); + connection->AddService<navigation::NavigatorHost>(this); + connection->AddService(&view_manager_client_factory_); return true; } @@ -505,6 +512,7 @@ class WindowManager : public ApplicationDelegate, Node* launcher_ui_; std::vector<Node*> windows_; ViewManager* view_manager_; + ViewManagerClientFactory view_manager_client_factory_; scoped_ptr<RootLayoutManager> root_layout_manager_; // Id of the node most content is added to. The keyboard is NOT added here. |