Skip to content

Commit

Permalink
Move fetching logic out of ApplicationManager, eliminate url mappings.
Browse files Browse the repository at this point in the history
BUG=

Review URL: https://codereview.chromium.org/1342503003

Cr-Commit-Position: refs/heads/master@{#348659}
  • Loading branch information
ben authored and Commit bot committed Sep 14, 2015
1 parent 4717575 commit 7134773
Show file tree
Hide file tree
Showing 48 changed files with 635 additions and 938 deletions.
5 changes: 4 additions & 1 deletion components/web_view/test_runner/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "mojo/runner/context.h"
#include "url/gurl.h"

namespace web_view {

int LaunchTestRunner(int argc, char** argv) {
base::FilePath shell_dir;
PathService::Get(base::DIR_MODULE, &shell_dir);
// We want the runner::Context to outlive the MessageLoop so that pipes are
// all gracefully closed / error-out before we try to shut the Context down.
mojo::runner::Context shell_context;
mojo::runner::Context shell_context(shell_dir);
{
base::MessageLoop message_loop;
if (!shell_context.Init()) {
Expand Down
1 change: 1 addition & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ source_set("browser") {
"//mojo/application/public/cpp:cpp_for_chromium",
"//mojo/application/public/interfaces",
"//mojo/common",
"//mojo/fetcher",
"//mojo/shell",
"//net",
"//net:extras",
Expand Down
26 changes: 10 additions & 16 deletions content/browser/mojo/mojo_shell_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "content/common/process_control.mojom.h"
Expand All @@ -17,6 +18,7 @@
#include "content/public/common/service_registry.h"
#include "mojo/application/public/cpp/application_delegate.h"
#include "mojo/common/url_type_converters.h"
#include "mojo/fetcher/base_application_fetcher.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/connect_to_application_params.h"
#include "mojo/shell/identity.h"
Expand Down Expand Up @@ -152,10 +154,16 @@ void MojoShellContext::SetApplicationsForTest(
g_applications_for_test = apps;
}

MojoShellContext::MojoShellContext()
: application_manager_(new mojo::shell::ApplicationManager(this)) {
MojoShellContext::MojoShellContext() {
proxy_.Get().reset(new Proxy(this));

// Construct with an empty filepath since mojo: urls can't be registered now
// the url scheme registry is locked.
scoped_ptr<mojo::fetcher::BaseApplicationFetcher> fetcher(
new mojo::fetcher::BaseApplicationFetcher(base::FilePath()));
application_manager_.reset(
new mojo::shell::ApplicationManager(fetcher.Pass()));

application_manager_->set_default_loader(
scoped_ptr<mojo::shell::ApplicationLoader>(new DefaultApplicationLoader));

Expand Down Expand Up @@ -240,18 +248,4 @@ void MojoShellContext::ConnectToApplicationOnOwnThread(
application_manager_->ConnectToApplication(params.Pass());
}

GURL MojoShellContext::ResolveMappings(const GURL& url) {
return url;
}

GURL MojoShellContext::ResolveMojoURL(const GURL& url) {
return url;
}

bool MojoShellContext::CreateFetcher(
const GURL& url,
const mojo::shell::Fetcher::FetchCallback& loader_callback) {
return false;
}

} // namespace content
12 changes: 2 additions & 10 deletions content/browser/mojo/mojo_shell_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ namespace content {

// MojoShellContext hosts the browser's ApplicationManager, coordinating
// app registration and interconnection.
class CONTENT_EXPORT MojoShellContext
: public NON_EXPORTED_BASE(mojo::shell::ApplicationManager::Delegate) {
class CONTENT_EXPORT MojoShellContext {
public:
using StaticApplicationMap =
std::map<GURL, base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>>;

MojoShellContext();
~MojoShellContext() override;
~MojoShellContext();

// Connects an application at |url| and gets a handle to its exposed services.
// This is only intended for use in browser code that's not part of some Mojo
Expand Down Expand Up @@ -61,13 +60,6 @@ class CONTENT_EXPORT MojoShellContext
const mojo::shell::CapabilityFilter& filter,
const mojo::Shell::ConnectToApplicationCallback& callback);

// mojo::shell::ApplicationManager::Delegate:
GURL ResolveMappings(const GURL& url) override;
GURL ResolveMojoURL(const GURL& url) override;
bool CreateFetcher(
const GURL& url,
const mojo::shell::Fetcher::FetchCallback& loader_callback) override;

static base::LazyInstance<scoped_ptr<Proxy>> proxy_;

scoped_ptr<mojo::shell::ApplicationManager> application_manager_;
Expand Down
1 change: 1 addition & 0 deletions content/content_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'../mojo/mojo_services.gyp:network_service_bindings_lib',
'../mojo/mojo_services.gyp:updater_bindings_lib',
'../mojo/mojo_shell.gyp:mojo_shell_lib',
'../mojo/mojo_shell.gyp:mojo_fetcher_lib',
'../net/net.gyp:net',
'../net/net.gyp:net_extras',
'../skia/skia.gyp:skia',
Expand Down
5 changes: 4 additions & 1 deletion mandoline/app/desktop/launcher_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/synchronization/waitable_event.h"
#include "base/trace_event/trace_event.h"
#include "components/tracing/trace_config_file.h"
Expand Down Expand Up @@ -99,7 +100,9 @@ int LauncherProcessMain(int argc, char** argv) {

// We want the runner::Context to outlive the MessageLoop so that pipes are
// all gracefully closed / error-out before we try to shut the Context down.
mojo::runner::Context shell_context;
base::FilePath shell_dir;
PathService::Get(base::DIR_MODULE, &shell_dir);
mojo::runner::Context shell_context(shell_dir);
InitCoreServicesForContext(&shell_context);
{
base::MessageLoop message_loop;
Expand Down
43 changes: 43 additions & 0 deletions mojo/fetcher/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")

source_set("fetcher") {
sources = [
"about_fetcher.cc",
"about_fetcher.h",
"base_application_fetcher.cc",
"base_application_fetcher.h",
"local_fetcher.cc",
"local_fetcher.h",
"network_fetcher.cc",
"network_fetcher.h",
"switches.cc",
"switches.h",
"update_fetcher.cc",
"update_fetcher.h",
"url_resolver.cc",
"url_resolver.h",
]

public_deps = [
"//base",
"//mojo/application/public/interfaces",
"//mojo/common",
"//third_party/mojo/src/mojo/public/cpp/bindings",
"//mojo/services/network/public/interfaces",
"//mojo/services/updater",
"//url",
]
deps = [
"//base/third_party/dynamic_annotations",
"//crypto:crypto",
"//mojo/application/public/cpp:sources",
"//url",
"//third_party/mojo/src/mojo/edk/system",
"//mojo/environment:chromium",
"//mojo/util:filename_util",
]
}
10 changes: 10 additions & 0 deletions mojo/fetcher/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include_rules = [
"+crypto",
"-mojo/runner",
]

specific_include_rules = {
"about_fetcher_unittest.cc": [
"+mojo/runner/context.h"
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/runner/about_fetcher.h"
#include "mojo/fetcher/about_fetcher.h"

#include "base/bind.h"
#include "base/files/file_path.h"
Expand All @@ -11,7 +11,7 @@
#include "base/message_loop/message_loop.h"

namespace mojo {
namespace runner {
namespace fetcher {
namespace {

void RunFetcherCallback(const shell::Fetcher::FetchCallback& callback,
Expand Down Expand Up @@ -107,5 +107,5 @@ bool AboutFetcher::PeekFirstLine(std::string* line) {
return false;
}

} // namespace runner
} // namespace fetcher
} // namespace mojo
10 changes: 5 additions & 5 deletions mojo/runner/about_fetcher.h → mojo/fetcher/about_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_RUNNER_ABOUT_FETCHER_H_
#define MOJO_RUNNER_ABOUT_FETCHER_H_
#ifndef MOJO_FETCHER_ABOUT_FETCHER_H_
#define MOJO_FETCHER_ABOUT_FETCHER_H_

#include "mojo/shell/fetcher.h"

Expand All @@ -12,7 +12,7 @@
#include "url/gurl.h"

namespace mojo {
namespace runner {
namespace fetcher {

// Implements Fetcher for about: URLs.
class AboutFetcher : public shell::Fetcher {
Expand Down Expand Up @@ -52,7 +52,7 @@ class AboutFetcher : public shell::Fetcher {
DISALLOW_COPY_AND_ASSIGN(AboutFetcher);
};

} // namespace runner
} // namespace fetcher
} // namespace mojo

#endif // MOJO_RUNNER_ABOUT_FETCHER_H_
#endif // MOJO_FETCHER_ABOUT_FETCHER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
#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/application/public/cpp/application_connection.h"
#include "mojo/application/public/cpp/application_delegate.h"
#include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/application/public/interfaces/content_handler.mojom.h"
#include "mojo/common/weak_binding_set.h"
#include "mojo/runner/about_fetcher.h"
#include "mojo/fetcher/about_fetcher.h"
#include "mojo/fetcher/base_application_fetcher.h"
#include "mojo/runner/context.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/application_manager.h"
#include "mojo/util/filename_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {
namespace runner {
namespace fetcher {
namespace {

class TestContentHandler : public ApplicationDelegate,
Expand Down Expand Up @@ -67,30 +70,6 @@ class TestContentHandler : public ApplicationDelegate,
DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
};

class TestApplicationManagerDelegate
: public shell::ApplicationManager::Delegate {
public:
TestApplicationManagerDelegate() {}
~TestApplicationManagerDelegate() override {}

private:
// Overridden from ApplicationManager::Delegate:
GURL ResolveMappings(const GURL& url) override { return url; }
GURL ResolveMojoURL(const GURL& url) override { return url; }
bool CreateFetcher(
const GURL& url,
const shell::Fetcher::FetchCallback& loader_callback) override {
if (url.SchemeIs(AboutFetcher::kAboutScheme)) {
AboutFetcher::Start(url, loader_callback);
return true;
}

return false;
}

DISALLOW_COPY_AND_ASSIGN(TestApplicationManagerDelegate);
};

class TestLoader : public shell::ApplicationLoader {
public:
explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
Expand Down Expand Up @@ -143,8 +122,11 @@ class AboutFetcherTest : public testing::Test {

// Overridden from testing::Test:
void SetUp() override {
Context::EnsureEmbedderIsInitialized();
application_manager_.reset(new shell::ApplicationManager(&test_delegate_));
runner::Context::EnsureEmbedderIsInitialized();
base::FilePath shell_dir;
PathService::Get(base::DIR_MODULE, &shell_dir);
application_manager_.reset(new shell::ApplicationManager(
make_scoped_ptr(new BaseApplicationFetcher(shell_dir))));
application_manager_->SetLoaderForURL(
make_scoped_ptr(new TestLoader(&html_content_handler_)),
GURL("test:html_content_handler"));
Expand All @@ -156,7 +138,6 @@ class AboutFetcherTest : public testing::Test {

private:
base::ShadowingAtExitManager at_exit_;
TestApplicationManagerDelegate test_delegate_;
TestContentHandler html_content_handler_;
base::MessageLoop loop_;
scoped_ptr<shell::ApplicationManager> application_manager_;
Expand All @@ -183,5 +164,5 @@ TEST_F(AboutFetcherTest, UnrecognizedURL) {
}

} // namespace
} // namespace runner
} // namespace fetcher
} // namespace mojo
Loading

0 comments on commit 7134773

Please sign in to comment.