| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | |
| 10 #include "base/base_switches.h" | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ptr_util.h" |
| 13 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/app/content_service_manager_main_delegate.h" |
| 14 #include "content/public/app/content_main.h" | 13 #include "content/public/app/content_main.h" |
| 15 #include "content/public/app/content_main_delegate.h" | 14 #include "content/public/app/content_main_delegate.h" |
| 16 #include "content/public/app/content_main_runner.h" | |
| 17 #include "content/public/common/content_switches.h" | |
| 18 #include "jni/ContentMain_jni.h" | 15 #include "jni/ContentMain_jni.h" |
| 16 #include "services/service_manager/embedder/main.h" |
| 19 | 17 |
| 20 using base::LazyInstance; | 18 using base::LazyInstance; |
| 21 using base::android::JavaParamRef; | 19 using base::android::JavaParamRef; |
| 22 | 20 |
| 23 namespace content { | 21 namespace content { |
| 24 | 22 |
| 25 namespace { | 23 namespace { |
| 26 LazyInstance<std::unique_ptr<ContentMainRunner>>::DestructorAtExit | 24 |
| 27 g_content_runner = LAZY_INSTANCE_INITIALIZER; | 25 LazyInstance<std::unique_ptr<service_manager::MainDelegate>>::DestructorAtExit |
| 26 g_service_manager_main_delegate = LAZY_INSTANCE_INITIALIZER; |
| 28 | 27 |
| 29 LazyInstance<std::unique_ptr<ContentMainDelegate>>::DestructorAtExit | 28 LazyInstance<std::unique_ptr<ContentMainDelegate>>::DestructorAtExit |
| 30 g_content_main_delegate = LAZY_INSTANCE_INITIALIZER; | 29 g_content_main_delegate = LAZY_INSTANCE_INITIALIZER; |
| 31 | 30 |
| 32 } // namespace | 31 } // namespace |
| 33 | 32 |
| 34 static jint Start(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 33 static jint Start(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| 35 TRACE_EVENT0("startup", "content::Start"); | 34 TRACE_EVENT0("startup", "content::Start"); |
| 36 | 35 |
| 37 // On Android we can have multiple requests to start the browser in process | 36 // On Android we can have multiple requests to start the browser in process |
| 38 // simultaneously. If we get an asynchonous request followed by a synchronous | 37 // simultaneously. If we get an asynchonous request followed by a synchronous |
| 39 // request then we have to call this a second time to finish starting the | 38 // request then we have to call this a second time to finish starting the |
| 40 // browser synchronously. | 39 // browser synchronously. |
| 41 if (!g_content_runner.Get().get()) { | 40 if (!g_service_manager_main_delegate.Get()) { |
| 42 ContentMainParams params(g_content_main_delegate.Get().get()); | 41 g_service_manager_main_delegate.Get() = |
| 43 g_content_runner.Get().reset(ContentMainRunner::Create()); | 42 base::MakeUnique<ContentServiceManagerMainDelegate>( |
| 44 g_content_runner.Get()->Initialize(params); | 43 ContentMainParams(g_content_main_delegate.Get().get())); |
| 45 } | 44 } |
| 46 return g_content_runner.Get()->Run(); | 45 |
| 46 service_manager::MainParams main_params( |
| 47 g_service_manager_main_delegate.Get().get()); |
| 48 return service_manager::Main(main_params); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void SetContentMainDelegate(ContentMainDelegate* delegate) { | 51 void SetContentMainDelegate(ContentMainDelegate* delegate) { |
| 50 DCHECK(!g_content_main_delegate.Get().get()); | 52 DCHECK(!g_content_main_delegate.Get().get()); |
| 51 g_content_main_delegate.Get().reset(delegate); | 53 g_content_main_delegate.Get().reset(delegate); |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool RegisterContentMain(JNIEnv* env) { | 56 bool RegisterContentMain(JNIEnv* env) { |
| 55 return RegisterNativesImpl(env); | 57 return RegisterNativesImpl(env); |
| 56 } | 58 } |
| 57 | 59 |
| 58 } // namespace content | 60 } // namespace content |
| OLD | NEW |