OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/app/android/content_main.h" |
| 6 |
| 7 #include "base/base_switches.h" |
| 8 #include "base/at_exit.h" |
| 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" |
| 11 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 12 #include "content/common/android/user_agent.h" |
| 13 #endif |
| 14 #include "content/public/app/content_main_delegate.h" |
| 15 #include "content/public/app/content_main_runner.h" |
| 16 #include "content/public/common/content_switches.h" |
| 17 #include "jni/content_main_jni.h" |
| 18 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 19 #include "webkit/glue/user_agent.h" |
| 20 #endif |
| 21 |
| 22 using base::LazyInstance; |
| 23 using content::ContentMainRunner; |
| 24 using content::ContentMainDelegate; |
| 25 |
| 26 namespace { |
| 27 LazyInstance<scoped_ptr<ContentMainRunner> > g_content_runner = |
| 28 LAZY_INSTANCE_INITIALIZER; |
| 29 |
| 30 LazyInstance<scoped_ptr<ContentMainDelegate> > g_content_main_delegate = |
| 31 LAZY_INSTANCE_INITIALIZER; |
| 32 |
| 33 } // namespace |
| 34 |
| 35 static void InitApplicationContext(JNIEnv* env, |
| 36 _jclass* clazz, |
| 37 _jobject* context) { |
| 38 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
| 39 base::android::InitApplicationContext(scoped_context); |
| 40 } |
| 41 |
| 42 static jint Start(JNIEnv* env, jclass clazz) { |
| 43 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 44 |
| 45 // This is only for browser process. We want to start waiting as early as |
| 46 // possible though here is the common initialization code. |
| 47 if (parsed_command_line.HasSwitch(switches::kWaitForDebugger) && |
| 48 "" == parsed_command_line.GetSwitchValueASCII(switches::kProcessType)) { |
| 49 LOG(ERROR) << "Browser waiting for GDB because flag " |
| 50 << switches::kWaitForDebugger << " was supplied."; |
| 51 base::debug::WaitForDebugger(24*60*60, false); |
| 52 } |
| 53 |
| 54 #if !defined(ANDROID_UPSTREAM_BRINGUP) |
| 55 webkit_glue::InitUserAgent(GetUserAgentOSInfo()); |
| 56 #endif |
| 57 |
| 58 DCHECK(!g_content_runner.Get().get()); |
| 59 g_content_runner.Get().reset(ContentMainRunner::Create()); |
| 60 g_content_runner.Get()->Initialize(0, NULL, |
| 61 g_content_main_delegate.Get().get()); |
| 62 return g_content_runner.Get()->Run(); |
| 63 } |
| 64 |
| 65 namespace content { |
| 66 |
| 67 void SetContentMainDelegate(ContentMainDelegate* delegate) { |
| 68 DCHECK(!g_content_main_delegate.Get().get()); |
| 69 g_content_main_delegate.Get().reset(delegate); |
| 70 } |
| 71 |
| 72 bool RegisterContentMain(JNIEnv* env) { |
| 73 return RegisterNativesImpl(env); |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |