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

Side by Side Diff: mojo/shell/application_manager/application_manager.h

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
6 #define SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
7
8 #include <map>
9
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "mojo/public/cpp/bindings/interface_request.h"
15 #include "mojo/public/interfaces/application/application.mojom.h"
16 #include "mojo/public/interfaces/application/service_provider.mojom.h"
17 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
18 #include "mojo/shell/application_manager/application_loader.h"
19 #include "mojo/shell/application_manager/identity.h"
20 #include "mojo/shell/application_manager/native_runner.h"
21 #include "mojo/shell/native_application_support.h"
22 #include "url/gurl.h"
23
24 namespace base {
25 class FilePath;
26 class SequencedWorkerPool;
27 }
28
29 namespace mojo {
30 namespace shell {
31
32 class Fetcher;
33 class ShellImpl;
34
35 class ApplicationManager {
36 public:
37 class Delegate {
38 public:
39 virtual ~Delegate();
40 virtual GURL ResolveURL(const GURL& url);
41 virtual GURL ResolveMappings(const GURL& url);
42 };
43
44 // API for testing.
45 class TestAPI {
46 public:
47 explicit TestAPI(ApplicationManager* manager);
48 ~TestAPI();
49
50 // Returns true if the shared instance has been created.
51 static bool HasCreatedInstance();
52 // Returns true if there is a ShellImpl for this URL.
53 bool HasFactoryForURL(const GURL& url) const;
54
55 private:
56 ApplicationManager* manager_;
57
58 DISALLOW_COPY_AND_ASSIGN(TestAPI);
59 };
60
61 explicit ApplicationManager(Delegate* delegate);
62 ~ApplicationManager();
63
64 // Loads a service if necessary and establishes a new client connection.
65 void ConnectToApplication(const GURL& application_url,
66 const GURL& requestor_url,
67 InterfaceRequest<ServiceProvider> services,
68 ServiceProviderPtr exposed_services,
69 const base::Closure& on_application_end);
70
71 template <typename Interface>
72 inline void ConnectToService(const GURL& application_url,
73 InterfacePtr<Interface>* ptr) {
74 ScopedMessagePipeHandle service_handle =
75 ConnectToServiceByName(application_url, Interface::Name_);
76 ptr->Bind(service_handle.Pass());
77 }
78
79 ScopedMessagePipeHandle ConnectToServiceByName(
80 const GURL& application_url,
81 const std::string& interface_name);
82
83 void RegisterContentHandler(const std::string& mime_type,
84 const GURL& content_handler_url);
85
86 void RegisterExternalApplication(const GURL& application_url,
87 const std::vector<std::string>& args,
88 ApplicationPtr application);
89
90 // Sets the default Loader to be used if not overridden by SetLoaderForURL()
91 // or SetLoaderForScheme().
92 void set_default_loader(scoped_ptr<ApplicationLoader> loader) {
93 default_loader_ = loader.Pass();
94 }
95 void set_native_runner_factory(
96 scoped_ptr<NativeRunnerFactory> runner_factory) {
97 native_runner_factory_ = runner_factory.Pass();
98 }
99 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) {
100 blocking_pool_ = blocking_pool;
101 }
102 void set_disable_cache(bool disable_cache) { disable_cache_ = disable_cache; }
103 // Sets a Loader to be used for a specific url.
104 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
105 // Sets a Loader to be used for a specific url scheme.
106 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader,
107 const std::string& scheme);
108 // These strings will be passed to the Initialize() method when an Application
109 // is instantiated.
110 // TODO(vtl): Maybe we should store/compare resolved URLs, like
111 // SetNativeOptionsForURL() below?
112 void SetArgsForURL(const std::vector<std::string>& args, const GURL& url);
113 // These options will be used in running any native application at |url|
114 // (which shouldn't contain a query string). (|url| will be mapped and
115 // resolved, and any application whose base resolved URL matches it will have
116 // |options| applied.)
117 // TODO(vtl): This may not do what's desired if the resolved URL results in an
118 // HTTP redirect. Really, we want options to be identified with a particular
119 // implementation, maybe via a signed manifest or something like that.
120 void SetNativeOptionsForURL(const NativeRunnerFactory::Options& options,
121 const GURL& url);
122
123 // Destroys all Shell-ends of connections established with Applications.
124 // Applications connected by this ApplicationManager will observe pipe errors
125 // and have a chance to shutdown.
126 void TerminateShellConnections();
127
128 // Removes a ShellImpl when it encounters an error.
129 void OnShellImplError(ShellImpl* shell_impl);
130
131 private:
132 class ContentHandlerConnection;
133
134 typedef std::map<std::string, ApplicationLoader*> SchemeToLoaderMap;
135 typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap;
136 typedef std::map<Identity, ShellImpl*> IdentityToShellImplMap;
137 typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap;
138 typedef std::map<GURL, std::vector<std::string>> URLToArgsMap;
139 typedef std::map<std::string, GURL> MimeTypeToURLMap;
140 typedef std::map<GURL, NativeRunnerFactory::Options> URLToNativeOptionsMap;
141
142 void ConnectToApplicationWithParameters(
143 const GURL& application_url,
144 const GURL& requestor_url,
145 InterfaceRequest<ServiceProvider> services,
146 ServiceProviderPtr exposed_services,
147 const base::Closure& on_application_end,
148 const std::vector<std::string>& pre_redirect_parameters);
149
150 bool ConnectToRunningApplication(const GURL& resolved_url,
151 const GURL& requestor_url,
152 InterfaceRequest<ServiceProvider>* services,
153 ServiceProviderPtr* exposed_services);
154
155 bool ConnectToApplicationWithLoader(
156 const GURL& resolved_url,
157 const GURL& requestor_url,
158 InterfaceRequest<ServiceProvider>* services,
159 ServiceProviderPtr* exposed_services,
160 const base::Closure& on_application_end,
161 const std::vector<std::string>& parameters,
162 ApplicationLoader* loader);
163
164 InterfaceRequest<Application> RegisterShell(
165 // The URL after resolution and redirects, including the querystring.
166 const GURL& resolved_url,
167 const GURL& requestor_url,
168 InterfaceRequest<ServiceProvider> services,
169 ServiceProviderPtr exposed_services,
170 const base::Closure& on_application_end,
171 const std::vector<std::string>& parameters);
172
173 ShellImpl* GetShellImpl(const GURL& url);
174
175 void ConnectToClient(ShellImpl* shell_impl,
176 const GURL& resolved_url,
177 const GURL& requestor_url,
178 InterfaceRequest<ServiceProvider> services,
179 ServiceProviderPtr exposed_services);
180
181 void HandleFetchCallback(const GURL& requestor_url,
182 InterfaceRequest<ServiceProvider> services,
183 ServiceProviderPtr exposed_services,
184 const base::Closure& on_application_end,
185 const std::vector<std::string>& parameters,
186 NativeApplicationCleanup cleanup,
187 scoped_ptr<Fetcher> fetcher);
188
189 void RunNativeApplication(InterfaceRequest<Application> application_request,
190 const NativeRunnerFactory::Options& options,
191 NativeApplicationCleanup cleanup,
192 scoped_ptr<Fetcher> fetcher,
193 const base::FilePath& file_path,
194 bool path_exists);
195
196 void LoadWithContentHandler(const GURL& content_handler_url,
197 InterfaceRequest<Application> application_request,
198 URLResponsePtr url_response);
199
200 // Returns the appropriate loader for |url|, or null if there is no loader
201 // configured for the URL.
202 ApplicationLoader* GetLoaderForURL(const GURL& url);
203
204 // Removes a ContentHandler when it encounters an error.
205 void OnContentHandlerError(ContentHandlerConnection* content_handler);
206
207 // Returns the arguments for the given url.
208 std::vector<std::string> GetArgsForURL(const GURL& url);
209
210 void CleanupRunner(NativeRunner* runner);
211
212 Delegate* const delegate_;
213 // Loader management.
214 // Loaders are chosen in the order they are listed here.
215 URLToLoaderMap url_to_loader_;
216 SchemeToLoaderMap scheme_to_loader_;
217 scoped_ptr<ApplicationLoader> default_loader_;
218 scoped_ptr<NativeRunnerFactory> native_runner_factory_;
219
220 IdentityToShellImplMap identity_to_shell_impl_;
221 URLToContentHandlerMap url_to_content_handler_;
222 URLToArgsMap url_to_args_;
223 // Note: The keys are URLs after mapping and resolving.
224 URLToNativeOptionsMap url_to_native_options_;
225
226 base::SequencedWorkerPool* blocking_pool_;
227 NetworkServicePtr network_service_;
228 MimeTypeToURLMap mime_type_to_url_;
229 ScopedVector<NativeRunner> native_runners_;
230 bool disable_cache_;
231 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
232
233 DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
234 };
235
236 } // namespace shell
237 } // namespace mojo
238
239 #endif // SHELL_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
OLDNEW
« no previous file with comments | « mojo/shell/application_manager/application_loader.h ('k') | mojo/shell/application_manager/application_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698