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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 NativeViewportServiceLoader() {} | 68 NativeViewportServiceLoader() {} |
69 virtual ~NativeViewportServiceLoader() {} | 69 virtual ~NativeViewportServiceLoader() {} |
70 | 70 |
71 private: | 71 private: |
72 virtual void LoadService(ServiceManager* manager, | 72 virtual void LoadService( |
73 const GURL& url, | 73 ServiceManager* manager, |
74 ScopedMessagePipeHandle shell_handle) OVERRIDE { | 74 const GURL& url, |
75 app_.reset(services::CreateNativeViewportService(shell_handle.Pass())); | 75 scoped_refptr<LoadServiceCallbacks> callbacks) OVERRIDE { |
76 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | |
77 if (shell_handle.is_valid()) { | |
DaveMoore
2014/08/04 21:50:51
Nit: no braces
Aaron Boodman
2014/08/05 05:44:54
Done.
| |
78 app_.reset(services::CreateNativeViewportService(shell_handle.Pass())); | |
79 } | |
76 } | 80 } |
77 | 81 |
78 virtual void OnServiceError(ServiceManager* manager, | 82 virtual void OnServiceError(ServiceManager* manager, |
79 const GURL& url) OVERRIDE { | 83 const GURL& url) OVERRIDE { |
80 } | 84 } |
81 | 85 |
82 scoped_ptr<ApplicationImpl> app_; | 86 scoped_ptr<ApplicationImpl> app_; |
83 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader); | 87 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader); |
84 }; | 88 }; |
85 | 89 |
86 Context::Context() | 90 Context::Context() |
87 : task_runners_(base::MessageLoop::current()->message_loop_proxy()) { | 91 : task_runners_(base::MessageLoop::current()->message_loop_proxy()) { |
88 setup.Get(); | 92 setup.Get(); |
89 | 93 |
90 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) | 94 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) |
91 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); | 95 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); |
92 | 96 |
93 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 97 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
94 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; | 98 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; |
95 if (cmdline->HasSwitch(switches::kEnableMultiprocess)) | 99 if (cmdline->HasSwitch(switches::kEnableMultiprocess)) |
96 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); | 100 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); |
97 else | 101 else |
98 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); | 102 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); |
99 | 103 |
104 DynamicServiceLoader* dynamic_service_loader = | |
105 new DynamicServiceLoader(this, runner_factory.Pass()); | |
106 dynamic_service_loader->set_content_handler( | |
107 "text/plain", GURL("mojo://mojo_content_handler_demo/")); | |
DaveMoore
2014/08/04 21:50:51
mojo_content_handler_demo?
Aaron Boodman
2014/08/05 05:44:54
I don't understand this comment, but I've removed
| |
100 service_manager_.set_default_loader( | 108 service_manager_.set_default_loader( |
101 scoped_ptr<ServiceLoader>( | 109 scoped_ptr<ServiceLoader>(dynamic_service_loader)); |
102 new DynamicServiceLoader(this, runner_factory.Pass()))); | 110 |
103 // The native viewport service synchronously waits for certain messages. If we | 111 // The native viewport service synchronously waits for certain messages. If we |
104 // don't run it on its own thread we can easily deadlock. Long term native | 112 // don't run it on its own thread we can easily deadlock. Long term native |
105 // viewport should run its own process so that this isn't an issue. | 113 // viewport should run its own process so that this isn't an issue. |
106 #if defined(OS_ANDROID) | 114 #if defined(OS_ANDROID) |
107 service_manager_.SetLoaderForURL( | 115 service_manager_.SetLoaderForURL( |
108 scoped_ptr<ServiceLoader>( | 116 scoped_ptr<ServiceLoader>( |
109 new UIServiceLoader( | 117 new UIServiceLoader( |
110 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), | 118 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), |
111 this)), | 119 this)), |
112 GURL("mojo:mojo_native_viewport_service")); | 120 GURL("mojo:mojo_native_viewport_service")); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>()); | 170 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>()); |
163 service_manager_.TerminateShellConnections(); | 171 service_manager_.TerminateShellConnections(); |
164 } | 172 } |
165 | 173 |
166 Context::~Context() { | 174 Context::~Context() { |
167 Shutdown(); | 175 Shutdown(); |
168 } | 176 } |
169 | 177 |
170 } // namespace shell | 178 } // namespace shell |
171 } // namespace mojo | 179 } // namespace mojo |
OLD | NEW |