Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: shell/context.cc

Issue 805113002: Moves android specific code into android directory (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: merge 2 trunk Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/context.h ('k') | shell/ui_application_loader_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "shell/context.h" 5 #include "shell/context.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 13 matching lines...) Expand all
24 #include "mojo/public/cpp/application/application_connection.h" 24 #include "mojo/public/cpp/application/application_connection.h"
25 #include "mojo/public/cpp/application/application_delegate.h" 25 #include "mojo/public/cpp/application/application_delegate.h"
26 #include "mojo/public/cpp/application/application_impl.h" 26 #include "mojo/public/cpp/application/application_impl.h"
27 #include "mojo/spy/spy.h" 27 #include "mojo/spy/spy.h"
28 #include "services/tracing/tracing.mojom.h" 28 #include "services/tracing/tracing.mojom.h"
29 #include "shell/dynamic_application_loader.h" 29 #include "shell/dynamic_application_loader.h"
30 #include "shell/external_application_listener.h" 30 #include "shell/external_application_listener.h"
31 #include "shell/in_process_dynamic_service_runner.h" 31 #include "shell/in_process_dynamic_service_runner.h"
32 #include "shell/out_of_process_dynamic_service_runner.h" 32 #include "shell/out_of_process_dynamic_service_runner.h"
33 #include "shell/switches.h" 33 #include "shell/switches.h"
34 #include "shell/ui_application_loader_android.h"
35 #include "url/gurl.h" 34 #include "url/gurl.h"
36 35
37 #if defined(OS_ANDROID)
38 #include "services/gles2/gpu_impl.h"
39 #include "services/native_viewport/native_viewport_impl.h"
40 #include "shell/android/android_handler_loader.h"
41 #endif // defined(OS_ANDROID)
42
43 namespace mojo { 36 namespace mojo {
44 namespace shell { 37 namespace shell {
45 namespace { 38 namespace {
46 39
47 // These mojo: URLs are loaded directly from the local filesystem. They 40 // These mojo: URLs are loaded directly from the local filesystem. They
48 // correspond to shared libraries bundled alongside the mojo_shell. 41 // correspond to shared libraries bundled alongside the mojo_shell.
49 const char* kLocalMojoURLs[] = { 42 const char* kLocalMojoURLs[] = {
50 "mojo:network_service", 43 "mojo:network_service",
51 }; 44 };
52 45
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const GURL to(pair.second); 108 const GURL to(pair.second);
116 if (!from.is_valid() || !to.is_valid()) 109 if (!from.is_valid() || !to.is_valid())
117 return false; 110 return false;
118 resolver->AddCustomMapping(from, to); 111 resolver->AddCustomMapping(from, to);
119 } 112 }
120 return true; 113 return true;
121 } 114 }
122 115
123 } // namespace 116 } // namespace
124 117
125 #if defined(OS_ANDROID)
126 class Context::NativeViewportApplicationLoader
127 : public ApplicationLoader,
128 public ApplicationDelegate,
129 public InterfaceFactory<NativeViewport>,
130 public InterfaceFactory<Gpu> {
131 public:
132 NativeViewportApplicationLoader() : gpu_state_(new gles2::GpuImpl::State) {}
133 virtual ~NativeViewportApplicationLoader() {}
134
135 private:
136 // ApplicationLoader implementation.
137 virtual void Load(ApplicationManager* manager,
138 const GURL& url,
139 ScopedMessagePipeHandle shell_handle,
140 LoadCallback callback) override {
141 DCHECK(shell_handle.is_valid());
142 app_.reset(new ApplicationImpl(this, shell_handle.Pass()));
143 }
144
145 virtual void OnApplicationError(ApplicationManager* manager,
146 const GURL& url) override {}
147
148 // ApplicationDelegate implementation.
149 virtual bool ConfigureIncomingConnection(
150 mojo::ApplicationConnection* connection) override {
151 connection->AddService<NativeViewport>(this);
152 connection->AddService<Gpu>(this);
153 return true;
154 }
155
156 // InterfaceFactory<NativeViewport> implementation.
157 virtual void Create(ApplicationConnection* connection,
158 InterfaceRequest<NativeViewport> request) override {
159 BindToRequest(new native_viewport::NativeViewportImpl(app_.get(), false),
160 &request);
161 }
162
163 // InterfaceFactory<Gpu> implementation.
164 virtual void Create(ApplicationConnection* connection,
165 InterfaceRequest<Gpu> request) override {
166 new gles2::GpuImpl(request.Pass(), gpu_state_);
167 }
168
169 scoped_refptr<gles2::GpuImpl::State> gpu_state_;
170 scoped_ptr<ApplicationImpl> app_;
171 DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationLoader);
172 };
173 #endif
174
175 Context::Context() : application_manager_(this) { 118 Context::Context() : application_manager_(this) {
176 DCHECK(!base::MessageLoop::current()); 119 DCHECK(!base::MessageLoop::current());
177 } 120 }
178 121
179 Context::~Context() { 122 Context::~Context() {
180 DCHECK(!base::MessageLoop::current()); 123 DCHECK(!base::MessageLoop::current());
181 } 124 }
182 125
183 void Context::EnsureEmbedderIsInitialized() { 126 void Context::EnsureEmbedderIsInitialized() {
184 setup.Get(); 127 setup.Get();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); 167 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory());
225 else 168 else
226 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); 169 runner_factory.reset(new InProcessDynamicServiceRunnerFactory());
227 170
228 DynamicApplicationLoader* dynamic_application_loader = 171 DynamicApplicationLoader* dynamic_application_loader =
229 new DynamicApplicationLoader(this, runner_factory.Pass()); 172 new DynamicApplicationLoader(this, runner_factory.Pass());
230 InitContentHandlers(dynamic_application_loader, command_line); 173 InitContentHandlers(dynamic_application_loader, command_line);
231 application_manager_.set_default_loader( 174 application_manager_.set_default_loader(
232 scoped_ptr<ApplicationLoader>(dynamic_application_loader)); 175 scoped_ptr<ApplicationLoader>(dynamic_application_loader));
233 176
234 // The native viewport service synchronously waits for certain messages. If we
235 // don't run it on its own thread we can easily deadlock. Long term native
236 // viewport should run its own process so that this isn't an issue.
237 #if defined(OS_ANDROID)
238 application_manager_.SetLoaderForURL(
239 scoped_ptr<ApplicationLoader>(new UIApplicationLoader(
240 scoped_ptr<ApplicationLoader>(new NativeViewportApplicationLoader()),
241 this)),
242 GURL("mojo:native_viewport_service"));
243 #endif
244
245 if (command_line->HasSwitch(switches::kSpy)) { 177 if (command_line->HasSwitch(switches::kSpy)) {
246 spy_.reset( 178 spy_.reset(
247 new mojo::Spy(&application_manager_, 179 new mojo::Spy(&application_manager_,
248 command_line->GetSwitchValueASCII(switches::kSpy))); 180 command_line->GetSwitchValueASCII(switches::kSpy)));
249 // TODO(cpu): the spy can snoop, but can't tell anybody until 181 // TODO(cpu): the spy can snoop, but can't tell anybody until
250 // the Spy::WebSocketDelegate is implemented. In the original repo this 182 // the Spy::WebSocketDelegate is implemented. In the original repo this
251 // was implemented by src\mojo\spy\websocket_server.h and .cc. 183 // was implemented by src\mojo\spy\websocket_server.h and .cc.
252 } 184 }
253 185
254 #if defined(OS_ANDROID)
255 {
256 // Android handler is bundled with the Mojo shell, because it uses the
257 // MojoShell application as the JNI bridge to bootstrap execution of other
258 // Android Mojo apps that need JNI.
259 scoped_ptr<BackgroundShellApplicationLoader> loader(
260 new BackgroundShellApplicationLoader(
261 scoped_ptr<ApplicationLoader>(new AndroidHandlerLoader()),
262 "android_handler", base::MessageLoop::TYPE_DEFAULT));
263 application_manager_.SetLoaderForURL(loader.Pass(),
264 GURL("mojo:android_handler"));
265 }
266 #endif
267
268 tracing::TraceDataCollectorPtr trace_data_collector_ptr; 186 tracing::TraceDataCollectorPtr trace_data_collector_ptr;
269 application_manager_.ConnectToService(GURL("mojo:tracing"), 187 application_manager_.ConnectToService(GURL("mojo:tracing"),
270 &trace_data_collector_ptr); 188 &trace_data_collector_ptr);
271 TracingImpl::Create(trace_data_collector_ptr.Pass()); 189 TracingImpl::Create(trace_data_collector_ptr.Pass());
272 190
273 if (listener_) 191 if (listener_)
274 listener_->WaitForListening(); 192 listener_->WaitForListening();
275 193
276 return true; 194 return true;
277 } 195 }
(...skipping 22 matching lines...) Expand all
300 ScopedMessagePipeHandle Context::ConnectToServiceByName( 218 ScopedMessagePipeHandle Context::ConnectToServiceByName(
301 const GURL& application_url, 219 const GURL& application_url,
302 const std::string& service_name) { 220 const std::string& service_name) {
303 app_urls_.insert(application_url); 221 app_urls_.insert(application_url);
304 return application_manager_.ConnectToServiceByName(application_url, 222 return application_manager_.ConnectToServiceByName(application_url,
305 service_name).Pass(); 223 service_name).Pass();
306 } 224 }
307 225
308 } // namespace shell 226 } // namespace shell
309 } // namespace mojo 227 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/context.h ('k') | shell/ui_application_loader_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698