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

Side by Side Diff: shell/application_manager/application_manager.cc

Issue 930243006: Simplify the ApplicationLoader interface in preparation for changes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: trybot debugging ftw 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 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 #include "shell/application_manager/application_manager.h" 5 #include "shell/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 void ApplicationManager::TerminateShellConnections() { 97 void ApplicationManager::TerminateShellConnections() {
98 STLDeleteValues(&url_to_shell_impl_); 98 STLDeleteValues(&url_to_shell_impl_);
99 } 99 }
100 100
101 void ApplicationManager::ConnectToApplication( 101 void ApplicationManager::ConnectToApplication(
102 const GURL& requested_url, 102 const GURL& requested_url,
103 const GURL& requestor_url, 103 const GURL& requestor_url,
104 InterfaceRequest<ServiceProvider> services, 104 InterfaceRequest<ServiceProvider> services,
105 ServiceProviderPtr exposed_services) { 105 ServiceProviderPtr exposed_services) {
106 DCHECK(requested_url.is_valid()); 106 DCHECK(requested_url.is_valid());
107 GURL mapped_url = delegate_->ResolveMappings(requested_url);
108 107
109 // We check both the mapped and resolved urls for existing shell_impls because 108 // We check both the mapped and resolved urls for existing shell_impls because
110 // external applications can be registered for the unresolved mojo:foo urls. 109 // external applications can be registered for the unresolved mojo:foo urls.
111 ShellImpl* shell_impl = GetShellImpl(mapped_url); 110
112 if (shell_impl) { 111 GURL mapped_url = delegate_->ResolveMappings(requested_url);
113 ConnectToClient(shell_impl, mapped_url, requestor_url, services.Pass(), 112 if (ConnectToRunningApplication(mapped_url, requestor_url, &services,
114 exposed_services.Pass()); 113 &exposed_services)) {
115 return; 114 return;
116 } 115 }
117 116
118 GURL resolved_url = delegate_->ResolveURL(mapped_url); 117 GURL resolved_url = delegate_->ResolveURL(mapped_url);
119 shell_impl = GetShellImpl(resolved_url); 118 if (ConnectToRunningApplication(resolved_url, requestor_url, &services,
120 if (shell_impl) { 119 &exposed_services)) {
121 ConnectToClient(shell_impl, resolved_url, requestor_url, services.Pass(),
122 exposed_services.Pass());
123 return; 120 return;
124 } 121 }
125 122
126 ApplicationLoader* loader = 123 if (ConnectToApplicationWithLoader(requested_url, mapped_url, requestor_url,
127 GetLoaderForURL(mapped_url, DONT_INCLUDE_DEFAULT_LOADER); 124 &services, &exposed_services,
128 if (loader) { 125 GetLoaderForURL(mapped_url))) {
129 ConnectToApplicationImpl(requested_url, mapped_url, requestor_url,
130 services.Pass(), exposed_services.Pass(), loader);
131 return; 126 return;
132 } 127 }
133 128
134 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER); 129 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url,
135 if (loader) { 130 &services, &exposed_services,
136 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, 131 GetLoaderForURL(resolved_url))) {
137 services.Pass(), exposed_services.Pass(), loader);
138 return; 132 return;
139 } 133 }
140 134
135 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url,
136 &services, &exposed_services,
137 default_loader_.get())) {
138 return;
139 }
140
141 // TODO(aa): This case should go away, see comments in
142 // DynamicApplicationLoader.
143 if (dynamic_application_loader_.get()) {
144 dynamic_application_loader_->Load(
145 resolved_url,
146 RegisterShell(requested_url, resolved_url, requestor_url,
147 services.Pass(), exposed_services.Pass()).Pass(),
qsr 2015/02/19 09:25:01 Is the last .Pass() necessary?
Aaron Boodman 2015/02/19 20:38:46 Done.
148 base::Bind(&ApplicationManager::LoadWithContentHandler,
149 weak_ptr_factory_.GetWeakPtr()));
150 return;
151 }
152
141 LOG(WARNING) << "Could not find loader to load application: " 153 LOG(WARNING) << "Could not find loader to load application: "
142 << requested_url.spec(); 154 << requested_url.spec();
143 } 155 }
144 156
145 void ApplicationManager::ConnectToApplicationImpl( 157 bool ApplicationManager::ConnectToRunningApplication(
158 const GURL& application_url,
159 const GURL& requestor_url,
160 InterfaceRequest<ServiceProvider>* services,
161 ServiceProviderPtr* exposed_services) {
162 ShellImpl* shell_impl = GetShellImpl(application_url);
163 if (!shell_impl)
164 return false;
165
166 ConnectToClient(shell_impl, application_url, requestor_url, services->Pass(),
167 exposed_services->Pass());
168 return true;
169 }
170
171 bool ApplicationManager::ConnectToApplicationWithLoader(
172 const GURL& requested_url,
173 const GURL& resolved_url,
174 const GURL& requestor_url,
175 InterfaceRequest<ServiceProvider>* services,
176 ServiceProviderPtr* exposed_services,
177 ApplicationLoader* loader) {
178 if (!loader)
179 return false;
180
181 loader->Load(resolved_url,
182 RegisterShell(requested_url, resolved_url, requestor_url,
183 services->Pass(), exposed_services->Pass()));
184 return true;
185 }
186
187 InterfaceRequest<Application> ApplicationManager::RegisterShell(
146 const GURL& requested_url, 188 const GURL& requested_url,
147 const GURL& resolved_url, 189 const GURL& resolved_url,
148 const GURL& requestor_url, 190 const GURL& requestor_url,
149 InterfaceRequest<ServiceProvider> services, 191 InterfaceRequest<ServiceProvider> services,
150 ServiceProviderPtr exposed_services, 192 ServiceProviderPtr exposed_services) {
151 ApplicationLoader* loader) {
152 ApplicationPtr application; 193 ApplicationPtr application;
153 InterfaceRequest<Application> application_request = GetProxy(&application); 194 InterfaceRequest<Application> application_request = GetProxy(&application);
154 ShellImpl* shell = 195 ShellImpl* shell =
155 new ShellImpl(application.Pass(), this, requested_url, resolved_url); 196 new ShellImpl(application.Pass(), this, requested_url, resolved_url);
156 url_to_shell_impl_[resolved_url] = shell; 197 url_to_shell_impl_[resolved_url] = shell;
157 shell->InitializeApplication(GetArgsForURL(requested_url)); 198 shell->InitializeApplication(GetArgsForURL(requested_url));
158
159 loader->Load(this, resolved_url, application_request.Pass(),
160 base::Bind(&ApplicationManager::LoadWithContentHandler,
161 weak_ptr_factory_.GetWeakPtr()));
162 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), 199 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(),
163 exposed_services.Pass()); 200 exposed_services.Pass());
201 return application_request.Pass();
164 } 202 }
165 203
166 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { 204 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) {
167 const auto& shell_it = url_to_shell_impl_.find(url); 205 const auto& shell_it = url_to_shell_impl_.find(url);
168 if (shell_it != url_to_shell_impl_.end()) 206 if (shell_it != url_to_shell_impl_.end())
169 return shell_it->second; 207 return shell_it->second;
170 return nullptr; 208 return nullptr;
171 } 209 }
172 210
173 void ApplicationManager::ConnectToClient( 211 void ApplicationManager::ConnectToClient(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (it != scheme_to_loader_.end()) 265 if (it != scheme_to_loader_.end())
228 delete it->second; 266 delete it->second;
229 scheme_to_loader_[scheme] = loader.release(); 267 scheme_to_loader_[scheme] = loader.release();
230 } 268 }
231 269
232 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, 270 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args,
233 const GURL& url) { 271 const GURL& url) {
234 url_to_args_[url] = args; 272 url_to_args_[url] = args;
235 } 273 }
236 274
237 ApplicationLoader* ApplicationManager::GetLoaderForURL( 275 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
238 const GURL& url,
239 IncludeDefaultLoader include_default_loader) {
240 auto url_it = url_to_loader_.find(url); 276 auto url_it = url_to_loader_.find(url);
241 if (url_it != url_to_loader_.end()) 277 if (url_it != url_to_loader_.end())
242 return url_it->second; 278 return url_it->second;
243 auto scheme_it = scheme_to_loader_.find(url.scheme()); 279 auto scheme_it = scheme_to_loader_.find(url.scheme());
244 if (scheme_it != scheme_to_loader_.end()) 280 if (scheme_it != scheme_to_loader_.end())
245 return scheme_it->second; 281 return scheme_it->second;
246 if (include_default_loader == INCLUDE_DEFAULT_LOADER)
247 return default_loader_.get();
248 return NULL; 282 return NULL;
249 } 283 }
250 284
251 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { 285 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) {
252 // Called from ~ShellImpl, so we do not need to call Destroy here. 286 // Called from ~ShellImpl, so we do not need to call Destroy here.
253 const GURL url = shell_impl->url(); 287 const GURL url = shell_impl->url();
254 const GURL requested_url = shell_impl->requested_url(); 288 const GURL requested_url = shell_impl->requested_url();
255 // Remove the shell. 289 // Remove the shell.
256 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); 290 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url);
257 DCHECK(it != url_to_shell_impl_.end()); 291 DCHECK(it != url_to_shell_impl_.end());
258 delete it->second; 292 delete it->second;
259 url_to_shell_impl_.erase(it); 293 url_to_shell_impl_.erase(it);
260 ApplicationLoader* loader =
261 GetLoaderForURL(requested_url, INCLUDE_DEFAULT_LOADER);
262 if (loader)
263 loader->OnApplicationError(this, url);
264 delegate_->OnApplicationError(requested_url); 294 delegate_->OnApplicationError(requested_url);
265 } 295 }
266 296
267 void ApplicationManager::OnContentHandlerError( 297 void ApplicationManager::OnContentHandlerError(
268 ContentHandlerConnection* content_handler) { 298 ContentHandlerConnection* content_handler) {
269 // Remove the mapping to the content handler. 299 // Remove the mapping to the content handler.
270 auto it = 300 auto it =
271 url_to_content_handler_.find(content_handler->content_handler_url()); 301 url_to_content_handler_.find(content_handler->content_handler_url());
272 DCHECK(it != url_to_content_handler_.end()); 302 DCHECK(it != url_to_content_handler_.end());
273 delete it->second; 303 delete it->second;
(...skipping 10 matching lines...) Expand all
284 return pipe.handle0.Pass(); 314 return pipe.handle0.Pass();
285 } 315 }
286 316
287 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { 317 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) {
288 const auto& args_it = url_to_args_.find(url); 318 const auto& args_it = url_to_args_.find(url);
289 if (args_it != url_to_args_.end()) 319 if (args_it != url_to_args_.end())
290 return Array<String>::From(args_it->second); 320 return Array<String>::From(args_it->second);
291 return Array<String>(); 321 return Array<String>();
292 } 322 }
293 } // namespace mojo 323 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698