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

Side by Side Diff: mojo/shell/android/mojo_main.cc

Issue 420143003: mojo: shell::Context should outlive the shell MessageLoop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix + verify android Created 6 years, 4 months 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 | Annotate | Revision Log
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 "mojo/shell/android/mojo_main.h" 5 #include "mojo/shell/android/mojo_main.h"
6 6
7 #include "base/android/java_handler_thread.h" 7 #include "base/android/java_handler_thread.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 19 matching lines...) Expand all
30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = 30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop =
31 LAZY_INSTANCE_INITIALIZER; 31 LAZY_INSTANCE_INITIALIZER;
32 32
33 LazyInstance<scoped_ptr<shell::Context> > g_context = 33 LazyInstance<scoped_ptr<shell::Context> > g_context =
34 LAZY_INSTANCE_INITIALIZER; 34 LAZY_INSTANCE_INITIALIZER;
35 35
36 LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread = 36 LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread =
37 LAZY_INSTANCE_INITIALIZER; 37 LAZY_INSTANCE_INITIALIZER;
38 38
39 void RunShell(std::vector<GURL> app_urls) { 39 void RunShell(std::vector<GURL> app_urls) {
40 shell::Context* shell_context = new shell::Context(); 40 g_context.Get()->Init();
41 shell_context->set_ui_loop(g_java_message_loop.Get().get()); 41 g_context.Get()->set_ui_loop(g_java_message_loop.Get().get());
42 42 shell::Run(g_context.Get().get(), app_urls);
43 g_context.Get().reset(shell_context);
44 shell::Run(shell_context, app_urls);
45 } 43 }
46 44
47 } // namespace 45 } // namespace
48 46
49 static void Init(JNIEnv* env, jclass clazz, jobject context) { 47 static void Init(JNIEnv* env, jclass clazz, jobject context) {
50 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); 48 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
51 49
52 base::android::InitApplicationContext(env, scoped_context); 50 base::android::InitApplicationContext(env, scoped_context);
53 51
54 base::CommandLine::Init(0, 0); 52 base::CommandLine::Init(0, 0);
55 mojo::shell::InitializeLogging(); 53 mojo::shell::InitializeLogging();
56 54
55 // We want ~MessageLoop to happen prior to ~Context. Initializing
56 // LazyInstances is akin to stack-allocating objects; their destructors
57 // will be invoked first-in-last-out.
58 shell::Context* shell_context = new shell::Context();
59 g_context.Get().reset(shell_context);
57 g_java_message_loop.Get().reset(new base::MessageLoopForUI); 60 g_java_message_loop.Get().reset(new base::MessageLoopForUI);
58 base::MessageLoopForUI::current()->Start(); 61 base::MessageLoopForUI::current()->Start();
59 62
60 // TODO(abarth): At which point should we switch to cross-platform 63 // TODO(abarth): At which point should we switch to cross-platform
61 // initialization? 64 // initialization?
62 65
63 gfx::GLSurface::InitializeOneOff(); 66 gfx::GLSurface::InitializeOneOff();
64 } 67 }
65 68
66 static void Start(JNIEnv* env, jclass clazz, jstring jurl) { 69 static void Start(JNIEnv* env, jclass clazz, jstring jurl) {
(...skipping 12 matching lines...) Expand all
79 g_shell_thread.Get()->Start(); 82 g_shell_thread.Get()->Start();
80 g_shell_thread.Get()->message_loop()->PostTask( 83 g_shell_thread.Get()->message_loop()->PostTask(
81 FROM_HERE, base::Bind(&RunShell, app_urls)); 84 FROM_HERE, base::Bind(&RunShell, app_urls));
82 } 85 }
83 86
84 bool RegisterMojoMain(JNIEnv* env) { 87 bool RegisterMojoMain(JNIEnv* env) {
85 return RegisterNativesImpl(env); 88 return RegisterNativesImpl(env);
86 } 89 }
87 90
88 } // namespace mojo 91 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/window_manager/window_manager_api_unittest.cc ('k') | mojo/shell/child_process_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698