Chromium Code Reviews| Index: mojo/shell/context.cc |
| diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc |
| index d5bb30e32d6030461ca8d011d931912e202dca94..160291ccfd9df7b5b62c83b4b109cab37fcbf69f 100644 |
| --- a/mojo/shell/context.cc |
| +++ b/mojo/shell/context.cc |
| @@ -4,13 +4,18 @@ |
| #include "mojo/shell/context.h" |
| -#include "base/command_line.h" |
| #include "build/build_config.h" |
| +#include "base/command_line.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/memory/scoped_vector.h" |
| #include "mojo/embedder/embedder.h" |
| #include "mojo/gles2/gles2_support_impl.h" |
| +#include "mojo/public/cpp/shell/application.h" |
| #include "mojo/service_manager/service_loader.h" |
| #include "mojo/service_manager/service_manager.h" |
| #include "mojo/services/native_viewport/native_viewport_service.h" |
| +#include "mojo/services/view_manager/root_node_manager.h" |
| +#include "mojo/services/view_manager/view_manager_connection.h" |
| #include "mojo/shell/dynamic_service_loader.h" |
| #include "mojo/shell/in_process_dynamic_service_runner.h" |
| #include "mojo/shell/network_delegate.h" |
| @@ -24,6 +29,53 @@ |
| namespace mojo { |
| namespace shell { |
| +namespace { |
| + |
| +// Used to ensure we only init once. |
| +class Setup { |
| + public: |
| + Setup() { |
| + embedder::Init(); |
| + gles2::GLES2SupportImpl::Init(); |
| + } |
| + |
| + ~Setup() { |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(Setup); |
| +}; |
| + |
| +static base::LazyInstance<Setup> setup = LAZY_INSTANCE_INITIALIZER; |
| + |
| +class ViewManagerLoader : public ServiceLoader { |
| + public: |
| + ViewManagerLoader() {} |
| + virtual ~ViewManagerLoader() {} |
| + |
| + private: |
| + virtual void LoadService(ServiceManager* manager, |
| + const GURL& url, |
| + ScopedShellHandle shell_handle) OVERRIDE { |
| + scoped_ptr<Application> app(new Application(shell_handle.Pass())); |
| + app->AddServiceConnector( |
| + new ServiceConnector<services::view_manager::ViewManagerConnection, |
| + services::view_manager::RootNodeManager>( |
| + &root_node_manager_)); |
| + apps_.push_back(app.release()); |
| + } |
| + |
| + virtual void OnServiceError(ServiceManager* manager, |
| + const GURL& url) OVERRIDE { |
| + } |
| + |
| + services::view_manager::RootNodeManager root_node_manager_; |
| + ScopedVector<Application> apps_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ViewManagerLoader); |
| +}; |
| + |
| +} // namespace |
| class Context::NativeViewportServiceLoader : public ServiceLoader { |
| public: |
| @@ -54,9 +106,7 @@ Context::Context() |
| task_runners_.cache_runner(), |
| scoped_ptr<net::NetworkDelegate>(new NetworkDelegate()), |
| storage_.profile_path()) { |
| - embedder::Init(); |
| - gles2::GLES2SupportImpl::Init(); |
| - |
| + setup.Get(); |
| CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| scoped_ptr<DynamicServiceRunnerFactory> runner_factory; |
| if (cmdline->HasSwitch(switches::kEnableMultiprocess)) |
| @@ -70,6 +120,10 @@ Context::Context() |
| service_manager_.SetLoaderForURL( |
| scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)), |
| GURL("mojo:mojo_native_viewport_service")); |
| + // TODO(sky): need a better way to find this. It shouldn't be linked in. |
|
Ben Goodger (Google)
2014/04/28 19:21:09
this is related to mojo_view_manager being a compo
sky
2014/04/28 21:16:05
Things didn't work well when the rest of chrome wa
|
| + service_manager_.SetLoaderForURL( |
| + scoped_ptr<ServiceLoader>(new ViewManagerLoader()), |
| + GURL("mojo:mojo_view_manager")); |
| #if defined(OS_LINUX) |
| service_manager_.SetLoaderForScheme( |