Chromium Code Reviews| Index: content/app/android/content_main.cc |
| diff --git a/content/app/android/content_main.cc b/content/app/android/content_main.cc |
| index d6a1eecff0cfaf7bc6f63827418ef58066107954..fcdc17de91b76cfefee471a57269798bbfc74a7e 100644 |
| --- a/content/app/android/content_main.cc |
| +++ b/content/app/android/content_main.cc |
| @@ -10,12 +10,15 @@ |
| #include "base/base_switches.h" |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/trace_event/trace_event.h" |
| #include "content/public/app/content_main.h" |
| #include "content/public/app/content_main_delegate.h" |
| #include "content/public/app/content_main_runner.h" |
| #include "content/public/common/content_switches.h" |
| #include "jni/ContentMain_jni.h" |
| +#include "services/service_manager/embedder/main.h" |
| +#include "services/service_manager/embedder/main_delegate.h" |
| using base::LazyInstance; |
| using base::android::JavaParamRef; |
| @@ -23,12 +26,42 @@ using base::android::JavaParamRef; |
| namespace content { |
| namespace { |
| -LazyInstance<std::unique_ptr<ContentMainRunner>>::DestructorAtExit |
| - g_content_runner = LAZY_INSTANCE_INITIALIZER; |
| + |
| +LazyInstance<std::unique_ptr<service_manager::MainDelegate>>::DestructorAtExit |
| + g_service_manager_main_delegate = LAZY_INSTANCE_INITIALIZER; |
| LazyInstance<std::unique_ptr<ContentMainDelegate>>::DestructorAtExit |
| g_content_main_delegate = LAZY_INSTANCE_INITIALIZER; |
| +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
|
| + public: |
| + explicit ContentServiceManagerMainDelegate( |
| + ContentMainDelegate* content_main_delegate) |
| + : content_main_params_(content_main_delegate), |
| + main_runner_(ContentMainRunner::Create()) {} |
| + ~ContentServiceManagerMainDelegate() override {} |
| + |
| + // service_manager::MainDelegate: |
| + bool Initialize(const InitializeParams& params, int* exit_code) override { |
| + // If service_manager::Main is invoked multiple times, we only do real |
| + // initialization the first time. |
| + if (!initialized_) { |
| + initialized_ = true; |
| + main_runner_->Initialize(content_main_params_); |
| + } |
| + return true; |
| + } |
| + |
| + int Run() override { return main_runner_->Run(); } |
| + |
| + void ShutDown() override {} |
| + |
| + private: |
| + const ContentMainParams content_main_params_; |
| + bool initialized_ = false; |
| + std::unique_ptr<ContentMainRunner> main_runner_; |
| +}; |
| + |
| } // namespace |
| static jint Start(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| @@ -38,12 +71,15 @@ static jint Start(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| // simultaneously. If we get an asynchonous request followed by a synchronous |
| // request then we have to call this a second time to finish starting the |
| // browser synchronously. |
| - if (!g_content_runner.Get().get()) { |
| - ContentMainParams params(g_content_main_delegate.Get().get()); |
| - g_content_runner.Get().reset(ContentMainRunner::Create()); |
| - g_content_runner.Get()->Initialize(params); |
| + if (!g_service_manager_main_delegate.Get()) { |
| + g_service_manager_main_delegate.Get() = |
| + base::MakeUnique<ContentServiceManagerMainDelegate>( |
| + g_content_main_delegate.Get().get()); |
| } |
| - return g_content_runner.Get()->Run(); |
| + |
| + service_manager::MainParams main_params( |
| + g_service_manager_main_delegate.Get().get()); |
| + return service_manager::Main(main_params); |
| } |
| void SetContentMainDelegate(ContentMainDelegate* delegate) { |