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

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

Issue 951643002: Register application connections under their post-redirect URL. (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 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 GetLoaderForURL(resolved_url))) { 135 GetLoaderForURL(resolved_url))) {
136 return; 136 return;
137 } 137 }
138 138
139 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, 139 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url,
140 &services, &exposed_services, 140 &services, &exposed_services,
141 default_loader_.get())) { 141 default_loader_.get())) {
142 return; 142 return;
143 } 143 }
144 144
145 InterfaceRequest<Application> application_request =
146 RegisterShell(requested_url, resolved_url, requestor_url, services.Pass(),
147 exposed_services.Pass());
148
149 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback, 145 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback,
150 weak_ptr_factory_.GetWeakPtr(), 146 weak_ptr_factory_.GetWeakPtr(), requested_url,
151 base::Passed(application_request.Pass())); 147 requestor_url, base::Passed(services.Pass()),
148 base::Passed(exposed_services.Pass()));
152 149
153 if (resolved_url.SchemeIsFile()) { 150 if (resolved_url.SchemeIsFile()) {
154 new LocalFetcher(resolved_url, 151 new LocalFetcher(resolved_url,
155 base::Bind(callback, NativeRunner::DontDeleteAppPath)); 152 base::Bind(callback, NativeRunner::DontDeleteAppPath));
156 return; 153 return;
157 } 154 }
158 155
159 if (!network_service_) 156 if (!network_service_)
160 ConnectToService(GURL("mojo:network_service"), &network_service_); 157 ConnectToService(GURL("mojo:network_service"), &network_service_);
161 158
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 ShellImpl* shell_impl, 218 ShellImpl* shell_impl,
222 const GURL& url, 219 const GURL& url,
223 const GURL& requestor_url, 220 const GURL& requestor_url,
224 InterfaceRequest<ServiceProvider> services, 221 InterfaceRequest<ServiceProvider> services,
225 ServiceProviderPtr exposed_services) { 222 ServiceProviderPtr exposed_services) {
226 shell_impl->ConnectToClient(requestor_url, services.Pass(), 223 shell_impl->ConnectToClient(requestor_url, services.Pass(),
227 exposed_services.Pass()); 224 exposed_services.Pass());
228 } 225 }
229 226
230 void ApplicationManager::HandleFetchCallback( 227 void ApplicationManager::HandleFetchCallback(
231 InterfaceRequest<Application> application_request, 228 const GURL& requested_url,
229 const GURL& requestor_url,
230 InterfaceRequest<ServiceProvider> services,
231 ServiceProviderPtr exposed_services,
232 NativeRunner::CleanupBehavior cleanup_behavior, 232 NativeRunner::CleanupBehavior cleanup_behavior,
233 scoped_ptr<Fetcher> fetcher) { 233 scoped_ptr<Fetcher> fetcher) {
234 if (!fetcher) { 234 if (!fetcher) {
235 // Network error. Drop |application_request| to tell requestor. 235 // Network error. Drop |application_request| to tell requestor.
236 return; 236 return;
237 } 237 }
238 238
239 GURL resolved_url = fetcher->GetRedirectURL();
240 if (resolved_url.is_empty())
241 resolved_url = fetcher->GetURL();
242
243 // We already checked if the application was running before we fetched it, but
244 // it might have started while the fetch was outstanding. We don't want to
245 // have two copies of the app running, so check again.
246 //
247 // Also, it's possible the original URL was redirected to an app that is
248 // already running.
249 //
250 // TODO(aa): In the redirect case, we end up doing a request, then dropping
251 // the response on the floor. Also we miss all the intermediate redirects.
252 // Instead, we should follow the redirect chain manually, checking for
253 // existing connections along the way.
254 if (ConnectToRunningApplication(resolved_url, requestor_url, &services,
255 &exposed_services)) {
256 return;
257 }
258
259 InterfaceRequest<Application> application_request(
260 RegisterShell(requested_url, resolved_url, requestor_url, services.Pass(),
261 exposed_services.Pass()));
262
239 // If the response begins with a #!mojo <content-handler-url>, use it. 263 // If the response begins with a #!mojo <content-handler-url>, use it.
240 GURL url; 264 GURL content_handler_url;
241 std::string shebang; 265 std::string shebang;
242 if (fetcher->PeekContentHandler(&shebang, &url)) { 266 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) {
243 LoadWithContentHandler( 267 LoadWithContentHandler(
244 url, application_request.Pass(), 268 content_handler_url, application_request.Pass(),
245 fetcher->AsURLResponse(blocking_pool_, 269 fetcher->AsURLResponse(blocking_pool_,
246 static_cast<int>(shebang.size()))); 270 static_cast<int>(shebang.size())));
247 return; 271 return;
248 } 272 }
249 273
250 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); 274 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType());
251 if (iter != mime_type_to_url_.end()) { 275 if (iter != mime_type_to_url_.end()) {
252 LoadWithContentHandler(iter->second, application_request.Pass(), 276 LoadWithContentHandler(iter->second, application_request.Pass(),
253 fetcher->AsURLResponse(blocking_pool_, 0)); 277 fetcher->AsURLResponse(blocking_pool_, 0));
254 return; 278 return;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return Array<String>::From(args_it->second); 420 return Array<String>::From(args_it->second);
397 return Array<String>(); 421 return Array<String>();
398 } 422 }
399 423
400 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 424 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
401 native_runners_.erase( 425 native_runners_.erase(
402 std::find(native_runners_.begin(), native_runners_.end(), runner)); 426 std::find(native_runners_.begin(), native_runners_.end(), runner));
403 } 427 }
404 428
405 } // namespace mojo 429 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698