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