| OLD | NEW |
| 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 scoped_ptr<StartupTaskRunner::Observer> startup_observer( |
| 53 new AndroidStartupObserver(java_startup_observer)); |
| 54 |
| 55 delegate->SetStartupObserver(startup_observer.Pass()); |
| 56 delegate->EnableIncrementalStartup(!immediate_startup); |
| 57 |
| 58 g_content_runner.Get() |
| 59 ->Initialize(0, NULL, g_content_main_delegate.Get().get()); |
| 45 return g_content_runner.Get()->Run(); | 60 return g_content_runner.Get()->Run(); |
| 46 } | 61 } |
| 47 | 62 |
| 48 void SetContentMainDelegate(ContentMainDelegate* delegate) { | 63 void SetContentMainDelegate(ContentMainDelegate* delegate) { |
| 49 DCHECK(!g_content_main_delegate.Get().get()); | 64 DCHECK(!g_content_main_delegate.Get().get()); |
| 50 g_content_main_delegate.Get().reset(delegate); | 65 g_content_main_delegate.Get().reset(delegate); |
| 51 } | 66 } |
| 52 | 67 |
| 53 bool RegisterContentMain(JNIEnv* env) { | 68 bool RegisterContentMain(JNIEnv* env) { |
| 54 return RegisterNativesImpl(env); | 69 return RegisterNativesImpl(env); |
| 55 } | 70 } |
| 56 | 71 |
| 57 } // namespace content | 72 } // namespace content |
| OLD | NEW |