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

Side by Side Diff: shell/context.cc

Issue 939353002: Fix mojo::shell::Context shutdown. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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 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 "shell/context.h" 5 #include "shell/context.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/run_loop.h"
18 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "mojo/common/trace_controller_impl.h" 22 #include "mojo/common/trace_controller_impl.h"
22 #include "mojo/common/tracing_impl.h" 23 #include "mojo/common/tracing_impl.h"
23 #include "mojo/edk/embedder/embedder.h" 24 #include "mojo/edk/embedder/embedder.h"
24 #include "mojo/edk/embedder/simple_platform_support.h" 25 #include "mojo/edk/embedder/simple_platform_support.h"
25 #include "mojo/public/cpp/application/application_connection.h" 26 #include "mojo/public/cpp/application/application_connection.h"
26 #include "mojo/public/cpp/application/application_delegate.h" 27 #include "mojo/public/cpp/application/application_delegate.h"
27 #include "mojo/public/cpp/application/application_impl.h" 28 #include "mojo/public/cpp/application/application_impl.h"
(...skipping 20 matching lines...) Expand all
48 embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( 49 embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>(
49 new mojo::embedder::SimplePlatformSupport())); 50 new mojo::embedder::SimplePlatformSupport()));
50 } 51 }
51 52
52 ~Setup() {} 53 ~Setup() {}
53 54
54 private: 55 private:
55 DISALLOW_COPY_AND_ASSIGN(Setup); 56 DISALLOW_COPY_AND_ASSIGN(Setup);
56 }; 57 };
57 58
58 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
59
60 void InitContentHandlers(NativeApplicationLoader* loader, 59 void InitContentHandlers(NativeApplicationLoader* loader,
61 base::CommandLine* command_line) { 60 base::CommandLine* command_line) {
62 // Default content handlers. 61 // Default content handlers.
63 loader->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); 62 loader->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer"));
64 loader->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); 63 loader->RegisterContentHandler("image/png", GURL("mojo:png_viewer"));
65 loader->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); 64 loader->RegisterContentHandler("text/html", GURL("mojo:html_viewer"));
66 65
67 // Command-line-specified content handlers. 66 // Command-line-specified content handlers.
68 std::string handlers_spec = 67 std::string handlers_spec =
69 command_line->GetSwitchValueASCII(switches::kContentHandlers); 68 command_line->GetSwitchValueASCII(switches::kContentHandlers);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 186
188 base::FilePath cwd; 187 base::FilePath cwd;
189 PathService::Get(base::DIR_CURRENT, &cwd); 188 PathService::Get(base::DIR_CURRENT, &cwd);
190 SetCommandLineCWD(cwd); 189 SetCommandLineCWD(cwd);
191 } 190 }
192 191
193 Context::~Context() { 192 Context::~Context() {
194 DCHECK(!base::MessageLoop::current()); 193 DCHECK(!base::MessageLoop::current());
195 } 194 }
196 195
196 // static
197 void Context::EnsureEmbedderIsInitialized() { 197 void Context::EnsureEmbedderIsInitialized() {
198 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
198 setup.Get(); 199 setup.Get();
199 } 200 }
200 201
201 void Context::SetShellFileRoot(const base::FilePath& path) { 202 void Context::SetShellFileRoot(const base::FilePath& path) {
202 shell_file_root_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path)); 203 shell_file_root_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path));
203 } 204 }
204 205
205 GURL Context::ResolveShellFileURL(const std::string& path) { 206 GURL Context::ResolveShellFileURL(const std::string& path) {
206 return shell_file_root_.Resolve(path); 207 return shell_file_root_.Resolve(path);
207 } 208 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 GURL("mojo:tracing"), GURL(""), nullptr, 270 GURL("mojo:tracing"), GURL(""), nullptr,
270 tracing_service_provider_ptr.Pass()); 271 tracing_service_provider_ptr.Pass());
271 272
272 if (listener_) 273 if (listener_)
273 listener_->WaitForListening(); 274 listener_->WaitForListening();
274 275
275 return true; 276 return true;
276 } 277 }
277 278
278 void Context::Shutdown() { 279 void Context::Shutdown() {
280 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
281 task_runners_->shell_runner());
279 embedder::ShutdownIPCSupport(); 282 embedder::ShutdownIPCSupport();
283 // We'll quit when we get OnShutdownComplete().
284 base::MessageLoop::current()->Run();
280 } 285 }
281 286
282 void Context::OnApplicationError(const GURL& url) { 287 void Context::OnApplicationError(const GURL& url) {
283 if (app_urls_.find(url) != app_urls_.end()) { 288 if (app_urls_.find(url) != app_urls_.end()) {
284 app_urls_.erase(url); 289 app_urls_.erase(url);
285 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) 290 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) {
286 Shutdown(); 291 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
292 task_runners_->shell_runner());
293 base::MessageLoop::current()->Quit();
294 }
287 } 295 }
288 } 296 }
289 297
290 GURL Context::ResolveURL(const GURL& url) { 298 GURL Context::ResolveURL(const GURL& url) {
291 return url_resolver_.ResolveMojoURL(url); 299 return url_resolver_.ResolveMojoURL(url);
292 } 300 }
293 301
294 GURL Context::ResolveMappings(const GURL& url) { 302 GURL Context::ResolveMappings(const GURL& url) {
295 return url_resolver_.ApplyMappings(url); 303 return url_resolver_.ApplyMappings(url);
296 } 304 }
(...skipping 16 matching lines...) Expand all
313 ScopedMessagePipeHandle Context::ConnectToServiceByName( 321 ScopedMessagePipeHandle Context::ConnectToServiceByName(
314 const GURL& application_url, 322 const GURL& application_url,
315 const std::string& service_name) { 323 const std::string& service_name) {
316 app_urls_.insert(application_url); 324 app_urls_.insert(application_url);
317 return application_manager_.ConnectToServiceByName(application_url, 325 return application_manager_.ConnectToServiceByName(application_url,
318 service_name).Pass(); 326 service_name).Pass();
319 } 327 }
320 328
321 } // namespace shell 329 } // namespace shell
322 } // namespace mojo 330 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/context.h ('k') | shell/desktop/mojo_main.cc » ('j') | shell/desktop/mojo_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698