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

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

Issue 1343823002: Revert of Move fetching logic out of ApplicationManager, eliminate url mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « mojo/shell/application_fetcher.h ('k') | mojo/shell/application_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 MOJO_SHELL_APPLICATION_MANAGER_H_ 5 #ifndef MOJO_SHELL_APPLICATION_MANAGER_H_
6 #define MOJO_SHELL_APPLICATION_MANAGER_H_ 6 #define MOJO_SHELL_APPLICATION_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "mojo/application/public/interfaces/application.mojom.h" 14 #include "mojo/application/public/interfaces/application.mojom.h"
15 #include "mojo/application/public/interfaces/service_provider.mojom.h" 15 #include "mojo/application/public/interfaces/service_provider.mojom.h"
16 #include "mojo/application/public/interfaces/shell.mojom.h" 16 #include "mojo/application/public/interfaces/shell.mojom.h"
17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
18 #include "mojo/public/cpp/bindings/interface_request.h" 18 #include "mojo/public/cpp/bindings/interface_request.h"
19 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
20 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
19 #include "mojo/services/updater/updater.mojom.h" 21 #include "mojo/services/updater/updater.mojom.h"
20 #include "mojo/shell/application_loader.h" 22 #include "mojo/shell/application_loader.h"
21 #include "mojo/shell/capability_filter.h" 23 #include "mojo/shell/capability_filter.h"
22 #include "mojo/shell/connect_to_application_params.h" 24 #include "mojo/shell/connect_to_application_params.h"
23 #include "mojo/shell/fetcher.h" 25 #include "mojo/shell/fetcher.h"
24 #include "mojo/shell/identity.h" 26 #include "mojo/shell/identity.h"
25 #include "mojo/shell/native_runner.h" 27 #include "mojo/shell/native_runner.h"
26 #include "url/gurl.h" 28 #include "url/gurl.h"
27 29
28 namespace base { 30 namespace base {
29 class FilePath; 31 class FilePath;
30 class SequencedWorkerPool; 32 class SequencedWorkerPool;
31 } 33 }
32 34
33 namespace mojo { 35 namespace mojo {
34 namespace shell { 36 namespace shell {
35 37
36 class ApplicationFetcher;
37 class ApplicationInstance; 38 class ApplicationInstance;
38 class ContentHandlerConnection; 39 class ContentHandlerConnection;
39 40
40 class ApplicationManager { 41 class ApplicationManager {
41 public: 42 public:
43 class Delegate {
44 public:
45 // Gives the delegate a chance to apply any mappings for the specified url.
46 // This should not resolve 'mojo' urls, that is done by ResolveMojoURL().
47 virtual GURL ResolveMappings(const GURL& url) = 0;
48
49 // Used to map a url with the scheme 'mojo' to the appropriate url. Return
50 // |url| if the scheme is not 'mojo'.
51 virtual GURL ResolveMojoURL(const GURL& url) = 0;
52
53 // Asks the delegate to create a Fetcher for the specified url. Return
54 // true on success, false if the default fetcher should be created.
55 virtual bool CreateFetcher(
56 const GURL& url,
57 const Fetcher::FetchCallback& loader_callback) = 0;
58
59 protected:
60 virtual ~Delegate() {}
61 };
62
42 // API for testing. 63 // API for testing.
43 class TestAPI { 64 class TestAPI {
44 public: 65 public:
45 explicit TestAPI(ApplicationManager* manager); 66 explicit TestAPI(ApplicationManager* manager);
46 ~TestAPI(); 67 ~TestAPI();
47 68
48 // Returns true if the shared instance has been created. 69 // Returns true if the shared instance has been created.
49 static bool HasCreatedInstance(); 70 static bool HasCreatedInstance();
50 // Returns true if there is a ApplicationInstance for this URL. 71 // Returns true if there is a ApplicationInstance for this URL.
51 bool HasRunningInstanceForURL(const GURL& url) const; 72 bool HasRunningInstanceForURL(const GURL& url) const;
52 73
53 private: 74 private:
54 ApplicationManager* manager_; 75 ApplicationManager* manager_;
55 76
56 DISALLOW_COPY_AND_ASSIGN(TestAPI); 77 DISALLOW_COPY_AND_ASSIGN(TestAPI);
57 }; 78 };
58 79
59 explicit ApplicationManager(scoped_ptr<ApplicationFetcher> fetcher); 80 explicit ApplicationManager(Delegate* delegate);
60 ~ApplicationManager(); 81 ~ApplicationManager();
61 82
62 // Loads a service if necessary and establishes a new client connection. 83 // Loads a service if necessary and establishes a new client connection.
63 // |originator| can be NULL (e.g. for the first application or in tests), but 84 // |originator| can be NULL (e.g. for the first application or in tests), but
64 // typically is non-NULL and identifies the instance initiating the 85 // typically is non-NULL and identifies the instance initiating the
65 // connection. 86 // connection.
66 // Please see the comments in connect_to_application_params.h for more details 87 // Please see the comments in connect_to_application_params.h for more details
67 // about the parameters. 88 // about the parameters.
68 void ConnectToApplication( 89 void ConnectToApplication(
69 ApplicationInstance* originator, 90 ApplicationInstance* originator,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { 126 void set_default_loader(scoped_ptr<ApplicationLoader> loader) {
106 default_loader_ = loader.Pass(); 127 default_loader_ = loader.Pass();
107 } 128 }
108 void set_native_runner_factory( 129 void set_native_runner_factory(
109 scoped_ptr<NativeRunnerFactory> runner_factory) { 130 scoped_ptr<NativeRunnerFactory> runner_factory) {
110 native_runner_factory_ = runner_factory.Pass(); 131 native_runner_factory_ = runner_factory.Pass();
111 } 132 }
112 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { 133 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) {
113 blocking_pool_ = blocking_pool; 134 blocking_pool_ = blocking_pool;
114 } 135 }
136 void set_disable_cache(bool disable_cache) { disable_cache_ = disable_cache; }
115 // Sets a Loader to be used for a specific url. 137 // Sets a Loader to be used for a specific url.
116 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); 138 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
117 // Sets a Loader to be used for a specific url scheme. 139 // Sets a Loader to be used for a specific url scheme.
118 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, 140 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader,
119 const std::string& scheme); 141 const std::string& scheme);
120 // These options will be used in running any native application at |url| 142 // These options will be used in running any native application at |url|
121 // (which shouldn't contain a query string). (|url| will be mapped and 143 // (which shouldn't contain a query string). (|url| will be mapped and
122 // resolved, and any application whose base resolved URL matches it will have 144 // resolved, and any application whose base resolved URL matches it will have
123 // |options| applied.) 145 // |options| applied.)
124 // TODO(vtl): This may not do what's desired if the resolved URL results in an 146 // TODO(vtl): This may not do what's desired if the resolved URL results in an
(...skipping 27 matching lines...) Expand all
152 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; 174 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>;
153 using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>; 175 using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>;
154 176
155 // Takes the contents of |params| only when it returns true. 177 // Takes the contents of |params| only when it returns true.
156 bool ConnectToRunningApplication( 178 bool ConnectToRunningApplication(
157 scoped_ptr<ConnectToApplicationParams>* params); 179 scoped_ptr<ConnectToApplicationParams>* params);
158 // |resolved_url| is the URL to load by |loader| (if loader is not null). It 180 // |resolved_url| is the URL to load by |loader| (if loader is not null). It
159 // may be different from |(*params)->app_url()| because of mappings and 181 // may be different from |(*params)->app_url()| because of mappings and
160 // resolution rules. 182 // resolution rules.
161 // Takes the contents of |params| only when it returns true. 183 // Takes the contents of |params| only when it returns true.
162 void ConnectToApplicationWithLoader( 184 bool ConnectToApplicationWithLoader(
163 scoped_ptr<ConnectToApplicationParams>* params, 185 scoped_ptr<ConnectToApplicationParams>* params,
164 const GURL& resolved_url, 186 const GURL& resolved_url,
165 ApplicationLoader* loader); 187 ApplicationLoader* loader);
166 188
167 InterfaceRequest<Application> RegisterInstance( 189 InterfaceRequest<Application> RegisterInstance(
168 scoped_ptr<ConnectToApplicationParams> params, 190 scoped_ptr<ConnectToApplicationParams> params,
169 ApplicationInstance** resulting_instance); 191 ApplicationInstance** resulting_instance);
170 192
171 // Called once |fetcher| has found app. |params->app_url()| is the url of 193 // Called once |fetcher| has found app. |params->app_url()| is the url of
172 // the requested application before any mappings/resolution have been applied. 194 // the requested application before any mappings/resolution have been applied.
173 // The corresponding URLRequest struct in |params| has been taken. 195 // The corresponding URLRequest struct in |params| has been taken.
174 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, 196 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params,
197 NativeApplicationCleanup cleanup,
175 scoped_ptr<Fetcher> fetcher); 198 scoped_ptr<Fetcher> fetcher);
176 199
177 void RunNativeApplication(InterfaceRequest<Application> application_request, 200 void RunNativeApplication(InterfaceRequest<Application> application_request,
178 bool start_sandboxed, 201 bool start_sandboxed,
179 const NativeRunnerFactory::Options& options, 202 const NativeRunnerFactory::Options& options,
203 NativeApplicationCleanup cleanup,
180 scoped_ptr<Fetcher> fetcher, 204 scoped_ptr<Fetcher> fetcher,
181 const base::FilePath& file_path, 205 const base::FilePath& file_path,
182 bool path_exists); 206 bool path_exists);
183 207
184 void LoadWithContentHandler( 208 void LoadWithContentHandler(
185 const Identity& originator_identity, 209 const Identity& originator_identity,
186 const CapabilityFilter& originator_filter, 210 const CapabilityFilter& originator_filter,
187 const GURL& content_handler_url, 211 const GURL& content_handler_url,
188 const std::string& qualifier, 212 const std::string& qualifier,
189 const CapabilityFilter& filter, 213 const CapabilityFilter& filter,
190 const Shell::ConnectToApplicationCallback& connect_callback, 214 const Shell::ConnectToApplicationCallback& connect_callback,
191 ApplicationInstance* app, 215 ApplicationInstance* app,
192 InterfaceRequest<Application> application_request, 216 InterfaceRequest<Application> application_request,
193 URLResponsePtr url_response); 217 URLResponsePtr url_response);
194 218
195 // Returns the appropriate loader for |url|, or the default loader if there is 219 // Returns the appropriate loader for |url|, or null if there is no loader
196 // no loader configured for the URL. 220 // configured for the URL.
197 ApplicationLoader* GetLoaderForURL(const GURL& url); 221 ApplicationLoader* GetLoaderForURL(const GURL& url);
198 222
199 void CleanupRunner(NativeRunner* runner); 223 void CleanupRunner(NativeRunner* runner);
200 224
201 ScopedMessagePipeHandle ConnectToServiceByName( 225 ScopedMessagePipeHandle ConnectToServiceByName(
202 const GURL& application_url, 226 const GURL& application_url,
203 const std::string& interface_name); 227 const std::string& interface_name);
204 228
205 scoped_ptr<ApplicationFetcher> const fetcher_; 229 Delegate* const delegate_;
206 // Loader management. 230 // Loader management.
207 // Loaders are chosen in the order they are listed here. 231 // Loaders are chosen in the order they are listed here.
208 URLToLoaderMap url_to_loader_; 232 URLToLoaderMap url_to_loader_;
209 SchemeToLoaderMap scheme_to_loader_; 233 SchemeToLoaderMap scheme_to_loader_;
210 scoped_ptr<ApplicationLoader> default_loader_; 234 scoped_ptr<ApplicationLoader> default_loader_;
211 scoped_ptr<NativeRunnerFactory> native_runner_factory_; 235 scoped_ptr<NativeRunnerFactory> native_runner_factory_;
212 236
213 ApplicationPackagedAlias application_package_alias_; 237 ApplicationPackagedAlias application_package_alias_;
214 IdentityToApplicationInstanceMap identity_to_instance_; 238 IdentityToApplicationInstanceMap identity_to_instance_;
215 URLToContentHandlerMap url_to_content_handler_; 239 URLToContentHandlerMap url_to_content_handler_;
216 // Note: The keys are URLs after mapping and resolving. 240 // Note: The keys are URLs after mapping and resolving.
217 URLToNativeOptionsMap url_to_native_options_; 241 URLToNativeOptionsMap url_to_native_options_;
218 242
219 base::SequencedWorkerPool* blocking_pool_; 243 base::SequencedWorkerPool* blocking_pool_;
244 NetworkServicePtr network_service_;
245 URLLoaderFactoryPtr url_loader_factory_;
220 updater::UpdaterPtr updater_; 246 updater::UpdaterPtr updater_;
221 MimeTypeToURLMap mime_type_to_url_; 247 MimeTypeToURLMap mime_type_to_url_;
222 ScopedVector<NativeRunner> native_runners_; 248 ScopedVector<NativeRunner> native_runners_;
249 bool disable_cache_;
223 // Counter used to assign ids to content_handlers. 250 // Counter used to assign ids to content_handlers.
224 uint32_t content_handler_id_counter_; 251 uint32_t content_handler_id_counter_;
225 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; 252 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
226 253
227 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); 254 DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
228 }; 255 };
229 256
230 Shell::ConnectToApplicationCallback EmptyConnectCallback(); 257 Shell::ConnectToApplicationCallback EmptyConnectCallback();
231 258
232 } // namespace shell 259 } // namespace shell
233 } // namespace mojo 260 } // namespace mojo
234 261
235 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ 262 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_
OLDNEW
« no previous file with comments | « mojo/shell/application_fetcher.h ('k') | mojo/shell/application_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698