Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/fetcher/base_application_fetcher.h" | |
| 6 | |
| 7 #include "mojo/fetcher/about_fetcher.h" | |
| 8 #include "mojo/fetcher/local_fetcher.h" | |
| 9 #include "mojo/fetcher/network_fetcher.h" | |
| 10 #include "mojo/fetcher/switches.h" | |
| 11 #include "mojo/fetcher/update_fetcher.h" | |
| 12 #include "mojo/shell/application_manager.h" | |
| 13 #include "mojo/shell/query_util.h" | |
| 14 #include "mojo/util/filename_util.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace mojo { | |
| 18 namespace fetcher { | |
| 19 | |
| 20 BaseApplicationFetcher::BaseApplicationFetcher( | |
| 21 const base::FilePath& shell_file_root) | |
| 22 : disable_cache_(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 23 switches::kDisableCache)) { | |
| 24 GURL mojo_root_file_url = | |
| 25 util::FilePathToFileURL(shell_file_root).Resolve(std::string()); | |
| 26 url_resolver_.reset(new URLResolver(mojo_root_file_url)); | |
| 27 } | |
| 28 | |
| 29 BaseApplicationFetcher::~BaseApplicationFetcher() { | |
| 30 } | |
| 31 | |
| 32 void BaseApplicationFetcher::SetApplicationManager( | |
| 33 shell::ApplicationManager* manager) { | |
| 34 application_manager_ = manager; | |
| 35 } | |
| 36 | |
| 37 GURL BaseApplicationFetcher::ResolveURL(const GURL& url) { | |
| 38 return url_resolver_->ResolveMojoURL(url); | |
| 39 } | |
| 40 | |
| 41 void BaseApplicationFetcher::FetchRequest( | |
| 42 URLRequestPtr request, | |
| 43 const shell::Fetcher::FetchCallback& loader_callback) { | |
| 44 GURL url(request->url); | |
| 45 if (url.SchemeIs(AboutFetcher::kAboutScheme)) { | |
| 46 AboutFetcher::Start(url, loader_callback); | |
| 47 return; | |
| 48 } | |
| 49 | |
| 50 GURL resolved_url = ResolveURL(url); | |
| 51 | |
| 52 if (resolved_url.SchemeIsFile()) { | |
| 53 // LocalFetcher uses the network service to infer MIME types from URLs. | |
| 54 // Skip this for mojo URLs to avoid recursively loading the network service. | |
| 55 if (!network_service_ && !url.SchemeIs("mojo")) { | |
| 56 application_manager_->ConnectToService(GURL("mojo:network_service"), | |
| 57 &network_service_); | |
| 58 } | |
| 59 new LocalFetcher( | |
|
sky
2015/09/11 23:05:27
It's worth a comment as to who owns the fetcher, s
| |
| 60 network_service_.get(), resolved_url, | |
| 61 shell::GetBaseURLAndQuery(resolved_url, nullptr), | |
| 62 loader_callback); | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 #if 0 | |
| 67 // TODO(beng): figure out how this should be integrated now that mapped_url | |
| 68 // is toast. | |
| 69 // TODO(scottmg): to quote someone I know, if you liked this you shouldda put | |
| 70 // a test on it. | |
| 71 if (url.SchemeIs("mojo") && | |
| 72 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 73 switches::kUseUpdater)) { | |
| 74 application_manager_->ConnectToService(GURL("mojo:updater"), &updater_); | |
| 75 new UpdateFetcher(url, updater_.get(), loader_callback); | |
| 76 return; | |
| 77 } | |
| 78 #endif | |
| 79 | |
| 80 if (!url_loader_factory_) { | |
| 81 application_manager_->ConnectToService(GURL("mojo:network_service"), | |
| 82 &url_loader_factory_); | |
| 83 } | |
| 84 | |
| 85 new NetworkFetcher(disable_cache_, request.Pass(), url_loader_factory_.get(), | |
| 86 loader_callback); | |
| 87 } | |
| 88 | |
| 89 } // namespace fetcher | |
| 90 } // namespace mojo | |
| OLD | NEW |