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 "shell/android/main.h" | 5 #include "shell/android/main.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/android/fifo_utils.h" | 9 #include "base/android/fifo_utils.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/threading/simple_thread.h" | 25 #include "base/threading/simple_thread.h" |
26 #include "gpu/config/gpu_util.h" | 26 #include "gpu/config/gpu_util.h" |
27 #include "jni/ShellService_jni.h" | 27 #include "jni/ShellService_jni.h" |
28 #include "mojo/message_pump/message_pump_mojo.h" | 28 #include "mojo/message_pump/message_pump_mojo.h" |
29 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 29 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
30 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" | 30 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" |
31 #include "shell/android/android_handler_loader.h" | 31 #include "shell/android/android_handler_loader.h" |
32 #include "shell/android/java_application_loader.h" | 32 #include "shell/android/java_application_loader.h" |
33 #include "shell/android/native_viewport_application_loader.h" | 33 #include "shell/android/native_viewport_application_loader.h" |
34 #include "shell/android/ui_application_loader_android.h" | 34 #include "shell/android/ui_application_loader_android.h" |
| 35 #include "shell/android/url_response_disk_cache_delegate_impl.h" |
35 #include "shell/application_manager/application_loader.h" | 36 #include "shell/application_manager/application_loader.h" |
36 #include "shell/background_application_loader.h" | 37 #include "shell/background_application_loader.h" |
37 #include "shell/command_line_util.h" | 38 #include "shell/command_line_util.h" |
38 #include "shell/context.h" | 39 #include "shell/context.h" |
39 #include "shell/crash/breakpad.h" | 40 #include "shell/crash/breakpad.h" |
40 #include "shell/crash/crash_upload.h" | 41 #include "shell/crash/crash_upload.h" |
41 #include "shell/init.h" | 42 #include "shell/init.h" |
42 #include "shell/switches.h" | 43 #include "shell/switches.h" |
43 #include "shell/tracer.h" | 44 #include "shell/tracer.h" |
44 #include "ui/gl/gl_surface_egl.h" | 45 #include "ui/gl/gl_surface_egl.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 scoped_ptr<MojoShellRunner> shell_runner; | 89 scoped_ptr<MojoShellRunner> shell_runner; |
89 | 90 |
90 // Thread to run the shell on. | 91 // Thread to run the shell on. |
91 scoped_ptr<base::DelegateSimpleThread> shell_thread; | 92 scoped_ptr<base::DelegateSimpleThread> shell_thread; |
92 | 93 |
93 // TaskRunner used to execute tasks on the shell thread. | 94 // TaskRunner used to execute tasks on the shell thread. |
94 scoped_refptr<base::SingleThreadTaskRunner> shell_task_runner; | 95 scoped_refptr<base::SingleThreadTaskRunner> shell_task_runner; |
95 | 96 |
96 // Event signalling when the shell task runner has been initialized. | 97 // Event signalling when the shell task runner has been initialized. |
97 scoped_ptr<base::WaitableEvent> shell_runner_ready; | 98 scoped_ptr<base::WaitableEvent> shell_runner_ready; |
| 99 |
| 100 // Delegate for URLResponseDiskCache. Allows to access bundled application on |
| 101 // cold start. |
| 102 scoped_ptr<URLResponseDiskCacheDelegateImpl> url_response_disk_cache_delegate; |
98 }; | 103 }; |
99 | 104 |
100 LazyInstance<InternalShellData> g_internal_data = LAZY_INSTANCE_INITIALIZER; | 105 LazyInstance<InternalShellData> g_internal_data = LAZY_INSTANCE_INITIALIZER; |
101 | 106 |
102 void ConfigureAndroidServices(Context* context) { | 107 void ConfigureAndroidServices(Context* context) { |
103 context->application_manager()->SetLoaderForURL( | 108 context->application_manager()->SetLoaderForURL( |
104 make_scoped_ptr(new UIApplicationLoader( | 109 make_scoped_ptr(new UIApplicationLoader( |
105 make_scoped_ptr(new NativeViewportApplicationLoader()), | 110 make_scoped_ptr(new NativeViewportApplicationLoader()), |
106 g_internal_data.Get().java_message_loop.get())), | 111 g_internal_data.Get().java_message_loop.get())), |
107 GURL("mojo:native_viewport_service")); | 112 GURL("mojo:native_viewport_service")); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 145 } |
141 | 146 |
142 void MojoShellRunner::Run() { | 147 void MojoShellRunner::Run() { |
143 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); | 148 base::MessageLoop loop(mojo::common::MessagePumpMojo::Create()); |
144 g_internal_data.Get().shell_task_runner = loop.task_runner(); | 149 g_internal_data.Get().shell_task_runner = loop.task_runner(); |
145 // Signal that the shell is ready to receive requests. | 150 // Signal that the shell is ready to receive requests. |
146 g_internal_data.Get().shell_runner_ready->Signal(); | 151 g_internal_data.Get().shell_runner_ready->Signal(); |
147 | 152 |
148 Context* context = g_internal_data.Get().context.get(); | 153 Context* context = g_internal_data.Get().context.get(); |
149 ConfigureAndroidServices(context); | 154 ConfigureAndroidServices(context); |
150 CHECK(context->InitWithPaths(mojo_shell_child_path_)); | 155 CHECK(context->InitWithPaths( |
| 156 mojo_shell_child_path_, |
| 157 g_internal_data.Get().url_response_disk_cache_delegate.get())); |
151 | 158 |
152 RunCommandLineApps(context); | 159 RunCommandLineApps(context); |
153 | 160 |
154 loop.Run(); | 161 loop.Run(); |
155 | 162 |
156 g_internal_data.Get().java_message_loop.get()->PostTask( | 163 g_internal_data.Get().java_message_loop.get()->PostTask( |
157 FROM_HERE, base::Bind(&QuitShellThread)); | 164 FROM_HERE, base::Bind(&QuitShellThread)); |
158 } | 165 } |
159 | 166 |
160 // Initialize stdout redirection if the command line switch is present. | 167 // Initialize stdout redirection if the command line switch is present. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 &network_service); | 219 &network_service); |
213 breakpad::UploadCrashes(dumps_path, context->task_runners()->blocking_pool(), | 220 breakpad::UploadCrashes(dumps_path, context->task_runners()->blocking_pool(), |
214 network_service.Pass()); | 221 network_service.Pass()); |
215 } | 222 } |
216 | 223 |
217 } // namespace | 224 } // namespace |
218 | 225 |
219 static void Start(JNIEnv* env, | 226 static void Start(JNIEnv* env, |
220 jclass clazz, | 227 jclass clazz, |
221 jobject application_context, | 228 jobject application_context, |
| 229 jobject j_asset_manager, |
222 jstring mojo_shell_child_path, | 230 jstring mojo_shell_child_path, |
223 jobjectArray jparameters, | 231 jobjectArray jparameters, |
224 jstring j_local_apps_directory, | 232 jstring j_local_apps_directory, |
225 jstring j_tmp_dir, | 233 jstring j_tmp_dir, |
226 jstring j_home_dir) { | 234 jstring j_home_dir) { |
227 // Initially, the shell runner is not ready. | 235 // Initially, the shell runner is not ready. |
228 g_internal_data.Get().shell_runner_ready.reset( | 236 g_internal_data.Get().shell_runner_ready.reset( |
229 new base::WaitableEvent(true, false)); | 237 new base::WaitableEvent(true, false)); |
230 | 238 |
231 std::string tmp_dir = base::android::ConvertJavaStringToUTF8(env, j_tmp_dir); | 239 std::string tmp_dir = base::android::ConvertJavaStringToUTF8(env, j_tmp_dir); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 InitializeRedirection(); | 285 InitializeRedirection(); |
278 | 286 |
279 // We want ~MessageLoop to happen prior to ~Context. Initializing | 287 // We want ~MessageLoop to happen prior to ~Context. Initializing |
280 // LazyInstances is akin to stack-allocating objects; their destructors | 288 // LazyInstances is akin to stack-allocating objects; their destructors |
281 // will be invoked first-in-last-out. | 289 // will be invoked first-in-last-out. |
282 Context* shell_context = new Context(tracer); | 290 Context* shell_context = new Context(tracer); |
283 shell_context->SetShellFileRoot(base::FilePath( | 291 shell_context->SetShellFileRoot(base::FilePath( |
284 base::android::ConvertJavaStringToUTF8(env, j_local_apps_directory))); | 292 base::android::ConvertJavaStringToUTF8(env, j_local_apps_directory))); |
285 g_internal_data.Get().context.reset(shell_context); | 293 g_internal_data.Get().context.reset(shell_context); |
286 | 294 |
| 295 g_internal_data.Get().url_response_disk_cache_delegate.reset( |
| 296 new URLResponseDiskCacheDelegateImpl(shell_context, j_asset_manager)); |
| 297 |
287 g_internal_data.Get().java_message_loop.reset(new base::MessageLoopForUI); | 298 g_internal_data.Get().java_message_loop.reset(new base::MessageLoopForUI); |
288 base::MessageLoopForUI::current()->Start(); | 299 base::MessageLoopForUI::current()->Start(); |
289 tracer->DidCreateMessageLoop(); | 300 tracer->DidCreateMessageLoop(); |
290 | 301 |
291 g_internal_data.Get().shell_thread.reset(new base::DelegateSimpleThread( | 302 g_internal_data.Get().shell_thread.reset(new base::DelegateSimpleThread( |
292 g_internal_data.Get().shell_runner.get(), "ShellThread")); | 303 g_internal_data.Get().shell_runner.get(), "ShellThread")); |
293 g_internal_data.Get().shell_thread->Start(); | 304 g_internal_data.Get().shell_thread->Start(); |
294 | 305 |
295 // TODO(abarth): At which point should we switch to cross-platform | 306 // TODO(abarth): At which point should we switch to cross-platform |
296 // initialization? | 307 // initialization? |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 mojo::MessagePipeHandle(services_handle))), | 342 mojo::MessagePipeHandle(services_handle))), |
332 base::Passed(mojo::ScopedMessagePipeHandle( | 343 base::Passed(mojo::ScopedMessagePipeHandle( |
333 mojo::MessagePipeHandle(exposed_services_handle))))); | 344 mojo::MessagePipeHandle(exposed_services_handle))))); |
334 } | 345 } |
335 | 346 |
336 bool RegisterShellService(JNIEnv* env) { | 347 bool RegisterShellService(JNIEnv* env) { |
337 return RegisterNativesImpl(env); | 348 return RegisterNativesImpl(env); |
338 } | 349 } |
339 | 350 |
340 } // namespace shell | 351 } // namespace shell |
OLD | NEW |