OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 auto callback = base::Bind( | 174 auto callback = base::Bind( |
175 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), | 175 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), |
176 requestor_url, base::Passed(services.Pass()), | 176 requestor_url, base::Passed(services.Pass()), |
177 base::Passed(exposed_services.Pass()), on_application_end, | 177 base::Passed(exposed_services.Pass()), on_application_end, |
178 parameters); | 178 parameters); |
179 | 179 |
180 if (resolved_url.SchemeIsFile()) { | 180 if (resolved_url.SchemeIsFile()) { |
181 new LocalFetcher( | 181 new LocalFetcher(resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), |
182 resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), | 182 callback); |
183 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); | |
184 return; | 183 return; |
185 } | 184 } |
186 | 185 |
187 if (!network_service_) | 186 if (!network_service_) { |
188 ConnectToService(GURL("mojo:network_service"), &network_service_); | 187 ConnectToService(GURL("mojo:network_service"), &network_service_); |
189 | 188 ConnectToService(GURL("mojo:url_response_disk_cache"), |
190 const NativeApplicationCleanup cleanup = | 189 &url_response_disk_cache_); |
191 base::CommandLine::ForCurrentProcess()->HasSwitch( | 190 } |
192 switches::kDontDeleteOnDownload) | |
193 ? NativeApplicationCleanup::DONT_DELETE | |
194 : NativeApplicationCleanup::DELETE; | |
195 | 191 |
196 new NetworkFetcher(disable_cache_, resolved_url, network_service_.get(), | 192 new NetworkFetcher(disable_cache_, resolved_url, network_service_.get(), |
197 base::Bind(callback, cleanup)); | 193 url_response_disk_cache_.get(), callback); |
198 } | 194 } |
199 | 195 |
200 bool ApplicationManager::ConnectToRunningApplication( | 196 bool ApplicationManager::ConnectToRunningApplication( |
201 const GURL& resolved_url, | 197 const GURL& resolved_url, |
202 const GURL& requestor_url, | 198 const GURL& requestor_url, |
203 InterfaceRequest<ServiceProvider>* services, | 199 InterfaceRequest<ServiceProvider>* services, |
204 ServiceProviderPtr* exposed_services) { | 200 ServiceProviderPtr* exposed_services) { |
205 GURL application_url = GetBaseURLAndQuery(resolved_url, nullptr); | 201 GURL application_url = GetBaseURLAndQuery(resolved_url, nullptr); |
206 ShellImpl* shell_impl = GetShellImpl(application_url); | 202 ShellImpl* shell_impl = GetShellImpl(application_url); |
207 if (!shell_impl) | 203 if (!shell_impl) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 shell_impl->ConnectToClient(resolved_url, requestor_url, services.Pass(), | 263 shell_impl->ConnectToClient(resolved_url, requestor_url, services.Pass(), |
268 exposed_services.Pass()); | 264 exposed_services.Pass()); |
269 } | 265 } |
270 | 266 |
271 void ApplicationManager::HandleFetchCallback( | 267 void ApplicationManager::HandleFetchCallback( |
272 const GURL& requestor_url, | 268 const GURL& requestor_url, |
273 InterfaceRequest<ServiceProvider> services, | 269 InterfaceRequest<ServiceProvider> services, |
274 ServiceProviderPtr exposed_services, | 270 ServiceProviderPtr exposed_services, |
275 const base::Closure& on_application_end, | 271 const base::Closure& on_application_end, |
276 const std::vector<std::string>& parameters, | 272 const std::vector<std::string>& parameters, |
277 NativeApplicationCleanup cleanup, | |
278 scoped_ptr<Fetcher> fetcher) { | 273 scoped_ptr<Fetcher> fetcher) { |
279 if (!fetcher) { | 274 if (!fetcher) { |
280 // Network error. Drop |application_request| to tell requestor. | 275 // Network error. Drop |application_request| to tell requestor. |
281 return; | 276 return; |
282 } | 277 } |
283 | 278 |
284 GURL redirect_url = fetcher->GetRedirectURL(); | 279 GURL redirect_url = fetcher->GetRedirectURL(); |
285 if (!redirect_url.is_empty()) { | 280 if (!redirect_url.is_empty()) { |
286 // And around we go again... Whee! | 281 // And around we go again... Whee! |
287 ConnectToApplicationWithParameters(redirect_url, requestor_url, | 282 ConnectToApplicationWithParameters(redirect_url, requestor_url, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 url_to_native_options_.end()) { | 330 url_to_native_options_.end()) { |
336 DVLOG(2) << "Applying stored native options to resolved URL " | 331 DVLOG(2) << "Applying stored native options to resolved URL " |
337 << fetcher->GetURL(); | 332 << fetcher->GetURL(); |
338 options = url_to_native_options_[base_resolved_url]; | 333 options = url_to_native_options_[base_resolved_url]; |
339 } | 334 } |
340 | 335 |
341 fetcher->AsPath( | 336 fetcher->AsPath( |
342 blocking_pool_, | 337 blocking_pool_, |
343 base::Bind(&ApplicationManager::RunNativeApplication, | 338 base::Bind(&ApplicationManager::RunNativeApplication, |
344 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), | 339 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), |
345 options, cleanup, base::Passed(fetcher.Pass()))); | 340 options, base::Passed(fetcher.Pass()))); |
346 } | 341 } |
347 | 342 |
348 void ApplicationManager::RunNativeApplication( | 343 void ApplicationManager::RunNativeApplication( |
349 InterfaceRequest<Application> application_request, | 344 InterfaceRequest<Application> application_request, |
350 const NativeRunnerFactory::Options& options, | 345 const NativeRunnerFactory::Options& options, |
351 NativeApplicationCleanup cleanup, | |
352 scoped_ptr<Fetcher> fetcher, | 346 scoped_ptr<Fetcher> fetcher, |
353 const base::FilePath& path, | 347 const base::FilePath& path, |
354 bool path_exists) { | 348 bool path_exists) { |
355 // We only passed fetcher to keep it alive. Done with it now. | 349 // We only passed fetcher to keep it alive. Done with it now. |
356 fetcher.reset(); | 350 fetcher.reset(); |
357 | 351 |
358 DCHECK(application_request.is_pending()); | 352 DCHECK(application_request.is_pending()); |
359 | 353 |
360 if (!path_exists) { | 354 if (!path_exists) { |
361 LOG(ERROR) << "Library not started because library path '" << path.value() | 355 LOG(ERROR) << "Library not started because library path '" << path.value() |
362 << "' does not exist."; | 356 << "' does not exist."; |
363 return; | 357 return; |
364 } | 358 } |
365 | 359 |
366 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", | 360 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", |
367 path.AsUTF8Unsafe()); | 361 path.AsUTF8Unsafe()); |
368 NativeRunner* runner = native_runner_factory_->Create(options).release(); | 362 NativeRunner* runner = native_runner_factory_->Create(options).release(); |
369 native_runners_.push_back(runner); | 363 native_runners_.push_back(runner); |
370 runner->Start(path, cleanup, application_request.Pass(), | 364 runner->Start(path, application_request.Pass(), |
371 base::Bind(&ApplicationManager::CleanupRunner, | 365 base::Bind(&ApplicationManager::CleanupRunner, |
372 weak_ptr_factory_.GetWeakPtr(), runner)); | 366 weak_ptr_factory_.GetWeakPtr(), runner)); |
373 } | 367 } |
374 | 368 |
375 void ApplicationManager::RegisterContentHandler( | 369 void ApplicationManager::RegisterContentHandler( |
376 const std::string& mime_type, | 370 const std::string& mime_type, |
377 const GURL& content_handler_url) { | 371 const GURL& content_handler_url) { |
378 DCHECK(content_handler_url.is_valid()) | 372 DCHECK(content_handler_url.is_valid()) |
379 << "Content handler URL is invalid for mime type " << mime_type; | 373 << "Content handler URL is invalid for mime type " << mime_type; |
380 mime_type_to_url_[mime_type] = content_handler_url; | 374 mime_type_to_url_[mime_type] = content_handler_url; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 return args_it->second; | 489 return args_it->second; |
496 return std::vector<std::string>(); | 490 return std::vector<std::string>(); |
497 } | 491 } |
498 | 492 |
499 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 493 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
500 native_runners_.erase( | 494 native_runners_.erase( |
501 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 495 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
502 } | 496 } |
503 | 497 |
504 } // namespace shell | 498 } // namespace shell |
OLD | NEW |