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

Side by Side Diff: content/app/android/content_main.cc

Issue 19957002: Run the later parts of startup as UI thread tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run the later parts of startup as UI thread tasks - patch for Yaron's comments Created 7 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/app/android/content_main.h" 5 #include "content/app/android/content_main.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "content/browser/android/android_startup_observer.h"
12 #include "content/public/app/content_main.h" 13 #include "content/public/app/content_main.h"
13 #include "content/public/app/content_main_delegate.h" 14 #include "content/public/app/content_main_delegate.h"
14 #include "content/public/app/content_main_runner.h" 15 #include "content/public/app/content_main_runner.h"
15 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
16 #include "jni/ContentMain_jni.h" 17 #include "jni/ContentMain_jni.h"
17 18
18 using base::LazyInstance; 19 using base::LazyInstance;
19 using content::ContentMainRunner; 20 using content::ContentMainRunner;
20 using content::ContentMainDelegate; 21 using content::ContentMainDelegate;
21 22
22 namespace { 23 namespace {
23 LazyInstance<scoped_ptr<ContentMainRunner> > g_content_runner = 24 LazyInstance<scoped_ptr<ContentMainRunner> > g_content_runner =
24 LAZY_INSTANCE_INITIALIZER; 25 LAZY_INSTANCE_INITIALIZER;
25 26
26 LazyInstance<scoped_ptr<ContentMainDelegate> > g_content_main_delegate = 27 LazyInstance<scoped_ptr<ContentMainDelegate> > g_content_main_delegate =
27 LAZY_INSTANCE_INITIALIZER; 28 LAZY_INSTANCE_INITIALIZER;
28 29
29 } // namespace 30 } // namespace
30 31
31 namespace content { 32 namespace content {
32 33
33 static void InitApplicationContext(JNIEnv* env, jclass clazz, jobject context) { 34 static void InitApplicationContext(JNIEnv* env, jclass clazz, jobject context) {
34 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); 35 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
35 base::android::InitApplicationContext(scoped_context); 36 base::android::InitApplicationContext(scoped_context);
36 } 37 }
37 38
38 static jint Start(JNIEnv* env, jclass clazz) { 39 static jint Start(JNIEnv* env,
40 jclass clazz,
41 jboolean immediate_startup,
42 jobject java_startup_observer) {
39 TRACE_EVENT0("startup", "content::Start"); 43 TRACE_EVENT0("startup", "content::Start");
40 44
45 java_startup_observer = env->NewGlobalRef(java_startup_observer);
46
41 DCHECK(!g_content_runner.Get().get()); 47 DCHECK(!g_content_runner.Get().get());
42 g_content_runner.Get().reset(ContentMainRunner::Create()); 48 g_content_runner.Get().reset(ContentMainRunner::Create());
43 g_content_runner.Get()->Initialize(0, NULL, 49
44 g_content_main_delegate.Get().get()); 50 ContentMainDelegate* delegate = g_content_main_delegate.Get().get();
51
52 if(java_startup_observer != NULL){
53 scoped_ptr<StartupTaskRunner::Observer> startup_observer(
54 new AndroidStartupObserver(java_startup_observer));
55 delegate->SetStartupObserver(startup_observer.Pass());
56 }
57 delegate->EnableIncrementalStartup(!immediate_startup);
58
59 g_content_runner.Get()
60 ->Initialize(0, NULL, g_content_main_delegate.Get().get());
45 return g_content_runner.Get()->Run(); 61 return g_content_runner.Get()->Run();
46 } 62 }
47 63
48 void SetContentMainDelegate(ContentMainDelegate* delegate) { 64 void SetContentMainDelegate(ContentMainDelegate* delegate) {
49 DCHECK(!g_content_main_delegate.Get().get()); 65 DCHECK(!g_content_main_delegate.Get().get());
50 g_content_main_delegate.Get().reset(delegate); 66 g_content_main_delegate.Get().reset(delegate);
51 } 67 }
52 68
53 bool RegisterContentMain(JNIEnv* env) { 69 bool RegisterContentMain(JNIEnv* env) {
54 return RegisterNativesImpl(env); 70 return RegisterNativesImpl(env);
55 } 71 }
56 72
57 } // namespace content 73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698