Index: chrome/app/mash/mash_runner.cc |
diff --git a/chrome/app/mash/mash_runner.cc b/chrome/app/mash/mash_runner.cc |
index f4720fb00761b75508c6e561ecfa4cb47b1c1349..06988e80b43bfbd52620f34c366a065836f2d2e9 100644 |
--- a/chrome/app/mash/mash_runner.cc |
+++ b/chrome/app/mash/mash_runner.cc |
@@ -32,8 +32,9 @@ |
#include "components/tracing/common/tracing_switches.h" |
#include "content/public/common/content_switches.h" |
#include "content/public/common/service_names.mojom.h" |
+#include "mash/common/config.h" |
#include "mash/package/mash_packaged_service.h" |
-#include "mash/session/public/interfaces/constants.mojom.h" |
+#include "mash/quick_launch/public/interfaces/constants.mojom.h" |
#include "mojo/edk/embedder/embedder.h" |
#include "mojo/edk/embedder/scoped_ipc_support.h" |
#include "mojo/public/cpp/bindings/binding_set.h" |
@@ -158,11 +159,11 @@ int MashRunner::Run() { |
if (IsChild()) |
return RunChild(); |
- RunMain(); |
- return 0; |
+ |
+ return RunMain(); |
} |
-void MashRunner::RunMain() { |
+int MashRunner::RunMain() { |
base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
mojo::edk::Init(); |
@@ -174,6 +175,17 @@ void MashRunner::RunMain() { |
ipc_thread.task_runner(), |
mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
+ RunServiceManagerInMain(); |
+ |
+ ipc_thread.Stop(); |
+ base::TaskScheduler::GetInstance()->Shutdown(); |
+ return main_return_value_; |
+} |
+ |
+void MashRunner::RunServiceManagerInMain() { |
+ // Ensure run loop exists before instance quit callback is constructed. |
+ main_run_loop_ = base::MakeUnique<base::RunLoop>(); |
+ |
// TODO(sky): refactor BackgroundServiceManager so can supply own context, we |
// shouldn't we using context as it has a lot of stuff we don't really want |
// in chrome. |
@@ -189,11 +201,33 @@ void MashRunner::RunMain() { |
kChromeMashServiceName, service_manager::mojom::kRootUserID), |
std::move(service), nullptr); |
- // Ping mash_session to ensure an instance is brought up |
- context_->connector()->Connect(mash::session::mojom::kServiceName); |
- base::RunLoop().Run(); |
+ // Quit the main process if an important child (e.g. window manager) dies. |
+ background_service_manager.SetInstanceQuitCallback( |
+ base::Bind(&MashRunner::OnInstanceQuitInMain, base::Unretained(this))); |
Ken Rockot(use gerrit already)
2017/01/31 23:33:28
Instead of making the RunLoop and return values in
Ken Rockot(use gerrit already)
2017/01/31 23:34:51
Note: I just realized this would also mean there's
James Cook
2017/02/01 00:41:32
Done and done. I used an anonymous function becaus
|
- base::TaskScheduler::GetInstance()->Shutdown(); |
+ // Ping services that we know we want to launch on startup. |
+ // TODO(jamescook): Start the window server / ui service explicitly. |
+ context_->connector()->Connect(mash::common::GetWindowManagerServiceName()); |
+ context_->connector()->Connect(mash::quick_launch::mojom::kServiceName); |
+ |
+ main_run_loop_->Run(); |
+ |
+ context_.reset(); |
+} |
+ |
+void MashRunner::OnInstanceQuitInMain( |
+ const service_manager::Identity& identity) { |
+ // If the window manager goes down then exit the main process with an error. |
+ // On Chrome OS the OS-level session_manager will restart the main process. |
+ // TODO(jamescook): Also shut down if the window server dies. |
+ if (identity.name() != mash::common::GetWindowManagerServiceName()) |
+ return; |
+ |
+ if (!main_run_loop_->running()) |
+ return; |
+ |
+ main_return_value_ = 1; |
+ main_run_loop_->Quit(); |
} |
int MashRunner::RunChild() { |
@@ -213,10 +247,13 @@ void MashRunner::StartChildApp( |
// going to be mojo:ui at this point. So always create a TYPE_UI message loop |
// for now. |
base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
+ base::RunLoop run_loop; |
context_.reset(new service_manager::ServiceContext( |
base::MakeUnique<mash::MashPackagedService>(), |
std::move(service_request))); |
- base::RunLoop().Run(); |
+ // Quit the child process if it loses its connection to service manager. |
+ context_->SetConnectionLostClosure(run_loop.QuitClosure()); |
+ run_loop.Run(); |
} |
int MashMain() { |