Chromium Code Reviews| 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" | 9 #include "base/at_exit.h" |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ptr_util.h" | |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "content/public/app/content_main.h" | 15 #include "content/public/app/content_main.h" |
| 15 #include "content/public/app/content_main_delegate.h" | 16 #include "content/public/app/content_main_delegate.h" |
| 16 #include "content/public/app/content_main_runner.h" | 17 #include "content/public/app/content_main_runner.h" |
| 17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 18 #include "jni/ContentMain_jni.h" | 19 #include "jni/ContentMain_jni.h" |
| 20 #include "services/service_manager/embedder/main.h" | |
| 21 #include "services/service_manager/embedder/main_delegate.h" | |
| 19 | 22 |
| 20 using base::LazyInstance; | 23 using base::LazyInstance; |
| 21 using base::android::JavaParamRef; | 24 using base::android::JavaParamRef; |
| 22 | 25 |
| 23 namespace content { | 26 namespace content { |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 LazyInstance<std::unique_ptr<ContentMainRunner>>::DestructorAtExit | 29 |
| 27 g_content_runner = LAZY_INSTANCE_INITIALIZER; | 30 LazyInstance<std::unique_ptr<service_manager::MainDelegate>>::DestructorAtExit |
| 31 g_service_manager_main_delegate = LAZY_INSTANCE_INITIALIZER; | |
| 28 | 32 |
| 29 LazyInstance<std::unique_ptr<ContentMainDelegate>>::DestructorAtExit | 33 LazyInstance<std::unique_ptr<ContentMainDelegate>>::DestructorAtExit |
| 30 g_content_main_delegate = LAZY_INSTANCE_INITIALIZER; | 34 g_content_main_delegate = LAZY_INSTANCE_INITIALIZER; |
| 31 | 35 |
| 36 class ContentServiceManagerMainDelegate : public service_manager::MainDelegate { | |
|
jam
2017/03/20 15:06:16
why isn't this shared with the version in content/
Ken Rockot(use gerrit already)
2017/03/20 17:27:05
There were reasons, but in retrospect they weren't
| |
| 37 public: | |
| 38 explicit ContentServiceManagerMainDelegate( | |
| 39 ContentMainDelegate* content_main_delegate) | |
| 40 : content_main_params_(content_main_delegate), | |
| 41 main_runner_(ContentMainRunner::Create()) {} | |
| 42 ~ContentServiceManagerMainDelegate() override {} | |
| 43 | |
| 44 // service_manager::MainDelegate: | |
| 45 bool Initialize(const InitializeParams& params, int* exit_code) override { | |
| 46 // If service_manager::Main is invoked multiple times, we only do real | |
| 47 // initialization the first time. | |
| 48 if (!initialized_) { | |
| 49 initialized_ = true; | |
| 50 main_runner_->Initialize(content_main_params_); | |
| 51 } | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 int Run() override { return main_runner_->Run(); } | |
| 56 | |
| 57 void ShutDown() override {} | |
| 58 | |
| 59 private: | |
| 60 const ContentMainParams content_main_params_; | |
| 61 bool initialized_ = false; | |
| 62 std::unique_ptr<ContentMainRunner> main_runner_; | |
| 63 }; | |
| 64 | |
| 32 } // namespace | 65 } // namespace |
| 33 | 66 |
| 34 static jint Start(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 67 static jint Start(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| 35 TRACE_EVENT0("startup", "content::Start"); | 68 TRACE_EVENT0("startup", "content::Start"); |
| 36 | 69 |
| 37 // On Android we can have multiple requests to start the browser in process | 70 // 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 | 71 // 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 | 72 // request then we have to call this a second time to finish starting the |
| 40 // browser synchronously. | 73 // browser synchronously. |
| 41 if (!g_content_runner.Get().get()) { | 74 if (!g_service_manager_main_delegate.Get()) { |
| 42 ContentMainParams params(g_content_main_delegate.Get().get()); | 75 g_service_manager_main_delegate.Get() = |
| 43 g_content_runner.Get().reset(ContentMainRunner::Create()); | 76 base::MakeUnique<ContentServiceManagerMainDelegate>( |
| 44 g_content_runner.Get()->Initialize(params); | 77 g_content_main_delegate.Get().get()); |
| 45 } | 78 } |
| 46 return g_content_runner.Get()->Run(); | 79 |
| 80 service_manager::MainParams main_params( | |
| 81 g_service_manager_main_delegate.Get().get()); | |
| 82 return service_manager::Main(main_params); | |
| 47 } | 83 } |
| 48 | 84 |
| 49 void SetContentMainDelegate(ContentMainDelegate* delegate) { | 85 void SetContentMainDelegate(ContentMainDelegate* delegate) { |
| 50 DCHECK(!g_content_main_delegate.Get().get()); | 86 DCHECK(!g_content_main_delegate.Get().get()); |
| 51 g_content_main_delegate.Get().reset(delegate); | 87 g_content_main_delegate.Get().reset(delegate); |
| 52 } | 88 } |
| 53 | 89 |
| 54 bool RegisterContentMain(JNIEnv* env) { | 90 bool RegisterContentMain(JNIEnv* env) { |
| 55 return RegisterNativesImpl(env); | 91 return RegisterNativesImpl(env); |
| 56 } | 92 } |
| 57 | 93 |
| 58 } // namespace content | 94 } // namespace content |
| OLD | NEW |