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

Side by Side Diff: shell/context.h

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 #ifndef SHELL_CONTEXT_H_ 5 #ifndef SHELL_CONTEXT_H_
6 #define SHELL_CONTEXT_H_ 6 #define SHELL_CONTEXT_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "mojo/edk/embedder/process_delegate.h" 11 #include "mojo/edk/embedder/process_delegate.h"
12 #include "shell/application_manager/application_manager.h" 12 #include "shell/application_manager/application_manager.h"
13 #include "shell/task_runners.h" 13 #include "shell/task_runners.h"
14 #include "shell/url_resolver.h" 14 #include "shell/url_resolver.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 namespace shell { 18 namespace shell {
19 19
20 class ExternalApplicationListener; 20 class ExternalApplicationListener;
21 class NativeApplicationLoader; 21 class NativeApplicationLoader;
22 22
23 // The "global" context for the shell's main process. 23 // The "global" context for the shell's main process.
24 class Context : ApplicationManager::Delegate, embedder::ProcessDelegate { 24 class Context : ApplicationManager::Delegate, embedder::ProcessDelegate {
25 public: 25 public:
26 Context(); 26 Context();
27 ~Context() override; 27 ~Context() override;
28 28
29 static void EnsureEmbedderIsInitialized();
30
29 // Point to the directory containing installed services, such as the network 31 // Point to the directory containing installed services, such as the network
30 // service. By default this directory is used as the base URL for resolving 32 // service. By default this directory is used as the base URL for resolving
31 // unknown mojo: URLs. The network service will be loaded from this directory, 33 // unknown mojo: URLs. The network service will be loaded from this directory,
32 // even when the base URL for unknown mojo: URLs is overridden. 34 // even when the base URL for unknown mojo: URLs is overridden.
33 void SetShellFileRoot(const base::FilePath& path); 35 void SetShellFileRoot(const base::FilePath& path);
34 36
35 // Resolve an URL relative to the shell file root. This is a nop for 37 // Resolve an URL relative to the shell file root. This is a nop for
36 // everything but relative file URLs or URLs without a scheme. 38 // everything but relative file URLs or URLs without a scheme.
37 GURL ResolveShellFileURL(const std::string& path); 39 GURL ResolveShellFileURL(const std::string& path);
38 40
39 // Override the CWD, which is used for resolving file URLs passed in from the 41 // Override the CWD, which is used for resolving file URLs passed in from the
40 // command line. 42 // command line.
41 void SetCommandLineCWD(const base::FilePath& path); 43 void SetCommandLineCWD(const base::FilePath& path);
42 44
43 // Resolve an URL relative to the CWD mojo_shell was invoked from. This is a 45 // Resolve an URL relative to the CWD mojo_shell was invoked from. This is a
44 // nop for everything but relative file URLs or URLs without a scheme. 46 // nop for everything but relative file URLs or URLs without a scheme.
45 GURL ResolveCommandLineURL(const std::string& path); 47 GURL ResolveCommandLineURL(const std::string& path);
46 48
47 static void EnsureEmbedderIsInitialized(); 49 // This must be called with a message loop set up for the current thread,
50 // which must remain alive until after Shutdown() is called. Returns true on
51 // success.
48 bool Init(); 52 bool Init();
49 53
54 // If Init() was called and succeeded, this must be called before destruction.
55 void Shutdown();
56
50 void Run(const GURL& url); 57 void Run(const GURL& url);
51 ScopedMessagePipeHandle ConnectToServiceByName( 58 ScopedMessagePipeHandle ConnectToServiceByName(
52 const GURL& application_url, 59 const GURL& application_url,
53 const std::string& service_name); 60 const std::string& service_name);
54 61
55 TaskRunners* task_runners() { return task_runners_.get(); } 62 TaskRunners* task_runners() { return task_runners_.get(); }
56 ApplicationManager* application_manager() { return &application_manager_; } 63 ApplicationManager* application_manager() { return &application_manager_; }
57 URLResolver* url_resolver() { return &url_resolver_; } 64 URLResolver* url_resolver() { return &url_resolver_; }
58 65
59 private: 66 private:
60 class NativeViewportApplicationLoader; 67 class NativeViewportApplicationLoader;
61 68
62 void Shutdown();
63
64 // ApplicationManager::Delegate overrides. 69 // ApplicationManager::Delegate overrides.
65 void OnApplicationError(const GURL& url) override; 70 void OnApplicationError(const GURL& url) override;
66 GURL ResolveURL(const GURL& url) override; 71 GURL ResolveURL(const GURL& url) override;
67 GURL ResolveMappings(const GURL& url) override; 72 GURL ResolveMappings(const GURL& url) override;
68 73
69 // ProcessDelegate implementation. 74 // ProcessDelegate implementation.
70 void OnShutdownComplete() override; 75 void OnShutdownComplete() override;
71 76
72 std::set<GURL> app_urls_; 77 std::set<GURL> app_urls_;
73 scoped_ptr<TaskRunners> task_runners_; 78 scoped_ptr<TaskRunners> task_runners_;
74 scoped_ptr<ExternalApplicationListener> listener_; 79 scoped_ptr<ExternalApplicationListener> listener_;
75 ApplicationManager application_manager_; 80 ApplicationManager application_manager_;
76 URLResolver url_resolver_; 81 URLResolver url_resolver_;
77 GURL shell_file_root_; 82 GURL shell_file_root_;
78 GURL command_line_cwd_; 83 GURL command_line_cwd_;
79 84
80 DISALLOW_COPY_AND_ASSIGN(Context); 85 DISALLOW_COPY_AND_ASSIGN(Context);
81 }; 86 };
82 87
83 } // namespace shell 88 } // namespace shell
84 } // namespace mojo 89 } // namespace mojo
85 90
86 #endif // SHELL_CONTEXT_H_ 91 #endif // SHELL_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698