Commit 773d00ff authored by erg's avatar erg Committed by Commit bot

core_services: Selectively move network_service to core_services.

This moves the network_service to the core_services package, but only
on non-android platforms. (Android does some sort of odd packaging
steps that I don't understand.)

BUG=477435

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

Cr-Commit-Position: refs/heads/master@{#329189}
parent db072b1c
...@@ -14,6 +14,10 @@ void InitCoreServicesForContext(mojo::runner::Context* context) { ...@@ -14,6 +14,10 @@ void InitCoreServicesForContext(mojo::runner::Context* context) {
mojo::shell::ApplicationManager* manager = context->application_manager(); mojo::shell::ApplicationManager* manager = context->application_manager();
manager->RegisterApplicationPackageAlias(GURL("mojo:clipboard"), manager->RegisterApplicationPackageAlias(GURL("mojo:clipboard"),
GURL("mojo:core_services")); GURL("mojo:core_services"));
#if !defined(OS_ANDROID)
manager->RegisterApplicationPackageAlias(GURL("mojo:network_service"),
GURL("mojo:core_services"));
#endif
manager->RegisterApplicationPackageAlias(GURL("mojo:tracing"), manager->RegisterApplicationPackageAlias(GURL("mojo:tracing"),
GURL("mojo:core_services")); GURL("mojo:core_services"));
manager->RegisterApplicationPackageAlias(GURL("mojo:view_manager"), manager->RegisterApplicationPackageAlias(GURL("mojo:view_manager"),
......
...@@ -28,4 +28,10 @@ mojo_native_application("core_services") { ...@@ -28,4 +28,10 @@ mojo_native_application("core_services") {
"//third_party/mojo/src/mojo/public/cpp/bindings:bindings", "//third_party/mojo/src/mojo/public/cpp/bindings:bindings",
"//third_party/mojo_services/src/content_handler/public/interfaces", "//third_party/mojo_services/src/content_handler/public/interfaces",
] ]
# TODO(erg): The android network service has some weirdness to let it link
# with java stuff. Someone who understand how that works should look at this.
if (!is_android) {
deps += [ "//mojo/services/network:lib" ]
}
} }
...@@ -4,6 +4,7 @@ include_rules = [ ...@@ -4,6 +4,7 @@ include_rules = [
"+components/view_manager", "+components/view_manager",
"+mojo/application", "+mojo/application",
"+mojo/common", "+mojo/common",
"+mojo/services/network",
"+mojo/services/tracing", "+mojo/services/tracing",
"+third_party/mojo_services/src/clipboard", "+third_party/mojo_services/src/clipboard",
"+third_party/mojo/src/mojo/public", "+third_party/mojo/src/mojo/public",
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(OS_ANDROID)
#include "mojo/services/network/network_service_delegate.h"
#endif
namespace core_services { namespace core_services {
class ApplicationThread; class ApplicationThread;
...@@ -121,6 +125,10 @@ void CoreServicesApplicationDelegate::StartApplication( ...@@ -121,6 +125,10 @@ void CoreServicesApplicationDelegate::StartApplication(
scoped_ptr<mojo::ApplicationDelegate> delegate; scoped_ptr<mojo::ApplicationDelegate> delegate;
if (url == "mojo://clipboard/") if (url == "mojo://clipboard/")
delegate.reset(new clipboard::ClipboardApplicationDelegate); delegate.reset(new clipboard::ClipboardApplicationDelegate);
#if !defined(OS_ANDROID)
else if (url == "mojo://network_service/")
delegate.reset(new NetworkServiceDelegate);
#endif
else if (url == "mojo://tracing/") else if (url == "mojo://tracing/")
delegate.reset(new tracing::TracingApp); delegate.reset(new tracing::TracingApp);
else if (url == "mojo://view_manager/") else if (url == "mojo://view_manager/")
...@@ -130,10 +138,16 @@ void CoreServicesApplicationDelegate::StartApplication( ...@@ -130,10 +138,16 @@ void CoreServicesApplicationDelegate::StartApplication(
else else
NOTREACHED() << "This application package does not support " << url; NOTREACHED() << "This application package does not support " << url;
// We must use a MessagePumpMojo to awake on mojo messages.
base::Thread::Options thread_options; base::Thread::Options thread_options;
thread_options.message_pump_factory =
base::Bind(&mojo::common::MessagePumpMojo::Create); // In the case of mojo:network_service, we must use an IO message loop.
if (url == "mojo://network_service/") {
thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
} else {
// We must use a MessagePumpMojo to awake on mojo messages.
thread_options.message_pump_factory =
base::Bind(&mojo::common::MessagePumpMojo::Create);
}
scoped_ptr<ApplicationThread> thread( scoped_ptr<ApplicationThread> thread(
new ApplicationThread(url, delegate.Pass(), request.Pass())); new ApplicationThread(url, delegate.Pass(), request.Pass()));
......
...@@ -56,6 +56,8 @@ source_set("lib") { ...@@ -56,6 +56,8 @@ source_set("lib") {
"net_address_type_converters.h", "net_address_type_converters.h",
"network_context.cc", "network_context.cc",
"network_context.h", "network_context.h",
"network_service_delegate.cc",
"network_service_delegate.h",
"network_service_impl.cc", "network_service_impl.cc",
"network_service_impl.h", "network_service_impl.h",
"tcp_bound_socket_impl.cc", "tcp_bound_socket_impl.cc",
...@@ -89,7 +91,7 @@ source_set("sources") { ...@@ -89,7 +91,7 @@ source_set("sources") {
visibility = [ ":*" ] visibility = [ ":*" ]
sources = [ sources = [
"network_service.cc", "main.cc",
] ]
deps = [ deps = [
......
// 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 "base/message_loop/message_loop.h"
#include "mojo/application/application_runner_chromium.h"
#include "mojo/services/network/network_service_delegate.h"
#include "third_party/mojo/src/mojo/public/c/system/main.h"
MojoResult MojoMain(MojoHandle shell_handle) {
mojo::ApplicationRunnerChromium runner(new NetworkServiceDelegate);
runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
return runner.Run(shell_handle);
}
// 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/services/network/network_service_delegate.h"
#include "base/at_exit.h"
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "third_party/mojo/src/mojo/public/cpp/application/application_connection.h"
NetworkServiceDelegate::NetworkServiceDelegate() {}
NetworkServiceDelegate::~NetworkServiceDelegate() {}
void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) {
base::FilePath base_path;
CHECK(PathService::Get(base::DIR_TEMP, &base_path));
base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
context_.reset(new mojo::NetworkContext(base_path));
}
bool NetworkServiceDelegate::ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) {
DCHECK(context_);
connection->AddService(this);
return true;
}
void NetworkServiceDelegate::Quit() {
// Destroy the NetworkContext now as it requires MessageLoop::current() upon
// destruction and it is the last moment we know for sure that it is
// running.
context_.reset();
}
void NetworkServiceDelegate::Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NetworkService> request) {
mojo::BindToRequest(
new mojo::NetworkServiceImpl(connection, context_.get()), &request);
}
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/at_exit.h" #ifndef MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
#include "base/base_paths.h" #define MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
#include "base/command_line.h"
#include "base/files/file_path.h" #include "mojo/public/cpp/application/application_impl.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "mojo/application/application_runner_chromium.h"
#include "mojo/services/network/network_context.h" #include "mojo/services/network/network_context.h"
#include "mojo/services/network/network_service_impl.h" #include "mojo/services/network/network_service_impl.h"
#include "third_party/mojo/src/mojo/public/c/system/main.h"
#include "third_party/mojo/src/mojo/public/cpp/application/application_connection.h"
#include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.h" #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.h"
#include "third_party/mojo/src/mojo/public/cpp/application/interface_factory.h" #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h"
...@@ -20,42 +15,23 @@ ...@@ -20,42 +15,23 @@
class NetworkServiceDelegate class NetworkServiceDelegate
: public mojo::ApplicationDelegate, : public mojo::ApplicationDelegate,
public mojo::InterfaceFactory<mojo::NetworkService> { public mojo::InterfaceFactory<mojo::NetworkService> {
private: public:
void Initialize(mojo::ApplicationImpl* app) override { NetworkServiceDelegate();
base::FilePath base_path; ~NetworkServiceDelegate() override;
CHECK(PathService::Get(base::DIR_TEMP, &base_path));
base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
context_.reset(new mojo::NetworkContext(base_path));
}
private:
// mojo::ApplicationDelegate implementation. // mojo::ApplicationDelegate implementation.
void Initialize(mojo::ApplicationImpl* app) override;
bool ConfigureIncomingConnection( bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override { mojo::ApplicationConnection* connection) override;
DCHECK(context_); void Quit() override;
connection->AddService(this);
return true;
}
void Quit() override {
// Destroy the NetworkContext now as it requires MessageLoop::current() upon
// destruction and it is the last moment we know for sure that it is
// running.
context_.reset();
}
// mojo::InterfaceFactory<mojo::NetworkService> implementation. // mojo::InterfaceFactory<mojo::NetworkService> implementation.
void Create(mojo::ApplicationConnection* connection, void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NetworkService> request) override { mojo::InterfaceRequest<mojo::NetworkService> request) override;
mojo::BindToRequest(
new mojo::NetworkServiceImpl(connection, context_.get()), &request);
}
private: private:
scoped_ptr<mojo::NetworkContext> context_; scoped_ptr<mojo::NetworkContext> context_;
}; };
MojoResult MojoMain(MojoHandle shell_handle) { #endif // MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
mojo::ApplicationRunnerChromium runner(new NetworkServiceDelegate);
runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
return runner.Run(shell_handle);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment