Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: services/service_manager/background/background_service_manager.cc

Issue 2646033002: mash: Exit the root process if the window manager service crashes (Closed)
Patch Set: review comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/service_manager/background/background_service_manager.h" 5 #include "services/service_manager/background/background_service_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_pump_default.h" 13 #include "base/message_loop/message_pump_default.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/threading/simple_thread.h" 19 #include "base/threading/simple_thread.h"
20 #include "services/catalog/store.h" 20 #include "services/catalog/store.h"
21 #include "services/service_manager/connect_params.h" 21 #include "services/service_manager/connect_params.h"
22 #include "services/service_manager/public/cpp/service.h" 22 #include "services/service_manager/public/cpp/service.h"
23 #include "services/service_manager/public/cpp/service_context.h" 23 #include "services/service_manager/public/cpp/service_context.h"
24 #include "services/service_manager/service_manager.h" 24 #include "services/service_manager/service_manager.h"
25 #include "services/service_manager/standalone/context.h" 25 #include "services/service_manager/standalone/context.h"
26 26
27 namespace service_manager { 27 namespace service_manager {
28 namespace {
29
30 // Calls |callback| on |callback_task_runner|'s thread.
31 void CallCallbackWithIdentity(
32 const scoped_refptr<base::TaskRunner> callback_task_runner,
33 const base::Callback<void(const Identity&)>& callback,
34 const Identity& identity) {
35 DCHECK(callback);
36 DCHECK(identity.IsValid());
37 callback_task_runner->PostTask(FROM_HERE, base::Bind(callback, identity));
38 }
39
40 } // namespace
28 41
29 BackgroundServiceManager::BackgroundServiceManager( 42 BackgroundServiceManager::BackgroundServiceManager(
30 service_manager::ServiceProcessLauncher::Delegate* launcher_delegate, 43 service_manager::ServiceProcessLauncher::Delegate* launcher_delegate,
31 std::unique_ptr<base::Value> catalog_contents) 44 std::unique_ptr<base::Value> catalog_contents)
32 : background_thread_("service_manager") { 45 : background_thread_("service_manager") {
33 background_thread_.Start(); 46 background_thread_.Start();
34 background_thread_.task_runner()->PostTask( 47 background_thread_.task_runner()->PostTask(
35 FROM_HERE, 48 FROM_HERE,
36 base::Bind(&BackgroundServiceManager::InitializeOnBackgroundThread, 49 base::Bind(&BackgroundServiceManager::InitializeOnBackgroundThread,
37 base::Unretained(this), launcher_delegate, 50 base::Unretained(this), launcher_delegate,
(...skipping 17 matching lines...) Expand all
55 mojom::ServicePtr service, 68 mojom::ServicePtr service,
56 mojom::PIDReceiverRequest pid_receiver_request) { 69 mojom::PIDReceiverRequest pid_receiver_request) {
57 mojom::ServicePtrInfo service_info = service.PassInterface(); 70 mojom::ServicePtrInfo service_info = service.PassInterface();
58 background_thread_.task_runner()->PostTask( 71 background_thread_.task_runner()->PostTask(
59 FROM_HERE, 72 FROM_HERE,
60 base::Bind(&BackgroundServiceManager::RegisterServiceOnBackgroundThread, 73 base::Bind(&BackgroundServiceManager::RegisterServiceOnBackgroundThread,
61 base::Unretained(this), identity, base::Passed(&service_info), 74 base::Unretained(this), identity, base::Passed(&service_info),
62 base::Passed(&pid_receiver_request))); 75 base::Passed(&pid_receiver_request)));
63 } 76 }
64 77
78 void BackgroundServiceManager::SetInstanceQuitCallback(
79 base::Callback<void(const Identity&)> callback) {
80 DCHECK(callback);
81 // Hop to the background thread. The provided callback will be called on
82 // whichever thread called this function.
83 background_thread_.task_runner()->PostTask(
84 FROM_HERE,
85 base::Bind(
86 &BackgroundServiceManager::SetInstanceQuitCallbackOnBackgroundThread,
87 base::Unretained(this), base::ThreadTaskRunnerHandle::Get(),
88 callback));
89 }
90
91 void BackgroundServiceManager::SetInstanceQuitCallbackOnBackgroundThread(
92 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
93 const base::Callback<void(const Identity&)>& callback) {
94 DCHECK(callback_task_runner);
95 DCHECK(callback);
96 // Calls |callback| with the identity of the service that is quitting.
97 context_->service_manager()->SetInstanceQuitCallback(
98 base::Bind(&CallCallbackWithIdentity, callback_task_runner, callback));
99 }
100
65 void BackgroundServiceManager::InitializeOnBackgroundThread( 101 void BackgroundServiceManager::InitializeOnBackgroundThread(
66 service_manager::ServiceProcessLauncher::Delegate* launcher_delegate, 102 service_manager::ServiceProcessLauncher::Delegate* launcher_delegate,
67 std::unique_ptr<base::Value> catalog_contents) { 103 std::unique_ptr<base::Value> catalog_contents) {
68 context_ = 104 context_ =
69 base::MakeUnique<Context>(launcher_delegate, std::move(catalog_contents)); 105 base::MakeUnique<Context>(launcher_delegate, std::move(catalog_contents));
70 } 106 }
71 107
72 void BackgroundServiceManager::ShutDownOnBackgroundThread( 108 void BackgroundServiceManager::ShutDownOnBackgroundThread(
73 base::WaitableEvent* done_event) { 109 base::WaitableEvent* done_event) {
74 context_.reset(); 110 context_.reset();
75 done_event->Signal(); 111 done_event->Signal();
76 } 112 }
77 113
78 void BackgroundServiceManager::RegisterServiceOnBackgroundThread( 114 void BackgroundServiceManager::RegisterServiceOnBackgroundThread(
79 const Identity& identity, 115 const Identity& identity,
80 mojom::ServicePtrInfo service_info, 116 mojom::ServicePtrInfo service_info,
81 mojom::PIDReceiverRequest pid_receiver_request) { 117 mojom::PIDReceiverRequest pid_receiver_request) {
82 mojom::ServicePtr service; 118 mojom::ServicePtr service;
83 service.Bind(std::move(service_info)); 119 service.Bind(std::move(service_info));
84 context_->service_manager()->RegisterService( 120 context_->service_manager()->RegisterService(
85 identity, std::move(service), std::move(pid_receiver_request)); 121 identity, std::move(service), std::move(pid_receiver_request));
86 } 122 }
87 123
88 } // namespace service_manager 124 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/background/background_service_manager.h ('k') | services/service_manager/background/tests/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698