summaryrefslogtreecommitdiffstats
path: root/mojo/shell
diff options
context:
space:
mode:
authorben <ben@chromium.org>2016-02-17 18:10:23 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-18 02:11:20 +0000
commit41f2fe9d2925a4cb17582dfa974217f5765e83d5 (patch)
tree7a62c50d0f30034e940e8f4e031c6164f5a704eb /mojo/shell
parentdf7c0802a46e34a48c5497a9133dddd25b94a14f (diff)
downloadchromium_src-41f2fe9d2925a4cb17582dfa974217f5765e83d5.zip
chromium_src-41f2fe9d2925a4cb17582dfa974217f5765e83d5.tar.gz
chromium_src-41f2fe9d2925a4cb17582dfa974217f5765e83d5.tar.bz2
Remove the old package manager
BUG= Review URL: https://codereview.chromium.org/1701933004 Cr-Commit-Position: refs/heads/master@{#376064}
Diffstat (limited to 'mojo/shell')
-rw-r--r--mojo/shell/BUILD.gn19
-rw-r--r--mojo/shell/application_manager.cc206
-rw-r--r--mojo/shell/application_manager.h47
-rw-r--r--mojo/shell/application_manager_unittest.cc27
-rw-r--r--mojo/shell/background/background_shell.cc2
-rw-r--r--mojo/shell/capability_filter_test.cc4
-rw-r--r--mojo/shell/capability_filter_test.h4
-rw-r--r--mojo/shell/capability_filter_unittest.cc6
-rw-r--r--mojo/shell/connect_util.cc2
-rw-r--r--mojo/shell/content_handler_connection.cc (renamed from mojo/shell/package_manager/content_handler_connection.cc)2
-rw-r--r--mojo/shell/content_handler_connection.h (renamed from mojo/shell/package_manager/content_handler_connection.h)6
-rw-r--r--mojo/shell/data_pipe_peek.cc163
-rw-r--r--mojo/shell/data_pipe_peek.h40
-rw-r--r--mojo/shell/data_pipe_peek_unittest.cc133
-rw-r--r--mojo/shell/fetcher.cc40
-rw-r--r--mojo/shell/fetcher.h82
-rw-r--r--mojo/shell/fetcher/BUILD.gn43
-rw-r--r--mojo/shell/fetcher/DEPS17
-rw-r--r--mojo/shell/fetcher/about_fetcher.cc116
-rw-r--r--mojo/shell/fetcher/about_fetcher.h60
-rw-r--r--mojo/shell/fetcher/about_fetcher_unittest.cc196
-rw-r--r--mojo/shell/fetcher/data_fetcher.cc119
-rw-r--r--mojo/shell/fetcher/data_fetcher.h52
-rw-r--r--mojo/shell/fetcher/data_fetcher_unittest.cc119
-rw-r--r--mojo/shell/fetcher/local_fetcher.cc153
-rw-r--r--mojo/shell/fetcher/local_fetcher.h65
-rw-r--r--mojo/shell/fetcher/network_fetcher.cc253
-rw-r--r--mojo/shell/fetcher/network_fetcher.h88
-rw-r--r--mojo/shell/fetcher/network_fetcher_unittest.cc181
-rw-r--r--mojo/shell/fetcher/switches.cc15
-rw-r--r--mojo/shell/fetcher/switches.h18
-rw-r--r--mojo/shell/fetcher/url_resolver.cc64
-rw-r--r--mojo/shell/fetcher/url_resolver.h42
-rw-r--r--mojo/shell/fetcher/url_resolver_unittest.cc51
-rw-r--r--mojo/shell/identity.cc8
-rw-r--r--mojo/shell/package_manager.h78
-rw-r--r--mojo/shell/package_manager/BUILD.gn42
-rw-r--r--mojo/shell/package_manager/DEPS3
-rw-r--r--mojo/shell/package_manager/capability_filter_content_handler_unittest.cc160
-rw-r--r--mojo/shell/package_manager/content_handler_unittest.cc328
-rw-r--r--mojo/shell/package_manager/package_manager_impl.cc417
-rw-r--r--mojo/shell/package_manager/package_manager_impl.h166
-rw-r--r--mojo/shell/query_util.cc31
-rw-r--r--mojo/shell/query_util.h23
-rw-r--r--mojo/shell/query_util_unittest.cc47
-rw-r--r--mojo/shell/standalone/BUILD.gn17
-rw-r--r--mojo/shell/standalone/context.cc68
-rw-r--r--mojo/shell/standalone/context.h5
-rw-r--r--mojo/shell/standalone/register_local_aliases.cc13
-rw-r--r--mojo/shell/standalone/register_local_aliases.h17
-rw-r--r--mojo/shell/switches.cc3
-rw-r--r--mojo/shell/switches.h1
-rw-r--r--mojo/shell/test_package_manager.cc49
-rw-r--r--mojo/shell/test_package_manager.h51
54 files changed, 106 insertions, 3856 deletions
diff --git a/mojo/shell/BUILD.gn b/mojo/shell/BUILD.gn
index f221d8c..eaa6554 100644
--- a/mojo/shell/BUILD.gn
+++ b/mojo/shell/BUILD.gn
@@ -29,16 +29,11 @@ source_set("shell") {
"connect_to_application_params.h",
"connect_util.cc",
"connect_util.h",
- "data_pipe_peek.cc",
- "data_pipe_peek.h",
- "fetcher.cc",
- "fetcher.h",
+ "content_handler_connection.cc",
+ "content_handler_connection.h",
"identity.cc",
"identity.h",
"native_runner.h",
- "package_manager.h",
- "query_util.cc",
- "query_util.h",
"shell_application_delegate.cc",
"shell_application_delegate.h",
"shell_application_loader.cc",
@@ -79,8 +74,6 @@ source_set("test_support") {
sources = [
"capability_filter_test.cc",
"capability_filter_test.h",
- "test_package_manager.cc",
- "test_package_manager.h",
]
deps = [
@@ -98,12 +91,6 @@ test("mojo_shell_unittests") {
sources = [
"application_manager_unittest.cc",
"capability_filter_unittest.cc",
- "data_pipe_peek_unittest.cc",
- "fetcher/about_fetcher_unittest.cc",
- "fetcher/data_fetcher_unittest.cc",
- "fetcher/network_fetcher_unittest.cc",
- "fetcher/url_resolver_unittest.cc",
- "query_util_unittest.cc",
]
deps = [
@@ -114,8 +101,6 @@ test("mojo_shell_unittests") {
"//mojo/edk/system:test_utils",
"//mojo/edk/test:run_all_unittests",
"//mojo/public/cpp/system",
- "//mojo/shell/fetcher",
- "//mojo/shell/package_manager",
"//mojo/shell/public/cpp",
"//mojo/util:filename_util",
"//testing/gtest",
diff --git a/mojo/shell/application_manager.cc b/mojo/shell/application_manager.cc
index 7116c7b..91c8e5d2 100644
--- a/mojo/shell/application_manager.cc
+++ b/mojo/shell/application_manager.cc
@@ -20,10 +20,9 @@
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/services/package_manager/loader.h"
#include "mojo/shell/application_instance.h"
-#include "mojo/shell/fetcher.h"
-#include "mojo/shell/package_manager.h"
+#include "mojo/shell/connect_util.h"
+#include "mojo/shell/content_handler_connection.h"
#include "mojo/shell/public/cpp/connect.h"
-#include "mojo/shell/query_util.h"
#include "mojo/shell/shell_application_loader.h"
#include "mojo/shell/switches.h"
#include "mojo/util/filename_util.h"
@@ -60,28 +59,24 @@ bool ApplicationManager::TestAPI::HasRunningInstanceForURL(
}
ApplicationManager::ApplicationManager(
- scoped_ptr<PackageManager> package_manager,
bool register_mojo_url_schemes)
- : ApplicationManager(std::move(package_manager), nullptr, nullptr,
- register_mojo_url_schemes) {}
+ : ApplicationManager(nullptr, nullptr, register_mojo_url_schemes) {}
ApplicationManager::ApplicationManager(
- scoped_ptr<PackageManager> package_manager,
scoped_ptr<NativeRunnerFactory> native_runner_factory,
base::TaskRunner* task_runner,
bool register_mojo_url_schemes)
- : use_remote_package_manager_(false),
- package_manager_(std::move(package_manager)),
- task_runner_(task_runner),
+ : task_runner_(task_runner),
native_runner_factory_(std::move(native_runner_factory)),
weak_ptr_factory_(this) {
- package_manager_->SetApplicationManager(this);
SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)),
- GURL("mojo:shell"));
- if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDontUseRemotePackageManager)) {
- UseRemotePackageManager(register_mojo_url_schemes);
- }
+ GURL("mojo://shell/"));
+
+ GURL package_manager_url("mojo://package_manager/");
+ SetLoaderForURL(make_scoped_ptr(new package_manager::Loader(
+ task_runner_, register_mojo_url_schemes)), package_manager_url);
+
+ ConnectToInterface(this, package_manager_url, &shell_resolver_);
}
ApplicationManager::~ApplicationManager() {
@@ -110,10 +105,9 @@ void ApplicationManager::ConnectToApplication(
ApplicationLoader* loader = GetLoaderForURL(params->target().url());
if (loader) {
GURL url = params->target().url();
- package_manager_->BuiltinAppLoaded(url);
mojom::ShellClientRequest request;
- std::string application_name =
- package_manager_->GetApplicationName(params->target().url().spec());
+ // TODO(beng): move this to OnGotResolvedURL & read from manifest.
+ std::string application_name = url.spec();
ApplicationInstance* instance = CreateAndConnectToInstance(
std::move(params), nullptr, nullptr, application_name, &request);
loader->Load(url, std::move(request));
@@ -121,52 +115,11 @@ void ApplicationManager::ConnectToApplication(
return;
}
- if (use_remote_package_manager_) {
- std::string url = params->target().url().spec();
- shell_resolver_->ResolveMojoURL(
- url,
- base::Bind(&ApplicationManager::OnGotResolvedURL,
- weak_ptr_factory_.GetWeakPtr(), base::Passed(&params)));
- } else {
- URLRequestPtr original_url_request = params->TakeTargetURLRequest();
- auto callback =
- base::Bind(&ApplicationManager::HandleFetchCallback,
- weak_ptr_factory_.GetWeakPtr(), base::Passed(&params));
- package_manager_->FetchRequest(std::move(original_url_request), callback);
- }
-}
-
-void ApplicationManager::UseRemotePackageManager(
- bool register_mojo_url_schemes) {
- use_remote_package_manager_ = true;
-
- GURL package_manager_url("mojo://package_manager/");
-
- SetLoaderForURL(make_scoped_ptr(new package_manager::Loader(
- task_runner_, register_mojo_url_schemes)), package_manager_url);
-
- shell::mojom::InterfaceProviderPtr interfaces;
- scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
- params->set_source(Identity(GURL("mojo:shell"), std::string(),
- GetPermissiveCapabilityFilter()));
- params->set_remote_interfaces(GetProxy(&interfaces));
-
- if (false) {
- GURL file_url =
- package_manager_->ResolveMojoURL(package_manager_url);
- params->SetTarget(Identity(file_url, std::string(),
- GetPermissiveCapabilityFilter()));
- // TODO(beng): Fish the name out of a manifest. There's a chicken-and-egg
- // issue here as the package manager reads the manifests. The solution is
- //probably to defer application name loading.
- CreateAndRunLocalApplication(std::move(params), "Package Manager",
- file_url);
- } else {
- params->SetTarget(Identity(package_manager_url, std::string(),
- GetPermissiveCapabilityFilter()));
- ConnectToApplication(std::move(params));
- }
- GetInterface(interfaces.get(), &shell_resolver_);
+ std::string url = params->target().url().spec();
+ shell_resolver_->ResolveMojoURL(
+ url,
+ base::Bind(&ApplicationManager::OnGotResolvedURL,
+ weak_ptr_factory_.GetWeakPtr(), base::Passed(&params)));
}
bool ApplicationManager::ConnectToRunningApplication(
@@ -199,9 +152,10 @@ void ApplicationManager::CreateInstanceForHandle(
CapabilityFilter local_filter = filter->filter.To<CapabilityFilter>();
Identity target_id(url, std::string(), local_filter);
mojom::ShellClientRequest request;
+ // TODO(beng): do better than url.spec() for application name.
ApplicationInstance* instance = CreateInstance(
target_id, EmptyConnectCallback(), base::Closure(),
- package_manager_->GetApplicationName(url.spec()), &request);
+ url.spec(), &request);
instance->BindPIDReceiver(std::move(pid_receiver));
scoped_ptr<NativeRunner> runner =
native_runner_factory_->Create(base::FilePath());
@@ -280,6 +234,44 @@ ApplicationInstance* ApplicationManager::CreateInstance(
return instance;
}
+uint32_t ApplicationManager::StartContentHandler(
+ const Identity& source,
+ const Identity& content_handler,
+ const GURL& url,
+ mojom::ShellClientRequest request) {
+ URLResponsePtr response(URLResponse::New());
+ response->url = url.spec();
+ ContentHandlerConnection* connection =
+ GetContentHandler(content_handler, source);
+ connection->StartApplication(std::move(request), std::move(response));
+ return connection->id();
+}
+
+ContentHandlerConnection* ApplicationManager::GetContentHandler(
+ const Identity& content_handler_identity,
+ const Identity& source_identity) {
+ auto it = identity_to_content_handler_.find(content_handler_identity);
+ if (it != identity_to_content_handler_.end())
+ return it->second;
+
+ ContentHandlerConnection* connection = new ContentHandlerConnection(
+ this, source_identity,
+ content_handler_identity,
+ ++content_handler_id_counter_,
+ base::Bind(&ApplicationManager::OnContentHandlerConnectionClosed,
+ weak_ptr_factory_.GetWeakPtr()));
+ identity_to_content_handler_[content_handler_identity] = connection;
+ return connection;
+}
+
+void ApplicationManager::OnContentHandlerConnectionClosed(
+ ContentHandlerConnection* connection) {
+ // Remove the mapping.
+ auto it = identity_to_content_handler_.find(connection->identity());
+ DCHECK(it != identity_to_content_handler_.end());
+ identity_to_content_handler_.erase(it);
+}
+
void ApplicationManager::OnGotResolvedURL(
scoped_ptr<ConnectToApplicationParams> params,
const String& resolved_url,
@@ -307,7 +299,7 @@ void ApplicationManager::OnGotResolvedURL(
ApplicationInstance* instance = CreateAndConnectToInstance(
std::move(params), &source, &target, application_name, &request);
- uint32_t content_handler_id = package_manager_->StartContentHandler(
+ uint32_t content_handler_id = StartContentHandler(
source, Identity(resolved_gurl, target.qualifier(), capability_filter),
target.url(), std::move(request));
CHECK(content_handler_id != mojom::Shell::kInvalidApplicationID);
@@ -328,86 +320,19 @@ void ApplicationManager::CreateAndRunLocalApplication(
ApplicationInstance* instance = CreateAndConnectToInstance(
std::move(params), &source, &target, application_name, &request);
- scoped_ptr<Fetcher> fetcher;
bool start_sandboxed = false;
- RunNativeApplication(std::move(request), start_sandboxed, std::move(fetcher),
- instance, util::UrlToFilePath(file_url), true);
- instance->RunConnectCallback();
-}
-
-void ApplicationManager::HandleFetchCallback(
- scoped_ptr<ConnectToApplicationParams> params,
- scoped_ptr<Fetcher> fetcher) {
- if (!fetcher) {
- // Network error. Drop |params| to tell the requestor.
- params->connect_callback().Run(mojom::Shell::kInvalidApplicationID,
- mojom::Shell::kInvalidApplicationID);
- return;
- }
-
- GURL redirect_url = fetcher->GetRedirectURL();
- if (!redirect_url.is_empty()) {
- // And around we go again... Whee!
- // TODO(sky): this loses the original URL info.
- URLRequestPtr new_request = URLRequest::New();
- new_request->url = redirect_url.spec();
- HttpHeaderPtr header = HttpHeader::New();
- header->name = "Referer";
- header->value = fetcher->GetRedirectReferer().spec();
- new_request->headers.push_back(std::move(header));
- params->SetTargetURLRequest(std::move(new_request));
- ConnectToApplication(std::move(params));
- return;
- }
-
- // We already checked if the application was running before we fetched it, but
- // it might have started while the fetch was outstanding. We don't want to
- // have two copies of the app running, so check again.
- if (ConnectToRunningApplication(&params))
- return;
-
- Identity source, target;
- mojom::ShellClientRequest request;
- std::string application_name =
- package_manager_->GetApplicationName(params->target().url().spec());
- ApplicationInstance* instance = CreateAndConnectToInstance(
- std::move(params), &source, &target, application_name, &request);
-
- uint32_t content_handler_id = package_manager_->HandleWithContentHandler(
- fetcher.get(), source, target.url(), target.filter(), &request);
- if (content_handler_id != mojom::Shell::kInvalidApplicationID) {
- instance->set_requesting_content_handler_id(content_handler_id);
- } else {
- bool start_sandboxed = false;
- fetcher->AsPath(
- task_runner_,
- base::Bind(&ApplicationManager::RunNativeApplication,
- weak_ptr_factory_.GetWeakPtr(),
- base::Passed(std::move(request)), start_sandboxed,
- base::Passed(std::move(fetcher)),
- base::Unretained(instance)));
- }
+ RunNativeApplication(std::move(request), start_sandboxed, instance,
+ util::UrlToFilePath(file_url));
instance->RunConnectCallback();
}
void ApplicationManager::RunNativeApplication(
InterfaceRequest<mojom::ShellClient> request,
bool start_sandboxed,
- scoped_ptr<Fetcher> fetcher,
ApplicationInstance* instance,
- const base::FilePath& path,
- bool path_exists) {
- // We only passed fetcher to keep it alive. Done with it now.
- fetcher.reset();
-
+ const base::FilePath& path) {
DCHECK(request.is_pending());
- if (!path_exists) {
- LOG(ERROR) << "Library not started because library path '" << path.value()
- << "' does not exist.";
- return;
- }
-
TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path",
path.AsUTF8Unsafe());
scoped_ptr<NativeRunner> runner = native_runner_factory_->Create(path);
@@ -429,7 +354,7 @@ void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
}
ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
- auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr));
+ auto url_it = url_to_loader_.find(url);
if (url_it != url_to_loader_.end())
return url_it->second;
return default_loader_.get();
@@ -441,10 +366,7 @@ mojom::ApplicationInfoPtr ApplicationManager::CreateApplicationInfoForInstance(
info->id = instance->id();
info->url = instance->identity().url().spec();
info->qualifier = instance->identity().qualifier();
- if (use_remote_package_manager_)
- info->name = instance->application_name();
- else
- info->name = package_manager_->GetApplicationName(info->url);
+ info->name = instance->application_name();
if (instance->identity().url().spec() == "mojo://shell/")
info->pid = base::Process::Current().Pid();
else
diff --git a/mojo/shell/application_manager.h b/mojo/shell/application_manager.h
index ecfc5e3..7487cc6 100644
--- a/mojo/shell/application_manager.h
+++ b/mojo/shell/application_manager.h
@@ -6,20 +6,16 @@
#define MOJO_SHELL_APPLICATION_MANAGER_H_
#include <map>
-#include <utility>
#include <vector>
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "mojo/public/cpp/bindings/interface_ptr_info.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/weak_interface_ptr_set.h"
#include "mojo/services/package_manager/public/interfaces/shell_resolver.mojom.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/capability_filter.h"
#include "mojo/shell/connect_to_application_params.h"
-#include "mojo/shell/fetcher.h"
#include "mojo/shell/identity.h"
#include "mojo/shell/native_runner.h"
#include "mojo/shell/public/interfaces/application_manager.mojom.h"
@@ -36,7 +32,6 @@ class SequencedWorkerPool;
namespace mojo {
namespace shell {
-class PackageManager;
class ApplicationInstance;
class ContentHandlerConnection;
@@ -59,10 +54,7 @@ class ApplicationManager {
};
// Creates an ApplicationManager.
- // |package_manager| is an instance of an object that handles URL resolution,
- // fetching and updating of applications. See package_manager.h.
- ApplicationManager(scoped_ptr<PackageManager> package_manager,
- bool register_mojo_url_schemes);
+ explicit ApplicationManager(bool register_mojo_url_schemes);
// |native_runner_factory| is an instance of an object capable of vending
// implementations of NativeRunner, e.g. for in or out-of-process execution.
// See native_runner.h and RunNativeApplication().
@@ -71,8 +63,7 @@ class ApplicationManager {
// loaded via ApplicationLoader implementations.
// When |register_mojo_url_schemes| is true, mojo: and exe: URL schems are
// registered as "standard" which faciliates resolving.
- ApplicationManager(scoped_ptr<PackageManager> package_manager,
- scoped_ptr<NativeRunnerFactory> native_runner_factory,
+ ApplicationManager(scoped_ptr<NativeRunnerFactory> native_runner_factory,
base::TaskRunner* task_runner,
bool register_mojo_url_schemes);
~ApplicationManager();
@@ -112,8 +103,8 @@ class ApplicationManager {
private:
using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>;
using URLToLoaderMap = std::map<GURL, ApplicationLoader*>;
-
- void UseRemotePackageManager(bool register_mojo_url_schemes);
+ using IdentityToContentHandlerMap =
+ std::map<Identity, ContentHandlerConnection*>;
// Takes the contents of |params| only when it returns true.
bool ConnectToRunningApplication(
@@ -132,6 +123,18 @@ class ApplicationManager {
const String& application_name,
mojom::ShellClientRequest* request);
+ uint32_t StartContentHandler(const Identity& source,
+ const Identity& content_handler,
+ const GURL& url,
+ mojom::ShellClientRequest request);
+ // Returns a running ContentHandler for |content_handler_identity|, if there
+ // is not one running one is started for |source_identity|.
+ ContentHandlerConnection* GetContentHandler(
+ const Identity& content_handler_identity,
+ const Identity& source_identity);
+ void OnContentHandlerConnectionClosed(
+ ContentHandlerConnection* content_handler);
+
// Callback when remote PackageManager resolves mojo:foo to mojo:bar.
// |params| are the params passed to Connect().
// |resolved_url| is the mojo: url identifying the physical package
@@ -154,20 +157,10 @@ class ApplicationManager {
const String& application_name,
const GURL& file_url);
- void AddListenerManifestsReady(mojom::ApplicationManagerListenerPtr listener);
-
- // Called once |fetcher| has found app. |params->app_url()| is the url of
- // the requested application before any mappings/resolution have been applied.
- // The corresponding URLRequest struct in |params| has been taken.
- void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params,
- scoped_ptr<Fetcher> fetcher);
-
void RunNativeApplication(InterfaceRequest<mojom::ShellClient> request,
bool start_sandboxed,
- scoped_ptr<Fetcher> fetcher,
ApplicationInstance* instance,
- const base::FilePath& file_path,
- bool path_exists);
+ const base::FilePath& file_path);
// Returns the appropriate loader for |url|, or the default loader if there is
// no loader configured for the URL.
@@ -178,10 +171,8 @@ class ApplicationManager {
mojom::ApplicationInfoPtr CreateApplicationInfoForInstance(
ApplicationInstance* instance) const;
- bool use_remote_package_manager_;
package_manager::mojom::ShellResolverPtr shell_resolver_;
- scoped_ptr<PackageManager> const package_manager_;
// Loader management.
// Loaders are chosen in the order they are listed here.
URLToLoaderMap url_to_loader_;
@@ -189,6 +180,10 @@ class ApplicationManager {
IdentityToInstanceMap identity_to_instance_;
+ IdentityToContentHandlerMap identity_to_content_handler_;
+ // Counter used to assign ids to content handlers.
+ uint32_t content_handler_id_counter_;
+
WeakInterfacePtrSet<mojom::ApplicationManagerListener> listeners_;
base::TaskRunner* task_runner_;
diff --git a/mojo/shell/application_manager_unittest.cc b/mojo/shell/application_manager_unittest.cc
index fa4d96c..2ce0b3a 100644
--- a/mojo/shell/application_manager_unittest.cc
+++ b/mojo/shell/application_manager_unittest.cc
@@ -15,14 +15,11 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/connect_util.h"
-#include "mojo/shell/fetcher.h"
-#include "mojo/shell/package_manager.h"
#include "mojo/shell/public/cpp/interface_factory.h"
#include "mojo/shell/public/cpp/shell_client.h"
#include "mojo/shell/public/cpp/shell_connection.h"
#include "mojo/shell/public/interfaces/interface_provider.mojom.h"
#include "mojo/shell/test.mojom.h"
-#include "mojo/shell/test_package_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
@@ -394,8 +391,7 @@ class ApplicationManagerTest : public testing::Test {
~ApplicationManagerTest() override {}
void SetUp() override {
- application_manager_.reset(new ApplicationManager(
- make_scoped_ptr(new TestPackageManager), true));
+ application_manager_.reset(new ApplicationManager(true));
test_loader_ = new TestApplicationLoader;
test_loader_->set_context(&context_);
application_manager_->set_default_loader(
@@ -452,7 +448,7 @@ TEST_F(ApplicationManagerTest, ClientError) {
TEST_F(ApplicationManagerTest, Deletes) {
{
- ApplicationManager am(make_scoped_ptr(new TestPackageManager), true);
+ ApplicationManager am(true);
TestApplicationLoader* default_loader = new TestApplicationLoader;
default_loader->set_context(&context_);
TestApplicationLoader* url_loader1 = new TestApplicationLoader;
@@ -600,29 +596,18 @@ TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
TestServicePtr test_service;
ConnectToInterface(application_manager_.get(),
- GURL("http://www.example.org/abc?def"), &test_service);
+ GURL("mojo:foo"), &test_service);
EXPECT_EQ(2, test_loader_->num_loads());
// Exactly the same URL as above.
ConnectToInterface(application_manager_.get(),
- GURL("http://www.example.org/abc?def"), &test_service);
+ GURL("mojo:foo"), &test_service);
EXPECT_EQ(2, test_loader_->num_loads());
- // The same identity as the one above because only the query string is
- // different.
- ConnectToInterface(application_manager_.get(),
- GURL("http://www.example.org/abc"), &test_service);
- EXPECT_EQ(2, test_loader_->num_loads());
-
- // A different identity because the path is different.
- ConnectToInterface(application_manager_.get(),
- GURL("http://www.example.org/another_path"), &test_service);
- EXPECT_EQ(3, test_loader_->num_loads());
-
// A different identity because the domain is different.
ConnectToInterface(application_manager_.get(),
- GURL("http://www.another_domain.org/abc"), &test_service);
- EXPECT_EQ(4, test_loader_->num_loads());
+ GURL("mojo:bar"), &test_service);
+ EXPECT_EQ(3, test_loader_->num_loads());
}
} // namespace test
diff --git a/mojo/shell/background/background_shell.cc b/mojo/shell/background/background_shell.cc
index 17522f0..0c5adda 100644
--- a/mojo/shell/background/background_shell.cc
+++ b/mojo/shell/background/background_shell.cc
@@ -173,7 +173,5 @@ InterfaceRequest<mojom::ShellClient> BackgroundShell::CreateShellClientRequest(
return request;
}
-void RegisterLocalAliases(PackageManagerImpl* manager) {}
-
} // namespace shell
} // namespace mojo
diff --git a/mojo/shell/capability_filter_test.cc b/mojo/shell/capability_filter_test.cc
index 7351a0a..56e6d07 100644
--- a/mojo/shell/capability_filter_test.cc
+++ b/mojo/shell/capability_filter_test.cc
@@ -12,7 +12,6 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/weak_binding_set.h"
#include "mojo/shell/application_loader.h"
-#include "mojo/shell/package_manager.h"
#include "mojo/shell/public/cpp/connection.h"
#include "mojo/shell/public/cpp/interface_factory.h"
#include "mojo/shell/public/cpp/shell_connection.h"
@@ -281,8 +280,7 @@ void CapabilityFilterTest::RunWildcardTest() {
void CapabilityFilterTest::SetUp() {
- application_manager_.reset(
- new ApplicationManager(make_scoped_ptr(CreatePackageManager()), true));
+ application_manager_.reset(new ApplicationManager(true));
CreateLoader<ServiceApplication>("test:service");
CreateLoader<ServiceApplication>("test:service2");
}
diff --git a/mojo/shell/capability_filter_test.h b/mojo/shell/capability_filter_test.h
index e235802..118f6cb 100644
--- a/mojo/shell/capability_filter_test.h
+++ b/mojo/shell/capability_filter_test.h
@@ -74,10 +74,6 @@ class CapabilityFilterTest : public testing::Test {
void RunBlockingTest();
void RunWildcardTest();
- // Implement to provide an implementation of PackageManager for the test's
- // ApplicationManager.
- virtual PackageManager* CreatePackageManager() = 0;
-
// Overridden from testing::Test:
void SetUp() override;
void TearDown() override;
diff --git a/mojo/shell/capability_filter_unittest.cc b/mojo/shell/capability_filter_unittest.cc
index 5ef2310..8c54e6e 100644
--- a/mojo/shell/capability_filter_unittest.cc
+++ b/mojo/shell/capability_filter_unittest.cc
@@ -4,7 +4,6 @@
#include "base/macros.h"
#include "mojo/shell/capability_filter_test.h"
-#include "mojo/shell/test_package_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
@@ -17,11 +16,6 @@ class CapabilityFilterApplicationTest : public CapabilityFilterTest {
~CapabilityFilterApplicationTest() override {}
private:
- // Overridden from CapabilityFilterTest:
- PackageManager* CreatePackageManager() override {
- return new TestPackageManager;
- }
-
DISALLOW_COPY_AND_ASSIGN(CapabilityFilterApplicationTest);
};
diff --git a/mojo/shell/connect_util.cc b/mojo/shell/connect_util.cc
index d3d0c2d..d33fad8 100644
--- a/mojo/shell/connect_util.cc
+++ b/mojo/shell/connect_util.cc
@@ -19,6 +19,8 @@ ScopedMessagePipeHandle ConnectToInterfaceByName(
const std::string& interface_name) {
shell::mojom::InterfaceProviderPtr remote_interfaces;
scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
+ params->set_source(Identity(GURL("mojo://shell/"), std::string(),
+ GetPermissiveCapabilityFilter()));
params->SetTarget(Identity(application_url, std::string(),
GetPermissiveCapabilityFilter()));
params->set_remote_interfaces(GetProxy(&remote_interfaces));
diff --git a/mojo/shell/package_manager/content_handler_connection.cc b/mojo/shell/content_handler_connection.cc
index 5fb2252..a905bc4 100644
--- a/mojo/shell/package_manager/content_handler_connection.cc
+++ b/mojo/shell/content_handler_connection.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/shell/package_manager/content_handler_connection.h"
+#include "mojo/shell/content_handler_connection.h"
#include <stdint.h>
diff --git a/mojo/shell/package_manager/content_handler_connection.h b/mojo/shell/content_handler_connection.h
index 11d3b70..7b05354 100644
--- a/mojo/shell/package_manager/content_handler_connection.h
+++ b/mojo/shell/content_handler_connection.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_SHELL_PACKAGE_MANAGER_CONTENT_HANDLER_CONNECTION_H_
-#define MOJO_SHELL_PACKAGE_MANAGER_CONTENT_HANDLER_CONNECTION_H_
+#ifndef MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_
+#define MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_
#include <stdint.h>
@@ -64,4 +64,4 @@ class ContentHandlerConnection {
} // namespace shell
} // namespace mojo
-#endif // MOJO_SHELL_PACKAGE_MANAGER_CONTENT_HANDLER_CONNECTION_H_
+#endif // MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_
diff --git a/mojo/shell/data_pipe_peek.cc b/mojo/shell/data_pipe_peek.cc
deleted file mode 100644
index 46293ee..0000000
--- a/mojo/shell/data_pipe_peek.cc
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/data_pipe_peek.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <algorithm>
-
-#include "base/bind.h"
-#include "base/macros.h"
-
-namespace mojo {
-namespace shell {
-
-namespace {
-
-// Sleep for as long as max_sleep_micros if the deadline hasn't been reached
-// and the number of bytes read is still increasing. Returns true if sleep
-// was actually called.
-//
-// This class is a substitute for being able to wait until N bytes are available
-// from a data pipe. The MaybeSleep method is called when num_bytes_read are
-// available but more are needed by the Peek operation. If a second
-// Peek operation finds the same number of bytes after sleeping we assume
-// that there's no point in trying again.
-// TODO(hansmuller): this heuristic is weak. crbug.com/429377
-class PeekSleeper {
- public:
- explicit PeekSleeper(MojoTimeTicks deadline)
- : deadline_(deadline),
- last_number_bytes_read_(0) {}
-
- bool MaybeSleep(uint32_t num_bytes_read) {
- if (num_bytes_read > 0 && last_number_bytes_read_ >= num_bytes_read)
- return false;
- last_number_bytes_read_ = num_bytes_read;
-
- MojoTimeTicks now(GetTimeTicksNow());
- if (now > deadline_)
- return false;
-
- MojoTimeTicks sleep_time =
- (deadline_ == 0) ? kMaxSleepMicros
- : std::min<int64_t>(deadline_ - now, kMaxSleepMicros);
- base::PlatformThread::Sleep(base::TimeDelta::FromMicroseconds(sleep_time));
- return true;
- }
-
- private:
- static const MojoTimeTicks kMaxSleepMicros = 1000 * 10; // 10 ms
-
- const MojoTimeTicks deadline_; // 0 => MOJO_DEADLINE_INDEFINITE
- uint32_t last_number_bytes_read_;
-
- DISALLOW_COPY_AND_ASSIGN(PeekSleeper);
-};
-
-const MojoTimeTicks PeekSleeper::kMaxSleepMicros;
-
-enum PeekStatus { kSuccess, kFail, kKeepReading };
-typedef const base::Callback<PeekStatus(const void*, uint32_t, std::string*)>&
- PeekFunc;
-
-// When data is available on source, call peek_func and then either return true
-// and value, continue waiting for enough data to satisfy peek_func, or fail
-// and return false. Fail if the timeout is exceeded.
-// This function is not guaranteed to work correctly if applied to a data pipe
-// that's already been read from.
-bool BlockingPeekHelper(DataPipeConsumerHandle source,
- std::string* value,
- MojoDeadline timeout,
- PeekFunc peek_func) {
- DCHECK(value);
- value->clear();
-
- MojoTimeTicks deadline =
- (timeout == MOJO_DEADLINE_INDEFINITE)
- ? 0
- : 1 + GetTimeTicksNow() + static_cast<MojoTimeTicks>(timeout);
- PeekSleeper sleeper(deadline);
-
- MojoResult result;
- do {
- const void* buffer;
- uint32_t num_bytes;
- result =
- BeginReadDataRaw(source, &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE);
-
- if (result == MOJO_RESULT_OK) {
- PeekStatus status = peek_func.Run(buffer, num_bytes, value);
- CHECK_EQ(EndReadDataRaw(source, 0), MOJO_RESULT_OK);
- switch (status) {
- case PeekStatus::kSuccess:
- return true;
- case PeekStatus::kFail:
- return false;
- case PeekStatus::kKeepReading:
- break;
- }
- if (!sleeper.MaybeSleep(num_bytes))
- return false;
- } else if (result == MOJO_RESULT_SHOULD_WAIT) {
- MojoTimeTicks now(GetTimeTicksNow());
- if (timeout == MOJO_DEADLINE_INDEFINITE || now < deadline)
- result =
- Wait(source, MOJO_HANDLE_SIGNAL_READABLE, deadline - now, nullptr);
- }
- } while (result == MOJO_RESULT_OK);
-
- return false;
-}
-
-PeekStatus PeekLine(size_t max_line_length,
- const void* buffer,
- uint32_t buffer_num_bytes,
- std::string* line) {
- const char* p = static_cast<const char*>(buffer);
- size_t max_p_index = std::min<size_t>(buffer_num_bytes, max_line_length);
- for (size_t i = 0; i < max_p_index; i++) {
- if (p[i] == '\n') {
- *line = std::string(p, i + 1); // Include the trailing newline.
- return PeekStatus::kSuccess;
- }
- }
- return (buffer_num_bytes >= max_line_length) ? PeekStatus::kFail
- : PeekStatus::kKeepReading;
-}
-
-PeekStatus PeekNBytes(size_t bytes_length,
- const void* buffer,
- uint32_t buffer_num_bytes,
- std::string* bytes) {
- if (buffer_num_bytes >= bytes_length) {
- const char* p = static_cast<const char*>(buffer);
- *bytes = std::string(p, bytes_length);
- return PeekStatus::kSuccess;
- }
- return PeekStatus::kKeepReading;
-}
-
-} // namespace
-
-bool BlockingPeekNBytes(DataPipeConsumerHandle source,
- std::string* bytes,
- size_t bytes_length,
- MojoDeadline timeout) {
- PeekFunc peek_nbytes = base::Bind(PeekNBytes, bytes_length);
- return BlockingPeekHelper(source, bytes, timeout, peek_nbytes);
-}
-
-bool BlockingPeekLine(DataPipeConsumerHandle source,
- std::string* line,
- size_t max_line_length,
- MojoDeadline timeout) {
- PeekFunc peek_line = base::Bind(PeekLine, max_line_length);
- return BlockingPeekHelper(source, line, timeout, peek_line);
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/data_pipe_peek.h b/mojo/shell/data_pipe_peek.h
deleted file mode 100644
index 215cc477..0000000
--- a/mojo/shell/data_pipe_peek.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_DATA_PIPE_PEEK_H_
-#define MOJO_SHELL_DATA_PIPE_PEEK_H_
-
-#include <stddef.h>
-
-#include <string>
-
-#include "mojo/public/cpp/system/core.h"
-
-namespace mojo {
-namespace shell {
-
-// The Peek functions are only intended to be used by the
-// DyanmicApplicationLoader class for discovering the type of a
-// URL response. They are a stopgap to be replaced by real support
-// in the DataPipe classes.
-
-// Return true and the first newline terminated line from source. Return false
-// if more than max_line_length bytes are scanned without seeing a newline, or
-// if the timeout is exceeded.
-bool BlockingPeekLine(DataPipeConsumerHandle source,
- std::string* line,
- size_t max_line_length,
- MojoDeadline timeout);
-
-// Return true and the first bytes_length bytes from source. Return false
-// if the timeout is exceeded.
-bool BlockingPeekNBytes(DataPipeConsumerHandle source,
- std::string* bytes,
- size_t bytes_length,
- MojoDeadline timeout);
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_DATA_PIPE_PEEK_H_
diff --git a/mojo/shell/data_pipe_peek_unittest.cc b/mojo/shell/data_pipe_peek_unittest.cc
deleted file mode 100644
index 7129f77..0000000
--- a/mojo/shell/data_pipe_peek_unittest.cc
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/data_pipe_peek.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "mojo/edk/system/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace runner {
-namespace {
-
-// In various places, we have to poll (since, e.g., we can't yet wait for a
-// certain amount of data to be available). This is the maximum number of
-// iterations (separated by a short sleep).
-// TODO(vtl): Get rid of this.
-const size_t kMaxPoll = 100;
-
-TEST(DataPipePeek, PeekNBytes) {
- DataPipe data_pipe;
- DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get());
- DataPipeProducerHandle producer(data_pipe.producer_handle.get());
-
- // Inialize the pipe with 4 bytes.
-
- const char* s4 = "1234";
- uint32_t num_bytes4 = 4;
- EXPECT_EQ(MOJO_RESULT_OK,
- WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE));
- EXPECT_EQ(4u, num_bytes4);
-
- // We're not consuming data, so peeking for 4 bytes should always succeed.
-
- std::string bytes;
- MojoDeadline timeout = MOJO_DEADLINE_INDEFINITE;
- EXPECT_TRUE(shell::BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
- EXPECT_EQ(bytes, std::string(s4));
-
- timeout = 1000; // 1ms
- EXPECT_TRUE(shell::BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
- EXPECT_EQ(bytes, std::string(s4));
-
- timeout = MOJO_DEADLINE_INDEFINITE;
- EXPECT_TRUE(shell::BlockingPeekNBytes(consumer, &bytes, num_bytes4, timeout));
- EXPECT_EQ(bytes, std::string(s4));
-
- // Peeking for 5 bytes should fail, until another byte is written.
-
- uint32_t bytes1 = 1;
- uint32_t num_bytes5 = 5;
- const char* s1 = "5";
- const char* s5 = "12345";
-
- timeout = 0;
- EXPECT_FALSE(
- shell::BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
-
- timeout = 500; // Should cause peek to timeout after about 0.5ms.
- EXPECT_FALSE(
- shell::BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
-
- EXPECT_EQ(MOJO_RESULT_OK,
- WriteDataRaw(producer, s1, &bytes1, MOJO_WRITE_DATA_FLAG_NONE));
- EXPECT_EQ(1u, bytes1);
-
- EXPECT_TRUE(shell::BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
- EXPECT_EQ(bytes, std::string(s5));
-
- // If the consumer side of the pipe is closed, peek should fail.
-
- data_pipe.consumer_handle.reset();
- timeout = 0;
- EXPECT_FALSE(
- shell::BlockingPeekNBytes(consumer, &bytes, num_bytes5, timeout));
-}
-
-TEST(DataPipePeek, PeekLine) {
- DataPipe data_pipe;
- DataPipeConsumerHandle consumer(data_pipe.consumer_handle.get());
- DataPipeProducerHandle producer(data_pipe.producer_handle.get());
-
- // Inialize the pipe with 4 bytes and no newline.
-
- const char* s4 = "1234";
- uint32_t num_bytes4 = 4;
- EXPECT_EQ(MOJO_RESULT_OK,
- WriteDataRaw(producer, s4, &num_bytes4, MOJO_WRITE_DATA_FLAG_NONE));
- EXPECT_EQ(4u, num_bytes4);
-
- // Peeking for a line should fail.
-
- std::string str;
- size_t max_str_length = 5;
- MojoDeadline timeout = 0;
- EXPECT_FALSE(
- shell::BlockingPeekLine(consumer, &str, max_str_length, timeout));
-
- // Writing a newline should cause PeekLine to succeed.
-
- uint32_t bytes1 = 1;
- const char* s1 = "\n";
- timeout = MOJO_DEADLINE_INDEFINITE;
- EXPECT_EQ(MOJO_RESULT_OK,
- WriteDataRaw(producer, s1, &bytes1, MOJO_WRITE_DATA_FLAG_NONE));
- EXPECT_EQ(1u, bytes1);
-
- bool succeeded = false;
- for (size_t i = 0; i < kMaxPoll; i++) {
- if (shell::BlockingPeekLine(consumer, &str, max_str_length, timeout)) {
- succeeded = true;
- break;
- }
- edk::test::Sleep(edk::test::EpsilonDeadline());
- }
- EXPECT_TRUE(succeeded);
- EXPECT_EQ(str, std::string(s4) + "\n");
-
- // If the max_line_length parameter is less than the length of the
- // newline terminated string, then peek should fail.
-
- max_str_length = 3;
- timeout = 0;
- EXPECT_FALSE(
- shell::BlockingPeekLine(consumer, &str, max_str_length, timeout));
-}
-
-} // namespace
-} // namespace runner
-} // namespace mojo
diff --git a/mojo/shell/fetcher.cc b/mojo/shell/fetcher.cc
deleted file mode 100644
index 16b1cee..0000000
--- a/mojo/shell/fetcher.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher.h"
-
-#include <stddef.h>
-
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-
-const char Fetcher::kMojoMagic[] = "#!mojo ";
-const size_t Fetcher::kMaxShebangLength = 2048;
-
-Fetcher::Fetcher(const FetchCallback& loader_callback)
- : loader_callback_(loader_callback) {
-}
-
-Fetcher::~Fetcher() {
-}
-
-bool Fetcher::PeekContentHandler(std::string* mojo_shebang,
- GURL* mojo_content_handler_url) {
- // TODO(aa): I guess this should just go in ApplicationManager now.
- std::string shebang;
- if (HasMojoMagic() && PeekFirstLine(&shebang)) {
- GURL url(shebang.substr(arraysize(kMojoMagic) - 1, std::string::npos));
- if (url.is_valid()) {
- *mojo_shebang = shebang;
- *mojo_content_handler_url = url;
- return true;
- }
- }
- return false;
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher.h b/mojo/shell/fetcher.h
deleted file mode 100644
index 58df0ea..0000000
--- a/mojo/shell/fetcher.h
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_H_
-#define MOJO_SHELL_FETCHER_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "base/callback.h"
-#include "base/memory/scoped_ptr.h"
-
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-
-class GURL;
-
-namespace base {
-class FilePath;
-class TaskRunner;
-}
-
-namespace mojo {
-namespace shell {
-
-// Fetcher abstracts getting an application by either file or http[s] URL.
-//
-// Although it is possible to use the Network implementation for http[s] URLs
-// (because the underlying net library knows how to handle them), it is
-// extremely slow because network responses must be copied to disk in order to
-// get a file handle we can use with dlopen.
-//
-// Until this is solved, we use two different implementations so that
-// performance isn't completely absymal.
-class Fetcher {
- public:
- // The param will be null in the case where the content could not be fetched.
- // Reasons include:
- // - network error
- typedef base::Callback<void(scoped_ptr<Fetcher>)> FetchCallback;
-
- Fetcher(const FetchCallback& fetch_callback);
- virtual ~Fetcher();
-
- // Returns the original URL that was fetched.
- virtual const GURL& GetURL() const = 0;
-
- // If the fetch resulted in a redirect, this returns the final URL after all
- // redirects. Otherwise, it returns an empty URL.
- virtual GURL GetRedirectURL() const = 0;
-
- // If the fetch resulted in a redirect, this returns the referer URL to use
- // with the redirect.
- virtual GURL GetRedirectReferer() const = 0;
-
- virtual URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) = 0;
-
- virtual void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) = 0;
-
- virtual std::string MimeType() = 0;
-
- virtual bool HasMojoMagic() = 0;
-
- virtual bool PeekFirstLine(std::string* line) = 0;
-
- bool PeekContentHandler(std::string* mojo_shebang,
- GURL* mojo_content_handler_url);
-
- protected:
- static const char kMojoMagic[];
- static const size_t kMaxShebangLength;
-
- FetchCallback loader_callback_;
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_H_
diff --git a/mojo/shell/fetcher/BUILD.gn b/mojo/shell/fetcher/BUILD.gn
deleted file mode 100644
index 61dd583..0000000
--- a/mojo/shell/fetcher/BUILD.gn
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright 2015 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//mojo/public/tools/bindings/mojom.gni")
-
-source_set("fetcher") {
- sources = [
- "about_fetcher.cc",
- "about_fetcher.h",
- "data_fetcher.cc",
- "data_fetcher.h",
- "local_fetcher.cc",
- "local_fetcher.h",
- "network_fetcher.cc",
- "network_fetcher.h",
- "switches.cc",
- "switches.h",
- "url_resolver.cc",
- "url_resolver.h",
- ]
-
- public_deps = [
- "//base",
- "//mojo/common",
- "//mojo/public/cpp/bindings",
- "//mojo/services/network/public/interfaces",
- "//mojo/services/updater",
- "//mojo/shell/public/interfaces",
- "//url",
- ]
- deps = [
- "//base/third_party/dynamic_annotations",
- "//crypto:crypto",
- "//mojo/edk/system",
- "//mojo/environment:chromium",
- "//mojo/shell",
- "//mojo/shell/public/cpp:sources",
- "//mojo/util:filename_util",
- "//net",
- "//url",
- ]
-}
diff --git a/mojo/shell/fetcher/DEPS b/mojo/shell/fetcher/DEPS
deleted file mode 100644
index 879b25c..0000000
--- a/mojo/shell/fetcher/DEPS
+++ /dev/null
@@ -1,17 +0,0 @@
-include_rules = [
- "+crypto",
- "-mojo/runner",
- "+net/base",
-]
-
-specific_include_rules = {
- "about_fetcher_unittest.cc": [
- "+mojo/runner/context.h"
- ],
- "data_fetcher_unittest.cc": [
- "+mojo/runner/context.h"
- ],
- "network_fetcher_unittest.cc": [
- "+mojo/runner/context.h"
- ],
-}
diff --git a/mojo/shell/fetcher/about_fetcher.cc b/mojo/shell/fetcher/about_fetcher.cc
deleted file mode 100644
index 1118198..0000000
--- a/mojo/shell/fetcher/about_fetcher.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/about_fetcher.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/files/file_path.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-void RunFetcherCallback(const Fetcher::FetchCallback& callback,
- scoped_ptr<Fetcher> fetcher,
- bool success) {
- callback.Run(success ? std::move(fetcher) : nullptr);
-}
-
-} // namespace
-
-const char AboutFetcher::kAboutScheme[] = "about";
-const char AboutFetcher::kAboutBlankURL[] = "about:blank";
-
-// static
-void AboutFetcher::Start(const GURL& url,
- const FetchCallback& loader_callback) {
- // The object manages its own lifespan.
- new AboutFetcher(url, loader_callback);
-}
-
-AboutFetcher::AboutFetcher(const GURL& url,
- const FetchCallback& loader_callback)
- : Fetcher(loader_callback), url_(url) {
- BuildResponse();
-}
-
-AboutFetcher::~AboutFetcher() {}
-
-void AboutFetcher::BuildResponse() {
- response_ = URLResponse::New();
- response_->url = url_.spec();
-
- // about: URLs other than about:blank are not supported yet.
- //
- // TODO(yzshen): crbug.com/516494 Eventually we need a general solution to
- // generate error page for network errors/unrecognized app format/etc.
- response_->status_code = (url_ == GURL(kAboutBlankURL)) ? 200 : 404;
-
- response_->mime_type = "text/html";
- PostToRunCallback(true);
-}
-
-void AboutFetcher::PostToRunCallback(bool success) {
- // Also pass |this| on failure, so that we won't destroy the object while the
- // constructor is still on the call stack.
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(RunFetcherCallback, loader_callback_,
- base::Passed(make_scoped_ptr<Fetcher>(this)), success));
-}
-
-const GURL& AboutFetcher::GetURL() const {
- return url_;
-}
-
-GURL AboutFetcher::GetRedirectURL() const {
- return GURL::EmptyGURL();
-}
-
-GURL AboutFetcher::GetRedirectReferer() const {
- return GURL::EmptyGURL();
-}
-
-URLResponsePtr AboutFetcher::AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) {
- DCHECK(response_);
-
- // Ignore |skip| because the only URL handled currently is "about:blank" which
- // doesn't have a body.
- DCHECK(!response_->body.is_valid());
-
- return std::move(response_);
-}
-
-void AboutFetcher::AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) {
- NOTIMPLEMENTED();
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, base::FilePath(), false));
-}
-
-std::string AboutFetcher::MimeType() {
- DCHECK(response_);
- return response_->mime_type;
-}
-
-bool AboutFetcher::HasMojoMagic() {
- return false;
-}
-
-bool AboutFetcher::PeekFirstLine(std::string* line) {
- // The only URL handled currently is "about:blank" which doesn't have a body.
- return false;
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/about_fetcher.h b/mojo/shell/fetcher/about_fetcher.h
deleted file mode 100644
index 80ff7c9..0000000
--- a/mojo/shell/fetcher/about_fetcher.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_ABOUT_FETCHER_H_
-#define MOJO_SHELL_FETCHER_ABOUT_FETCHER_H_
-
-#include "mojo/shell/fetcher.h"
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-
-// Implements Fetcher for about: URLs.
-class AboutFetcher : public shell::Fetcher {
- public:
- static const char kAboutScheme[];
- static const char kAboutBlankURL[];
-
- static void Start(const GURL& url, const FetchCallback& loader_callback);
-
- private:
- AboutFetcher(const GURL& url, const FetchCallback& loader_callback);
- ~AboutFetcher() override;
-
- void BuildResponse();
-
- // Must be called exactly once to run the loader callback (asynchrously). On
- // success, the ownership of this object is passed to the loader callback;
- // otherwise, the callback is run with a nullptr and this object is destroyed.
- void PostToRunCallback(bool success);
-
- // shell::Fetcher implementation.
- const GURL& GetURL() const override;
- GURL GetRedirectURL() const override;
- GURL GetRedirectReferer() const override;
- URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) override;
- void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) override;
- std::string MimeType() override;
- bool HasMojoMagic() override;
- bool PeekFirstLine(std::string* line) override;
-
- const GURL url_;
- URLResponsePtr response_;
-
- DISALLOW_COPY_AND_ASSIGN(AboutFetcher);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_ABOUT_FETCHER_H_
diff --git a/mojo/shell/fetcher/about_fetcher_unittest.cc b/mojo/shell/fetcher/about_fetcher_unittest.cc
deleted file mode 100644
index 09e881f..0000000
--- a/mojo/shell/fetcher/about_fetcher_unittest.cc
+++ /dev/null
@@ -1,196 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/about_fetcher.h"
-
-#include <stddef.h>
-
-#include <utility>
-
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/path_service.h"
-#include "base/run_loop.h"
-#include "mojo/public/cpp/bindings/weak_binding_set.h"
-#include "mojo/shell/application_loader.h"
-#include "mojo/shell/application_manager.h"
-#include "mojo/shell/package_manager/package_manager_impl.h"
-#include "mojo/shell/public/cpp/interface_factory.h"
-#include "mojo/shell/public/cpp/shell_client.h"
-#include "mojo/shell/public/cpp/shell_connection.h"
-#include "mojo/shell/public/interfaces/content_handler.mojom.h"
-#include "mojo/shell/switches.h"
-#include "mojo/util/filename_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-class TestContentHandler : public ShellClient,
- public InterfaceFactory<mojom::ContentHandler>,
- public mojom::ContentHandler {
- public:
- TestContentHandler() : response_number_(0) {}
- ~TestContentHandler() override {}
-
- size_t response_number() const { return response_number_; }
- const URLResponse* latest_response() const { return latest_response_.get(); }
-
- private:
- // Overridden from ShellClient:
- void Initialize(Shell* shell, const std::string& url, uint32_t id) override {}
- bool AcceptConnection(Connection* connection) override {
- connection->AddInterface<mojom::ContentHandler>(this);
- return true;
- }
-
- // Overridden from InterfaceFactory<mojom::ContentHandler>:
- void Create(Connection* connection,
- InterfaceRequest<mojom::ContentHandler> request) override {
- bindings_.AddBinding(this, std::move(request));
- }
-
- // Overridden from mojom::ContentHandler:
- void StartApplication(
- InterfaceRequest<mojom::ShellClient> request,
- URLResponsePtr response,
- const Callback<void()>& destruct_callback) override {
- response_number_++;
- latest_response_ = std::move(response);
- destruct_callback.Run();
-
- // Drop |application| request. This results in the application manager
- // dropping the InterfaceProvider interface request provided by the client
- // who made the ConnectToApplication() call. Therefore the client could
- // listen for connection error of the InterfaceProvider interface to learn
- // that StartApplication() has been called.
- }
-
- size_t response_number_;
- URLResponsePtr latest_response_;
- WeakBindingSet<mojom::ContentHandler> bindings_;
-
- DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
-};
-
-class TestLoader : public ApplicationLoader {
- public:
- explicit TestLoader(ShellClient* delegate) : delegate_(delegate) {}
- ~TestLoader() override {}
-
- private:
- // Overridden from ApplicationLoader:
- void Load(const GURL& url,
- InterfaceRequest<mojom::ShellClient> request) override {
- app_.reset(new ShellConnection(delegate_, std::move(request)));
- }
-
- ShellClient* delegate_;
- scoped_ptr<ShellConnection> app_;
-
- DISALLOW_COPY_AND_ASSIGN(TestLoader);
-};
-
-class AboutFetcherTest : public testing::Test {
- public:
- AboutFetcherTest() {}
- ~AboutFetcherTest() override {}
-
- protected:
- const TestContentHandler* html_content_handler() const {
- return &html_content_handler_;
- }
-
- void ConnectAndWait(const std::string& url) {
- base::RunLoop run_loop;
-
- shell::mojom::InterfaceProviderPtr remote_interfaces;
- shell::mojom::InterfaceProviderRequest remote_request =
- GetProxy(&remote_interfaces);
- // This connection error handler will be called when:
- // - TestContentHandler::StartApplication() has been called (please see
- // comments in that method); or
- // - the application manager fails to fetch the requested URL.
- remote_interfaces.set_connection_error_handler(
- [&run_loop]() { run_loop.Quit(); });
-
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->SetTargetURL(GURL(url));
- params->set_remote_interfaces(std::move(remote_request));
- application_manager_->ConnectToApplication(std::move(params));
-
- run_loop.Run();
- }
-
- // Overridden from testing::Test:
- void SetUp() override {
- if (!ShouldRunTest())
- return;
- base::FilePath shell_dir;
- PathService::Get(base::DIR_MODULE, &shell_dir);
- scoped_ptr<PackageManagerImpl> package_manager(
- new PackageManagerImpl(shell_dir, nullptr, nullptr));
- package_manager->RegisterContentHandler(
- "text/html", GURL("test:html_content_handler"));
- application_manager_.reset(
- new ApplicationManager(std::move(package_manager), true));
- application_manager_->SetLoaderForURL(
- make_scoped_ptr(new TestLoader(&html_content_handler_)),
- GURL("test:html_content_handler"));
- }
-
- void TearDown() override { application_manager_.reset(); }
-
- bool ShouldRunTest() const {
- return base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDontUseRemotePackageManager);
- }
-
- private:
- base::ShadowingAtExitManager at_exit_;
- TestContentHandler html_content_handler_;
- base::MessageLoop loop_;
- scoped_ptr<ApplicationManager> application_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(AboutFetcherTest);
-};
-
-TEST_F(AboutFetcherTest, AboutBlank) {
- if (!ShouldRunTest())
- return;
-
- ConnectAndWait("about:blank");
-
- ASSERT_EQ(1u, html_content_handler()->response_number());
-
- const URLResponse* response = html_content_handler()->latest_response();
- EXPECT_EQ("about:blank", response->url);
- EXPECT_EQ(200u, response->status_code);
- EXPECT_EQ("text/html", response->mime_type);
- EXPECT_FALSE(response->body.is_valid());
-}
-
-TEST_F(AboutFetcherTest, UnrecognizedURL) {
- if (!ShouldRunTest())
- return;
-
- ConnectAndWait("about:some_unrecognized_url");
-
- ASSERT_EQ(1u, html_content_handler()->response_number());
-
- const URLResponse* response = html_content_handler()->latest_response();
- EXPECT_EQ("about:some_unrecognized_url", response->url);
- EXPECT_EQ(404u, response->status_code);
- EXPECT_EQ("text/html", response->mime_type);
- EXPECT_FALSE(response->body.is_valid());
-}
-
-} // namespace
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/data_fetcher.cc b/mojo/shell/fetcher/data_fetcher.cc
deleted file mode 100644
index 2c63a9b..0000000
--- a/mojo/shell/fetcher/data_fetcher.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/data_fetcher.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/files/file_path.h"
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/thread_task_runner_handle.h"
-#include "mojo/public/cpp/system/data_pipe.h"
-#include "net/base/data_url.h"
-
-namespace mojo {
-namespace shell {
-
-ScopedDataPipeConsumerHandle CreateConsumerHandleForString(
- const std::string& data) {
- if (data.size() > std::numeric_limits<uint32_t>::max())
- return ScopedDataPipeConsumerHandle();
- uint32_t num_bytes = static_cast<uint32_t>(data.size());
- MojoCreateDataPipeOptions options;
- options.struct_size = sizeof(MojoCreateDataPipeOptions);
- options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
- options.element_num_bytes = 1;
- options.capacity_num_bytes = num_bytes;
- mojo::DataPipe data_pipe(options);
- MojoResult result =
- WriteDataRaw(data_pipe.producer_handle.get(), data.data(), &num_bytes,
- MOJO_WRITE_DATA_FLAG_ALL_OR_NONE);
- CHECK_EQ(MOJO_RESULT_OK, result);
- return std::move(data_pipe.consumer_handle);
-}
-
-// static
-void DataFetcher::Start(const GURL& url, const FetchCallback& loader_callback) {
- // The object manages its own lifespan.
- new DataFetcher(url, loader_callback);
-}
-
-DataFetcher::DataFetcher(const GURL& url, const FetchCallback& loader_callback)
- : Fetcher(loader_callback), url_(url) {
- BuildAndDispatchResponse();
-}
-
-DataFetcher::~DataFetcher() {}
-
-void DataFetcher::BuildAndDispatchResponse() {
- response_ = URLResponse::New();
- response_->url = url_.spec();
-
- response_->status_code = 400; // Bad request
- if (url_.SchemeIs(url::kDataScheme)) {
- std::string mime_type, charset, data;
- if (net::DataURL::Parse(url_, &mime_type, &charset, &data)) {
- response_->status_code = 200;
- response_->mime_type = mime_type;
- response_->charset = charset;
- if (!data.empty())
- response_->body = CreateConsumerHandleForString(data);
- }
- }
-
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(loader_callback_,
- base::Passed(make_scoped_ptr<Fetcher>(this))));
-}
-
-const GURL& DataFetcher::GetURL() const {
- return url_;
-}
-
-GURL DataFetcher::GetRedirectURL() const {
- return GURL::EmptyGURL();
-}
-
-GURL DataFetcher::GetRedirectReferer() const {
- return GURL::EmptyGURL();
-}
-
-URLResponsePtr DataFetcher::AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) {
- DCHECK(response_);
- return std::move(response_);
-}
-
-void DataFetcher::AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) {
- NOTIMPLEMENTED();
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, base::FilePath(), false));
-}
-
-std::string DataFetcher::MimeType() {
- DCHECK(response_);
- return response_->mime_type;
-}
-
-bool DataFetcher::HasMojoMagic() {
- return false;
-}
-
-bool DataFetcher::PeekFirstLine(std::string* line) {
- // This is only called for 'mojo magic' (i.e. detecting shebang'ed
- // content-handler. Since HasMojoMagic() returns false above, this should
- // never be reached.
- NOTREACHED();
- return false;
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/data_fetcher.h b/mojo/shell/fetcher/data_fetcher.h
deleted file mode 100644
index 31737ca..0000000
--- a/mojo/shell/fetcher/data_fetcher.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_DATA_FETCHER_H_
-#define MOJO_SHELL_FETCHER_DATA_FETCHER_H_
-
-#include "mojo/shell/fetcher.h"
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-
-// Implements Fetcher for data: URLs.
-class DataFetcher : public Fetcher {
- public:
- static void Start(const GURL& url, const FetchCallback& loader_callback);
-
- private:
- DataFetcher(const GURL& url, const FetchCallback& loader_callback);
- ~DataFetcher() override;
-
- void BuildAndDispatchResponse();
-
- // Fetcher implementation.
- const GURL& GetURL() const override;
- GURL GetRedirectURL() const override;
- GURL GetRedirectReferer() const override;
- URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) override;
- void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) override;
- std::string MimeType() override;
- bool HasMojoMagic() override;
- bool PeekFirstLine(std::string* line) override;
-
- const GURL url_;
- URLResponsePtr response_;
-
- DISALLOW_COPY_AND_ASSIGN(DataFetcher);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_DATA_FETCHER_H_
diff --git a/mojo/shell/fetcher/data_fetcher_unittest.cc b/mojo/shell/fetcher/data_fetcher_unittest.cc
deleted file mode 100644
index 7974b02..0000000
--- a/mojo/shell/fetcher/data_fetcher_unittest.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/data_fetcher.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/auto_reset.h"
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "mojo/public/cpp/system/data_pipe.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-class FetchCallbackHelper {
- public:
- FetchCallbackHelper() : run_loop_(nullptr) {}
- ~FetchCallbackHelper() {}
-
- Fetcher::FetchCallback GetCallback() {
- return base::Bind(&FetchCallbackHelper::CallbackHandler,
- base::Unretained(this));
- }
-
- void WaitForCallback() {
- base::RunLoop run_loop;
- base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop);
- run_loop.Run();
- }
-
- Fetcher* fetcher() const { return fetcher_.get(); }
-
- private:
- void CallbackHandler(scoped_ptr<Fetcher> fetcher) {
- fetcher_ = std::move(fetcher);
- if (run_loop_)
- run_loop_->Quit();
- }
-
- // If it is not null, it points to a stack-allocated base::RunLoop instance in
- // WaitForCallback().
- base::RunLoop* run_loop_;
- scoped_ptr<Fetcher> fetcher_;
- DISALLOW_COPY_AND_ASSIGN(FetchCallbackHelper);
-};
-
-class DataFetcherTest : public testing::Test {
- public:
- DataFetcherTest() {}
- ~DataFetcherTest() override {}
-
- protected:
- void TestFetchURL(const std::string& url,
- uint32_t expected_status_code,
- const std::string& expected_mime_type,
- const std::string& expected_body) {
- FetchCallbackHelper helper;
- DataFetcher::Start(GURL(url), helper.GetCallback());
- helper.WaitForCallback();
-
- ASSERT_TRUE(helper.fetcher());
- URLResponsePtr response = helper.fetcher()->AsURLResponse(nullptr, 0);
- ASSERT_TRUE(response);
- EXPECT_EQ(url, response->url);
- EXPECT_EQ(expected_status_code, response->status_code);
-
- if (expected_status_code != 200)
- return;
-
- ASSERT_TRUE(response->body.is_valid());
- EXPECT_EQ(expected_mime_type, response->mime_type);
-
- uint32_t num_bytes = 0;
- Handle body_handle = response->body.release();
-
- MojoHandleSignalsState hss;
- ASSERT_EQ(MOJO_RESULT_OK,
- MojoWait(body_handle.value(), MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, &hss));
-
- MojoResult result = MojoReadData(body_handle.value(), nullptr, &num_bytes,
- MOJO_READ_DATA_FLAG_QUERY);
- ASSERT_EQ(MOJO_RESULT_OK, result);
-
- scoped_ptr<char[]> body(new char[num_bytes]);
- result = MojoReadData(body_handle.value(), body.get(), &num_bytes,
- MOJO_READ_DATA_FLAG_ALL_OR_NONE);
- ASSERT_EQ(MOJO_RESULT_OK, result);
- EXPECT_EQ(expected_body, std::string(body.get(), num_bytes));
- }
-
- private:
- base::MessageLoop loop_;
-
- DISALLOW_COPY_AND_ASSIGN(DataFetcherTest);
-};
-
-TEST_F(DataFetcherTest, BasicSuccess) {
- TestFetchURL("data:text/html,Hello world", 200, "text/html", "Hello world");
-}
-
-TEST_F(DataFetcherTest, BasicFailure) {
- TestFetchURL("about:blank", 400, std::string(), std::string());
- TestFetchURL("data:;base64,aGVs_-_-", 400, std::string(), std::string());
-}
-
-} // namespace
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/local_fetcher.cc b/mojo/shell/fetcher/local_fetcher.cc
deleted file mode 100644
index 7c1565f..0000000
--- a/mojo/shell/fetcher/local_fetcher.cc
+++ /dev/null
@@ -1,153 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/local_fetcher.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/files/file_util.h"
-#include "base/format_macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-#include "base/trace_event/trace_event.h"
-#include "mojo/common/common_type_converters.h"
-#include "mojo/common/data_pipe_utils.h"
-#include "mojo/common/url_type_converters.h"
-#include "mojo/services/network/public/interfaces/network_service.mojom.h"
-#include "mojo/shell/switches.h"
-#include "mojo/util/filename_util.h"
-#include "url/url_util.h"
-
-namespace mojo {
-namespace shell {
-
-namespace {
-void IgnoreResult(bool result) {
-}
-
-} // namespace
-
-// A loader for local files.
-LocalFetcher::LocalFetcher(NetworkService* network_service,
- const GURL& url,
- const GURL& url_without_query,
- const base::FilePath& shell_file_root,
- const FetchCallback& loader_callback)
- : Fetcher(loader_callback),
- url_(url),
- path_(util::UrlToFilePath(url_without_query)),
- shell_file_root_(shell_file_root) {
- TRACE_EVENT1("mojo_shell", "LocalFetcher::LocalFetcher", "url", url.spec());
- const std::string ext(base::FilePath(path_.Extension()).AsUTF8Unsafe());
- if (network_service && !base::EqualsCaseInsensitiveASCII(ext, ".mojo")) {
- network_service->GetMimeTypeFromFile(
- path_.AsUTF8Unsafe(),
- base::Bind(&LocalFetcher::GetMimeTypeFromFileCallback,
- base::Unretained(this)));
- } else {
- loader_callback_.Run(make_scoped_ptr(this));
- }
-}
-
-LocalFetcher::~LocalFetcher() {}
-
-void LocalFetcher::GetMimeTypeFromFileCallback(const mojo::String& mime_type) {
- mime_type_ = mime_type.To<std::string>();
- loader_callback_.Run(make_scoped_ptr(this));
-}
-
-const GURL& LocalFetcher::GetURL() const {
- return url_;
-}
-
-GURL LocalFetcher::GetRedirectURL() const {
- // Use Mandoline's Google Storage bucket if the Mojo component does not exist.
- // TODO(msw): Integrate with Mandoline's component updater? crbug.com/479169
- // TODO(msw): Integrate with planned Omaha fetcher and updater work.
- // TODO(msw): Support fetching apps with resource files.
- // TODO(msw): Handle broken URLs. (unavailable component files, etc.)
- // TODO(msw): Avoid kPredictableAppFilenames switch? (need executable bit set)
- if (!base::PathExists(path_) && shell_file_root_.IsParent(path_) &&
- path_.MatchesExtension(FILE_PATH_LITERAL(".mojo")) &&
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPredictableAppFilenames)) {
- GURL url("https://storage.googleapis.com/mandoline/");
- const std::string version("latest/");
-#if defined(OS_WIN)
- const std::string platform("win/");
-#elif defined(OS_LINUX)
- const std::string platform("linux/");
-#else
- const std::string platform("unknown/");
-#endif
- // Get the app path relative to the shell (and Google Storage) file root.
- base::FilePath app_path;
- bool result = shell_file_root_.AppendRelativePath(path_, &app_path);
- DCHECK(result);
- url = url.Resolve(version).Resolve(platform).Resolve(app_path.value());
- return url;
- }
- return GURL::EmptyGURL();
-}
-
-GURL LocalFetcher::GetRedirectReferer() const {
- return GURL::EmptyGURL();
-}
-
-URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) {
- URLResponsePtr response(URLResponse::New());
- response->url = String::From(url_);
- DataPipe data_pipe;
- response->body = std::move(data_pipe.consumer_handle);
- int64_t file_size;
- if (base::GetFileSize(path_, &file_size)) {
- response->headers = Array<HttpHeaderPtr>(1);
- HttpHeaderPtr header = HttpHeader::New();
- header->name = "Content-Length";
- header->value = base::StringPrintf("%" PRId64, file_size);
- response->headers[0] = std::move(header);
- }
- response->mime_type = String::From(MimeType());
- common::CopyFromFile(path_, std::move(data_pipe.producer_handle), skip,
- task_runner, base::Bind(&IgnoreResult));
- return response;
-}
-
-void LocalFetcher::AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) {
- // Async for consistency with network case.
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
-}
-
-std::string LocalFetcher::MimeType() {
- return mime_type_;
-}
-
-bool LocalFetcher::HasMojoMagic() {
- std::string magic;
- ReadFileToString(path_, &magic, strlen(kMojoMagic));
- return magic == kMojoMagic;
-}
-
-bool LocalFetcher::PeekFirstLine(std::string* line) {
- std::string start_of_file;
- ReadFileToString(path_, &start_of_file, kMaxShebangLength);
- size_t return_position = start_of_file.find('\n');
- if (return_position == std::string::npos)
- return false;
- *line = start_of_file.substr(0, return_position + 1);
- return true;
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/local_fetcher.h b/mojo/shell/fetcher/local_fetcher.h
deleted file mode 100644
index 4ad508f..0000000
--- a/mojo/shell/fetcher/local_fetcher.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_LOCAL_FETCHER_H_
-#define MOJO_SHELL_FETCHER_LOCAL_FETCHER_H_
-
-#include <stdint.h>
-
-#include <string>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "mojo/shell/fetcher.h"
-#include "url/gurl.h"
-
-namespace mojo {
-
-class NetworkService;
-
-namespace shell {
-
-// Implements Fetcher for file:// URLs.
-class LocalFetcher : public Fetcher {
- public:
- LocalFetcher(NetworkService* network_service,
- const GURL& url,
- const GURL& url_without_query,
- const base::FilePath& shell_file_root,
- const FetchCallback& loader_callback);
-
- ~LocalFetcher() override;
-
- void GetMimeTypeFromFileCallback(const mojo::String& mime_type);
-
- private:
- const GURL& GetURL() const override;
- GURL GetRedirectURL() const override;
- GURL GetRedirectReferer() const override;
-
- URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) override;
-
- void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) override;
-
- std::string MimeType() override;
-
- bool HasMojoMagic() override;
-
- bool PeekFirstLine(std::string* line) override;
-
- GURL url_;
- base::FilePath path_;
- base::FilePath shell_file_root_;
- std::string mime_type_;
-
- DISALLOW_COPY_AND_ASSIGN(LocalFetcher);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_LOCAL_FETCHER_H_
diff --git a/mojo/shell/fetcher/network_fetcher.cc b/mojo/shell/fetcher/network_fetcher.cc
deleted file mode 100644
index 7274cde..0000000
--- a/mojo/shell/fetcher/network_fetcher.cc
+++ /dev/null
@@ -1,253 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/network_fetcher.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/files/file.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/message_loop/message_loop.h"
-#include "base/process/process.h"
-#include "base/stl_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/trace_event/trace_event.h"
-#include "crypto/secure_hash.h"
-#include "crypto/sha2.h"
-#include "mojo/common/common_type_converters.h"
-#include "mojo/common/data_pipe_utils.h"
-#include "mojo/common/url_type_converters.h"
-#include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
-#include "mojo/shell/data_pipe_peek.h"
-#include "mojo/shell/switches.h"
-
-namespace mojo {
-namespace shell {
-
-NetworkFetcher::NetworkFetcher(bool disable_cache,
- mojo::URLRequestPtr request,
- URLLoaderFactory* url_loader_factory,
- const FetchCallback& loader_callback)
- : Fetcher(loader_callback),
- disable_cache_(false),
- url_(request->url.To<GURL>()),
- weak_ptr_factory_(this) {
- StartNetworkRequest(std::move(request), url_loader_factory);
-}
-
-NetworkFetcher::~NetworkFetcher() {
-}
-
-const GURL& NetworkFetcher::GetURL() const {
- return url_;
-}
-
-GURL NetworkFetcher::GetRedirectURL() const {
- if (!response_)
- return GURL::EmptyGURL();
-
- if (response_->redirect_url.is_null())
- return GURL::EmptyGURL();
-
- return GURL(response_->redirect_url.get());
-}
-
-GURL NetworkFetcher::GetRedirectReferer() const {
- if (!response_)
- return GURL::EmptyGURL();
-
- if (response_->redirect_referrer.is_null())
- return GURL::EmptyGURL();
-
- return GURL(response_->redirect_referrer.get());
-}
-URLResponsePtr NetworkFetcher::AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) {
- if (skip != 0) {
- MojoResult result = ReadDataRaw(
- response_->body.get(), nullptr, &skip,
- MOJO_READ_DATA_FLAG_ALL_OR_NONE | MOJO_READ_DATA_FLAG_DISCARD);
- DCHECK_EQ(result, MOJO_RESULT_OK);
- }
- return std::move(response_);
-}
-
-void NetworkFetcher::RecordCacheToURLMapping(const base::FilePath& path,
- const GURL& url) {
- // This is used to extract symbols on android.
- // TODO(eseidel): All users of this log should move to using the map file.
- VLOG(1) << "Caching mojo app " << url << " at " << path.value();
-
- base::FilePath temp_dir;
- base::GetTempDir(&temp_dir);
- base::ProcessId pid = base::Process::Current().Pid();
- std::string map_name = base::StringPrintf("mojo_shell.%d.maps", pid);
- base::FilePath map_path = temp_dir.AppendASCII(map_name);
-
- // TODO(eseidel): Paths or URLs with spaces will need quoting.
- std::string map_entry = base::StringPrintf(
- "%" PRIsFP " %s\n", path.value().c_str(), url.spec().c_str());
- // TODO(eseidel): AppendToFile is missing O_CREAT, crbug.com/450696
- if (!PathExists(map_path)) {
- base::WriteFile(map_path, map_entry.data(),
- static_cast<int>(map_entry.length()));
- } else {
- base::AppendToFile(map_path, map_entry.data(),
- static_cast<int>(map_entry.length()));
- }
-}
-
-// For remote debugging, GDB needs to be, a apriori, aware of the filename a
-// library will be loaded from. AppIds should be be both predictable and unique,
-// but any hash would work. Currently we use sha256 from crypto/secure_hash.h
-bool NetworkFetcher::ComputeAppId(const base::FilePath& path,
- std::string* digest_string) {
- scoped_ptr<crypto::SecureHash> ctx(
- crypto::SecureHash::Create(crypto::SecureHash::SHA256));
- base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
- if (!file.IsValid()) {
- LOG(ERROR) << "Failed to open " << path.value() << " for computing AppId";
- return false;
- }
- char buf[1024];
- while (file.IsValid()) {
- int bytes_read = file.ReadAtCurrentPos(buf, sizeof(buf));
- if (bytes_read == 0)
- break;
- ctx->Update(buf, bytes_read);
- }
- if (!file.IsValid()) {
- LOG(ERROR) << "Error reading " << path.value();
- return false;
- }
- // The output is really a vector of unit8, we're cheating by using a string.
- std::string output(crypto::kSHA256Length, 0);
- ctx->Finish(string_as_array(&output), output.size());
- output = base::HexEncode(output.c_str(), output.size());
- // Using lowercase for compatiblity with sha256sum output.
- *digest_string = base::ToLowerASCII(output);
- return true;
-}
-
-bool NetworkFetcher::RenameToAppId(const GURL& url,
- const base::FilePath& old_path,
- base::FilePath* new_path) {
- std::string app_id;
- if (!ComputeAppId(old_path, &app_id))
- return false;
-
- // Using a hash of the url as a directory to prevent a race when the same
- // bytes are downloaded from 2 different urls. In particular, if the same
- // application is connected to twice concurrently with different query
- // parameters, the directory will be different, which will prevent the
- // collision.
- std::string dirname = base::HexEncode(
- crypto::SHA256HashString(url.spec()).data(), crypto::kSHA256Length);
-
- base::FilePath temp_dir;
- base::GetTempDir(&temp_dir);
- base::FilePath app_dir = temp_dir.AppendASCII(dirname);
- // The directory is leaked, because it can be reused at any time if the same
- // application is downloaded. Deleting it would be racy. This is only
- // happening when --predictable-app-filenames is used.
- bool result = base::CreateDirectoryAndGetError(app_dir, nullptr);
- DCHECK(result);
- std::string unique_name = base::StringPrintf("%s.mojo", app_id.c_str());
- *new_path = app_dir.AppendASCII(unique_name);
- return base::Move(old_path, *new_path);
-}
-
-void NetworkFetcher::CopyCompleted(
- base::Callback<void(const base::FilePath&, bool)> callback,
- bool success) {
- if (success) {
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPredictableAppFilenames)) {
- // The copy completed, now move to $TMP/$APP_ID.mojo before the dlopen.
- success = false;
- base::FilePath new_path;
- if (RenameToAppId(url_, path_, &new_path)) {
- if (base::PathExists(new_path)) {
- path_ = new_path;
- success = true;
- }
- }
- }
- }
-
- if (success)
- RecordCacheToURLMapping(path_, url_);
-
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(callback, path_, success));
-}
-
-void NetworkFetcher::AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) {
- if (!path_.empty() || !response_) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
- return;
- }
-
- base::CreateTemporaryFile(&path_);
- common::CopyToFile(std::move(response_->body), path_, task_runner,
- base::Bind(&NetworkFetcher::CopyCompleted,
- weak_ptr_factory_.GetWeakPtr(), callback));
-}
-
-std::string NetworkFetcher::MimeType() {
- return response_->mime_type;
-}
-
-bool NetworkFetcher::HasMojoMagic() {
- std::string magic;
- return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic),
- kPeekTimeout) && magic == kMojoMagic;
-}
-
-bool NetworkFetcher::PeekFirstLine(std::string* line) {
- return BlockingPeekLine(response_->body.get(), line, kMaxShebangLength,
- kPeekTimeout);
-}
-
-void NetworkFetcher::StartNetworkRequest(mojo::URLRequestPtr request,
- URLLoaderFactory* url_loader_factory) {
- TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "NetworkFetcher::NetworkRequest", this,
- "url", request->url.To<std::string>());
- request->auto_follow_redirects = false;
- request->bypass_cache = disable_cache_;
-
- url_loader_factory->CreateURLLoader(GetProxy(&url_loader_));
- url_loader_->Start(std::move(request),
- base::Bind(&NetworkFetcher::OnLoadComplete,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void NetworkFetcher::OnLoadComplete(URLResponsePtr response) {
- TRACE_EVENT_ASYNC_END0("mojo_shell", "NetworkFetcher::NetworkRequest", this);
- scoped_ptr<Fetcher> owner(this);
- if (response->error) {
- LOG(ERROR) << "Error (" << response->error->code << ": "
- << response->error->description << ") while fetching "
- << response->url;
- loader_callback_.Run(nullptr);
- return;
- }
-
- response_ = std::move(response);
- loader_callback_.Run(std::move(owner));
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/network_fetcher.h b/mojo/shell/fetcher/network_fetcher.h
deleted file mode 100644
index 94755b3..0000000
--- a/mojo/shell/fetcher/network_fetcher.h
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_NETWORK_FETCHER_H_
-#define MOJO_SHELL_FETCHER_NETWORK_FETCHER_H_
-
-#include "mojo/shell/fetcher.h"
-
-#include <stdint.h>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-#include "url/gurl.h"
-
-namespace mojo {
-
-class URLLoaderFactory;
-
-namespace shell {
-
-// Implements Fetcher for http[s] files.
-class NetworkFetcher : public Fetcher {
- public:
- NetworkFetcher(bool disable_cache,
- mojo::URLRequestPtr request,
- URLLoaderFactory* url_loader_factory,
- const FetchCallback& loader_callback);
-
- ~NetworkFetcher() override;
-
- private:
- // TODO(hansmuller): Revisit this when a real peek operation is available.
- static const MojoDeadline kPeekTimeout = MOJO_DEADLINE_INDEFINITE;
-
- const GURL& GetURL() const override;
- GURL GetRedirectURL() const override;
- GURL GetRedirectReferer() const override;
-
- URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) override;
-
- static void RecordCacheToURLMapping(const base::FilePath& path,
- const GURL& url);
-
- // AppIds should be be both predictable and unique, but any hash would work.
- // Currently we use sha256 from crypto/secure_hash.h
- static bool ComputeAppId(const base::FilePath& path,
- std::string* digest_string);
-
- static bool RenameToAppId(const GURL& url,
- const base::FilePath& old_path,
- base::FilePath* new_path);
-
- void CopyCompleted(base::Callback<void(const base::FilePath&, bool)> callback,
- bool success);
-
- void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) override;
-
- std::string MimeType() override;
-
- bool HasMojoMagic() override;
-
- bool PeekFirstLine(std::string* line) override;
-
- void StartNetworkRequest(mojo::URLRequestPtr request,
- URLLoaderFactory* url_loader_factory);
-
- void OnLoadComplete(URLResponsePtr response);
-
- bool disable_cache_;
- const GURL url_;
- URLLoaderPtr url_loader_;
- URLResponsePtr response_;
- base::FilePath path_;
- base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(NetworkFetcher);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_NETWORK_FETCHER_H_
diff --git a/mojo/shell/fetcher/network_fetcher_unittest.cc b/mojo/shell/fetcher/network_fetcher_unittest.cc
deleted file mode 100644
index ba58c47..0000000
--- a/mojo/shell/fetcher/network_fetcher_unittest.cc
+++ /dev/null
@@ -1,181 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/network_fetcher.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/at_exit.h"
-#include "base/auto_reset.h"
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-#include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-const char k200Request[] = "http://request_expect_200";
-const char k404Request[] = "http://request_expect_404";
-const char k504Request[] = "http://request_expect_504";
-const char kErrorRequest[] = "http://request_expect_error";
-
-class TestURLLoaderImpl : public URLLoader {
- public:
- explicit TestURLLoaderImpl(InterfaceRequest<URLLoader> request)
- : binding_(this, std::move(request)) {}
- ~TestURLLoaderImpl() override {}
-
- private:
- // URLLoader implementation.
- void Start(URLRequestPtr request,
- const Callback<void(URLResponsePtr)>& callback) override {
- URLResponsePtr response(URLResponse::New());
- response->url = request->url;
- if (request->url == std::string(k200Request)) {
- response->mime_type = "text/html";
- response->status_code = 200;
- } else if (request->url == std::string(k404Request)) {
- response->mime_type = "text/html";
- response->status_code = 404;
- } else if (request->url == std::string(k504Request)) {
- response->mime_type = "text/html";
- response->status_code = 504;
- } else {
- response->error = NetworkError::New();
- response->error->code = -2;
- }
- callback.Run(std::move(response));
- }
- void FollowRedirect(const Callback<void(URLResponsePtr)>& callback) override {
- NOTREACHED();
- }
- void QueryStatus(
- const Callback<void(URLLoaderStatusPtr)>& callback) override {
- NOTREACHED();
- }
-
- StrongBinding<URLLoader> binding_;
- DISALLOW_COPY_AND_ASSIGN(TestURLLoaderImpl);
-};
-
-class TestURLLoaderFactoryImpl : public URLLoaderFactory {
- public:
- explicit TestURLLoaderFactoryImpl(InterfaceRequest<URLLoaderFactory> request)
- : binding_(this, std::move(request)) {}
- ~TestURLLoaderFactoryImpl() override {}
-
- private:
- // URLLoaderFactory implementation.
- void CreateURLLoader(InterfaceRequest<URLLoader> loader) override {
- new TestURLLoaderImpl(std::move(loader));
- }
-
- StrongBinding<URLLoaderFactory> binding_;
- DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactoryImpl);
-};
-
-class FetchCallbackHelper {
- public:
- FetchCallbackHelper() : run_loop_(nullptr) {}
- ~FetchCallbackHelper() {}
-
- Fetcher::FetchCallback GetCallback() {
- return base::Bind(&FetchCallbackHelper::CallbackHandler,
- base::Unretained(this));
- }
-
- void WaitForCallback() {
- base::RunLoop run_loop;
- base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop);
- run_loop.Run();
- }
-
- Fetcher* fetcher() const { return fetcher_.get(); }
-
- private:
- void CallbackHandler(scoped_ptr<Fetcher> fetcher) {
- fetcher_ = std::move(fetcher);
- if (run_loop_)
- run_loop_->Quit();
- }
-
- // If it is not null, it points to a stack-allocated base::RunLoop instance in
- // WaitForCallback().
- base::RunLoop* run_loop_;
- scoped_ptr<Fetcher> fetcher_;
- DISALLOW_COPY_AND_ASSIGN(FetchCallbackHelper);
-};
-
-class NetworkFetcherTest : public testing::Test {
- public:
- NetworkFetcherTest() {}
- ~NetworkFetcherTest() override {}
-
- protected:
- // Overridden from testing::Test:
- void SetUp() override {
- // Automatically destroyed when |url_loader_factory_| is closed.
- new TestURLLoaderFactoryImpl(GetProxy(&url_loader_factory_));
- }
-
- // When |expect_fetch_success| is false, |expected_status_code| is ignored.
- void TestFetchURL(const std::string& url,
- bool expect_fetch_success,
- uint32_t expected_status_code) {
- FetchCallbackHelper helper;
-
- URLRequestPtr request(URLRequest::New());
- request->url = url;
- new NetworkFetcher(true, std::move(request), url_loader_factory_.get(),
- helper.GetCallback());
- helper.WaitForCallback();
-
- if (!expect_fetch_success) {
- ASSERT_FALSE(helper.fetcher());
- } else {
- ASSERT_TRUE(helper.fetcher());
- URLResponsePtr response = helper.fetcher()->AsURLResponse(nullptr, 0);
- ASSERT_TRUE(response);
- EXPECT_EQ(url, response->url);
- EXPECT_EQ(expected_status_code, response->status_code);
- }
- }
-
- private:
- base::ShadowingAtExitManager at_exit_;
- base::MessageLoop loop_;
- URLLoaderFactoryPtr url_loader_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(NetworkFetcherTest);
-};
-
-TEST_F(NetworkFetcherTest, FetchSucceeded200) {
- TestFetchURL(k200Request, true, 200u);
-}
-
-TEST_F(NetworkFetcherTest, FetchSucceeded404) {
- TestFetchURL(k404Request, true, 404u);
-}
-
-TEST_F(NetworkFetcherTest, FetchSucceeded504) {
- TestFetchURL(k504Request, true, 504u);
-}
-
-TEST_F(NetworkFetcherTest, FetchFailed) {
- TestFetchURL(kErrorRequest, false, 0u);
-}
-
-} // namespace
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/switches.cc b/mojo/shell/fetcher/switches.cc
deleted file mode 100644
index 9c3737a..0000000
--- a/mojo/shell/fetcher/switches.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/switches.h"
-
-namespace mojo {
-namespace switches {
-
-// Force dynamically loaded apps or services to be loaded irrespective of cache
-// instructions.
-const char kDisableCache[] = "disable-cache";
-
-} // namespace switches
-} // namespace mojo
diff --git a/mojo/shell/fetcher/switches.h b/mojo/shell/fetcher/switches.h
deleted file mode 100644
index 534b0ca..0000000
--- a/mojo/shell/fetcher/switches.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_SWITCHES_H_
-#define MOJO_SHELL_FETCHER_SWITCHES_H_
-
-namespace mojo {
-namespace switches {
-
-// All switches in alphabetical order. The switches should be documented
-// alongside the definition of their values in the .cc file.
-extern const char kDisableCache[];
-
-} // namespace switches
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_SWITCHES_H_
diff --git a/mojo/shell/fetcher/url_resolver.cc b/mojo/shell/fetcher/url_resolver.cc
deleted file mode 100644
index 0b2c182..0000000
--- a/mojo/shell/fetcher/url_resolver.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/url_resolver.h"
-
-#include "base/base_paths.h"
-#include "base/logging.h"
-#include "base/strings/utf_string_conversions.h"
-#include "mojo/shell/query_util.h"
-#include "mojo/util/filename_util.h"
-#include "url/url_util.h"
-
-namespace mojo {
-namespace shell {
-
-URLResolver::URLResolver(const GURL& mojo_base_url)
- : mojo_base_url_(util::AddTrailingSlashIfNeeded(mojo_base_url)) {
- DCHECK(mojo_base_url_.is_valid());
- // Needed to treat first component of mojo URLs as host, not path.
- url::AddStandardScheme("mojo", url::SCHEME_WITHOUT_AUTHORITY);
- url::AddStandardScheme("exe", url::SCHEME_WITHOUT_AUTHORITY);
-}
-
-URLResolver::~URLResolver() {
-}
-
-GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const {
- if (mojo_url.SchemeIs("mojo")) {
- // It's still a mojo: URL, use the default mapping scheme.
- std::string query;
- GURL base_url = GetBaseURLAndQuery(mojo_url, &query);
- const std::string host = base_url.host();
- return mojo_base_url_.Resolve(host + "/" + host + ".mojo" + query);
- } else if (mojo_url.SchemeIs("exe")) {
-#if defined OS_WIN
- std::string extension = ".exe";
-#else
- std::string extension;
-#endif
- std::string query;
- GURL base_url = GetBaseURLAndQuery(mojo_url, &query);
- return mojo_base_url_.Resolve(base_url.host() + extension);
- } else {
- // The mapping has produced some sort of non-mojo: URL - file:, http:, etc.
- return mojo_url;
- }
-}
-
-GURL URLResolver::ResolveMojoManifest(const GURL& mojo_url) const {
- // TODO(beng): think more about how this should be done for exe targets.
- if (mojo_url.SchemeIs("mojo")) {
- std::string host = GetBaseURLAndQuery(mojo_url, nullptr).host();
- return mojo_base_url_.Resolve(host +
- "/manifest.json");
- } else if (mojo_url.SchemeIs("exe")) {
- return mojo_base_url_.Resolve(GetBaseURLAndQuery(mojo_url, nullptr).host() +
- "_manifest.json");
- }
- return GURL();
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/fetcher/url_resolver.h b/mojo/shell/fetcher/url_resolver.h
deleted file mode 100644
index c76e544..0000000
--- a/mojo/shell/fetcher/url_resolver.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_FETCHER_URL_RESOLVER_H_
-#define MOJO_SHELL_FETCHER_URL_RESOLVER_H_
-
-#include <map>
-#include <set>
-
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-
-// Supports resolving "mojo:" URLs to a file location, with ".mojo" appended.
-class URLResolver {
- public:
- explicit URLResolver(const GURL& mojo_base_url);
- ~URLResolver();
-
- // Resolve the given "mojo:" URL to the URL that should be used to fetch the
- // code for the corresponding Mojo App.
- GURL ResolveMojoURL(const GURL& mojo_url) const;
- // Resolve the given "mojo:" URL to the URL that should be used to fetch the
- // application manifest for the corresponding Mojo App. Returns an empty url
- // if no manifest can be resolved (e.g. for non-Mojo application URLs).
- GURL ResolveMojoManifest(const GURL& mojo_url) const;
-
- private:
- GURL mojo_base_url_;
-
- DISALLOW_COPY_AND_ASSIGN(URLResolver);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_FETCHER_URL_RESOLVER_H_
diff --git a/mojo/shell/fetcher/url_resolver_unittest.cc b/mojo/shell/fetcher/url_resolver_unittest.cc
deleted file mode 100644
index 23a829e..0000000
--- a/mojo/shell/fetcher/url_resolver_unittest.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/fetcher/url_resolver.h"
-
-#include "base/files/file_util.h"
-#include "base/files/scoped_temp_dir.h"
-#include "base/logging.h"
-#include "mojo/util/filename_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace test {
-namespace {
-
-typedef testing::Test URLResolverTest;
-
-TEST_F(URLResolverTest, TestQueryForBaseFileURL) {
- URLResolver resolver(GURL("file:///base"));
- GURL mapped_url = resolver.ResolveMojoURL(GURL("mojo:foo?a=b"));
- EXPECT_EQ("file:///base/foo/foo.mojo?a=b", mapped_url.spec());
-}
-
-TEST_F(URLResolverTest, TestQueryForBaseHttpURL) {
- URLResolver resolver(GURL("http://127.0.0.1:1234"));
- GURL mapped_url = resolver.ResolveMojoURL(GURL("mojo:foo?a=b"));
- EXPECT_EQ("http://127.0.0.1:1234/foo/foo.mojo?a=b", mapped_url.spec());
-}
-
-TEST_F(URLResolverTest, TestManifest) {
- URLResolver resolver(GURL("file:///base"));
- {
- GURL mapped_url = resolver.ResolveMojoManifest(GURL("mojo:foo"));
- EXPECT_EQ("file:///base/foo/manifest.json", mapped_url.spec());
- }
- {
- GURL mapped_url = resolver.ResolveMojoManifest(GURL("exe:foo"));
- EXPECT_EQ("file:///base/foo_manifest.json", mapped_url.spec());
- }
- {
- GURL mapped_url = resolver.ResolveMojoManifest(GURL("http://localhost/"));
- EXPECT_TRUE(mapped_url.is_empty());
- }
-}
-
-} // namespace
-} // namespace test
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/identity.cc b/mojo/shell/identity.cc
index be74bfb..fef8658 100644
--- a/mojo/shell/identity.cc
+++ b/mojo/shell/identity.cc
@@ -4,8 +4,6 @@
#include "mojo/shell/identity.h"
-#include "mojo/shell/query_util.h"
-
namespace mojo {
namespace shell {
namespace {
@@ -30,17 +28,17 @@ CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) {
Identity::Identity() {}
Identity::Identity(const GURL& url)
- : url_(GetBaseURLAndQuery(url, nullptr)),
+ : url_(url),
qualifier_(url_.spec()) {}
Identity::Identity(const GURL& url, const std::string& qualifier)
- : url_(GetBaseURLAndQuery(url, nullptr)),
+ : url_(url),
qualifier_(qualifier.empty() ? url_.spec() : qualifier) {}
Identity::Identity(const GURL& url,
const std::string& qualifier,
CapabilityFilter filter)
- : url_(GetBaseURLAndQuery(url, nullptr)),
+ : url_(url),
qualifier_(qualifier.empty() ? url_.spec() : qualifier),
filter_(CanonicalizeFilter(filter)) {}
diff --git a/mojo/shell/package_manager.h b/mojo/shell/package_manager.h
deleted file mode 100644
index a49b30e..0000000
--- a/mojo/shell/package_manager.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_PACKAGE_MANAGER_H_
-#define MOJO_SHELL_PACKAGE_MANAGER_H_
-
-#include <stdint.h>
-
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-#include "mojo/shell/capability_filter.h"
-#include "mojo/shell/fetcher.h"
-#include "mojo/shell/public/interfaces/shell_client.mojom.h"
-
-class GURL;
-
-namespace mojo {
-namespace shell {
-
-class ApplicationManager;
-class Identity;
-
-// A class implementing this interface assists Shell::ConnectToApplication in
-// fetching the applications located therein.
-class PackageManager {
- public:
- PackageManager() {}
- virtual ~PackageManager() {}
-
- // Called once, during initialization, to tell the package manager about the
- // associated ApplicationManager.
- virtual void SetApplicationManager(ApplicationManager* manager) = 0;
-
- // Called when an app is loaded via an ApplicationLoader.
- virtual void BuiltinAppLoaded(const GURL& url) = 0;
-
- // Asks the delegate to fetch the specified url.
- // TODO(beng): figure out how not to expose Fetcher at all at this layer.
- virtual void FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) = 0;
-
- // Determine if a content handler should handle the response received by
- // |fetcher|.
- // |source| is the identity of the application that issued the request.
- // |target_url| is the URL of that may be content that could be handled by a
- // content handler.
- // |target_filter| is a CapabilityFilter that should be applied if a content
- // handler is started to handle |target_url|.
- // |request| is a request for an Application implementation that
- // will be taken by ContentHandler::StartApplication if a content handler ends
- // up handling |target_url|.
- virtual uint32_t HandleWithContentHandler(
- Fetcher* fetcher,
- const Identity& source,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- InterfaceRequest<shell::mojom::ShellClient>* request) = 0;
-
- // Returns true if a manifest for |url| exists within the PackageManager's
- // application catalog.
- virtual bool IsURLInCatalog(const std::string& url) const = 0;
-
- // Returns the name for the application at |url| from its manifest.
- virtual std::string GetApplicationName(const std::string& url) const = 0;
-
- virtual GURL ResolveMojoURL(const GURL& mojo_url) = 0;
-
- virtual uint32_t StartContentHandler(const Identity& source,
- const Identity& content_handler,
- const GURL& url,
- mojom::ShellClientRequest request) = 0;
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_PACKAGE_MANAGER_H_
diff --git a/mojo/shell/package_manager/BUILD.gn b/mojo/shell/package_manager/BUILD.gn
deleted file mode 100644
index cad38c8..0000000
--- a/mojo/shell/package_manager/BUILD.gn
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright 2015 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//testing/test.gni")
-
-source_set("package_manager") {
- sources = [
- "content_handler_connection.cc",
- "content_handler_connection.h",
- "package_manager_impl.cc",
- "package_manager_impl.h",
- ]
-
- deps = [
- "//mojo/services/package_manager/public/interfaces",
- "//mojo/shell",
- "//mojo/shell/fetcher",
- "//mojo/util:filename_util",
- "//net",
- ]
-}
-
-test("unittests") {
- output_name = "mojo_package_manager_unittests"
-
- sources = [
- "capability_filter_content_handler_unittest.cc",
- "content_handler_unittest.cc",
- ]
-
- deps = [
- ":package_manager",
- "//base",
- "//mojo/edk/test:run_all_unittests",
- "//mojo/shell",
- "//mojo/shell:test_support",
- "//mojo/shell/public/cpp",
- "//testing/gtest",
- "//url",
- ]
-}
diff --git a/mojo/shell/package_manager/DEPS b/mojo/shell/package_manager/DEPS
deleted file mode 100644
index 6a2f02e..0000000
--- a/mojo/shell/package_manager/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+net/base",
-]
diff --git a/mojo/shell/package_manager/capability_filter_content_handler_unittest.cc b/mojo/shell/package_manager/capability_filter_content_handler_unittest.cc
deleted file mode 100644
index 832515d..0000000
--- a/mojo/shell/package_manager/capability_filter_content_handler_unittest.cc
+++ /dev/null
@@ -1,160 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/macros.h"
-#include "base/path_service.h"
-#include "mojo/public/cpp/bindings/weak_binding_set.h"
-#include "mojo/shell/capability_filter_test.h"
-#include "mojo/shell/fetcher.h"
-#include "mojo/shell/package_manager/package_manager_impl.h"
-#include "mojo/shell/public/cpp/interface_factory.h"
-#include "mojo/shell/public/cpp/shell_client.h"
-#include "mojo/shell/public/cpp/shell_connection.h"
-#include "mojo/shell/public/interfaces/content_handler.mojom.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace test {
-namespace {
-
-const char kTestMimeType[] = "test/mime-type";
-
-// A custom Fetcher used to trigger a content handler for kTestMimeType for a
-// specific test.
-class TestFetcher : public Fetcher {
- public:
- TestFetcher(const GURL& url, const FetchCallback& callback)
- : Fetcher(callback),
- url_(url) {
- loader_callback_.Run(make_scoped_ptr(this));
- }
- ~TestFetcher() override {}
-
- private:
- // Overridden from Fetcher:
- const GURL& GetURL() const override { return url_; }
- GURL GetRedirectURL() const override { return GURL(); }
- GURL GetRedirectReferer() const override { return GURL(); }
- URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) override {
- URLResponsePtr response(URLResponse::New());
- response->url = url_.spec();
- return response;
- }
- void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) override {}
- std::string MimeType() override { return kTestMimeType; }
- bool HasMojoMagic() override { return false; }
- bool PeekFirstLine(std::string* line) override { return false; }
-
- const GURL url_;
-
- DISALLOW_COPY_AND_ASSIGN(TestFetcher);
-};
-
-class TestPackageManager : public PackageManagerImpl {
- public:
- TestPackageManager(const base::FilePath& package_path)
- : PackageManagerImpl(package_path, nullptr, nullptr) {}
- ~TestPackageManager() override {}
-
- private:
- // Overridden from PackageManagerImpl:
- void FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) override {
- new TestFetcher(GURL(request->url.get()), loader_callback);
- }
-
- DISALLOW_COPY_AND_ASSIGN(TestPackageManager);
-};
-
-class TestContentHandler : public ShellClient,
- public InterfaceFactory<mojom::ContentHandler>,
- public mojom::ContentHandler {
- public:
- TestContentHandler() {}
- ~TestContentHandler() override {}
-
- private:
- // Overridden from ShellClient:
- void Initialize(Shell* shell, const std::string& url, uint32_t id) override {}
- bool AcceptConnection(Connection* connection) override {
- connection->AddInterface<mojom::ContentHandler>(this);
- return true;
- }
-
- // Overridden from InterfaceFactory<mojom::ContentHandler>:
- void Create(Connection* connection,
- InterfaceRequest<mojom::ContentHandler> request) override {
- bindings_.AddBinding(this, std::move(request));
- }
-
- // Overridden from mojom::ContentHandler:
- void StartApplication(InterfaceRequest<mojom::ShellClient> request,
- URLResponsePtr response,
- const Callback<void()>& destruct_callback) override {
- scoped_ptr<ShellClient> delegate(new test::TestApplication);
- embedded_apps_.push_back(
- new ShellConnection(delegate.get(), std::move(request)));
- embedded_app_delegates_.push_back(std::move(delegate));
- destruct_callback.Run();
- }
-
- WeakBindingSet<mojom::ContentHandler> bindings_;
- ScopedVector<ShellClient> embedded_app_delegates_;
- ScopedVector<ShellConnection> embedded_apps_;
-
- DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
-};
-
-} // namespace
-
-class CapabilityFilterContentHandlerTest : public test::CapabilityFilterTest {
- public:
- CapabilityFilterContentHandlerTest()
- : package_manager_(nullptr) {
- base::FilePath shell_dir;
- PathService::Get(base::DIR_MODULE, &shell_dir);
- package_manager_ = new TestPackageManager(shell_dir);
- }
- ~CapabilityFilterContentHandlerTest() override {}
-
- private:
- // Overridden from CapabilityFilterTest:
- PackageManager* CreatePackageManager() override {
- return package_manager_;
- }
- void SetUp() override {
- test::CapabilityFilterTest::SetUp();
-
- GURL content_handler_url("test:content_handler");
- package_manager_->RegisterContentHandler(kTestMimeType,
- content_handler_url);
- CreateLoader<TestContentHandler>(content_handler_url.spec());
- }
-
- // Owned by ApplicationManager in base class.
- PackageManagerImpl* package_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(CapabilityFilterContentHandlerTest);
-};
-
-TEST_F(CapabilityFilterContentHandlerTest, Blocking) {
- RunBlockingTest();
-}
-
-TEST_F(CapabilityFilterContentHandlerTest, Wildcards) {
- RunWildcardTest();
-}
-
-} // namespace test
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/package_manager/content_handler_unittest.cc b/mojo/shell/package_manager/content_handler_unittest.cc
deleted file mode 100644
index b30c30e..0000000
--- a/mojo/shell/package_manager/content_handler_unittest.cc
+++ /dev/null
@@ -1,328 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/at_exit.h"
-#include "base/bind.h"
-#include "base/macros.h"
-#include "base/memory/scoped_vector.h"
-#include "base/message_loop/message_loop.h"
-#include "base/path_service.h"
-#include "base/run_loop.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "mojo/shell/application_loader.h"
-#include "mojo/shell/application_manager.h"
-#include "mojo/shell/connect_util.h"
-#include "mojo/shell/fetcher.h"
-#include "mojo/shell/package_manager/package_manager_impl.h"
-#include "mojo/shell/public/cpp/interface_factory.h"
-#include "mojo/shell/public/cpp/shell_client.h"
-#include "mojo/shell/public/cpp/shell_connection.h"
-#include "mojo/shell/public/interfaces/content_handler.mojom.h"
-#include "mojo/shell/public/interfaces/interface_provider.mojom.h"
-#include "mojo/shell/test_package_manager.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace test {
-namespace {
-
-const char kTestMimeType[] = "test/mime-type";
-
-class TestFetcher : public Fetcher {
- public:
- TestFetcher(const FetchCallback& fetch_callback,
- const GURL& url,
- const std::string& mime_type)
- : Fetcher(fetch_callback), url_(url), mime_type_(mime_type) {
- loader_callback_.Run(make_scoped_ptr(this));
- }
- ~TestFetcher() override {}
-
- // Fetcher:
- const GURL& GetURL() const override { return url_; }
- GURL GetRedirectURL() const override { return GURL("yyy"); }
- GURL GetRedirectReferer() const override { return GURL(); }
- URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
- uint32_t skip) override {
- return URLResponse::New();
- }
- void AsPath(
- base::TaskRunner* task_runner,
- base::Callback<void(const base::FilePath&, bool)> callback) override {}
- std::string MimeType() override { return mime_type_; }
- bool HasMojoMagic() override { return false; }
- bool PeekFirstLine(std::string* line) override { return false; }
-
- private:
- const GURL url_;
- const std::string mime_type_;
-
- DISALLOW_COPY_AND_ASSIGN(TestFetcher);
-};
-
-void QuitClosure(bool* value) {
- *value = true;
- base::MessageLoop::current()->QuitWhenIdle();
-}
-
-class TestContentHandler : public mojom::ContentHandler,
- public ShellClient {
- public:
- TestContentHandler(Connection* connection,
- InterfaceRequest<mojom::ContentHandler> request)
- : binding_(this, std::move(request)) {}
-
- // ContentHandler:
- void StartApplication(
- InterfaceRequest<mojom::ShellClient> request,
- URLResponsePtr response,
- const Callback<void()>& destruct_callback) override {
- shell_connections_.push_back(new ShellConnection(this, std::move(request)));
- destruct_callback.Run();
- }
-
- private:
- StrongBinding<mojom::ContentHandler> binding_;
- ScopedVector<ShellConnection> shell_connections_;
-
- DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
-};
-
-class TestApplicationLoader : public ApplicationLoader,
- public ShellClient,
- public InterfaceFactory<mojom::ContentHandler> {
- public:
- TestApplicationLoader() : num_loads_(0) {}
- ~TestApplicationLoader() override {}
-
- int num_loads() const { return num_loads_; }
- const GURL& last_requestor_url() const { return last_requestor_url_; }
-
- private:
- // ApplicationLoader implementation.
- void Load(const GURL& url,
- InterfaceRequest<mojom::ShellClient> request) override {
- ++num_loads_;
- shell_connection_.reset(new ShellConnection(this, std::move(request)));
- }
-
- // mojo::ShellClient implementation.
- bool AcceptConnection(Connection* connection) override {
- connection->AddInterface<mojom::ContentHandler>(this);
- last_requestor_url_ = GURL(connection->GetRemoteApplicationURL());
- return true;
- }
- // InterfaceFactory<mojom::ContentHandler> implementation.
- void Create(Connection* connection,
- InterfaceRequest<mojom::ContentHandler> request) override {
- new TestContentHandler(connection, std::move(request));
- }
-
- scoped_ptr<ShellConnection> shell_connection_;
- int num_loads_;
- GURL last_requestor_url_;
-
- DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
-};
-
-class TestPackageManagerImpl : public PackageManagerImpl {
- public:
- explicit TestPackageManagerImpl(const base::FilePath& package_path)
- : PackageManagerImpl(package_path, nullptr, nullptr),
- mime_type_(kTestMimeType) {}
- ~TestPackageManagerImpl() override {}
-
- void set_mime_type(const std::string& mime_type) {
- mime_type_ = mime_type;
- }
-
- // PackageManagerImpl:
- void FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) override {
- new TestFetcher(loader_callback, GURL(request->url.get()), mime_type_);
- }
-
- private:
- std::string mime_type_;
-
- DISALLOW_COPY_AND_ASSIGN(TestPackageManagerImpl);
-};
-
-} // namespace
-
-class ContentHandlerTest : public testing::Test {
- public:
- ContentHandlerTest()
- : content_handler_url_("http://test.content.handler"),
- requestor_url_("http://requestor.url") {}
- ~ContentHandlerTest() override {}
-
- void SetUp() override {
- base::FilePath shell_dir;
- PathService::Get(base::DIR_MODULE, &shell_dir);
- test_package_manager_ = new TestPackageManagerImpl(shell_dir);
- test_package_manager_->RegisterContentHandler(kTestMimeType,
- content_handler_url_);
- application_manager_.reset(new ApplicationManager(
- make_scoped_ptr(test_package_manager_), true));
- }
-
- void TearDown() override {
- test_package_manager_ = nullptr;
- application_manager_.reset();
- }
-
- protected:
- const GURL content_handler_url_;
- const GURL requestor_url_;
-
- base::MessageLoop loop_;
- scoped_ptr<ApplicationManager> application_manager_;
- // Owned by ApplicationManager.
- TestPackageManagerImpl* test_package_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(ContentHandlerTest);
-};
-
-TEST_F(ContentHandlerTest, ContentHandlerConnectionGetsRequestorURL) {
- TestApplicationLoader* loader = new TestApplicationLoader;
- application_manager_->SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(loader),
- content_handler_url_);
-
- bool called = false;
- scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
- params->set_source(Identity(requestor_url_));
- params->SetTargetURL(GURL("test:test"));
- params->set_on_application_end(
- base::Bind(&QuitClosure, base::Unretained(&called)));
- application_manager_->ConnectToApplication(std::move(params));
- loop_.Run();
- EXPECT_TRUE(called);
-
- ASSERT_EQ(1, loader->num_loads());
- EXPECT_EQ(requestor_url_, loader->last_requestor_url());
-}
-
-TEST_F(ContentHandlerTest,
- MultipleConnectionsToContentHandlerGetSameContentHandlerId) {
- TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
- application_manager_->SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(content_handler_loader),
- content_handler_url_);
-
- uint32_t content_handler_id;
- {
- base::RunLoop run_loop;
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->set_source(Identity(requestor_url_));
- params->SetTargetURL(GURL("test:test"));
- params->set_connect_callback(
- [&content_handler_id, &run_loop](uint32_t, uint32_t t) {
- content_handler_id = t;
- run_loop.Quit();
- });
- application_manager_->ConnectToApplication(std::move(params));
- run_loop.Run();
- EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id);
- }
-
- uint32_t content_handler_id2;
- {
- base::RunLoop run_loop;
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->set_source(Identity(requestor_url_));
- params->SetTargetURL(GURL("test:test"));
- params->set_connect_callback(
- [&content_handler_id2, &run_loop](uint32_t, uint32_t t) {
- content_handler_id2 = t;
- run_loop.Quit();
- });
- application_manager_->ConnectToApplication(std::move(params));
- run_loop.Run();
- EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id2);
- }
- EXPECT_EQ(content_handler_id, content_handler_id2);
-}
-
-TEST_F(ContentHandlerTest, DifferedContentHandlersGetDifferentIDs) {
- TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
- application_manager_->SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(content_handler_loader),
- content_handler_url_);
-
- uint32_t content_handler_id;
- {
- base::RunLoop run_loop;
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->set_source(Identity(requestor_url_));
- params->SetTargetURL(GURL("test:test"));
- params->set_connect_callback(
- [&content_handler_id, &run_loop](uint32_t, uint32_t t) {
- content_handler_id = t;
- run_loop.Quit();
- });
- application_manager_->ConnectToApplication(std::move(params));
- run_loop.Run();
- EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id);
- }
-
- const std::string mime_type2 = "test/mime-type2";
- const GURL content_handler_url2("http://test.content.handler2");
- test_package_manager_->set_mime_type(mime_type2);
- test_package_manager_->RegisterContentHandler(mime_type2,
- content_handler_url2);
-
- TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader;
- application_manager_->SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(content_handler_loader2),
- content_handler_url2);
-
- uint32_t content_handler_id2;
- {
- base::RunLoop run_loop;
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->set_source(Identity(requestor_url_));
- params->SetTargetURL(GURL("test2:test2"));
- params->set_connect_callback(
- [&content_handler_id2, &run_loop](uint32_t, uint32_t t) {
- content_handler_id2 = t;
- run_loop.Quit();
- });
- application_manager_->ConnectToApplication(std::move(params));
- run_loop.Run();
- EXPECT_NE(mojom::Shell::kInvalidApplicationID, content_handler_id2);
- }
- EXPECT_NE(content_handler_id, content_handler_id2);
-}
-
-TEST_F(ContentHandlerTest,
- ConnectWithNoContentHandlerGetsInvalidContentHandlerId) {
- application_manager_->SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(new TestApplicationLoader),
- GURL("test:test"));
-
- uint32_t content_handler_id = 1u;
- scoped_ptr<ConnectToApplicationParams> params(
- new ConnectToApplicationParams);
- params->SetTargetURL(GURL("test:test"));
- params->set_connect_callback(
- [&content_handler_id](uint32_t, uint32_t t) { content_handler_id = t; });
- application_manager_->ConnectToApplication(std::move(params));
- EXPECT_EQ(0u, content_handler_id);
-}
-
-} // namespace test
-} // namespace package_manager
-} // namespace mojo
diff --git a/mojo/shell/package_manager/package_manager_impl.cc b/mojo/shell/package_manager/package_manager_impl.cc
deleted file mode 100644
index 26464d2..0000000
--- a/mojo/shell/package_manager/package_manager_impl.cc
+++ /dev/null
@@ -1,417 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/package_manager/package_manager_impl.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/json/json_file_value_serializer.h"
-#include "base/logging.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/task_runner_util.h"
-#include "base/values.h"
-#include "mojo/shell/application_manager.h"
-#include "mojo/shell/connect_util.h"
-#include "mojo/shell/fetcher/about_fetcher.h"
-#include "mojo/shell/fetcher/data_fetcher.h"
-#include "mojo/shell/fetcher/local_fetcher.h"
-#include "mojo/shell/fetcher/network_fetcher.h"
-#include "mojo/shell/fetcher/switches.h"
-#include "mojo/shell/package_manager/content_handler_connection.h"
-#include "mojo/shell/public/interfaces/content_handler.mojom.h"
-#include "mojo/shell/query_util.h"
-#include "mojo/shell/switches.h"
-#include "mojo/util/filename_util.h"
-#include "net/base/filename_util.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-CapabilityFilter BuildCapabilityFilterFromDictionary(
- const base::DictionaryValue& value) {
- CapabilityFilter filter;
- base::DictionaryValue::Iterator it(value);
- for (; !it.IsAtEnd(); it.Advance()) {
- const base::ListValue* values = nullptr;
- CHECK(it.value().GetAsList(&values));
- AllowedInterfaces interfaces;
- for (auto i = values->begin(); i != values->end(); ++i) {
- std::string iface_name;
- const base::Value* v = *i;
- CHECK(v->GetAsString(&iface_name));
- interfaces.insert(iface_name);
- }
- filter[it.key()] = interfaces;
- }
- return filter;
-}
-
-ApplicationInfo BuildApplicationInfoFromDictionary(
- const base::DictionaryValue& value) {
- ApplicationInfo info;
- CHECK(value.GetString("url", &info.url));
- CHECK(value.GetString("name", &info.name));
- const base::DictionaryValue* capabilities = nullptr;
- CHECK(value.GetDictionary("capabilities", &capabilities));
- info.base_filter = BuildCapabilityFilterFromDictionary(*capabilities);
- return info;
-}
-
-void SerializeEntry(const ApplicationInfo& entry,
- base::DictionaryValue** value) {
- *value = new base::DictionaryValue;
- (*value)->SetString("url", entry.url);
- (*value)->SetString("name", entry.name);
- base::DictionaryValue* capabilities = new base::DictionaryValue;
- for (const auto& pair : entry.base_filter) {
- scoped_ptr<base::ListValue> interfaces(new base::ListValue);
- for (const auto& iface_name : pair.second)
- interfaces->AppendString(iface_name);
- capabilities->Set(pair.first, std::move(interfaces));
- }
- (*value)->Set("capabilities", make_scoped_ptr(capabilities));
-}
-
-}
-
-ApplicationInfo::ApplicationInfo() {}
-ApplicationInfo::~ApplicationInfo() {}
-
-ApplicationCatalogStore::~ApplicationCatalogStore() {}
-
-PackageManagerImpl::PackageManagerImpl(
- const base::FilePath& shell_file_root,
- base::TaskRunner* task_runner,
- ApplicationCatalogStore* catalog_store)
- : application_manager_(nullptr),
- disable_cache_(base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableCache)),
- content_handler_id_counter_(0u),
- task_runner_(task_runner),
- shell_file_root_(shell_file_root),
- catalog_store_(catalog_store) {
- if (!shell_file_root.empty()) {
- GURL mojo_root_file_url =
- util::FilePathToFileURL(shell_file_root).Resolve(std::string());
- url_resolver_.reset(new URLResolver(mojo_root_file_url));
- }
- DeserializeCatalog();
-}
-
-PackageManagerImpl::~PackageManagerImpl() {
- IdentityToContentHandlerMap identity_to_content_handler(
- identity_to_content_handler_);
- for (auto& pair : identity_to_content_handler)
- pair.second->CloseConnection();
-}
-
-void PackageManagerImpl::RegisterContentHandler(
- const std::string& mime_type,
- const GURL& content_handler_url) {
- DCHECK(content_handler_url.is_valid())
- << "Content handler URL is invalid for mime type " << mime_type;
- mime_type_to_url_[mime_type] = content_handler_url;
-}
-
-void PackageManagerImpl::RegisterApplicationPackageAlias(
- const GURL& alias,
- const GURL& content_handler_package,
- const std::string& qualifier) {
- application_package_alias_[alias] =
- std::make_pair(content_handler_package, qualifier);
-}
-
-void PackageManagerImpl::SetApplicationManager(ApplicationManager* manager) {
- application_manager_ = manager;
-}
-
-void PackageManagerImpl::BuiltinAppLoaded(const GURL& url) {
- // TODO(beng): Determine if this is in the right place, and block
- // establishing the connection on receiving a complete manifest.
- EnsureURLInCatalog(url);
-}
-
-void PackageManagerImpl::FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) {
- GURL url(request->url.get());
- if (url.SchemeIs(AboutFetcher::kAboutScheme)) {
- AboutFetcher::Start(url, loader_callback);
- return;
- }
-
- if (url.SchemeIs(url::kDataScheme)) {
- DataFetcher::Start(url, loader_callback);
- return;
- }
-
- GURL resolved_url = ResolveURL(url);
- if (resolved_url.SchemeIsFile()) {
- // LocalFetcher uses the network service to infer MIME types from URLs.
- // Skip this for mojo URLs to avoid recursively loading the network service.
- if (!network_service_ && !url.SchemeIs("mojo") && !url.SchemeIs("exe")) {
- ConnectToInterface(application_manager_, GURL("mojo:network_service"),
- &network_service_);
- }
- // Ownership of this object is transferred to |loader_callback|.
- // TODO(beng): this is eff'n weird.
- new LocalFetcher(network_service_.get(), resolved_url,
- GetBaseURLAndQuery(resolved_url, nullptr),
- shell_file_root_, loader_callback);
-
- // TODO(beng): Determine if this is in the right place, and block
- // establishing the connection on receiving a complete manifest.
- EnsureURLInCatalog(url);
- return;
- }
-
- if (!url_loader_factory_) {
- ConnectToInterface(application_manager_, GURL("mojo:network_service"),
- &url_loader_factory_);
- }
-
- // Ownership of this object is transferred to |loader_callback|.
- // TODO(beng): this is eff'n weird.
- new NetworkFetcher(disable_cache_, std::move(request),
- url_loader_factory_.get(), loader_callback);
-}
-
-uint32_t PackageManagerImpl::HandleWithContentHandler(
- Fetcher* fetcher,
- const Identity& source,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- InterfaceRequest<mojom::ShellClient>* request) {
- Identity content_handler_identity;
- URLResponsePtr response;
- if (ShouldHandleWithContentHandler(fetcher,
- target_url,
- target_filter,
- &content_handler_identity,
- &response)) {
- ContentHandlerConnection* connection =
- GetContentHandler(content_handler_identity, source);
- connection->StartApplication(std::move(*request), std::move(response));
- return connection->id();
- }
- return mojom::Shell::kInvalidApplicationID;
-}
-
-bool PackageManagerImpl::IsURLInCatalog(const std::string& url) const {
- return catalog_.find(url) != catalog_.end();
-}
-
-std::string PackageManagerImpl::GetApplicationName(
- const std::string& url) const {
- auto it = catalog_.find(url);
- return it != catalog_.end() ? it->second.name : url;
-}
-
-GURL PackageManagerImpl::ResolveMojoURL(const GURL& mojo_url) {
- return ResolveURL(mojo_url);
-}
-
-uint32_t PackageManagerImpl::StartContentHandler(
- const Identity& source,
- const Identity& content_handler,
- const GURL& url,
- mojom::ShellClientRequest request) {
- URLResponsePtr response(URLResponse::New());
- response->url = url.spec();
- ContentHandlerConnection* connection =
- GetContentHandler(content_handler, source);
- connection->StartApplication(std::move(request), std::move(response));
- return connection->id();
-}
-
-GURL PackageManagerImpl::ResolveURL(const GURL& url) {
- return url_resolver_.get() ? url_resolver_->ResolveMojoURL(url) : url;
-}
-
-bool PackageManagerImpl::ShouldHandleWithContentHandler(
- Fetcher* fetcher,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- Identity* content_handler_identity,
- URLResponsePtr* response) const {
- // TODO(beng): it seems like some delegate should/would want to have a say in
- // configuring the qualifier also.
- // Why can't we use the real qualifier in single process mode? Because of
- // base::AtExitManager. If you link in ApplicationRunner into your code, and
- // then we make initialize multiple copies of the application, we end up
- // with multiple AtExitManagers and will check on the second one being
- // created.
- //
- // Why doesn't that happen when running different apps? Because
- // your_thing.mojo!base::AtExitManager and
- // my_thing.mojo!base::AtExitManager are different symbols.
- bool use_real_qualifier = !base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kSingleProcess);
-
- GURL content_handler_url;
- // The response begins with a #!mojo <content-handler-url>.
- std::string shebang;
- if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) {
- *response = fetcher->AsURLResponse(task_runner_,
- static_cast<int>(shebang.size()));
- *content_handler_identity = Identity(
- content_handler_url,
- use_real_qualifier ? (*response)->site.To<std::string>()
- : std::string(),
- target_filter);
- return true;
- }
-
- // The response MIME type matches a registered content handler.
- auto iter = mime_type_to_url_.find(fetcher->MimeType());
- if (iter != mime_type_to_url_.end()) {
- *response = fetcher->AsURLResponse(task_runner_, 0);
- *content_handler_identity = Identity(
- iter->second,
- use_real_qualifier ? (*response)->site.To<std::string>()
- : std::string(),
- target_filter);
- return true;
- }
-
- // The response URL matches a registered content handler.
- auto alias_iter = application_package_alias_.find(target_url);
- if (alias_iter != application_package_alias_.end()) {
- // We replace the qualifier with the one our package alias requested.
- *response = URLResponse::New();
- (*response)->url = target_url.spec();
- *content_handler_identity = Identity(
- alias_iter->second.first,
- use_real_qualifier ? alias_iter->second.second : std::string(),
- target_filter);
- return true;
- }
-
- return false;
-}
-
-ContentHandlerConnection* PackageManagerImpl::GetContentHandler(
- const Identity& content_handler_identity,
- const Identity& source_identity) {
- auto it = identity_to_content_handler_.find(content_handler_identity);
- if (it != identity_to_content_handler_.end())
- return it->second;
-
- ContentHandlerConnection* connection = new ContentHandlerConnection(
- application_manager_, source_identity,
- content_handler_identity,
- ++content_handler_id_counter_,
- base::Bind(&PackageManagerImpl::OnContentHandlerConnectionClosed,
- base::Unretained(this)));
- identity_to_content_handler_[content_handler_identity] = connection;
- return connection;
-}
-
-void PackageManagerImpl::OnContentHandlerConnectionClosed(
- ContentHandlerConnection* connection) {
- // Remove the mapping.
- auto it = identity_to_content_handler_.find(connection->identity());
- DCHECK(it != identity_to_content_handler_.end());
- identity_to_content_handler_.erase(it);
-}
-
-void PackageManagerImpl::EnsureURLInCatalog(const GURL& url) {
- if (IsURLInCatalog(url.spec()) || !url_resolver_)
- return;
-
- GURL manifest_url = url_resolver_->ResolveMojoManifest(url);
- if (manifest_url.is_empty())
- return;
- base::FilePath manifest_path;
- CHECK(net::FileURLToFilePath(manifest_url, &manifest_path));
- base::PostTaskAndReplyWithResult(
- task_runner_, FROM_HERE,
- base::Bind(&PackageManagerImpl::ReadManifest, base::Unretained(this),
- manifest_path),
- base::Bind(&PackageManagerImpl::OnReadManifest,
- base::Unretained(this)));
-}
-
-void PackageManagerImpl::DeserializeCatalog() {
- ApplicationInfo info;
- info.url = "mojo://shell/";
- info.name = "Mojo Shell";
- catalog_[info.url] = info;
-
- if (!catalog_store_)
- return;
- base::ListValue* catalog = nullptr;
- catalog_store_->GetStore(&catalog);
- CHECK(catalog);
- for (auto it = catalog->begin(); it != catalog->end(); ++it) {
- const base::DictionaryValue* dictionary = nullptr;
- const base::Value* v = *it;
- CHECK(v->GetAsDictionary(&dictionary));
- DeserializeApplication(dictionary);
- }
-}
-
-void PackageManagerImpl::SerializeCatalog() {
- scoped_ptr<base::ListValue> catalog(new base::ListValue);
- for (const auto& info : catalog_) {
- base::DictionaryValue* dictionary = nullptr;
- SerializeEntry(info.second, &dictionary);
- catalog->Append(make_scoped_ptr(dictionary));
- }
- if (catalog_store_)
- catalog_store_->UpdateStore(std::move(catalog));
-}
-
-const ApplicationInfo& PackageManagerImpl::DeserializeApplication(
- const base::DictionaryValue* dictionary) {
- ApplicationInfo info = BuildApplicationInfoFromDictionary(*dictionary);
- // If another app refers to this app, then we already added an entry for
- // |info| as a result of reading the first apps manifest.
- if (catalog_.count(info.url))
- return catalog_[info.url];
-
- catalog_[info.url] = info;
-
- if (dictionary->HasKey("applications")) {
- const base::ListValue* applications = nullptr;
- dictionary->GetList("applications", &applications);
- for (size_t i = 0; i < applications->GetSize(); ++i) {
- const base::DictionaryValue* child = nullptr;
- applications->GetDictionary(i, &child);
- const ApplicationInfo& child_info = DeserializeApplication(child);
- GURL child_url(child_info.url);
- RegisterApplicationPackageAlias(child_url, GURL(info.url),
- child_url.host());
- }
- }
- return catalog_[info.url];
-}
-
-scoped_ptr<base::Value> PackageManagerImpl::ReadManifest(
- const base::FilePath& manifest_path) {
- JSONFileValueDeserializer deserializer(manifest_path);
- int error = 0;
- std::string message;
- // TODO(beng): probably want to do more detailed error checking. This should
- // be done when figuring out if to unblock connection completion.
- return deserializer.Deserialize(&error, &message);
-}
-
-void PackageManagerImpl::OnReadManifest(scoped_ptr<base::Value> manifest) {
- if (!manifest)
- return;
-
- base::DictionaryValue* dictionary = nullptr;
- CHECK(manifest->GetAsDictionary(&dictionary));
- DeserializeApplication(dictionary);
- SerializeCatalog();
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/package_manager/package_manager_impl.h b/mojo/shell/package_manager/package_manager_impl.h
deleted file mode 100644
index 69bf5ca..0000000
--- a/mojo/shell/package_manager/package_manager_impl.h
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
-#define MOJO_SHELL_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
-
-#include <stdint.h>
-
-#include "base/files/file_path.h"
-#include "base/macros.h"
-#include "base/values.h"
-#include "mojo/services/network/public/interfaces/network_service.mojom.h"
-#include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
-#include "mojo/shell/fetcher/url_resolver.h"
-#include "mojo/shell/package_manager.h"
-
-namespace base {
-class TaskRunner;
-}
-
-namespace mojo {
-class ContentHandler;
-namespace shell {
-class ContentHandlerConnection;
-class Fetcher;
-class Identity;
-
-// Static information about an application package known to the PackageManager.
-struct ApplicationInfo {
- ApplicationInfo();
- ~ApplicationInfo();
-
- std::string url;
- std::string name;
- CapabilityFilter base_filter;
-};
-
-// Implemented by an object that provides storage for the application catalog
-// (e.g. in Chrome, preferences). The PackageManagerImpl is the canonical owner
-// of the contents of the store, so no one else must modify its contents.
-class ApplicationCatalogStore {
- public:
- // Called during initialization to construct the PackageManagerImpl's catalog.
- virtual void GetStore(base::ListValue** store) = 0;
-
- // Write the catalog to the store. Called when the PackageManagerImpl learns
- // of a newly encountered application.
- virtual void UpdateStore(scoped_ptr<base::ListValue> store) = 0;
-
- protected:
- virtual ~ApplicationCatalogStore();
-};
-
-// This is the default implementation of PackageManager. It loads http/s urls
-// off the network as well as providing special handling for mojo: and about:
-// urls.
-class PackageManagerImpl : public PackageManager {
- public:
- // mojo: urls are only supported if |shell_file_root| is non-empty.
- // |task_runner| is used by Fetchers created by the PackageManager to complete
- // file copies needed to obtain library paths that the ApplicationManager can
- // load. This can be null only in tests where application loading is handled
- // by custom ApplicationLoader implementations.
- PackageManagerImpl(const base::FilePath& shell_file_root,
- base::TaskRunner* task_runner,
- ApplicationCatalogStore* catalog_store);
- ~PackageManagerImpl() override;
-
- // Register a content handler to handle content of |mime_type|.
- void RegisterContentHandler(const std::string& mime_type,
- const GURL& content_handler_url);
-
- // Registers a package alias. When attempting to load |alias|, it will
- // instead redirect to |content_handler_package|, which is a content handler
- // which will be passed the |alias| as the URLResponse::url. Different values
- // of |alias| with the same |qualifier| that are in the same
- // |content_handler_package| will run in the same process in multi-process
- // mode.
- void RegisterApplicationPackageAlias(
- const GURL& alias,
- const GURL& content_handler_package,
- const std::string& qualifier);
-
- private:
- using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>;
- using MimeTypeToURLMap = std::map<std::string, GURL>;
- using IdentityToContentHandlerMap =
- std::map<Identity, ContentHandlerConnection*>;
-
- // Overridden from PackageManager:
- void SetApplicationManager(ApplicationManager* manager) override;
- void BuiltinAppLoaded(const GURL& url) override;
- void FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) override;
- uint32_t HandleWithContentHandler(
- Fetcher* fetcher,
- const Identity& source,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- InterfaceRequest<mojom::ShellClient>* request) override;
- bool IsURLInCatalog(const std::string& url) const override;
- std::string GetApplicationName(const std::string& url) const override;
- GURL ResolveMojoURL(const GURL& mojo_url) override;
- uint32_t StartContentHandler(const Identity& source,
- const Identity& content_handler,
- const GURL& url,
- mojom::ShellClientRequest request) override;
-
- GURL ResolveURL(const GURL& url);
- bool ShouldHandleWithContentHandler(
- Fetcher* fetcher,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- Identity* content_handler_identity,
- URLResponsePtr* response) const;
-
- // Returns a running ContentHandler for |content_handler_identity|, if there
- // is not one running one is started for |source_identity|.
- ContentHandlerConnection* GetContentHandler(
- const Identity& content_handler_identity,
- const Identity& source_identity);
-
- void OnContentHandlerConnectionClosed(
- ContentHandlerConnection* content_handler);
-
- // If |url| is not in the catalog, attempts to load a manifest for it.
- void EnsureURLInCatalog(const GURL& url);
-
- // Populate/serialize the catalog from/to the supplied store.
- void DeserializeCatalog();
- void SerializeCatalog();
-
- // Construct a catalog entry from |dictionary|.
- const ApplicationInfo& DeserializeApplication(
- const base::DictionaryValue* dictionary);
-
- // Reads a manifest in the blocking pool and returns a base::Value with its
- // contents via OnReadManifest().
- scoped_ptr<base::Value> ReadManifest(const base::FilePath& manifest_path);
- void OnReadManifest(scoped_ptr<base::Value> manifest);
-
- ApplicationManager* application_manager_;
- scoped_ptr<URLResolver> url_resolver_;
- const bool disable_cache_;
- NetworkServicePtr network_service_;
- URLLoaderFactoryPtr url_loader_factory_;
- ApplicationPackagedAlias application_package_alias_;
- MimeTypeToURLMap mime_type_to_url_;
- IdentityToContentHandlerMap identity_to_content_handler_;
- // Counter used to assign ids to content handlers.
- uint32_t content_handler_id_counter_;
- base::TaskRunner* task_runner_;
- base::FilePath shell_file_root_;
-
- ApplicationCatalogStore* catalog_store_;
- std::map<std::string, ApplicationInfo> catalog_;
-
- DISALLOW_COPY_AND_ASSIGN(PackageManagerImpl);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
diff --git a/mojo/shell/query_util.cc b/mojo/shell/query_util.cc
deleted file mode 100644
index fbe4c56..0000000
--- a/mojo/shell/query_util.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/query_util.h"
-
-#include "base/strings/string_util.h"
-
-namespace mojo {
-namespace shell {
-
-GURL GetBaseURLAndQuery(const GURL& url, std::string* query) {
- if (!url.has_query()) {
- if (query)
- *query = "";
- return url;
- }
-
- if (query)
- *query = "?" + url.query();
- GURL::Replacements repl;
- repl.SetQueryStr("");
- std::string result = url.ReplaceComponents(repl).spec();
-
- // Remove the dangling '?' because it's ugly.
- base::ReplaceChars(result, "?", "", &result);
- return GURL(result);
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/query_util.h b/mojo/shell/query_util.h
deleted file mode 100644
index a1f0ac7..0000000
--- a/mojo/shell/query_util.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_QUERY_UTIL_H_
-#define MOJO_SHELL_QUERY_UTIL_H_
-
-#include <utility>
-
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-
-// Returns the base URL (without the query string). If |query| is not nullptr,
-// set |*query| to the query string. If the url doesn't have a query string,
-// |*query| is set to the empty string.
-GURL GetBaseURLAndQuery(const GURL& url, std::string* query);
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_QUERY_UTIL_H_
diff --git a/mojo/shell/query_util_unittest.cc b/mojo/shell/query_util_unittest.cc
deleted file mode 100644
index 9b28bc5..0000000
--- a/mojo/shell/query_util_unittest.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/query_util.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace shell {
-namespace {
-
-TEST(QueryUtil, NoQuery) {
- GURL url("http://www.example.com/");
- std::string query;
- GURL base_url = GetBaseURLAndQuery(url, &query);
- EXPECT_EQ(base_url, url);
- EXPECT_EQ(query, "");
-}
-
-TEST(QueryUtil, WithEmptyQuery) {
- GURL url("http://www.example.com/?");
- std::string query;
- GURL base_url = GetBaseURLAndQuery(url, &query);
- EXPECT_EQ(base_url, GURL("http://www.example.com/"));
- EXPECT_EQ(query, "?");
-}
-
-TEST(QueryUtil, WithFullQuery) {
- GURL url("http://www.example.com/?a=b&c=d");
- std::string query;
- GURL base_url = GetBaseURLAndQuery(url, &query);
- EXPECT_EQ(base_url, GURL("http://www.example.com/"));
- EXPECT_EQ(query, "?a=b&c=d");
-}
-
-TEST(QueryUtil, ForFileURL) {
- GURL url("file:///tmp/file?a=b&c=d");
- std::string query;
- GURL base_url = GetBaseURLAndQuery(url, &query);
- EXPECT_EQ(base_url, GURL("file:///tmp/file"));
- EXPECT_EQ(query, "?a=b&c=d");
-}
-
-} // namespace
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/standalone/BUILD.gn b/mojo/shell/standalone/BUILD.gn
index e87bea5..d8a3aca 100644
--- a/mojo/shell/standalone/BUILD.gn
+++ b/mojo/shell/standalone/BUILD.gn
@@ -11,12 +11,6 @@ if (is_android) {
import("//build/config/android/rules.gni")
}
-source_set("register_local_aliases_fwd") {
- sources = [
- "register_local_aliases.h",
- ]
-}
-
# main() entrypoint definition is structured into a static lib for Android's
# benefit, as it is shared between the standalone executable and other
# executables (e.g. Mandoline).
@@ -35,11 +29,7 @@ source_set("main_lib") {
]
if (!is_android) {
- sources += [
- "desktop/main.cc",
- "register_local_aliases.cc",
- "register_local_aliases.h",
- ]
+ sources += [ "desktop/main.cc" ]
deps += [
"//components/tracing:startup_tracing",
"//third_party/icu:icudata",
@@ -74,12 +64,10 @@ executable("standalone") {
if (is_android) {
sources = [
"android/context_init.cc",
- "register_local_aliases.cc",
]
deps += [
":lib",
- ":register_local_aliases_fwd",
"//mojo/edk/system",
]
@@ -112,7 +100,6 @@ source_set("lib") {
"//mojo/services/tracing/public/cpp",
"//mojo/services/tracing/public/interfaces",
"//mojo/shell",
- "//mojo/shell/package_manager",
"//mojo/shell/public/cpp",
"//mojo/shell/runner:init",
"//mojo/shell/runner/child:interfaces",
@@ -204,8 +191,6 @@ if (is_android) {
shared_library("bootstrap") {
sources = [
"android/bootstrap.cc",
- "register_local_aliases.cc",
- "register_local_aliases.h",
]
deps = [
":jni_headers",
diff --git a/mojo/shell/standalone/context.cc b/mojo/shell/standalone/context.cc
index 921ab99..adc285d 100644
--- a/mojo/shell/standalone/context.cc
+++ b/mojo/shell/standalone/context.cc
@@ -33,11 +33,8 @@
#include "mojo/services/tracing/public/interfaces/tracing.mojom.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/connect_to_application_params.h"
-#include "mojo/shell/package_manager/package_manager_impl.h"
-#include "mojo/shell/query_util.h"
#include "mojo/shell/runner/host/in_process_native_runner.h"
#include "mojo/shell/runner/host/out_of_process_native_runner.h"
-#include "mojo/shell/standalone/register_local_aliases.h"
#include "mojo/shell/standalone/switches.h"
#include "mojo/shell/standalone/tracer.h"
#include "mojo/shell/switches.h"
@@ -59,59 +56,6 @@ class Setup {
DISALLOW_COPY_AND_ASSIGN(Setup);
};
-void InitContentHandlers(PackageManagerImpl* manager,
- const base::CommandLine& command_line) {
- // Default content handlers.
- manager->RegisterContentHandler("application/javascript",
- GURL("mojo:html_viewer"));
- manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer"));
- manager->RegisterContentHandler("image/gif", GURL("mojo:html_viewer"));
- manager->RegisterContentHandler("image/jpeg", GURL("mojo:html_viewer"));
- manager->RegisterContentHandler("image/png", GURL("mojo:html_viewer"));
- manager->RegisterContentHandler("text/css", GURL("mojo:html_viewer"));
- manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer"));
- manager->RegisterContentHandler("text/plain", GURL("mojo:html_viewer"));
-
- // Command-line-specified content handlers.
- std::string handlers_spec =
- command_line.GetSwitchValueASCII(switches::kContentHandlers);
- if (handlers_spec.empty())
- return;
-
-#if defined(OS_ANDROID)
- // TODO(eseidel): On Android we pass command line arguments is via the
- // 'parameters' key on the intent, which we specify during 'am shell start'
- // via --esa, however that expects comma-separated values and says:
- // am shell --help:
- // [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
- // (to embed a comma into a string escape it using "\,")
- // Whatever takes 'parameters' and constructs a CommandLine is failing to
- // un-escape the commas, we need to move this fix to that file.
- base::ReplaceSubstringsAfterOffset(&handlers_spec, 0, "\\,", ",");
-#endif
-
- std::vector<std::string> parts = base::SplitString(
- handlers_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- if (parts.size() % 2 != 0) {
- LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
- << ": must be a comma-separated list of mimetype/url pairs."
- << handlers_spec;
- return;
- }
-
- for (size_t i = 0; i < parts.size(); i += 2) {
- GURL url(parts[i + 1]);
- if (!url.is_valid()) {
- LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
- << ": '" << parts[i + 1] << "' is not a valid URL.";
- return;
- }
- // TODO(eseidel): We should also validate that the mimetype is valid
- // net/base/mime_util.h could do this, but we don't want to depend on net.
- manager->RegisterContentHandler(parts[i], url);
- }
-}
-
class TracingInterfaceProvider : public shell::mojom::InterfaceProvider {
public:
TracingInterfaceProvider(Tracer* tracer,
@@ -137,8 +81,7 @@ class TracingInterfaceProvider : public shell::mojom::InterfaceProvider {
} // namespace
-Context::Context()
- : package_manager_(nullptr), main_entry_time_(base::Time::Now()) {}
+Context::Context() : main_entry_time_(base::Time::Now()) {}
Context::~Context() {
DCHECK(!base::MessageLoop::current());
@@ -170,12 +113,6 @@ void Context::Init(const base::FilePath& shell_file_root) {
// TODO(vtl): This should be MASTER, not NONE.
edk::InitIPCSupport(this, task_runners_->io_runner());
- package_manager_ = new PackageManagerImpl(
- shell_file_root, task_runners_->blocking_pool(), nullptr);
- InitContentHandlers(package_manager_, command_line);
-
- RegisterLocalAliases(package_manager_);
-
scoped_ptr<NativeRunnerFactory> runner_factory;
if (command_line.HasSwitch(switches::kSingleProcess)) {
#if defined(COMPONENT_BUILD)
@@ -190,8 +127,7 @@ void Context::Init(const base::FilePath& shell_file_root) {
new OutOfProcessNativeRunnerFactory(task_runners_->blocking_pool()));
}
application_manager_.reset(new ApplicationManager(
- make_scoped_ptr(package_manager_), std::move(runner_factory),
- task_runners_->blocking_pool(), true));
+ std::move(runner_factory), task_runners_->blocking_pool(), true));
shell::mojom::InterfaceProviderPtr tracing_remote_interfaces;
shell::mojom::InterfaceProviderPtr tracing_local_interfaces;
diff --git a/mojo/shell/standalone/context.h b/mojo/shell/standalone/context.h
index fc923d2..f87b82c 100644
--- a/mojo/shell/standalone/context.h
+++ b/mojo/shell/standalone/context.h
@@ -21,7 +21,6 @@
namespace mojo {
namespace shell {
class NativeApplicationLoader;
-class PackageManagerImpl;
// The "global" context for the shell's main process.
class Context : public edk::ProcessDelegate {
@@ -52,8 +51,6 @@ class Context : public edk::ProcessDelegate {
return application_manager_.get();
}
- PackageManagerImpl* package_manager() { return package_manager_; }
-
private:
class NativeViewportApplicationLoader;
@@ -68,8 +65,6 @@ class Context : public edk::ProcessDelegate {
// Ensure this is destructed before task_runners_ since it owns a message pipe
// that needs the IO thread to destruct cleanly.
Tracer tracer_;
- // Owned by |application_manager_|.
- PackageManagerImpl* package_manager_;
scoped_ptr<ApplicationManager> application_manager_;
base::Closure app_complete_callback_;
base::Time main_entry_time_;
diff --git a/mojo/shell/standalone/register_local_aliases.cc b/mojo/shell/standalone/register_local_aliases.cc
deleted file mode 100644
index 0b43bd8..0000000
--- a/mojo/shell/standalone/register_local_aliases.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/shell/standalone/register_local_aliases.h"
-
-namespace mojo {
-namespace shell {
-
-void RegisterLocalAliases(PackageManagerImpl* manager) {}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/standalone/register_local_aliases.h b/mojo/shell/standalone/register_local_aliases.h
deleted file mode 100644
index 5211587..0000000
--- a/mojo/shell/standalone/register_local_aliases.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_STANDALONE_REGISTER_LOCAL_ALIASES_H_
-#define MOJO_SHELL_STANDALONE_REGISTER_LOCAL_ALIASES_H_
-
-namespace mojo {
-namespace shell {
-class PackageManagerImpl;
-
-void RegisterLocalAliases(PackageManagerImpl* manager);
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_STANDALONE_REGISTER_LOCAL_ALIASES_H_
diff --git a/mojo/shell/switches.cc b/mojo/shell/switches.cc
index 30c5ba6..8c49a12 100644
--- a/mojo/shell/switches.cc
+++ b/mojo/shell/switches.cc
@@ -7,9 +7,6 @@
namespace mojo {
namespace switches {
-// Uses the mojo:package_manager application instead of the builtin one.
-const char kDontUseRemotePackageManager[] = "dont-use-remote-package-manager";
-
// Disables the sandbox for debugging.
const char kNoSandbox[] = "no-sandbox";
diff --git a/mojo/shell/switches.h b/mojo/shell/switches.h
index c5ecb30..1bbd21f 100644
--- a/mojo/shell/switches.h
+++ b/mojo/shell/switches.h
@@ -13,7 +13,6 @@ namespace switches {
// All switches in alphabetical order. The switches should be documented
// alongside the definition of their values in the .cc file.
-extern const char kDontUseRemotePackageManager[];
extern const char kNoSandbox[];
extern const char kPredictableAppFilenames[];
extern const char kSingleProcess[];
diff --git a/mojo/shell/test_package_manager.cc b/mojo/shell/test_package_manager.cc
deleted file mode 100644
index a388e20..0000000
--- a/mojo/shell/test_package_manager.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stdint.h>
-
-#include "mojo/shell/test_package_manager.h"
-
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-namespace test {
-
-TestPackageManager::TestPackageManager() {}
-TestPackageManager::~TestPackageManager() {}
-
-void TestPackageManager::SetApplicationManager(ApplicationManager* manager) {}
-void TestPackageManager::BuiltinAppLoaded(const GURL& url) {}
-void TestPackageManager::FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) {}
-uint32_t TestPackageManager::HandleWithContentHandler(
- Fetcher* fetcher,
- const Identity& source,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- InterfaceRequest<shell::mojom::ShellClient>* request) {
- return 0;
-}
-bool TestPackageManager::IsURLInCatalog(const std::string& url) const {
- return true;
-}
-std::string TestPackageManager::GetApplicationName(
- const std::string& url) const { return url; }
-GURL TestPackageManager::ResolveMojoURL(const GURL& mojo_url) {
- return mojo_url;
-}
-uint32_t TestPackageManager::StartContentHandler(
- const Identity& source,
- const Identity& content_handler,
- const GURL& url,
- mojom::ShellClientRequest request) {
- return mojo::shell::mojom::Shell::kInvalidApplicationID;
-}
-
-} // namespace test
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/test_package_manager.h b/mojo/shell/test_package_manager.h
deleted file mode 100644
index 2d38cab..0000000
--- a/mojo/shell/test_package_manager.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SHELL_TEST_PACKAGE_MANAGER_H_
-#define MOJO_SHELL_TEST_PACKAGE_MANAGER_H_
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "mojo/shell/package_manager.h"
-
-namespace mojo {
-namespace shell {
-namespace test {
-
-class TestPackageManager : public PackageManager {
- public:
- TestPackageManager();
- ~TestPackageManager() override;
-
- private:
- // Overridden from PackageManager:
- void SetApplicationManager(ApplicationManager* manager) override;
- void BuiltinAppLoaded(const GURL& url) override;
- void FetchRequest(
- URLRequestPtr request,
- const Fetcher::FetchCallback& loader_callback) override;
- uint32_t HandleWithContentHandler(
- Fetcher* fetcher,
- const Identity& source,
- const GURL& target_url,
- const CapabilityFilter& target_filter,
- InterfaceRequest<shell::mojom::ShellClient>* request)
- override;
- bool IsURLInCatalog(const std::string& url) const override;
- std::string GetApplicationName(const std::string& url) const override;
- GURL ResolveMojoURL(const GURL& mojo_url) override;
- uint32_t StartContentHandler(const Identity& source,
- const Identity& content_handler,
- const GURL& url,
- mojom::ShellClientRequest request) override;
-
- DISALLOW_COPY_AND_ASSIGN(TestPackageManager);
-};
-
-} // namespace test
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_TEST_PACKAGE_MANAGER_H_