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