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

Side by Side Diff: mojo/shell/context.cc

Issue 437493002: mojo: allow BackgroundServiceLoader-loaded apps to Quit themselves. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « mojo/service_manager/service_manager_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/shell/context.h" 5 #include "mojo/shell/context.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "mojo/embedder/embedder.h" 11 #include "mojo/embedder/embedder.h"
12 #include "mojo/gles2/gles2_support_impl.h" 12 #include "mojo/gles2/gles2_support_impl.h"
13 #include "mojo/public/cpp/application/application_impl.h" 13 #include "mojo/public/cpp/application/application_impl.h"
14 #include "mojo/service_manager/background_service_loader.h" 14 #include "mojo/service_manager/background_shell_service_loader.h"
15 #include "mojo/service_manager/service_loader.h" 15 #include "mojo/service_manager/service_loader.h"
16 #include "mojo/service_manager/service_manager.h" 16 #include "mojo/service_manager/service_manager.h"
17 #include "mojo/services/native_viewport/native_viewport_service.h" 17 #include "mojo/services/native_viewport/native_viewport_service.h"
18 #include "mojo/shell/dynamic_service_loader.h" 18 #include "mojo/shell/dynamic_service_loader.h"
19 #include "mojo/shell/in_process_dynamic_service_runner.h" 19 #include "mojo/shell/in_process_dynamic_service_runner.h"
20 #include "mojo/shell/out_of_process_dynamic_service_runner.h" 20 #include "mojo/shell/out_of_process_dynamic_service_runner.h"
21 #include "mojo/shell/switches.h" 21 #include "mojo/shell/switches.h"
22 #include "mojo/shell/ui_service_loader_android.h" 22 #include "mojo/shell/ui_service_loader_android.h"
23 #include "mojo/spy/spy.h" 23 #include "mojo/spy/spy.h"
24 24
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // don't run it on its own thread we can easily deadlock. Long term native 109 // don't run it on its own thread we can easily deadlock. Long term native
110 // viewport should run its own process so that this isn't an issue. 110 // viewport should run its own process so that this isn't an issue.
111 #if defined(OS_ANDROID) 111 #if defined(OS_ANDROID)
112 service_manager_.SetLoaderForURL( 112 service_manager_.SetLoaderForURL(
113 scoped_ptr<ServiceLoader>( 113 scoped_ptr<ServiceLoader>(
114 new UIServiceLoader( 114 new UIServiceLoader(
115 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), 115 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
116 this)), 116 this)),
117 GURL("mojo:mojo_native_viewport_service")); 117 GURL("mojo:mojo_native_viewport_service"));
118 #else 118 #else
119 service_manager_.SetLoaderForURL( 119 {
120 scoped_ptr<ServiceLoader>( 120 scoped_ptr<BackgroundShellServiceLoader> loader(
121 new BackgroundServiceLoader( 121 new BackgroundShellServiceLoader(
122 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), 122 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
123 "native_viewport", 123 "native_viewport",
124 base::MessageLoop::TYPE_UI)), 124 base::MessageLoop::TYPE_UI));
125 GURL("mojo:mojo_native_viewport_service")); 125 // TODO(tim): NativeViewportService doesn't quit itself yet.
126 loader->set_quit_on_shutdown();
127 service_manager_.SetLoaderForURL(
128 loader.PassAs<ServiceLoader>(),
129 GURL("mojo:mojo_native_viewport_service"));
130 }
126 #endif 131 #endif
127 #if defined(USE_AURA) 132 #if defined(USE_AURA)
128 // TODO(sky): need a better way to find this. It shouldn't be linked in. 133 // TODO(sky): need a better way to find this. It shouldn't be linked in.
129 service_manager_.SetLoaderForURL( 134 service_manager_.SetLoaderForURL(
130 scoped_ptr<ServiceLoader>(new ViewManagerLoader()), 135 scoped_ptr<ServiceLoader>(new ViewManagerLoader()),
131 GURL("mojo:mojo_view_manager")); 136 GURL("mojo:mojo_view_manager"));
132 #endif 137 #endif
133 138
134 #if defined(OS_LINUX) 139 #if defined(OS_LINUX)
135 service_manager_.SetLoaderForScheme( 140 service_manager_.SetLoaderForScheme(
136 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)), 141 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)),
137 "dbus"); 142 "dbus");
138 #endif // defined(OS_LINUX) 143 #endif // defined(OS_LINUX)
139 144
140 if (cmdline->HasSwitch(switches::kSpy)) { 145 if (cmdline->HasSwitch(switches::kSpy)) {
141 spy_.reset(new mojo::Spy(&service_manager_, 146 spy_.reset(new mojo::Spy(&service_manager_,
142 cmdline->GetSwitchValueASCII(switches::kSpy))); 147 cmdline->GetSwitchValueASCII(switches::kSpy)));
143 } 148 }
144 149
145 #if defined(OS_ANDROID) 150 #if defined(OS_ANDROID)
146 // On android, the network service is bundled with the shell because the 151 // On android, the network service is bundled with the shell because the
147 // network stack depends on the android runtime. 152 // network stack depends on the android runtime.
148 service_manager_.SetLoaderForURL( 153 {
149 scoped_ptr<ServiceLoader>( 154 scoped_ptr<BackgroundShellServiceLoader> loader(
150 new BackgroundServiceLoader( 155 new BackgroundShellServiceLoader(
151 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()), 156 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()),
152 "network_service", 157 "network_service",
153 base::MessageLoop::TYPE_IO)), 158 base::MessageLoop::TYPE_IO));
154 GURL("mojo:mojo_network_service")); 159 // TODO(tim): NetworkService doesn't quit itself yet.
160 loader->set_quit_on_shutdown();
161 service_manager_.SetLoaderForURL(loader.PassAs<ServiceLoader>(),
162 GURL("mojo:mojo_network_service"));
163 }
155 #endif 164 #endif
156 } 165 }
157 166
158 void Context::Shutdown() { 167 void Context::Shutdown() {
159 // mojo_view_manager uses native_viewport. Destroy mojo_view_manager first so 168 // mojo_view_manager uses native_viewport. Destroy mojo_view_manager first so
160 // that there aren't shutdown ordering issues. Once native viewport service is 169 // that there aren't shutdown ordering issues. Once native viewport service is
161 // moved into its own process this can likely be nuked. 170 // moved into its own process this can likely be nuked.
162 #if defined(USE_AURA) 171 #if defined(USE_AURA)
163 service_manager_.SetLoaderForURL( 172 service_manager_.SetLoaderForURL(
164 scoped_ptr<ServiceLoader>(), 173 scoped_ptr<ServiceLoader>(),
165 GURL("mojo:mojo_view_manager")); 174 GURL("mojo:mojo_view_manager"));
166 #endif 175 #endif
167 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>()); 176 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>());
168 service_manager_.TerminateShellConnections(); 177 service_manager_.TerminateShellConnections();
169 } 178 }
170 179
171 Context::~Context() { 180 Context::~Context() {
172 DCHECK(!base::MessageLoop::current()); 181 DCHECK(!base::MessageLoop::current());
173 Shutdown(); 182 Shutdown();
174 } 183 }
175 184
176 } // namespace shell 185 } // namespace shell
177 } // namespace mojo 186 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698