| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/shell/context.h" | 5 #include "mojo/shell/context.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 private: | 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(Setup); | 59 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; | 62 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 class Context::NativeViewportServiceLoader : public ServiceLoader { | 66 class Context::NativeViewportServiceLoader : public ServiceLoader { |
| 67 public: | 67 public: |
| 68 explicit NativeViewportServiceLoader(Context* context) : context_(context) {} | 68 NativeViewportServiceLoader() {} |
| 69 virtual ~NativeViewportServiceLoader() {} | 69 virtual ~NativeViewportServiceLoader() {} |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 virtual void LoadService(ServiceManager* manager, | 72 virtual void LoadService(ServiceManager* manager, |
| 73 const GURL& url, | 73 const GURL& url, |
| 74 ScopedMessagePipeHandle shell_handle) OVERRIDE { | 74 ScopedMessagePipeHandle shell_handle) OVERRIDE { |
| 75 app_.reset(::CreateNativeViewportService(context_, shell_handle.Pass())); | 75 app_.reset(services::CreateNativeViewportService(shell_handle.Pass())); |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual void OnServiceError(ServiceManager* manager, | 78 virtual void OnServiceError(ServiceManager* manager, |
| 79 const GURL& url) OVERRIDE { | 79 const GURL& url) OVERRIDE { |
| 80 } | 80 } |
| 81 | 81 |
| 82 Context* context_; | |
| 83 scoped_ptr<ApplicationImpl> app_; | 82 scoped_ptr<ApplicationImpl> app_; |
| 84 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader); | 83 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader); |
| 85 }; | 84 }; |
| 86 | 85 |
| 87 Context::Context() | 86 Context::Context() |
| 88 : task_runners_(base::MessageLoop::current()->message_loop_proxy()) { | 87 : task_runners_(base::MessageLoop::current()->message_loop_proxy()) { |
| 89 setup.Get(); | 88 setup.Get(); |
| 90 | 89 |
| 91 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) | 90 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) |
| 92 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); | 91 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); |
| 93 | 92 |
| 94 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 93 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 95 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; | 94 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; |
| 96 if (cmdline->HasSwitch(switches::kEnableMultiprocess)) | 95 if (cmdline->HasSwitch(switches::kEnableMultiprocess)) |
| 97 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); | 96 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); |
| 98 else | 97 else |
| 99 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); | 98 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); |
| 100 | 99 |
| 101 service_manager_.set_default_loader( | 100 service_manager_.set_default_loader( |
| 102 scoped_ptr<ServiceLoader>( | 101 scoped_ptr<ServiceLoader>( |
| 103 new DynamicServiceLoader(this, runner_factory.Pass()))); | 102 new DynamicServiceLoader(this, runner_factory.Pass()))); |
| 104 // The native viewport service synchronously waits for certain messages. If we | 103 // The native viewport service synchronously waits for certain messages. If we |
| 105 // don't run it on its own thread we can easily deadlock. Long term native | 104 // don't run it on its own thread we can easily deadlock. Long term native |
| 106 // viewport should run its own process so that this isn't an issue. | 105 // viewport should run its own process so that this isn't an issue. |
| 107 #if defined(OS_ANDROID) | 106 #if defined(OS_ANDROID) |
| 108 service_manager_.SetLoaderForURL( | 107 service_manager_.SetLoaderForURL( |
| 109 scoped_ptr<ServiceLoader>( | 108 scoped_ptr<ServiceLoader>( |
| 110 new UIServiceLoader( | 109 new UIServiceLoader( |
| 111 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)), | 110 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), |
| 112 this)), | 111 this)), |
| 113 GURL("mojo:mojo_native_viewport_service")); | 112 GURL("mojo:mojo_native_viewport_service")); |
| 114 #else | 113 #else |
| 115 service_manager_.SetLoaderForURL( | 114 service_manager_.SetLoaderForURL( |
| 116 scoped_ptr<ServiceLoader>( | 115 scoped_ptr<ServiceLoader>( |
| 117 new BackgroundServiceLoader( | 116 new BackgroundServiceLoader( |
| 118 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)), | 117 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), |
| 119 "native_viewport", | 118 "native_viewport", |
| 120 base::MessageLoop::TYPE_UI)), | 119 base::MessageLoop::TYPE_UI)), |
| 121 GURL("mojo:mojo_native_viewport_service")); | 120 GURL("mojo:mojo_native_viewport_service")); |
| 122 #endif | 121 #endif |
| 123 #if defined(USE_AURA) | 122 #if defined(USE_AURA) |
| 124 // TODO(sky): need a better way to find this. It shouldn't be linked in. | 123 // TODO(sky): need a better way to find this. It shouldn't be linked in. |
| 125 service_manager_.SetLoaderForURL( | 124 service_manager_.SetLoaderForURL( |
| 126 scoped_ptr<ServiceLoader>(new ViewManagerLoader()), | 125 scoped_ptr<ServiceLoader>(new ViewManagerLoader()), |
| 127 GURL("mojo:mojo_view_manager")); | 126 GURL("mojo:mojo_view_manager")); |
| 128 #endif | 127 #endif |
| (...skipping 29 matching lines...) Expand all Loading... |
| 158 #if defined(USE_AURA) | 157 #if defined(USE_AURA) |
| 159 service_manager_.SetLoaderForURL( | 158 service_manager_.SetLoaderForURL( |
| 160 scoped_ptr<ServiceLoader>(), | 159 scoped_ptr<ServiceLoader>(), |
| 161 GURL("mojo:mojo_view_manager")); | 160 GURL("mojo:mojo_view_manager")); |
| 162 #endif | 161 #endif |
| 163 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>()); | 162 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>()); |
| 164 } | 163 } |
| 165 | 164 |
| 166 } // namespace shell | 165 } // namespace shell |
| 167 } // namespace mojo | 166 } // namespace mojo |
| OLD | NEW |