- add sources.
[platform/framework/web/crosswalk.git] / src / content / app / android / content_main.cc
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/at_exit.h"
8 #include "base/base_switches.h"
9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h"
11 #include "base/lazy_instance.h"
12 #include "content/public/app/content_main.h"
13 #include "content/public/app/content_main_delegate.h"
14 #include "content/public/app/content_main_runner.h"
15 #include "content/public/common/content_switches.h"
16 #include "jni/ContentMain_jni.h"
17
18 using base::LazyInstance;
19 using content::ContentMainRunner;
20 using content::ContentMainDelegate;
21
22 namespace {
23 LazyInstance<scoped_ptr<ContentMainRunner> > g_content_runner =
24     LAZY_INSTANCE_INITIALIZER;
25
26 LazyInstance<scoped_ptr<ContentMainDelegate> > g_content_main_delegate =
27     LAZY_INSTANCE_INITIALIZER;
28
29 }  // namespace
30
31 namespace content {
32
33 static void InitApplicationContext(JNIEnv* env, jclass clazz, jobject context) {
34   base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
35   base::android::InitApplicationContext(scoped_context);
36 }
37
38 static jint Start(JNIEnv* env, jclass clazz) {
39   TRACE_EVENT0("startup", "content::Start");
40
41   // On Android we can have multiple requests to start the browser in process
42   // simultaneously. If we get an asynchonous request followed by a synchronous
43   // request then we have to call this a second time to finish starting the
44   // browser synchronously.
45   if (!g_content_runner.Get().get()) {
46     g_content_runner.Get().reset(ContentMainRunner::Create());
47     g_content_runner.Get()->Initialize(
48         0, NULL, g_content_main_delegate.Get().get());
49   }
50   return g_content_runner.Get()->Run();
51 }
52
53 void SetContentMainDelegate(ContentMainDelegate* delegate) {
54   DCHECK(!g_content_main_delegate.Get().get());
55   g_content_main_delegate.Get().reset(delegate);
56 }
57
58 bool RegisterContentMain(JNIEnv* env) {
59   return RegisterNativesImpl(env);
60 }
61
62 }  // namespace content