Commit e856849f authored by Ken Rockot's avatar Ken Rockot Committed by Chromium LUCI CQ

Move ServiceManagerConnection into //chromecast

Also delete a bunch of dead code within.

Bug: 977637
Change-Id: Ieeb45f102332bf06568ab83b7183769b3da2fdf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568612
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834485}
parent eedfa790
......@@ -159,6 +159,7 @@ cast_source_set("browser_base") {
"service/cast_service_simple.h",
"service_connector.cc",
"service_connector.h",
"service_manager_connection.cc",
"service_manager_connection.h",
"service_manager_context.cc",
"service_manager_context.h",
......
......@@ -5,13 +5,82 @@
#ifndef CHROMECAST_BROWSER_SERVICE_MANAGER_CONNECTION_H_
#define CHROMECAST_BROWSER_SERVICE_MANAGER_CONNECTION_H_
#include "content/public/common/service_manager_connection.h"
#include <memory>
#include <string>
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/connector.mojom-forward.h"
#include "services/service_manager/public/mojom/service.mojom-forward.h"
namespace service_manager {
class Connector;
}
namespace chromecast {
// Temporary alias until the downstream internal repository can update its
// #includes to reference this file rather than the one in Content.
using ServiceManagerConnection = content::ServiceManagerConnection;
// Encapsulates a connection to a //services/service_manager.
// Access a global instance on the thread the ServiceContext was bound by
// calling Holder::Get().
// Clients can add service_manager::Service implementations whose exposed
// interfaces
// will be exposed to inbound connections to this object's Service.
// Alternatively clients can define named services that will be constructed when
// requests for those service names are received.
class ServiceManagerConnection {
public:
ServiceManagerConnection(
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
ServiceManagerConnection(const ServiceManagerConnection&) = delete;
ServiceManagerConnection& operator=(const ServiceManagerConnection) = delete;
~ServiceManagerConnection();
// Stores an instance of |connection| in TLS for the current process. Must be
// called on the thread the connection was created on.
static void SetForProcess(
std::unique_ptr<ServiceManagerConnection> connection);
// Returns the per-process instance, or nullptr if the Service Manager
// connection has not yet been bound. Must be called on the thread the
// connection was created on.
static ServiceManagerConnection* GetForProcess();
// Destroys the per-process instance. Must be called on the thread the
// connection was created on.
static void DestroyForProcess();
// Creates a ServiceManagerConnection from |request|. The connection binds
// its interfaces and accept new connections on |io_task_runner| only. Note
// that no incoming connections are accepted until Start() is called.
static std::unique_ptr<ServiceManagerConnection> Create(
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
// Begins accepting incoming connections.
void Start();
// Returns the service_manager::Connector received via this connection's
// Service
// implementation. Use this to initiate connections as this object's Identity.
service_manager::Connector* GetConnector();
private:
class IOThreadContext;
void OnConnectionLost();
void GetInterface(service_manager::mojom::InterfaceProvider* provider,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle);
std::unique_ptr<service_manager::Connector> connector_;
scoped_refptr<IOThreadContext> context_;
base::WeakPtrFactory<ServiceManagerConnection> weak_factory_{this};
};
} // namespace chromecast
......
......@@ -134,8 +134,6 @@ source_set("common") {
"pepper_renderer_instance_data.h",
"process_type.cc",
"resource_messages.h",
"service_manager/service_manager_connection_impl.cc",
"service_manager/service_manager_connection_impl.h",
"service_worker/service_worker_loader_helpers.cc",
"service_worker/service_worker_loader_helpers.h",
"service_worker/service_worker_utils.cc",
......
// Copyright 2016 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 CONTENT_COMMON_SERVICE_MANAGER_SERVICE_MANAGER_CONNECTION_IMPL_H_
#define CONTENT_COMMON_SERVICE_MANAGER_SERVICE_MANAGER_CONNECTION_IMPL_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "content/common/content_export.h"
#include "content/public/common/service_manager_connection.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/mojom/service.mojom.h"
namespace service_manager {
class Connector;
}
namespace content {
class CONTENT_EXPORT ServiceManagerConnectionImpl
: public ServiceManagerConnection {
public:
explicit ServiceManagerConnectionImpl(
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
~ServiceManagerConnectionImpl() override;
private:
class IOThreadContext;
// ServiceManagerConnection:
void Start() override;
void Stop() override;
service_manager::Connector* GetConnector() override;
void SetConnectionLostClosure(base::OnceClosure closure) override;
void AddServiceRequestHandler(
const std::string& name,
const ServiceRequestHandler& handler) override;
void AddServiceRequestHandlerWithCallback(
const std::string& name,
const ServiceRequestHandlerWithCallback& handler) override;
void SetDefaultServiceRequestHandler(
const DefaultServiceRequestHandler& handler) override;
void OnConnectionLost();
void GetInterface(service_manager::mojom::InterfaceProvider* provider,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle request_handle);
std::unique_ptr<service_manager::Connector> connector_;
scoped_refptr<IOThreadContext> context_;
base::OnceClosure connection_lost_handler_;
base::WeakPtrFactory<ServiceManagerConnectionImpl> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnectionImpl);
};
} // namespace content
#endif // CONTENT_COMMON_SERVICE_MANAGER_SERVICE_MANAGER_CONNECTION_IMPL_H_
// Copyright 2017 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 "content/common/service_manager/service_manager_connection_impl.h"
#include "base/callback_helpers.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/constants.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/cpp/service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace {
constexpr char kTestServiceName[] = "test service";
} // namespace
TEST(ServiceManagerConnectionImplTest, ServiceLaunchThreading) {
base::test::SingleThreadTaskEnvironment task_environment;
base::Thread io_thread("ServiceManagerConnectionImplTest IO Thread");
io_thread.Start();
mojo::Remote<service_manager::mojom::Service> service;
ServiceManagerConnectionImpl connection_impl(
service.BindNewPipeAndPassReceiver(), io_thread.task_runner());
ServiceManagerConnection& connection = connection_impl;
base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
connection.AddServiceRequestHandler(
kTestServiceName,
base::BindLambdaForTesting(
[&event](mojo::PendingReceiver<service_manager::mojom::Service>) {
event.Signal();
}));
connection.Start();
mojo::PendingRemote<service_manager::mojom::Service> packaged_service;
mojo::PendingRemote<service_manager::mojom::ProcessMetadata> metadata;
ignore_result(metadata.InitWithNewPipeAndPassReceiver());
service->CreatePackagedServiceInstance(
service_manager::Identity(kTestServiceName, base::Token::CreateRandom(),
base::Token(), base::Token::CreateRandom()),
packaged_service.InitWithNewPipeAndPassReceiver(), std::move(metadata));
event.Wait();
}
} // namespace content
......@@ -151,7 +151,6 @@ source_set("common_sources") {
"sandbox_init.h",
"sandboxed_process_launcher_delegate.cc",
"sandboxed_process_launcher_delegate.h",
"service_manager_connection.h",
"socket_permission_request.h",
"stop_find_action.h",
"storage_quota_params.h",
......
// Copyright 2016 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 CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_
#define CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_
#include <memory>
#include "base/callback_forward.h"
#include "base/sequenced_task_runner.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/mojom/connector.mojom-forward.h"
#include "services/service_manager/public/mojom/service.mojom-forward.h"
namespace service_manager {
class Connector;
}
namespace content {
// Encapsulates a connection to a //services/service_manager.
// Access a global instance on the thread the ServiceContext was bound by
// calling Holder::Get().
// Clients can add service_manager::Service implementations whose exposed
// interfaces
// will be exposed to inbound connections to this object's Service.
// Alternatively clients can define named services that will be constructed when
// requests for those service names are received.
// Clients must call any of the registration methods when receiving
// ContentBrowserClient::RegisterInProcessServices().
class CONTENT_EXPORT ServiceManagerConnection {
public:
using ServiceRequestHandler = base::RepeatingCallback<void(
mojo::PendingReceiver<service_manager::mojom::Service>)>;
using ServiceRequestHandlerWithCallback = base::RepeatingCallback<void(
mojo::PendingReceiver<service_manager::mojom::Service>,
service_manager::Service::CreatePackagedServiceInstanceCallback)>;
using Factory =
base::RepeatingCallback<std::unique_ptr<ServiceManagerConnection>(void)>;
// Stores an instance of |connection| in TLS for the current process. Must be
// called on the thread the connection was created on.
static void SetForProcess(
std::unique_ptr<ServiceManagerConnection> connection);
// Returns the per-process instance, or nullptr if the Service Manager
// connection has not yet been bound. Must be called on the thread the
// connection was created on.
static ServiceManagerConnection* GetForProcess();
// Destroys the per-process instance. Must be called on the thread the
// connection was created on.
static void DestroyForProcess();
virtual ~ServiceManagerConnection();
// Sets the factory used to create the ServiceManagerConnection. This must be
// called before the ServiceManagerConnection has been created.
static void SetFactoryForTest(Factory* factory);
// Creates a ServiceManagerConnection from |request|. The connection binds
// its interfaces and accept new connections on |io_task_runner| only. Note
// that no incoming connections are accepted until Start() is called.
static std::unique_ptr<ServiceManagerConnection> Create(
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
scoped_refptr<base::SequencedTaskRunner> io_task_runner);
// Begins accepting incoming connections.
virtual void Start() = 0;
// Stops accepting incoming connections. This happens asynchronously by
// posting to the IO thread, and cannot be undone.
virtual void Stop() = 0;
// Returns the service_manager::Connector received via this connection's
// Service
// implementation. Use this to initiate connections as this object's Identity.
virtual service_manager::Connector* GetConnector() = 0;
// Sets a closure that is called when the connection is lost. Note that
// connection may already have been closed, in which case |closure| will be
// run immediately before returning from this function.
virtual void SetConnectionLostClosure(base::OnceClosure closure) = 0;
// Adds a generic ServiceRequestHandler for a given service name. This
// will be used to satisfy any incoming calls to CreateService() which
// reference the given name.
virtual void AddServiceRequestHandler(
const std::string& name,
const ServiceRequestHandler& handler) = 0;
// Similar to above but for registering handlers which want to communicate
// additional information the process hosting the new service.
virtual void AddServiceRequestHandlerWithCallback(
const std::string& name,
const ServiceRequestHandlerWithCallback& handler) = 0;
// Sets a request handler to use if no registered handlers were interested in
// an incoming service request. Must be called before |Start()|.
using DefaultServiceRequestHandler = base::RepeatingCallback<void(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service>)>;
virtual void SetDefaultServiceRequestHandler(
const DefaultServiceRequestHandler& handler) = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_
......@@ -2066,7 +2066,6 @@ test("content_unittests") {
"../common/input/touch_event_stream_validator_unittest.cc",
"../common/inter_process_time_ticks_converter_unittest.cc",
"../common/net/ip_address_space_util_unittest.cc",
"../common/service_manager/service_manager_connection_impl_unittest.cc",
"../common/service_worker/service_worker_utils_unittest.cc",
"../common/state_transitions_unittest.cc",
"../common/user_agent_unittest.cc",
......
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