Eliminate Connector::Connect(), Connection, etc.
. Introduce a new Connector method StartService(Identity id); which allows a service to be started by the service manager but no connection to be made to it.
. Migrates service manager tests away from Connection, OnConnect etc.
. Eliminate Connector::Connect(), Service::OnConnect() & logic in ServiceManager supporting them.
. Eliminate the Connection object & remove #includes
. Change how Connector response callbacks are run to guarantee they're reliably called. (Called upon destruction of ConnectParams).
R=rockot@chromium.org,tsepez@chromium.org
Review-Url: https://codereview.chromium.org/2804373002
Cr-Commit-Position: refs/heads/master@{#464167}
diff --git a/ash/mus/app_launch_unittest.cc b/ash/mus/app_launch_unittest.cc
index 1ee880a4..e9a3e60 100644
--- a/ash/mus/app_launch_unittest.cc
+++ b/ash/mus/app_launch_unittest.cc
@@ -34,8 +34,8 @@
};
TEST_F(AppLaunchTest, TestQuickLaunch) {
- connector()->Connect(mojom::kServiceName);
- connector()->Connect(mash::quick_launch::mojom::kServiceName);
+ connector()->StartService(mojom::kServiceName);
+ connector()->StartService(mash::quick_launch::mojom::kServiceName);
ui::mojom::WindowServerTestPtr test_interface;
connector()->BindInterface(ui::mojom::kServiceName, &test_interface);
diff --git a/ash/mus/window_manager_application.cc b/ash/mus/window_manager_application.cc
index d530f49..abd098e 100644
--- a/ash/mus/window_manager_application.cc
+++ b/ash/mus/window_manager_application.cc
@@ -22,7 +22,6 @@
#include "chromeos/system/fake_statistics_provider.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/tracing/public/cpp/provider.h"
diff --git a/ash/mus/window_manager_unittest.cc b/ash/mus/window_manager_unittest.cc
index 84f23a4..3604021 100644
--- a/ash/mus/window_manager_unittest.cc
+++ b/ash/mus/window_manager_unittest.cc
@@ -87,7 +87,7 @@
WindowTreeClientDelegate window_tree_delegate;
- connector()->Connect(mojom::kServiceName);
+ connector()->StartService(mojom::kServiceName);
// Connect to mus and create a new top level window. The request goes to
// |ash|, but is async.
diff --git a/chrome/app/mash/mash_runner.cc b/chrome/app/mash/mash_runner.cc
index e857c97..a50a807 100644
--- a/chrome/app/mash/mash_runner.cc
+++ b/chrome/app/mash/mash_runner.cc
@@ -243,11 +243,13 @@
// Ping services that we know we want to launch on startup (UI service,
// window manager, quick launch app).
- context.connector()->Connect(ui::mojom::kServiceName);
- context.connector()->Connect(content::mojom::kPackagedServicesServiceName);
+ context.connector()->StartService(ui::mojom::kServiceName);
+ context.connector()->StartService(
+ content::mojom::kPackagedServicesServiceName);
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kMash)) {
- context.connector()->Connect(mash::common::GetWindowManagerServiceName());
- context.connector()->Connect(mash::quick_launch::mojom::kServiceName);
+ context.connector()->StartService(
+ mash::common::GetWindowManagerServiceName());
+ context.connector()->StartService(mash::quick_launch::mojom::kServiceName);
}
run_loop.Run();
diff --git a/chrome/test/base/mash_browser_tests_main.cc b/chrome/test/base/mash_browser_tests_main.cc
index bc097e1..d5ea89c 100644
--- a/chrome/test/base/mash_browser_tests_main.cc
+++ b/chrome/test/base/mash_browser_tests_main.cc
@@ -44,7 +44,7 @@
FILE_PATH_LITERAL("mash_browser_tests_catalog.json");
void ConnectToDefaultApps(service_manager::Connector* connector) {
- connector->Connect(mash::session::mojom::kServiceName);
+ connector->StartService(mash::session::mojom::kServiceName);
}
class MashTestSuite : public ChromeTestSuite {
diff --git a/components/filesystem/file_system_app.cc b/components/filesystem/file_system_app.cc
index e12cba1..c54639c 100644
--- a/components/filesystem/file_system_app.cc
+++ b/components/filesystem/file_system_app.cc
@@ -11,7 +11,6 @@
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_context.h"
diff --git a/components/font_service/font_service_app.cc b/components/font_service/font_service_app.cc
index 57700b2..5dfe5f9 100644
--- a/components/font_service/font_service_app.cc
+++ b/components/font_service/font_service_app.cc
@@ -9,7 +9,6 @@
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "mojo/public/cpp/system/platform_handle.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/service_context.h"
static_assert(
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 638e0ecc2..b7a99d5 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -42,7 +42,6 @@
#include "services/file/file_service.h"
#include "services/file/public/interfaces/constants.mojom.h"
#include "services/file/user_id_map.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
#include "storage/browser/database/database_tracker.h"
@@ -150,11 +149,9 @@
class BrowserContextServiceManagerConnectionHolder
: public base::SupportsUserData::Data {
public:
- BrowserContextServiceManagerConnectionHolder(
- std::unique_ptr<service_manager::Connection> connection,
+ explicit BrowserContextServiceManagerConnectionHolder(
service_manager::mojom::ServiceRequest request)
- : root_connection_(std::move(connection)),
- service_manager_connection_(ServiceManagerConnection::Create(
+ : service_manager_connection_(ServiceManagerConnection::Create(
std::move(request),
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))) {}
~BrowserContextServiceManagerConnectionHolder() override {}
@@ -164,7 +161,6 @@
}
private:
- std::unique_ptr<service_manager::Connection> root_connection_;
std::unique_ptr<ServiceManagerConnection> service_manager_connection_;
DISALLOW_COPY_AND_ASSIGN(BrowserContextServiceManagerConnectionHolder);
@@ -442,9 +438,9 @@
identity, std::move(service), mojo::MakeRequest(&pid_receiver));
pid_receiver->SetPID(base::GetCurrentProcId());
+ service_manager_connection->GetConnector()->StartService(identity);
BrowserContextServiceManagerConnectionHolder* connection_holder =
new BrowserContextServiceManagerConnectionHolder(
- service_manager_connection->GetConnector()->Connect(identity),
std::move(service_request));
browser_context->SetUserData(kServiceManagerConnection, connection_holder);
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc
index 39d00af7..2eade52 100644
--- a/content/browser/gpu/gpu_process_host.cc
+++ b/content/browser/gpu/gpu_process_host.cc
@@ -62,7 +62,6 @@
#include "media/media_features.h"
#include "mojo/edk/embedder/embedder.h"
#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/runner/common/client_util.h"
#include "ui/display/display_switches.h"
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index a691ef8..05f7cfe 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -183,7 +183,6 @@
#include "ppapi/features/features.h"
#include "services/resource_coordinator/memory/coordinator/coordinator_impl.h"
#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/runner/common/client_util.h"
diff --git a/content/browser/utility_process_host_impl.cc b/content/browser/utility_process_host_impl.cc
index ea61cbf..4c5b066 100644
--- a/content/browser/utility_process_host_impl.cc
+++ b/content/browser/utility_process_host_impl.cc
@@ -40,7 +40,6 @@
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "mojo/edk/embedder/embedder.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "ui/base/ui_base_switches.h"
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index a5718012..7500a8f 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -66,7 +66,6 @@
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h"
-#include "services/device/public/interfaces/constants.mojom.h"
#include "services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
@@ -510,13 +509,8 @@
// also for some edge cases where there is no ServiceManagerConnection, we do
// not create the power monitor.
if (!base::PowerMonitor::Get() && service_manager_connection_) {
- std::unique_ptr<service_manager::Connection> device_connection =
- service_manager_connection_->GetConnector()->Connect(
- device::mojom::kServiceName);
auto power_monitor_source =
- base::MakeUnique<device::PowerMonitorBroadcastSource>(
- device_connection->GetRemoteInterfaces());
-
+ base::MakeUnique<device::PowerMonitorBroadcastSource>(GetConnector());
power_monitor_.reset(
new base::PowerMonitor(std::move(power_monitor_source)));
}
diff --git a/content/public/test/test_service.cc b/content/public/test/test_service.cc
index 4e45f21..1763106 100644
--- a/content/public/test/test_service.cc
+++ b/content/public/test/test_service.cc
@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
namespace content {
diff --git a/mash/catalog_viewer/catalog_viewer.cc b/mash/catalog_viewer/catalog_viewer.cc
index aab46a79..2b817c59 100644
--- a/mash/catalog_viewer/catalog_viewer.cc
+++ b/mash/catalog_viewer/catalog_viewer.cc
@@ -15,7 +15,6 @@
#include "mojo/public/cpp/bindings/binding.h"
#include "services/catalog/public/interfaces/catalog.mojom.h"
#include "services/catalog/public/interfaces/constants.mojom.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_context.h"
diff --git a/mash/example/views_examples/views_examples.cc b/mash/example/views_examples/views_examples.cc
index cb6e3d3e..8e0c2fe1 100644
--- a/mash/example/views_examples/views_examples.cc
+++ b/mash/example/views_examples/views_examples.cc
@@ -11,7 +11,6 @@
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/c/main.h"
#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/service_manager/public/cpp/interface_registry.h"
diff --git a/mash/example/window_type_launcher/window_type_launcher.cc b/mash/example/window_type_launcher/window_type_launcher.cc
index 46c07923..a33422e 100644
--- a/mash/example/window_type_launcher/window_type_launcher.cc
+++ b/mash/example/window_type_launcher/window_type_launcher.cc
@@ -13,7 +13,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/platform_thread.h"
#include "services/service_manager/public/c/main.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
diff --git a/mash/session/session.cc b/mash/session/session.cc
index d00e7ec..d02dabb 100644
--- a/mash/session/session.cc
+++ b/mash/session/session.cc
@@ -24,19 +24,20 @@
StartQuickLaunch();
// Launch a chrome window for dev convience; don't do this in the long term.
- context()->connector()->Connect(content::mojom::kPackagedServicesServiceName);
+ context()->connector()->StartService(
+ content::mojom::kPackagedServicesServiceName);
}
void Session::StartWindowManager() {
// TODO(beng): monitor this service for death & bring down the whole system
// if necessary.
- context()->connector()->Connect(common::GetWindowManagerServiceName());
+ context()->connector()->StartService(common::GetWindowManagerServiceName());
}
void Session::StartQuickLaunch() {
// TODO(beng): monitor this service for death & bring down the whole system
// if necessary.
- context()->connector()->Connect(quick_launch::mojom::kServiceName);
+ context()->connector()->StartService(quick_launch::mojom::kServiceName);
}
} // namespace session
diff --git a/mash/task_viewer/task_viewer.cc b/mash/task_viewer/task_viewer.cc
index c7b8cf1..98204fa 100644
--- a/mash/task_viewer/task_viewer.cc
+++ b/mash/task_viewer/task_viewer.cc
@@ -17,7 +17,6 @@
#include "mojo/public/cpp/bindings/binding.h"
#include "services/catalog/public/interfaces/catalog.mojom.h"
#include "services/catalog/public/interfaces/constants.mojom.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_context.h"
diff --git a/media/mojo/services/media_service.cc b/media/mojo/services/media_service.cc
index 242040e..e1b5145 100644
--- a/media/mojo/services/media_service.cc
+++ b/media/mojo/services/media_service.cc
@@ -11,7 +11,6 @@
#include "media/mojo/services/interface_factory_impl.h"
#include "media/mojo/services/mojo_media_client.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
namespace media {
diff --git a/media/mojo/services/media_service_unittest.cc b/media/mojo/services/media_service_unittest.cc
index bdc2cd7..c7e611c 100644
--- a/media/mojo/services/media_service_unittest.cc
+++ b/media/mojo/services/media_service_unittest.cc
@@ -77,9 +77,8 @@
void SetUp() override {
ServiceTest::SetUp();
- connection_ = connector()->Connect("media");
media::mojom::MediaServicePtr media_service;
- connection_->GetInterface(&media_service);
+ connector()->BindInterface("media", &media_service);
auto registry =
base::MakeUnique<service_manager::InterfaceRegistry>(std::string());
@@ -148,7 +147,6 @@
MOCK_METHOD0(ConnectionClosed, void());
protected:
- std::unique_ptr<service_manager::Connection> connection_;
std::unique_ptr<base::RunLoop> run_loop_;
mojom::InterfaceFactoryPtr interface_factory_;
@@ -202,7 +200,12 @@
#endif // defined(ENABLE_MOJO_RENDERER)
TEST_F(MediaServiceTest, Lifetime) {
- connection_->SetConnectionLostClosure(
+ // The lifetime of the media service is controlled by the number of
+ // live InterfaceFactory impls, not MediaService impls, so this pipe should
+ // be closed when the last InterfaceFactory is destroyed.
+ media::mojom::MediaServicePtr media_service;
+ connector()->BindInterface("media", &media_service);
+ media_service.set_connection_error_handler(
base::Bind(&MediaServiceTest::ConnectionClosed, base::Unretained(this)));
// Disconnecting CDM and Renderer services doesn't terminate the app.
diff --git a/services/catalog/catalog.cc b/services/catalog/catalog.cc
index b062eb4..3189881d8 100644
--- a/services/catalog/catalog.cc
+++ b/services/catalog/catalog.cc
@@ -25,7 +25,6 @@
#include "services/catalog/entry_cache.h"
#include "services/catalog/instance.h"
#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/service_context.h"
namespace catalog {
diff --git a/services/device/device_service.cc b/services/device/device_service.cc
index ea0f021..5578cf5 100644
--- a/services/device/device_service.cc
+++ b/services/device/device_service.cc
@@ -23,7 +23,6 @@
#include "services/device/power_monitor/power_monitor_message_broadcaster.h"
#include "services/device/public/cpp/device_features.h"
#include "services/device/time_zone_monitor/time_zone_monitor.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_info.h"
#include "ui/gfx/native_widget_types.h"
diff --git a/services/device/device_service_test_base.cc b/services/device/device_service_test_base.cc
index e967c17..595f669 100644
--- a/services/device/device_service_test_base.cc
+++ b/services/device/device_service_test_base.cc
@@ -11,8 +11,8 @@
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/device/device_service.h"
#include "services/device/public/interfaces/constants.mojom.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/interfaces/service_factory.mojom.h"
@@ -31,14 +31,17 @@
explicit ServiceTestClient(service_manager::test::ServiceTest* test)
: service_manager::test::ServiceTestClient(test),
io_thread_("DeviceServiceTestIOThread"),
- file_thread_("DeviceServiceTestFileThread") {}
+ file_thread_("DeviceServiceTestFileThread") {
+ registry_.AddInterface<service_manager::mojom::ServiceFactory>(this);
+ }
~ServiceTestClient() override {}
protected:
- bool OnConnect(const service_manager::ServiceInfo& remote_info,
- service_manager::InterfaceRegistry* registry) override {
- registry->AddInterface<service_manager::mojom::ServiceFactory>(this);
- return true;
+ void OnBindInterface(const service_manager::ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
void CreateService(service_manager::mojom::ServiceRequest request,
@@ -69,6 +72,7 @@
private:
base::Thread io_thread_;
base::Thread file_thread_;
+ service_manager::BinderRegistry registry_;
mojo::BindingSet<service_manager::mojom::ServiceFactory>
service_factory_bindings_;
std::unique_ptr<service_manager::ServiceContext> device_service_context_;
diff --git a/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.cc b/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.cc
index 9fb1459..e325355 100644
--- a/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.cc
+++ b/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.cc
@@ -7,15 +7,18 @@
#include "base/location.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "services/device/public/interfaces/constants.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
namespace device {
PowerMonitorBroadcastSource::PowerMonitorBroadcastSource(
- service_manager::InterfaceProvider* interface_provider)
+ service_manager::Connector* connector)
: last_reported_battery_power_state_(false), binding_(this) {
- if (interface_provider) {
+ if (connector) {
device::mojom::PowerMonitorPtr power_monitor;
- interface_provider->GetInterface(mojo::MakeRequest(&power_monitor));
+ connector->BindInterface(device::mojom::kServiceName,
+ mojo::MakeRequest(&power_monitor));
power_monitor->AddClient(binding_.CreateInterfacePtrAndBind());
}
}
diff --git a/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h b/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h
index 5f8f06e..1969aff 100644
--- a/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h
+++ b/services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h
@@ -9,7 +9,10 @@
#include "base/power_monitor/power_monitor_source.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/device/public/interfaces/power_monitor.mojom.h"
-#include "services/service_manager/public/cpp/interface_provider.h"
+
+namespace service_manager {
+class Connector;
+}
namespace device {
@@ -18,8 +21,7 @@
class PowerMonitorBroadcastSource : public base::PowerMonitorSource,
public device::mojom::PowerMonitorClient {
public:
- explicit PowerMonitorBroadcastSource(
- service_manager::InterfaceProvider* interface_provider);
+ explicit PowerMonitorBroadcastSource(service_manager::Connector* connector);
~PowerMonitorBroadcastSource() override;
void PowerStateChange(bool on_battery_power) override;
diff --git a/services/file/file_service.cc b/services/file/file_service.cc
index d10ed4d..21946921 100644
--- a/services/file/file_service.cc
+++ b/services/file/file_service.cc
@@ -12,7 +12,6 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/file/file_system.h"
#include "services/file/user_id_map.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/service_context.h"
namespace file {
diff --git a/services/file/file_system.cc b/services/file/file_system.cc
index e022d4c..d4ff32f 100644
--- a/services/file/file_system.cc
+++ b/services/file/file_system.cc
@@ -14,7 +14,6 @@
#include "components/filesystem/lock_table.h"
#include "components/filesystem/public/interfaces/types.mojom.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "services/service_manager/public/cpp/connection.h"
namespace file {
diff --git a/services/identity/identity_service.cc b/services/identity/identity_service.cc
index 1cb95dc..dfdb742 100644
--- a/services/identity/identity_service.cc
+++ b/services/identity/identity_service.cc
@@ -5,7 +5,6 @@
#include "services/identity/identity_service.h"
#include "services/identity/identity_manager.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/service_context.h"
namespace identity {
diff --git a/services/navigation/navigation_unittest.cc b/services/navigation/navigation_unittest.cc
index 5dfc8adb..740cc6f 100644
--- a/services/navigation/navigation_unittest.cc
+++ b/services/navigation/navigation_unittest.cc
@@ -24,7 +24,7 @@
protected:
void SetUp() override {
service_manager::test::ServiceTest::SetUp();
- window_manager_connection_ = connector()->Connect("test_wm");
+ connector()->StartService("test_wm");
}
mojom::ViewClientPtr GetViewClient() {
@@ -66,7 +66,6 @@
int load_count_ = 0;
mojo::Binding<mojom::ViewClient> binding_;
base::RunLoop* loop_ = nullptr;
- std::unique_ptr<service_manager::Connection> window_manager_connection_;
DISALLOW_COPY_AND_ASSIGN(NavigationTest);
};
diff --git a/services/service_manager/background/tests/background_service_manager_unittest.cc b/services/service_manager/background/tests/background_service_manager_unittest.cc
index e939e0e..3d9f43d 100644
--- a/services/service_manager/background/tests/background_service_manager_unittest.cc
+++ b/services/service_manager/background/tests/background_service_manager_unittest.cc
@@ -27,12 +27,6 @@
ServiceImpl() {}
~ServiceImpl() override {}
- // Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- return false;
- }
-
private:
DISALLOW_COPY_AND_ASSIGN(ServiceImpl);
};
diff --git a/services/service_manager/background/tests/test_service.cc b/services/service_manager/background/tests/test_service.cc
index 96fd1522..1a4e59a 100644
--- a/services/service_manager/background/tests/test_service.cc
+++ b/services/service_manager/background/tests/test_service.cc
@@ -5,7 +5,7 @@
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/background/tests/test.mojom.h"
#include "services/service_manager/public/c/main.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_runner.h"
@@ -18,15 +18,16 @@
public InterfaceFactory<mojom::TestService>,
public mojom::TestService {
public:
- TestClient() {}
+ TestClient() { registry_.AddInterface(this); }
~TestClient() override {}
private:
// Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface(this);
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<mojom::TestService>:
@@ -42,6 +43,7 @@
void Quit() override { context()->RequestQuit(); }
+ BinderRegistry registry_;
mojo::BindingSet<mojom::TestService> bindings_;
DISALLOW_COPY_AND_ASSIGN(TestClient);
diff --git a/services/service_manager/connect_params.cc b/services/service_manager/connect_params.cc
index e8464a8..7947a75 100644
--- a/services/service_manager/connect_params.cc
+++ b/services/service_manager/connect_params.cc
@@ -7,6 +7,9 @@
namespace service_manager {
ConnectParams::ConnectParams() {}
-ConnectParams::~ConnectParams() {}
+ConnectParams::~ConnectParams() {
+ if (!start_service_callback_.is_null())
+ start_service_callback_.Run(result_, resolved_identity_);
+}
} // namespace service_manager
diff --git a/services/service_manager/connect_params.h b/services/service_manager/connect_params.h
index 8c8787a..c0cbf65 100644
--- a/services/service_manager/connect_params.h
+++ b/services/service_manager/connect_params.h
@@ -10,9 +10,9 @@
#include "base/callback.h"
#include "base/macros.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
-#include "services/service_manager/public/interfaces/interface_provider.mojom.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
namespace service_manager {
@@ -29,13 +29,6 @@
void set_target(const Identity& target) { target_ = target; }
const Identity& target() const { return target_; }
- void set_remote_interfaces(mojom::InterfaceProviderRequest value) {
- remote_interfaces_ = std::move(value);
- }
- mojom::InterfaceProviderRequest TakeRemoteInterfaces() {
- return std::move(remote_interfaces_);
- }
-
void set_client_process_info(
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) {
@@ -68,20 +61,15 @@
return std::move(interface_pipe_);
}
- void set_connect_callback(const mojom::Connector::ConnectCallback& value) {
- connect_callback_ = value;
- }
- const mojom::Connector::ConnectCallback& connect_callback() const {
- return connect_callback_;
+ void set_start_service_callback(
+ const Connector::StartServiceCallback& callback) {
+ start_service_callback_ = callback;
}
- void set_bind_interface_callback(
- const mojom::Connector::BindInterfaceCallback& callback) {
- bind_interface_callback_ = callback;
- }
- const mojom::Connector::BindInterfaceCallback&
- bind_interface_callback() const {
- return bind_interface_callback_;
+ void set_response_data(mojom::ConnectResult result,
+ const Identity& resolved_identity) {
+ result_ = result;
+ resolved_identity_ = resolved_identity;
}
private:
@@ -91,13 +79,16 @@
// The identity of the application being connected to.
Identity target_;
- mojom::InterfaceProviderRequest remote_interfaces_;
mojom::ServicePtr service_;
mojom::PIDReceiverRequest pid_receiver_request_;
std::string interface_name_;
mojo::ScopedMessagePipeHandle interface_pipe_;
- mojom::Connector::ConnectCallback connect_callback_;
- mojom::Connector::BindInterfaceCallback bind_interface_callback_;
+ mojom::Connector::StartServiceCallback start_service_callback_;
+
+ // These values are supplied to the response callback for StartService()/
+ // BindInterface() etc. when the connection is completed.
+ mojom::ConnectResult result_ = mojom::ConnectResult::INVALID_ARGUMENT;
+ Identity resolved_identity_;
DISALLOW_COPY_AND_ASSIGN(ConnectParams);
};
diff --git a/services/service_manager/connect_util.cc b/services/service_manager/connect_util.cc
index c37b662..085fdf60 100644
--- a/services/service_manager/connect_util.cc
+++ b/services/service_manager/connect_util.cc
@@ -7,11 +7,18 @@
#include <memory>
#include <utility>
+#include "base/bind.h"
#include "services/service_manager/connect_params.h"
#include "services/service_manager/service_manager.h"
namespace service_manager {
+namespace {
+
+void EmptyStartServiceCallback(mojom::ConnectResult result,
+ const Identity& resolved_identity) {}
+}
+
mojo::ScopedMessagePipeHandle BindInterface(
ServiceManager* service_manager,
const Identity& source,
@@ -22,6 +29,7 @@
params->set_target(target);
mojo::MessagePipe pipe;
params->set_interface_request_info(interface_name, std::move(pipe.handle1));
+ params->set_start_service_callback(base::Bind(&EmptyStartServiceCallback));
service_manager->Connect(std::move(params));
return std::move(pipe.handle0);
}
diff --git a/services/service_manager/public/cpp/BUILD.gn b/services/service_manager/public/cpp/BUILD.gn
index 3320e94..a2452f5c 100644
--- a/services/service_manager/public/cpp/BUILD.gn
+++ b/services/service_manager/public/cpp/BUILD.gn
@@ -13,7 +13,6 @@
sources = [
"binder_registry.h",
"connect.h",
- "connection.h",
"connector.h",
"identity.h",
"interface_binder.h",
@@ -25,8 +24,6 @@
"lib/binder_registry.cc",
"lib/callback_binder.cc",
"lib/callback_binder.h",
- "lib/connection_impl.cc",
- "lib/connection_impl.h",
"lib/connector_impl.cc",
"lib/connector_impl.h",
"lib/identity.cc",
diff --git a/services/service_manager/public/cpp/connection.h b/services/service_manager/public/cpp/connection.h
deleted file mode 100644
index 28eee4d4..0000000
--- a/services/service_manager/public/cpp/connection.h
+++ /dev/null
@@ -1,96 +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 SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTION_H_
-#define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTION_H_
-
-#include "base/memory/weak_ptr.h"
-#include "services/service_manager/public/cpp/identity.h"
-#include "services/service_manager/public/cpp/interface_provider.h"
-#include "services/service_manager/public/interfaces/connector.mojom.h"
-
-namespace service_manager {
-
-class InterfaceProvider;
-
-// Represents a connection to another application. An implementation of this
-// interface is returned from Connector::Connect().
-class Connection {
- public:
- virtual ~Connection() {}
-
- enum class State {
- // The service manager has not yet processed the connection.
- PENDING,
-
- // The service manager processed the connection and it was established.
- // GetResult() returns mojom::ConnectionResult::SUCCESS.
- CONNECTED,
-
- // The service manager processed the connection and establishment was
- // prevented by an error, call GetResult().
- DISCONNECTED
- };
-
- class TestApi {
- public:
- explicit TestApi(Connection* connection) : connection_(connection) {}
- base::WeakPtr<Connection> GetWeakPtr() {
- return connection_->GetWeakPtr();
- }
-
- private:
- Connection* connection_;
- };
-
- // Binds |ptr| to an implementation of Interface in the remote application.
- // |ptr| can immediately be used to start sending requests to the remote
- // interface.
- template <typename Interface>
- void GetInterface(mojo::InterfacePtr<Interface>* ptr) {
- GetRemoteInterfaces()->GetInterface(ptr);
- }
- template <typename Interface>
- void GetInterface(mojo::InterfaceRequest<Interface> request) {
- GetRemoteInterfaces()->GetInterface(std::move(request));
- }
-
- // Returns the remote identity. While the connection is in the pending state,
- // the user_id() field will be the value passed via Connect(). After the
- // connection is completed, it will change to the value assigned by the
- // service manager. Call AddConnectionCompletedClosure() to schedule a closure
- // to be run when the resolved user id is available.
- virtual const Identity& GetRemoteIdentity() const = 0;
-
- // Register a handler to receive an error notification on the pipe to the
- // remote application's InterfaceProvider.
- virtual void SetConnectionLostClosure(const base::Closure& handler) = 0;
-
- // Returns the result of the connection. This function should only be called
- // when the connection state is not pending. Call
- // AddConnectionCompletedClosure() to schedule a closure to be run when the
- // connection is processed by the service manager.
- virtual mojom::ConnectResult GetResult() const = 0;
-
- // Returns true if the connection has not yet been processed by the service
- // manager.
- virtual bool IsPending() const = 0;
-
- // Register a closure to be run when the connection has been completed by the
- // service manager and remote metadata is available. Useful only for
- // connections created
- // via Connector::Connect(). Once the connection is complete, metadata is
- // available immediately.
- virtual void AddConnectionCompletedClosure(const base::Closure& callback) = 0;
-
- // Returns an object encapsulating a remote InterfaceProvider.
- virtual InterfaceProvider* GetRemoteInterfaces() = 0;
-
- protected:
- virtual base::WeakPtr<Connection> GetWeakPtr() = 0;
-};
-
-} // namespace service_manager
-
-#endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONNECTION_H_
diff --git a/services/service_manager/public/cpp/connector.h b/services/service_manager/public/cpp/connector.h
index 37d8338..ae15116 100644
--- a/services/service_manager/public/cpp/connector.h
+++ b/services/service_manager/public/cpp/connector.h
@@ -7,7 +7,6 @@
#include <memory>
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
#include "services/service_manager/public/interfaces/service.mojom.h"
@@ -17,27 +16,31 @@
// An interface that encapsulates the Service Manager's brokering interface, by
// which
-// connections between services are established. Once Connect() is called,
-// this class is bound to the thread the call was made on and it cannot be
-// passed to another thread without calling Clone().
+// connections between services are established. Once either StartService() or
+// BindInterface() is called, this class is bound to the thread the call was
+// made on and it cannot be passed to another thread without calling Clone().
//
// An instance of this class is created internally by ServiceContext for use
// on the thread ServiceContext is instantiated on.
//
// To use this interface on another thread, call Clone() and pass the new
-// instance to the desired thread before calling Connect().
+// instance to the desired thread before calling StartService() or
+// BindInterface().
//
// While instances of this object are owned by the caller, the underlying
// connection with the service manager is bound to the lifetime of the instance
-// that
-// created it, i.e. when the application is terminated the Connector pipe is
-// closed.
+// that created it, i.e. when the application is terminated the Connector pipe
+// is closed.
class Connector {
public:
+ using StartServiceCallback =
+ base::Callback<void(mojom::ConnectResult, const Identity& identity)>;
+
class TestApi {
public:
using Binder = base::Callback<void(mojo::ScopedMessagePipeHandle)>;
explicit TestApi(Connector* connector) : connector_(connector) {}
+ ~TestApi() { connector_->ResetStartServiceCallback(); }
// Allows caller to specify a callback to bind requests for |interface_name|
// from |service_name| locally, rather than passing the request through the
@@ -50,6 +53,13 @@
}
void ClearBinderOverrides() { connector_->ClearBinderOverrides(); }
+ // Register a callback to be run with the result of an attempt to start a
+ // service. This will be run in response to calls to StartService() or
+ // BindInterface().
+ void SetStartServiceCallback(const StartServiceCallback& callback) {
+ connector_->SetStartServiceCallback(callback);
+ }
+
private:
Connector* connector_;
};
@@ -60,22 +70,20 @@
// for the other end the Connector's interface.
static std::unique_ptr<Connector> Create(mojom::ConnectorRequest* request);
+ // Creates an instance of a service for |identity|.
+ virtual void StartService(const Identity& identity) = 0;
+
+ // Creates an instance of the service |name| inheriting the caller's identity.
+ virtual void StartService(const std::string& name) = 0;
+
// Creates an instance of a service for |identity| in a process started by the
- // client (or someone else). Must be called before Connect() may be called to
- // |identity|.
+ // client (or someone else). Must be called before BindInterface() may be
+ // called to |identity|.
virtual void StartService(
const Identity& identity,
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) = 0;
- // Requests a new connection to a service. Returns a pointer to the
- // connection if the connection is permitted by that service, nullptr
- // otherwise. Once this method is called, this object is bound to the thread
- // on which the call took place. To pass to another thread, call Clone() and
- // pass the result.
- virtual std::unique_ptr<Connection> Connect(const std::string& name) = 0;
- virtual std::unique_ptr<Connection> Connect(const Identity& target) = 0;
-
// Connect to |target| & request to bind |Interface|.
template <typename Interface>
void BindInterface(const Identity& target,
@@ -100,8 +108,9 @@
mojo::ScopedMessagePipeHandle interface_pipe) = 0;
// Creates a new instance of this class which may be passed to another thread.
- // The returned object may be passed multiple times until Connect() is called,
- // at which point this method must be called again to pass again.
+ // The returned object may be passed multiple times until StartService() or
+ // BindInterface() is called, at which point this method must be called again
+ // to pass again.
virtual std::unique_ptr<Connector> Clone() = 0;
// Binds a Connector request to the other end of this Connector.
@@ -114,6 +123,9 @@
const std::string& interface_name,
const TestApi::Binder& binder) = 0;
virtual void ClearBinderOverrides() = 0;
+ virtual void SetStartServiceCallback(
+ const StartServiceCallback& callback) = 0;
+ virtual void ResetStartServiceCallback() = 0;
};
} // namespace service_manager
diff --git a/services/service_manager/public/cpp/lib/connection_impl.cc b/services/service_manager/public/cpp/lib/connection_impl.cc
deleted file mode 100644
index bd4ca44..0000000
--- a/services/service_manager/public/cpp/lib/connection_impl.cc
+++ /dev/null
@@ -1,100 +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 "services/service_manager/public/cpp/lib/connection_impl.h"
-
-#include <stdint.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "services/service_manager/public/cpp/connection.h"
-#include "services/service_manager/public/cpp/interface_binder.h"
-
-namespace service_manager {
-namespace internal {
-
-////////////////////////////////////////////////////////////////////////////////
-// ConnectionImpl, public:
-
-ConnectionImpl::ConnectionImpl()
- : weak_factory_(this) {}
-
-ConnectionImpl::ConnectionImpl(const Identity& remote, State initial_state)
- : remote_(remote),
- state_(initial_state),
- weak_factory_(this) {
-}
-
-ConnectionImpl::~ConnectionImpl() {}
-
-void ConnectionImpl::SetRemoteInterfaces(
- std::unique_ptr<InterfaceProvider> remote_interfaces) {
- remote_interfaces_owner_ = std::move(remote_interfaces);
- set_remote_interfaces(remote_interfaces_owner_.get());
-}
-
-service_manager::mojom::Connector::ConnectCallback
-ConnectionImpl::GetConnectCallback() {
- return base::Bind(&ConnectionImpl::OnConnectionCompleted,
- weak_factory_.GetWeakPtr());
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ConnectionImpl, Connection implementation:
-
-const Identity& ConnectionImpl::GetRemoteIdentity() const {
- return remote_;
-}
-
-void ConnectionImpl::SetConnectionLostClosure(const base::Closure& handler) {
- remote_interfaces_->SetConnectionLostClosure(handler);
-}
-
-service_manager::mojom::ConnectResult ConnectionImpl::GetResult() const {
- return result_;
-}
-
-bool ConnectionImpl::IsPending() const {
- return state_ == State::PENDING;
-}
-
-void ConnectionImpl::AddConnectionCompletedClosure(
- const base::Closure& callback) {
- if (IsPending())
- connection_completed_callbacks_.push_back(callback);
- else
- callback.Run();
-}
-
-InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
- return remote_interfaces_;
-}
-
-base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
- return weak_factory_.GetWeakPtr();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ConnectionImpl, private:
-
-void ConnectionImpl::OnConnectionCompleted(
- service_manager::mojom::ConnectResult result,
- const std::string& target_user_id) {
- DCHECK(State::PENDING == state_);
-
- result_ = result;
- state_ = result_ == service_manager::mojom::ConnectResult::SUCCEEDED
- ? State::CONNECTED
- : State::DISCONNECTED;
- remote_.set_user_id(target_user_id);
- std::vector<base::Closure> callbacks;
- callbacks.swap(connection_completed_callbacks_);
- for (auto callback : callbacks)
- callback.Run();
-}
-
-} // namespace internal
-} // namespace service_manager
diff --git a/services/service_manager/public/cpp/lib/connection_impl.h b/services/service_manager/public/cpp/lib/connection_impl.h
deleted file mode 100644
index a1fabf5..0000000
--- a/services/service_manager/public/cpp/lib/connection_impl.h
+++ /dev/null
@@ -1,76 +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 SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_
-#define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_
-
-#include <stdint.h>
-
-#include <set>
-#include <string>
-
-#include "base/callback.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/service_manager/public/cpp/connection.h"
-#include "services/service_manager/public/cpp/identity.h"
-#include "services/service_manager/public/cpp/interface_provider_spec.h"
-#include "services/service_manager/public/interfaces/connector.mojom.h"
-#include "services/service_manager/public/interfaces/interface_provider.mojom.h"
-
-namespace service_manager {
-namespace internal {
-
-// A ConnectionImpl represents each half of a connection between two
-// applications, allowing customization of which interfaces are published to the
-// other.
-class ConnectionImpl : public Connection {
- public:
- ConnectionImpl();
- ConnectionImpl(const Identity& remote, State initial_state);
- ~ConnectionImpl() override;
-
- // Sets the remote provider, transferring ownership to the ConnectionImpl.
- void SetRemoteInterfaces(
- std::unique_ptr<InterfaceProvider> remote_interfaces);
-
- // Sets the remote provider, without transferring ownership.
- void set_remote_interfaces(InterfaceProvider* remote_interfaces) {
- remote_interfaces_ = remote_interfaces;
- }
-
- service_manager::mojom::Connector::ConnectCallback GetConnectCallback();
-
- private:
- // Connection:
- const Identity& GetRemoteIdentity() const override;
- void SetConnectionLostClosure(const base::Closure& handler) override;
- service_manager::mojom::ConnectResult GetResult() const override;
- bool IsPending() const override;
- void AddConnectionCompletedClosure(const base::Closure& callback) override;
- InterfaceProvider* GetRemoteInterfaces() override;
- base::WeakPtr<Connection> GetWeakPtr() override;
-
- void OnConnectionCompleted(service_manager::mojom::ConnectResult result,
- const std::string& target_user_id);
-
- Identity remote_;
-
- State state_;
- service_manager::mojom::ConnectResult result_ =
- service_manager::mojom::ConnectResult::SUCCEEDED;
- std::vector<base::Closure> connection_completed_callbacks_;
-
- InterfaceProvider* remote_interfaces_ = nullptr;
-
- std::unique_ptr<InterfaceProvider> remote_interfaces_owner_;
-
- base::WeakPtrFactory<ConnectionImpl> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(ConnectionImpl);
-};
-
-} // namespace internal
-} // namespace service_manager
-
-#endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_
diff --git a/services/service_manager/public/cpp/lib/connector_impl.cc b/services/service_manager/public/cpp/lib/connector_impl.cc
index 3e7c8410..0040a32 100644
--- a/services/service_manager/public/cpp/lib/connector_impl.cc
+++ b/services/service_manager/public/cpp/lib/connector_impl.cc
@@ -6,14 +6,9 @@
#include "base/memory/ptr_util.h"
#include "services/service_manager/public/cpp/identity.h"
-#include "services/service_manager/public/cpp/lib/connection_impl.h"
namespace service_manager {
-namespace {
-void EmptyBindCallback(mojom::ConnectResult, const std::string&) {}
-}
-
ConnectorImpl::ConnectorImpl(mojom::ConnectorPtrInfo unbound_state)
: unbound_state_(std::move(unbound_state)), weak_factory_(this) {
thread_checker_.DetachFromThread();
@@ -32,6 +27,17 @@
connector_.reset();
}
+void ConnectorImpl::StartService(const Identity& identity) {
+ if (BindConnectorIfNecessary())
+ connector_->StartService(identity,
+ base::Bind(&ConnectorImpl::StartServiceCallback,
+ weak_factory_.GetWeakPtr()));
+}
+
+void ConnectorImpl::StartService(const std::string& name) {
+ StartService(Identity(name, mojom::kInheritUserID));
+}
+
void ConnectorImpl::StartService(
const Identity& identity,
mojom::ServicePtr service,
@@ -40,33 +46,11 @@
return;
DCHECK(service.is_bound() && pid_receiver_request.is_pending());
- connector_->StartService(identity,
- service.PassInterface().PassHandle(),
- std::move(pid_receiver_request));
-}
-
-std::unique_ptr<Connection> ConnectorImpl::Connect(const std::string& name) {
- return Connect(Identity(name, mojom::kInheritUserID));
-}
-
-std::unique_ptr<Connection> ConnectorImpl::Connect(const Identity& target) {
- if (!BindConnectorIfNecessary())
- return nullptr;
-
- DCHECK(thread_checker_.CalledOnValidThread());
-
- mojom::InterfaceProviderPtr remote_interfaces;
- mojom::InterfaceProviderRequest remote_request(&remote_interfaces);
- std::unique_ptr<internal::ConnectionImpl> connection(
- new internal::ConnectionImpl(target, Connection::State::PENDING));
- std::unique_ptr<InterfaceProvider> remote_interface_provider(
- new InterfaceProvider);
- remote_interface_provider->Bind(std::move(remote_interfaces));
- connection->SetRemoteInterfaces(std::move(remote_interface_provider));
-
- connector_->Connect(target, std::move(remote_request),
- connection->GetConnectCallback());
- return std::move(connection);
+ connector_->StartServiceWithProcess(
+ identity, service.PassInterface().PassHandle(),
+ std::move(pid_receiver_request),
+ base::Bind(&ConnectorImpl::StartServiceCallback,
+ weak_factory_.GetWeakPtr()));
}
void ConnectorImpl::BindInterface(
@@ -86,7 +70,8 @@
}
connector_->BindInterface(target, interface_name, std::move(interface_pipe),
- base::Bind(&EmptyBindCallback));
+ base::Bind(&ConnectorImpl::StartServiceCallback,
+ weak_factory_.GetWeakPtr()));
}
std::unique_ptr<Connector> ConnectorImpl::Clone() {
@@ -119,6 +104,15 @@
local_binder_overrides_.clear();
}
+void ConnectorImpl::SetStartServiceCallback(
+ const Connector::StartServiceCallback& callback) {
+ start_service_callback_ = callback;
+}
+
+void ConnectorImpl::ResetStartServiceCallback() {
+ start_service_callback_.Reset();
+}
+
bool ConnectorImpl::BindConnectorIfNecessary() {
// Bind this object to the current thread the first time it is used to
// connect.
@@ -142,6 +136,12 @@
return true;
}
+void ConnectorImpl::StartServiceCallback(mojom::ConnectResult result,
+ const Identity& user_id) {
+ if (!start_service_callback_.is_null())
+ start_service_callback_.Run(result, user_id);
+}
+
std::unique_ptr<Connector> Connector::Create(mojom::ConnectorRequest* request) {
mojom::ConnectorPtr proxy;
*request = mojo::MakeRequest(&proxy);
diff --git a/services/service_manager/public/cpp/lib/connector_impl.h b/services/service_manager/public/cpp/lib/connector_impl.h
index 6263f44..b07fb2b 100644
--- a/services/service_manager/public/cpp/lib/connector_impl.h
+++ b/services/service_manager/public/cpp/lib/connector_impl.h
@@ -25,11 +25,11 @@
void OnConnectionError();
// Connector:
+ void StartService(const Identity& identity) override;
+ void StartService(const std::string& name) override;
void StartService(const Identity& identity,
mojom::ServicePtr service,
mojom::PIDReceiverRequest pid_receiver_request) override;
- std::unique_ptr<Connection> Connect(const std::string& name) override;
- std::unique_ptr<Connection> Connect(const Identity& target) override;
void BindInterface(const Identity& target,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
@@ -40,9 +40,15 @@
const std::string& interface_name,
const TestApi::Binder& binder) override;
void ClearBinderOverrides() override;
+ void SetStartServiceCallback(const StartServiceCallback& callback) override;
+ void ResetStartServiceCallback() override;
bool BindConnectorIfNecessary();
+ // Callback passed to mojom methods StartService()/BindInterface().
+ void StartServiceCallback(mojom::ConnectResult result,
+ const Identity& user_id);
+
using BinderOverrideMap = std::map<std::string, TestApi::Binder>;
mojom::ConnectorPtrInfo unbound_state_;
@@ -51,8 +57,9 @@
base::ThreadChecker thread_checker_;
std::map<std::string, BinderOverrideMap> local_binder_overrides_;
+ Connector::StartServiceCallback start_service_callback_;
- base::WeakPtrFactory<Connector> weak_factory_;
+ base::WeakPtrFactory<ConnectorImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ConnectorImpl);
};
diff --git a/services/service_manager/public/cpp/lib/identity.cc b/services/service_manager/public/cpp/lib/identity.cc
index 4fa2ff2..409bee1 100644
--- a/services/service_manager/public/cpp/lib/identity.cc
+++ b/services/service_manager/public/cpp/lib/identity.cc
@@ -5,10 +5,11 @@
#include "services/service_manager/public/cpp/identity.h"
#include "base/guid.h"
+#include "services/service_manager/public/interfaces/connector.mojom.h"
namespace service_manager {
-Identity::Identity() {}
+Identity::Identity() : Identity("", mojom::kInheritUserID, "") {}
Identity::Identity(const std::string& name, const std::string& user_id)
: Identity(name, user_id, "") {}
diff --git a/services/service_manager/public/cpp/lib/interface_registry.cc b/services/service_manager/public/cpp/lib/interface_registry.cc
index 9fb605d8..e74df3c 100644
--- a/services/service_manager/public/cpp/lib/interface_registry.cc
+++ b/services/service_manager/public/cpp/lib/interface_registry.cc
@@ -9,7 +9,6 @@
#include "base/memory/ptr_util.h"
#include "mojo/public/cpp/bindings/message.h"
-#include "services/service_manager/public/cpp/connection.h"
namespace service_manager {
namespace {
diff --git a/services/service_manager/public/cpp/lib/service.cc b/services/service_manager/public/cpp/lib/service.cc
index 2b40a6c..b6a20a03b 100644
--- a/services/service_manager/public/cpp/lib/service.cc
+++ b/services/service_manager/public/cpp/lib/service.cc
@@ -6,8 +6,6 @@
#include "base/logging.h"
#include "services/service_manager/public/cpp/service_context.h"
-#include "services/service_manager/public/interfaces/interface_provider.mojom.h"
-#include "services/service_manager/public/interfaces/interface_provider_spec.mojom.h"
namespace service_manager {
@@ -17,30 +15,9 @@
void Service::OnStart() {}
-bool Service::OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) {
- return false;
-}
-
void Service::OnBindInterface(const ServiceInfo& source_info,
const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) {
- // TODO(beng): Eliminate this implementation once everyone is migrated to
- // OnBindInterface().
- mojom::InterfaceProviderPtr interface_provider;
- InterfaceProviderSpec source_spec, target_spec;
- GetInterfaceProviderSpec(
- mojom::kServiceManager_ConnectorSpec,
- service_context_->local_info().interface_provider_specs,
- &target_spec);
- GetInterfaceProviderSpec(
- mojom::kServiceManager_ConnectorSpec,
- source_info.interface_provider_specs,
- &source_spec);
- service_context_->CallOnConnect(source_info, source_spec, target_spec,
- MakeRequest(&interface_provider));
- interface_provider->GetInterface(interface_name, std::move(interface_pipe));
-}
+ mojo::ScopedMessagePipeHandle interface_pipe) {}
bool Service::OnServiceManagerConnectionLost() {
return true;
@@ -64,11 +41,6 @@
target_->OnStart();
}
-bool ForwardingService::OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) {
- return target_->OnConnect(remote_info, registry);
-}
-
void ForwardingService::OnBindInterface(
const ServiceInfo& remote_info,
const std::string& interface_name,
diff --git a/services/service_manager/public/cpp/lib/service_context.cc b/services/service_manager/public/cpp/lib/service_context.cc
index 6459459..0b53f8c 100644
--- a/services/service_manager/public/cpp/lib/service_context.cc
+++ b/services/service_manager/public/cpp/lib/service_context.cc
@@ -7,15 +7,8 @@
#include <utility>
#include "base/bind.h"
-#include "base/callback_helpers.h"
#include "base/logging.h"
-#include "base/memory/ptr_util.h"
-#include "base/message_loop/message_loop.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_request.h"
-#include "services/service_manager/public/cpp/interface_provider_spec.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/lib/connector_impl.h"
#include "services/service_manager/public/cpp/service.h"
@@ -88,22 +81,6 @@
service_->OnStart();
}
-void ServiceContext::OnConnect(
- const ServiceInfo& source_info,
- mojom::InterfaceProviderRequest interfaces,
- const OnConnectCallback& callback) {
- InterfaceProviderSpec source_spec, target_spec;
- GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec,
- local_info_.interface_provider_specs, &target_spec);
- GetInterfaceProviderSpec(mojom::kServiceManager_ConnectorSpec,
- source_info.interface_provider_specs, &source_spec);
-
- // Acknowledge the request regardless of whether it's accepted.
- callback.Run();
-
- CallOnConnect(source_info, source_spec, target_spec, std::move(interfaces));
-}
-
void ServiceContext::OnBindInterface(
const ServiceInfo& source_info,
const std::string& interface_name,
@@ -119,26 +96,6 @@
////////////////////////////////////////////////////////////////////////////////
// ServiceContext, private:
-void ServiceContext::CallOnConnect(const ServiceInfo& source_info,
- const InterfaceProviderSpec& source_spec,
- const InterfaceProviderSpec& target_spec,
- mojom::InterfaceProviderRequest interfaces) {
- auto registry =
- base::MakeUnique<InterfaceRegistry>(mojom::kServiceManager_ConnectorSpec);
- registry->Bind(std::move(interfaces), local_info_.identity, target_spec,
- source_info.identity, source_spec);
-
- if (!service_->OnConnect(source_info, registry.get()))
- return;
-
- InterfaceRegistry* raw_registry = registry.get();
- registry->AddConnectionLostClosure(base::Bind(
- &ServiceContext::OnRegistryConnectionError, base::Unretained(this),
- raw_registry));
- connection_interface_registries_.insert(
- std::make_pair(raw_registry, std::move(registry)));
-}
-
void ServiceContext::OnConnectionError() {
if (service_->OnServiceManagerConnectionLost()) {
// CAUTION: May delete |this|.
@@ -146,21 +103,4 @@
}
}
-void ServiceContext::OnRegistryConnectionError(InterfaceRegistry* registry) {
- // NOTE: We destroy the InterfaceRegistry asynchronously since it's calling
- // into us from its own connection error handler which may continue to access
- // the InterfaceRegistry's own state after we return.
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(&ServiceContext::DestroyConnectionInterfaceRegistry,
- weak_factory_.GetWeakPtr(), registry));
-}
-
-void ServiceContext::DestroyConnectionInterfaceRegistry(
- InterfaceRegistry* registry) {
- auto it = connection_interface_registries_.find(registry);
- CHECK(it != connection_interface_registries_.end());
- connection_interface_registries_.erase(it);
-}
-
} // namespace service_manager
diff --git a/services/service_manager/public/cpp/lib/service_test.cc b/services/service_manager/public/cpp/lib/service_test.cc
index 13689ad..30fd49b 100644
--- a/services/service_manager/public/cpp/lib/service_test.cc
+++ b/services/service_manager/public/cpp/lib/service_test.cc
@@ -27,11 +27,10 @@
context()->identity().user_id());
}
-bool ServiceTestClient::OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) {
- return false;
-}
-
+void ServiceTestClient::OnBindInterface(
+ const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) {}
ServiceTest::ServiceTest() {}
diff --git a/services/service_manager/public/cpp/service.h b/services/service_manager/public/cpp/service.h
index db5ad50..9d0c04e 100644
--- a/services/service_manager/public/cpp/service.h
+++ b/services/service_manager/public/cpp/service.h
@@ -12,7 +12,6 @@
namespace service_manager {
-class InterfaceRegistry;
class ServiceContext;
struct ServiceInfo;
@@ -28,16 +27,6 @@
// will be made before this.
virtual void OnStart();
- // Called each time a connection to this service is brokered by the Service
- // Manager. Implement this to expose interfaces to other services.
- //
- // Return true if the connection should succeed or false if the connection
- // should be rejected.
- //
- // The default implementation returns false.
- virtual bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry);
-
// Called when the service identified by |source_info| requests this service
// bind a request for |interface_name|. If this method has been called, the
// service manager has already determined that policy permits this interface
@@ -89,8 +78,6 @@
// Service:
void OnStart() override;
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override;
void OnBindInterface(const ServiceInfo& remote_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
diff --git a/services/service_manager/public/cpp/service_context.h b/services/service_manager/public/cpp/service_context.h
index f843462..8cfea21 100644
--- a/services/service_manager/public/cpp/service_context.h
+++ b/services/service_manager/public/cpp/service_context.h
@@ -108,33 +108,16 @@
private:
friend class service_manager::Service;
- using InterfaceRegistryMap =
- std::map<InterfaceRegistry*, std::unique_ptr<InterfaceRegistry>>;
-
// mojom::Service:
void OnStart(const ServiceInfo& info,
const OnStartCallback& callback) override;
- void OnConnect(const ServiceInfo& source_info,
- mojom::InterfaceProviderRequest interfaces,
- const OnConnectCallback& callback) override;
void OnBindInterface(
const ServiceInfo& source_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe,
const OnBindInterfaceCallback& callback) override;
- void CallOnConnect(const ServiceInfo& source_info,
- const InterfaceProviderSpec& source_spec,
- const InterfaceProviderSpec& target_spec,
- mojom::InterfaceProviderRequest request);
-
void OnConnectionError();
- void OnRegistryConnectionError(InterfaceRegistry* registry);
- void DestroyConnectionInterfaceRegistry(InterfaceRegistry* registry);
-
- // We track the lifetime of incoming connection registries as a convenience
- // for the client.
- InterfaceRegistryMap connection_interface_registries_;
// A pending Connector request which will eventually be passed to the Service
// Manager.
diff --git a/services/service_manager/public/cpp/service_test.h b/services/service_manager/public/cpp/service_test.h
index 1ee7b9a9..a4bfc74 100644
--- a/services/service_manager/public/cpp/service_test.h
+++ b/services/service_manager/public/cpp/service_test.h
@@ -43,8 +43,9 @@
protected:
void OnStart() override;
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override;
private:
ServiceTest* test_;
diff --git a/services/service_manager/public/interfaces/connector.mojom b/services/service_manager/public/interfaces/connector.mojom
index 3c759cbb..63168e4a 100644
--- a/services/service_manager/public/interfaces/connector.mojom
+++ b/services/service_manager/public/interfaces/connector.mojom
@@ -6,50 +6,51 @@
import "services/service_manager/public/interfaces/interface_provider.mojom";
+// TODO(beng): Determine who (if anyone) uses kRootUserID.
const string kRootUserID = "505C0EE9-3013-43C0-82B0-A84F50CF8D84";
const string kInheritUserID = "D26290E4-4485-4EAE-81A2-66D1EEB40A9D";
const uint32 kInvalidInstanceID = 0;
+// TODO(beng): Evalute the utility of this enum. There are some inconsistencies
+// in its use with BindInterface/StartService.
enum ConnectResult {
- // The connection was established successfully.
+ // The operation was established successfully.
SUCCEEDED,
// The name or user id supplied was malformed, or the service specified by
// |name| could not be loaded.
INVALID_ARGUMENT,
- // The connection was blocked by policy. Either connections to |name| are
- // forbidden from this app by the CapabilityFilter, or the service attempted
- // to connect using a user id other than its own, |kInheritUserID| or
- // |kRootUserID|.
+ // Policy prevented the successful completion of this operation. Either
+ // requests to bind to |name| are forbidden from the calling service by its
+ // manifest, or the service attempted to connect using a user id other than
+ // its own, |kInheritUserID| or |kRootUserID|.
ACCESS_DENIED
};
// A collection of metadata that disambiguates instances in the service manager.
struct Identity {
- // A service: or exe: name identifying a service.
+ // A name identifying a service.
string name;
- // The user id of the target service instance to connect to. If no such
- // instance exists, the service manager may start one. This user id will be
- // passed to the new instance via Initialize().
+ // The user id of the target service instance to bind to. If no such instance
+ // exists, the service manager may start one. This user id will be passed to
+ // the new instance via Initialize().
//
- // When connecting to other services, services must generally pass
- // kInheritUserID for this value, and the service manager will either connect
- // to an existing instance matching the caller's user id, create a new
- // instance matching the caller's user id, or connect to an existing instance
- // running as kRootUserID. By default, services do not have the ability to set
- // arbitrary values to this field, and doing so will result in a connection
- // error on the remote service provider.
+ // When binding to other services, services must generally pass kInheritUserID
+ // for this value, and the service manager will either bind to an existing
+ // instance matching the caller's user id, create a new instance matching the
+ // caller's user id, or bind to an existing instance running as kRootUserID.
+ // By default, services do not have the ability to set arbitrary values to
+ // this field, and doing so will result in an error response.
//
// A service with the ability to launch other services with arbitrary user ids
- // (e.g. a login service) may set this value to something meaningful to it.
- // The user id string is a valid guid of the form
- // "%08X-%04X-%04X-%04X-%012llX", and (aside from the root user whose
- // guid is defined above) intended to be not-guessable.
+ // (e.g. a login service) may set this value. The user id string is a valid
+ // guid of the form "%08X-%04X-%04X-%04X-%012llX", and (aside from the root
+ // user whose guid is defined above) intended to be not-guessable.
//
- // When a service is initialized or receives a connection from another
+ // When a service is initialized or receives a bind request from another
// service, this value is always the resolved user id, never |kInheritUserID|.
string user_id;
@@ -67,18 +68,85 @@
SetPID(uint32 pid);
};
-// Encapsulates establishing connections with other Services.
+// An interface that allows the holder to start other services & bind to
+// interfaces exposed by them.
interface Connector {
- // Typically, the service manager will start a process for a service the first
- // time it receives a connection request for it. This struct allows a client
- // to start the process itself and provide the service manager the pipes it
- // needs to communicate with it. When this function is called, the client owns
- // the lifetime of the child process it started, not the service manager. The
- // service manager binds the |service| pipe, and when it closes destroys the
- // associated instance but the process stays alive.
+ // Asks the service manager to route a request to bind an implementation of
+ // the interface to a named service instance.
+ //
+ // A service's ability to bind interfaces exposed by another is controlled by
+ // policy set out in each service's manifest. See
+ // //services/service_manager/README.md for more information on manifests.
+ // If policy prevents the requesting service from binding the specified
+ // interface, the request pipe will be closed.
//
// Parameters:
//
+ // target
+ // The identity of the service instance to route the request to. If no
+ // instance exists, the service will be started.
+ //
+ // interface_name
+ // The name of the interface to be bound. If the target service does not
+ // expose an interface of this name, the request pipe will be closed.
+ //
+ // interface_pipe
+ // A message pipe endpoint encapsulating a request for an interface named
+ // |interface_name|.
+ //
+ // Response parameters:
+ //
+ // result
+ // Indicates the result of the BindInterface() operation.
+ //
+ // identity
+ // The fully resolved identity of the instance in the service manager, with
+ // a resolved user id. Typically the client passes |kInheritUserID| as the
+ // user id to BindInterface(), which will be resolved by the service
+ // manager into a concrete user id.
+ //
+ BindInterface(Identity target,
+ string interface_name,
+ handle<message_pipe> interface_pipe) =>
+ (ConnectResult result, Identity user_id);
+
+ // Asks the service manager to create an instance for a service. No action is
+ // taken if an instance is already present. If the service is not yet running,
+ // it will be initialized and its OnStart() method will be called. A process
+ // may be allocated.
+ //
+ // Parameters:
+ //
+ // target
+ // The identity of the service to start.
+ //
+ // Response parameters:
+ //
+ // result
+ // Indicates the result of the StartService() operation.
+ //
+ // identity
+ // The fully resolved identity of the instance in the service manager, with
+ // a resolved user id. Typically the client passes |kInheritUserID| as the
+ // user id to BindInterface(), which will be resolved by the service
+ // manager into a concrete user id.
+ //
+ StartService(Identity target) => (ConnectResult result, Identity identity);
+
+ // Typically, the service manager will start a process for a service the first
+ // time it receives a bind interface request for it, or when StartService() is
+ // called. This struct allows a client to start the process itself and provide
+ // the service manager the pipes it needs to communicate with it. When this
+ // function is called, the client owns the lifetime of the child process it
+ // started, not the service manager. The service manager binds the |service|
+ // pipe, and when it closes destroys the associated instance but the process
+ // stays alive.
+ //
+ // Parameters:
+ //
+ // target
+ // The identity of the service to create the instance for.
+ //
// service
// A pipe to an implementation of Service that the service manager can use
// to communicate with the service.
@@ -86,57 +154,13 @@
// pid_receiver_request
// Allows the client process launcher to tell the service manager the PID of
// the process it created (the pid isn't supplied directly here as the
- // process may not have been launched by the time Connect() is called.)
+ // process may not have been launched by the time BindInterface() is
+ // called.)
//
- StartService(Identity name,
- handle<message_pipe> service,
- PIDReceiver& pid_receiver_request);
-
- // Requests a connection with another service. The service originating the
- // request is referred to as the "source" and the one receiving the "target".
- //
- // The connection is embodied by a pair of message pipes binding the
- // InterfaceProvider interface, which allows both the source and target
- // services to export interfaces to one another. The interfaces bound via
- // these InterfaceProviders are brokered by the service manager according to
- // the security policy defined by each service in its manifest.
- //
- // If the target service is not running, the service manager will run it,
- // calling its OnStart() method before completing the connection.
- //
- // Parameters:
- //
- // target
- // Identifies the target service instance to connect to.
- //
- // remote_interfaces
- // Allows the source service access to interface implementations exposed by
- // the target service. The interfaces accessible via this InterfaceProvider
- // are filtered by the security policy described by the source and target
- // service manifests.
- //
- // Response parameters:
- //
- // result
- // Indicates the result of the Connect() operation.
- //
- // user_id
- // The user id the service manager ran the target service as. Typically a
- // client passes |kInheritUserID| as the user id to Connect(), which is
- // resolved by the service manager into a valid user id returned through
- // this callback.
- //
- Connect(Identity target, InterfaceProvider&? remote_interfaces) =>
- (ConnectResult result, string user_id);
-
- // Variant of Connect() above. Will (gradually) replace it. Think of this like
- // a combination of Connect() and InterfaceProvider::GetInteface() - requests
- // a connection to a service and binds an interface in one step.
- // TODO(beng): Update this comment once the implementation is complete.
- BindInterface(Identity target,
- string interface_name,
- handle<message_pipe> interface_pipe) =>
- (ConnectResult result, string user_id);
+ StartServiceWithProcess(Identity target,
+ handle<message_pipe> service,
+ PIDReceiver& pid_receiver_request) =>
+ (ConnectResult result, Identity identity);
// Clones this Connector so it can be passed to another thread.
Clone(Connector& request);
diff --git a/services/service_manager/public/interfaces/service.mojom b/services/service_manager/public/interfaces/service.mojom
index 207da8cd..a0f14f4 100644
--- a/services/service_manager/public/interfaces/service.mojom
+++ b/services/service_manager/public/interfaces/service.mojom
@@ -48,26 +48,6 @@
OnStart(ServiceInfo info) => (Connector&? connector_request,
associated ServiceControl&? control_request);
- // Called when another service attempts to open a connection to this
- // service. A service implements this method to complete the exchange
- // of interface implementations with the remote service. See also
- // documentation in service_manager.mojom for Connect(). The service
- // originating the request is referred to as the "source" and the one
- // receiving the "target".
- //
- // The Service must respond to acknowledge receipt of the request.
- //
- // Parameters:
- //
- // source_info
- // Contains the source identity and interface provider specs.
- //
- // interfaces
- // A request for an InterfaceProvider by which the source service may
- // seek to bind interface implementations exported by the target.
- //
- OnConnect(ServiceInfo source_info, InterfaceProvider&? interfaces) => ();
-
// Called when a request to bind an interface is received from another
// ("source") service. This is the result of that service calling
// BindInterface() on a Connector. By the time this method is called, the
@@ -91,7 +71,6 @@
// the source's capability requirements to the target. This seems
// undesirable. The metadata supplied here should be germane to
// fulfilling this request and no more.
- // TODO(beng): This should replace OnConnect().
OnBindInterface(ServiceInfo source_info,
string interface_name,
handle<message_pipe> interface_pipe) => ();
diff --git a/services/service_manager/service_manager.cc b/services/service_manager/service_manager.cc
index 2a01504..d29b0c9 100644
--- a/services/service_manager/service_manager.cc
+++ b/services/service_manager/service_manager.cc
@@ -51,30 +51,6 @@
return result == mojom::ConnectResult::SUCCEEDED;
}
-bool RunConnectCallback(ConnectParams* params,
- mojom::ConnectResult result,
- const std::string& user_id) {
- if (!params->connect_callback().is_null()) {
- params->connect_callback().Run(result, user_id);
- return true;
- }
- return false;
-}
-
-void RunBindInterfaceCallback(ConnectParams* params,
- mojom::ConnectResult result,
- const std::string& user_id) {
- if (!params->bind_interface_callback().is_null())
- params->bind_interface_callback().Run(result, user_id);
-}
-
-void RunCallback(ConnectParams* params,
- mojom::ConnectResult result,
- const std::string& user_id) {
- if (!RunConnectCallback(params, result, user_id))
- RunBindInterfaceCallback(params, result, user_id);
-}
-
} // namespace
Identity CreateServiceManagerIdentity() {
@@ -152,36 +128,10 @@
Stop();
}
- bool CallOnConnect(std::unique_ptr<ConnectParams>* in_params) {
- if (!service_.is_bound()) {
- RunConnectCallback(in_params->get(), mojom::ConnectResult::ACCESS_DENIED,
- identity_.user_id());
- return false;
- }
-
- std::unique_ptr<ConnectParams> params(std::move(*in_params));
- RunConnectCallback(params.get(), mojom::ConnectResult::SUCCEEDED,
- identity_.user_id());
-
- InterfaceProviderSpecMap specs;
- Instance* source =
- service_manager_->GetExistingInstance(params->source());
- if (source)
- specs = source->interface_provider_specs_;
-
- pending_service_connections_++;
- service_->OnConnect(ServiceInfo(params->source(), specs),
- params->TakeRemoteInterfaces(),
- base::Bind(&Instance::OnConnectComplete,
- base::Unretained(this)));
- return true;
- }
-
bool CallOnBindInterface(std::unique_ptr<ConnectParams>* in_params) {
if (!service_.is_bound()) {
- RunBindInterfaceCallback(in_params->get(),
- mojom::ConnectResult::ACCESS_DENIED,
- identity_.user_id());
+ (*in_params)
+ ->set_response_data(mojom::ConnectResult::ACCESS_DENIED, identity_);
return false;
}
@@ -206,15 +156,11 @@
<< params->source().name() << " from binding interface: "
<< params->interface_name() << " exposed by: " << identity_.name();
LOG(ERROR) << ss.str();
- params->bind_interface_callback().Run(mojom::ConnectResult::ACCESS_DENIED,
- identity_.user_id());
+ params->set_response_data(mojom::ConnectResult::ACCESS_DENIED, identity_);
return false;
}
- if (!params->bind_interface_callback().is_null()) {
- params->bind_interface_callback().Run(mojom::ConnectResult::SUCCEEDED,
- identity_.user_id());
- }
+ params->set_response_data(mojom::ConnectResult::SUCCEEDED, identity_);
pending_service_connections_++;
service_->OnBindInterface(
@@ -307,65 +253,67 @@
};
// mojom::Connector implementation:
- void StartService(
- const Identity& in_target,
- mojo::ScopedMessagePipeHandle service_handle,
- mojom::PIDReceiverRequest pid_receiver_request) override {
- Identity target = in_target;
- mojom::ConnectResult result =
- ValidateConnectParams(&target, nullptr, nullptr);
- if (!Succeeded(result))
- return;
+ void BindInterface(const service_manager::Identity& in_target,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe,
+ const BindInterfaceCallback& callback) override {
+ Identity target = in_target;
+ mojom::ConnectResult result =
+ ValidateConnectParams(&target, nullptr, nullptr);
+ if (!Succeeded(result)) {
+ callback.Run(result, Identity());
+ return;
+ }
- std::unique_ptr<ConnectParams> params(new ConnectParams);
- params->set_source(identity_);
- params->set_target(target);
+ std::unique_ptr<ConnectParams> params(new ConnectParams);
+ params->set_source(identity_);
+ params->set_target(target);
+ params->set_interface_request_info(interface_name,
+ std::move(interface_pipe));
+ params->set_start_service_callback(callback);
+ service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
+ }
- mojom::ServicePtr service;
- service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0));
- params->set_client_process_info(std::move(service),
- std::move(pid_receiver_request));
- service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
- }
+ void StartService(const Identity& in_target,
+ const StartServiceCallback& callback) override {
+ Identity target = in_target;
+ mojom::ConnectResult result =
+ ValidateConnectParams(&target, nullptr, nullptr);
+ if (!Succeeded(result)) {
+ callback.Run(result, Identity());
+ return;
+ }
- void Connect(const service_manager::Identity& in_target,
- mojom::InterfaceProviderRequest remote_interfaces,
- const ConnectCallback& callback) override {
- Identity target = in_target;
- mojom::ConnectResult result =
- ValidateConnectParams(&target, nullptr, nullptr);
- if (!Succeeded(result)) {
- callback.Run(result, mojom::kInheritUserID);
- return;
- }
+ std::unique_ptr<ConnectParams> params(new ConnectParams);
+ params->set_source(identity_);
+ params->set_target(target);
+ params->set_start_service_callback(callback);
+ service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
+ }
- std::unique_ptr<ConnectParams> params(new ConnectParams);
- params->set_source(identity_);
- params->set_target(target);
- params->set_remote_interfaces(std::move(remote_interfaces));
- params->set_connect_callback(callback);
- service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
- }
+ void StartServiceWithProcess(
+ const Identity& in_target,
+ mojo::ScopedMessagePipeHandle service_handle,
+ mojom::PIDReceiverRequest pid_receiver_request,
+ const StartServiceWithProcessCallback& callback) override {
+ Identity target = in_target;
+ mojom::ConnectResult result =
+ ValidateConnectParams(&target, nullptr, nullptr);
+ if (!Succeeded(result)) {
+ callback.Run(result, Identity());
+ return;
+ }
- void BindInterface(const service_manager::Identity& in_target,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe,
- const BindInterfaceCallback& callback) override {
- Identity target = in_target;
- mojom::ConnectResult result =
- ValidateConnectParams(&target, nullptr, nullptr);
- if (!Succeeded(result)) {
- callback.Run(result, mojom::kInheritUserID);
- return;
- }
+ std::unique_ptr<ConnectParams> params(new ConnectParams);
+ params->set_source(identity_);
+ params->set_target(target);
- std::unique_ptr<ConnectParams> params(new ConnectParams);
- params->set_source(identity_);
- params->set_target(target);
- params->set_interface_request_info(interface_name,
- std::move(interface_pipe));
- params->set_bind_interface_callback(callback);
- service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
+ mojom::ServicePtr service;
+ service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0));
+ params->set_client_process_info(std::move(service),
+ std::move(pid_receiver_request));
+ params->set_start_service_callback(callback);
+ service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
}
void Clone(mojom::ConnectorRequest request) override {
@@ -533,14 +481,6 @@
OnServiceLost(service_manager_->GetWeakPtr());
}
- void EmptyConnectCallback(mojom::ConnectResult result,
- const std::string& user_id) {}
- void BindCallbackWrapper(const BindInterfaceCallback& wrapped,
- mojom::ConnectResult result,
- const std::string& user_id) {
- wrapped.Run(result, user_id);
- }
-
service_manager::ServiceManager* const service_manager_;
// An id that identifies this instance. Distinct from pid, as a single process
@@ -560,7 +500,7 @@
base::ProcessId pid_ = base::kNullProcessId;
State state_;
- // The number of outstanding OnConnect requests which are in flight.
+ // The number of outstanding OnBindInterface requests which are in flight.
int pending_service_connections_ = 0;
base::WeakPtrFactory<Instance> weak_factory_;
@@ -852,14 +792,12 @@
bool ServiceManager::ConnectToExistingInstance(
std::unique_ptr<ConnectParams>* params) {
Instance* instance = GetExistingInstance((*params)->target());
- if (instance) {
- if ((*params)->HasInterfaceRequestInfo()) {
- instance->CallOnBindInterface(params);
- return true;
- }
- return instance->CallOnConnect(params);
- }
- return false;
+ if (!instance)
+ return false;
+
+ if ((*params)->HasInterfaceRequestInfo())
+ instance->CallOnBindInterface(params);
+ return true;
}
ServiceManager::Instance* ServiceManager::CreateInstance(
@@ -944,7 +882,8 @@
// If name resolution failed, we drop the connection.
if (!result) {
LOG(ERROR) << "Failed to resolve service name: " << params->target().name();
- RunCallback(params.get(), mojom::ConnectResult::INVALID_ARGUMENT, "");
+ params->set_response_data(mojom::ConnectResult::INVALID_ARGUMENT,
+ Identity());
return;
}
@@ -1011,7 +950,8 @@
LOG(ERROR)
<< "Error: The catalog was unable to read a manifest for service \""
<< result->name << "\".";
- RunCallback(params.get(), mojom::ConnectResult::ACCESS_DENIED, "");
+ params->set_response_data(mojom::ConnectResult::ACCESS_DENIED,
+ Identity());
return;
}
@@ -1049,19 +989,17 @@
if (!instance->StartWithFilePath(package_path)) {
OnInstanceError(instance);
- RunCallback(params.get(), mojom::ConnectResult::INVALID_ARGUMENT, "");
+ params->set_response_data(mojom::ConnectResult::INVALID_ARGUMENT,
+ Identity());
return;
}
}
}
- // Now that the instance has a Service, we can connect to it.
- if (params->HasInterfaceRequestInfo()) {
+ params->set_response_data(mojom::ConnectResult::SUCCEEDED,
+ instance->identity());
+ if (params->HasInterfaceRequestInfo())
instance->CallOnBindInterface(¶ms);
- } else {
- bool connected = instance->CallOnConnect(¶ms);
- DCHECK(connected);
- }
}
base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() {
diff --git a/services/service_manager/service_manager.h b/services/service_manager/service_manager.h
index ecba992..3596d8e 100644
--- a/services/service_manager/service_manager.h
+++ b/services/service_manager/service_manager.h
@@ -188,8 +188,6 @@
DISALLOW_COPY_AND_ASSIGN(ServiceManager);
};
-mojom::Connector::ConnectCallback EmptyConnectCallback();
-
} // namespace service_manager
#endif // SERVICES_SERVICE_MANAGER_SERVICE_MANAGER_H_
diff --git a/services/service_manager/standalone/context.cc b/services/service_manager/standalone/context.cc
index 5b38d528..99860361 100644
--- a/services/service_manager/standalone/context.cc
+++ b/services/service_manager/standalone/context.cc
@@ -156,13 +156,9 @@
void Context::Run(const std::string& name) {
service_manager_->SetInstanceQuitCallback(base::Bind(&OnInstanceQuit, name));
- mojom::InterfaceProviderPtr remote_interfaces;
- mojom::InterfaceProviderPtr local_interfaces;
-
std::unique_ptr<ConnectParams> params(new ConnectParams);
params->set_source(CreateServiceManagerIdentity());
params->set_target(Identity(name, mojom::kRootUserID));
- params->set_remote_interfaces(mojo::MakeRequest(&remote_interfaces));
service_manager_->Connect(std::move(params));
}
diff --git a/services/service_manager/tests/connect/connect_test_app.cc b/services/service_manager/tests/connect/connect_test_app.cc
index ad0a26e6..6203415 100644
--- a/services/service_manager/tests/connect/connect_test_app.cc
+++ b/services/service_manager/tests/connect/connect_test_app.cc
@@ -11,9 +11,9 @@
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/c/main.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_runner.h"
@@ -24,8 +24,14 @@
namespace {
-void QuitLoop(base::RunLoop* loop) {
+void QuitLoop(base::RunLoop* loop,
+ mojom::ConnectResult* out_result,
+ Identity* out_resolved_identity,
+ mojom::ConnectResult result,
+ const Identity& resolved_identity) {
loop->Quit();
+ *out_result = result;
+ *out_resolved_identity = resolved_identity;
}
void ReceiveString(std::string* string,
@@ -61,31 +67,30 @@
standalone_bindings_.set_connection_error_handler(
base::Bind(&ConnectTestApp::OnConnectionError,
base::Unretained(this)));
+ registry_.AddInterface<test::mojom::ConnectTestService>(this);
+ registry_.AddInterface<test::mojom::StandaloneApp>(this);
+ registry_.AddInterface<test::mojom::BlockedInterface>(this);
+ registry_.AddInterface<test::mojom::UserIdTest>(this);
}
-
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<test::mojom::ConnectTestService>(this);
- registry->AddInterface<test::mojom::StandaloneApp>(this);
- registry->AddInterface<test::mojom::BlockedInterface>(this);
- registry->AddInterface<test::mojom::UserIdTest>(this);
-
- test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New());
- state->connection_remote_name = remote_info.identity.name();
- state->connection_remote_userid = remote_info.identity.user_id();
- state->initialize_local_name = context()->identity().name();
- state->initialize_userid = context()->identity().user_id();
-
- context()->connector()->BindInterface(remote_info.identity, &caller_);
- caller_->ConnectionAccepted(std::move(state));
-
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<test::mojom::ConnectTestService>:
void Create(const Identity& remote_identity,
test::mojom::ConnectTestServiceRequest request) override {
bindings_.AddBinding(this, std::move(request));
+ test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New());
+ state->connection_remote_name = remote_identity.name();
+ state->connection_remote_userid = remote_identity.user_id();
+ state->initialize_local_name = context()->identity().name();
+ state->initialize_userid = context()->identity().user_id();
+
+ context()->connector()->BindInterface(remote_identity, &caller_);
+ caller_->ConnectionAccepted(std::move(state));
}
// InterfaceFactory<test::mojom::StandaloneApp>:
@@ -118,13 +123,11 @@
void ConnectToAllowedAppInBlockedPackage(
const ConnectToAllowedAppInBlockedPackageCallback& callback) override {
base::RunLoop run_loop;
- std::unique_ptr<Connection> connection =
- context()->connector()->Connect("connect_test_a");
- connection->SetConnectionLostClosure(
- base::Bind(&ConnectTestApp::OnConnectionBlocked,
- base::Unretained(this), callback, &run_loop));
test::mojom::ConnectTestServicePtr test_service;
- connection->GetInterface(&test_service);
+ context()->connector()->BindInterface("connect_test_a", &test_service);
+ test_service.set_connection_error_handler(
+ base::Bind(&ConnectTestApp::OnConnectionBlocked, base::Unretained(this),
+ callback, &run_loop));
test_service->GetTitle(
base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this),
callback, &run_loop));
@@ -138,10 +141,9 @@
}
void ConnectToClassInterface(
const ConnectToClassInterfaceCallback& callback) override {
- std::unique_ptr<Connection> connection =
- context()->connector()->Connect("connect_test_class_app");
test::mojom::ClassInterfacePtr class_interface;
- connection->GetInterface(&class_interface);
+ context()->connector()->BindInterface("connect_test_class_app",
+ &class_interface);
std::string ping_response;
{
base::RunLoop loop;
@@ -151,7 +153,7 @@
loop.Run();
}
test::mojom::ConnectTestServicePtr service;
- connection->GetInterface(&service);
+ context()->connector()->BindInterface("connect_test_class_app", &service);
std::string title_response;
{
base::RunLoop loop;
@@ -172,17 +174,19 @@
void ConnectToClassAppAsDifferentUser(
const service_manager::Identity& target,
const ConnectToClassAppAsDifferentUserCallback& callback) override {
- std::unique_ptr<Connection> connection =
- context()->connector()->Connect(target);
+ context()->connector()->StartService(target);
+ mojom::ConnectResult result;
+ Identity resolved_identity;
{
base::RunLoop loop;
- connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
+ Connector::TestApi test_api(context()->connector());
+ test_api.SetStartServiceCallback(
+ base::Bind(&QuitLoop, &loop, &result, &resolved_identity));
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
loop.Run();
}
- callback.Run(static_cast<int32_t>(connection->GetResult()),
- connection->GetRemoteIdentity());
+ callback.Run(static_cast<int32_t>(result), resolved_identity);
}
void OnConnectionBlocked(
@@ -205,6 +209,7 @@
base::MessageLoop::current()->QuitWhenIdle();
}
+ BinderRegistry registry_;
mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
mojo::BindingSet<test::mojom::StandaloneApp> standalone_bindings_;
mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_;
diff --git a/services/service_manager/tests/connect/connect_test_class_app.cc b/services/service_manager/tests/connect/connect_test_class_app.cc
index 8e19e61..f5a26ca 100644
--- a/services/service_manager/tests/connect/connect_test_class_app.cc
+++ b/services/service_manager/tests/connect/connect_test_class_app.cc
@@ -8,11 +8,12 @@
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/c/main.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
+#include "services/service_manager/public/cpp/service_context_ref.h"
#include "services/service_manager/public/cpp/service_runner.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
#include "services/service_manager/tests/connect/connect_test.mojom.h"
@@ -28,31 +29,38 @@
public test::mojom::ConnectTestService,
public test::mojom::ClassInterface {
public:
- ConnectTestClassApp() {}
+ ConnectTestClassApp()
+ : ref_factory_(base::Bind(&ConnectTestClassApp::HandleQuit,
+ base::Unretained(this))) {
+ bindings_.set_connection_error_handler(base::Bind(
+ &ConnectTestClassApp::HandleInterfaceClose, base::Unretained(this)));
+ class_interface_bindings_.set_connection_error_handler(base::Bind(
+ &ConnectTestClassApp::HandleInterfaceClose, base::Unretained(this)));
+ registry_.AddInterface<test::mojom::ConnectTestService>(this);
+ registry_.AddInterface<test::mojom::ClassInterface>(this);
+ }
~ConnectTestClassApp() override {}
private:
// service_manager::Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<test::mojom::ConnectTestService>(this);
- registry->AddInterface<test::mojom::ClassInterface>(this);
- inbound_connections_.insert(registry);
- registry->AddConnectionLostClosure(
- base::Bind(&ConnectTestClassApp::OnConnectionError,
- base::Unretained(this), registry));
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<test::mojom::ConnectTestService>:
void Create(const Identity& remote_identity,
test::mojom::ConnectTestServiceRequest request) override {
+ refs_.push_back(ref_factory_.CreateRef());
bindings_.AddBinding(this, std::move(request));
}
// InterfaceFactory<test::mojom::ClassInterface>:
void Create(const Identity& remote_identity,
test::mojom::ClassInterfaceRequest request) override {
+ refs_.push_back(ref_factory_.CreateRef());
class_interface_bindings_.AddBinding(this, std::move(request));
}
@@ -69,17 +77,15 @@
callback.Run("PONG");
}
- void OnConnectionError(InterfaceRegistry* registry) {
- auto it = inbound_connections_.find(registry);
- DCHECK(it != inbound_connections_.end());
- inbound_connections_.erase(it);
- if (inbound_connections_.empty())
- context()->QuitNow();
- }
+ void HandleQuit() { context()->QuitNow(); }
- std::set<InterfaceRegistry*> inbound_connections_;
+ void HandleInterfaceClose() { refs_.pop_back(); }
+
+ BinderRegistry registry_;
mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_;
+ ServiceContextRefFactory ref_factory_;
+ std::vector<std::unique_ptr<ServiceContextRef>> refs_;
DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp);
};
diff --git a/services/service_manager/tests/connect/connect_test_package.cc b/services/service_manager/tests/connect/connect_test_package.cc
index 974e387..2494479d 100644
--- a/services/service_manager/tests/connect/connect_test_package.cc
+++ b/services/service_manager/tests/connect/connect_test_package.cc
@@ -16,9 +16,9 @@
#include "base/threading/simple_thread.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/c/main.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_runner.h"
@@ -30,6 +30,19 @@
// the package's manifest and are thus registered with the PackageManager.
namespace service_manager {
+namespace {
+
+void QuitLoop(base::RunLoop* loop,
+ mojom::ConnectResult* out_result,
+ Identity* out_resolved_identity,
+ mojom::ConnectResult result,
+ const Identity& resolved_identity) {
+ loop->Quit();
+ *out_result = result;
+ *out_resolved_identity = resolved_identity;
+}
+
+} // namespace
using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback;
@@ -60,30 +73,29 @@
bindings_.set_connection_error_handler(
base::Bind(&ProvidedService::OnConnectionError,
base::Unretained(this)));
+ registry_.AddInterface<test::mojom::ConnectTestService>(this);
+ registry_.AddInterface<test::mojom::BlockedInterface>(this);
+ registry_.AddInterface<test::mojom::UserIdTest>(this);
}
-
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<test::mojom::ConnectTestService>(this);
- registry->AddInterface<test::mojom::BlockedInterface>(this);
- registry->AddInterface<test::mojom::UserIdTest>(this);
-
- test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New());
- state->connection_remote_name = remote_info.identity.name();
- state->connection_remote_userid = remote_info.identity.user_id();
- state->initialize_local_name = context()->identity().name();
- state->initialize_userid = context()->identity().user_id();
-
- context()->connector()->BindInterface(remote_info.identity, &caller_);
- caller_->ConnectionAccepted(std::move(state));
-
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<test::mojom::ConnectTestService>:
void Create(const Identity& remote_identity,
test::mojom::ConnectTestServiceRequest request) override {
bindings_.AddBinding(this, std::move(request));
+ test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New());
+ state->connection_remote_name = remote_identity.name();
+ state->connection_remote_userid = remote_identity.user_id();
+ state->initialize_local_name = context()->identity().name();
+ state->initialize_userid = context()->identity().user_id();
+
+ context()->connector()->BindInterface(remote_identity, &caller_);
+ caller_->ConnectionAccepted(std::move(state));
}
// InterfaceFactory<test::mojom::BlockedInterface>:
@@ -116,17 +128,19 @@
void ConnectToClassAppAsDifferentUser(
const service_manager::Identity& target,
const ConnectToClassAppAsDifferentUserCallback& callback) override {
- std::unique_ptr<Connection> connection =
- context()->connector()->Connect(target);
+ context()->connector()->StartService(target);
+ mojom::ConnectResult result;
+ Identity resolved_identity;
{
base::RunLoop loop;
- connection->AddConnectionCompletedClosure(loop.QuitClosure());
+ Connector::TestApi test_api(context()->connector());
+ test_api.SetStartServiceCallback(
+ base::Bind(&QuitLoop, &loop, &result, &resolved_identity));
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
loop.Run();
}
- callback.Run(static_cast<int32_t>(connection->GetResult()),
- connection->GetRemoteIdentity());
+ callback.Run(static_cast<int32_t>(result), resolved_identity);
}
// base::SimpleThread:
@@ -147,6 +161,7 @@
const std::string title_;
mojom::ServiceRequest request_;
test::mojom::ExposedInterfacePtr caller_;
+ BinderRegistry registry_;
mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
mojo::BindingSet<test::mojom::BlockedInterface> blocked_bindings_;
mojo::BindingSet<test::mojom::UserIdTest> user_id_test_bindings_;
@@ -172,13 +187,14 @@
base::Unretained(this));
bindings_.set_connection_error_handler(error_handler);
service_factory_bindings_.set_connection_error_handler(error_handler);
+ registry_.AddInterface<ServiceFactory>(this);
+ registry_.AddInterface<test::mojom::ConnectTestService>(this);
}
-
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<ServiceFactory>(this);
- registry->AddInterface<test::mojom::ConnectTestService>(this);
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
bool OnServiceManagerConnectionLost() override {
@@ -226,6 +242,7 @@
std::vector<std::unique_ptr<Service>> delegates_;
mojo::BindingSet<mojom::ServiceFactory> service_factory_bindings_;
+ BinderRegistry registry_;
mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
std::list<std::unique_ptr<ProvidedService>> provided_services_;
diff --git a/services/service_manager/tests/connect/connect_test_singleton_app.cc b/services/service_manager/tests/connect/connect_test_singleton_app.cc
index b9928d3..108225c 100644
--- a/services/service_manager/tests/connect/connect_test_singleton_app.cc
+++ b/services/service_manager/tests/connect/connect_test_singleton_app.cc
@@ -15,12 +15,6 @@
~ConnectTestSingletonApp() override {}
private:
- // service_manager::Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- return true;
- }
-
DISALLOW_COPY_AND_ASSIGN(ConnectTestSingletonApp);
};
diff --git a/services/service_manager/tests/connect/connect_unittest.cc b/services/service_manager/tests/connect/connect_unittest.cc
index e4f978c..c3b2abf6 100644
--- a/services/service_manager/tests/connect/connect_unittest.cc
+++ b/services/service_manager/tests/connect/connect_unittest.cc
@@ -16,8 +16,8 @@
#include "base/run_loop.h"
#include "base/test/test_suite.h"
#include "mojo/public/cpp/bindings/binding_set.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_test.h"
#include "services/service_manager/public/interfaces/service_manager.mojom.h"
#include "services/service_manager/tests/connect/connect_test.mojom.h"
@@ -65,6 +65,19 @@
loop->Quit();
}
+void StartServiceResponse(base::RunLoop* quit_loop,
+ mojom::ConnectResult* out_result,
+ Identity* out_resolved_identity,
+ mojom::ConnectResult result,
+ const Identity& resolved_identity) {
+ if (quit_loop)
+ quit_loop->Quit();
+ if (out_result)
+ *out_result = result;
+ if (out_resolved_identity)
+ *out_resolved_identity = resolved_identity;
+}
+
void QuitLoop(base::RunLoop* loop) {
loop->Quit();
}
@@ -79,14 +92,6 @@
~ConnectTest() override {}
protected:
- std::unique_ptr<Connection> ConnectTo(const Identity& target) {
- std::unique_ptr<Connection> connection = connector()->Connect(target);
- base::RunLoop loop;
- connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
- loop.Run();
- return connection;
- }
-
void CompareConnectionState(
const std::string& connection_local_name,
const std::string& connection_remote_name,
@@ -105,18 +110,22 @@
class TestService : public test::ServiceTestClient {
public:
explicit TestService(ConnectTest* connect_test)
- : test::ServiceTestClient(connect_test),
- connect_test_(connect_test) {}
+ : test::ServiceTestClient(connect_test), connect_test_(connect_test) {
+ registry_.AddInterface<test::mojom::ExposedInterface>(connect_test_);
+ }
~TestService() override {}
private:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<test::mojom::ExposedInterface>(connect_test_);
- return true;
+ void OnBindInterface(
+ const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
ConnectTest* connect_test_;
+ BinderRegistry registry_;
DISALLOW_COPY_AND_ASSIGN(TestService);
};
@@ -129,9 +138,7 @@
// package app's manifest and register aliases for the applications it
// provides.
test::mojom::ConnectTestServicePtr root_service;
- std::unique_ptr<Connection> connection =
- connector()->Connect(kTestPackageName);
- connection->GetInterface(&root_service);
+ connector()->BindInterface(kTestPackageName, &root_service);
base::RunLoop run_loop;
std::string root_name;
root_service->GetTitle(
@@ -161,34 +168,29 @@
// Ensure the connection was properly established and that a round trip
// method call/response is completed.
-TEST_F(ConnectTest, Connect) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName);
+TEST_F(ConnectTest, BindInterface) {
test::mojom::ConnectTestServicePtr service;
- connection->GetInterface(&service);
+ connector()->BindInterface(kTestAppName, &service);
base::RunLoop run_loop;
std::string title;
service->GetTitle(base::Bind(&ReceiveOneString, &title, &run_loop));
run_loop.Run();
EXPECT_EQ("APP", title);
- EXPECT_FALSE(connection->IsPending());
- EXPECT_EQ(connection->GetRemoteIdentity().name(), kTestAppName);
}
TEST_F(ConnectTest, Instances) {
Identity identity_a(kTestAppName, mojom::kInheritUserID, "A");
- std::unique_ptr<Connection> connection_a1 = ConnectTo(identity_a);
- std::unique_ptr<Connection> connection_a2 = ConnectTo(identity_a);
std::string instance_a1, instance_a2;
test::mojom::ConnectTestServicePtr service_a1;
{
- connection_a1->GetInterface(&service_a1);
+ connector()->BindInterface(identity_a, &service_a1);
base::RunLoop loop;
service_a1->GetInstance(base::Bind(&ReceiveOneString, &instance_a1, &loop));
loop.Run();
}
test::mojom::ConnectTestServicePtr service_a2;
{
- connection_a2->GetInterface(&service_a2);
+ connector()->BindInterface(identity_a, &service_a2);
base::RunLoop loop;
service_a2->GetInstance(base::Bind(&ReceiveOneString, &instance_a2, &loop));
loop.Run();
@@ -196,11 +198,10 @@
EXPECT_EQ(instance_a1, instance_a2);
Identity identity_b(kTestAppName, mojom::kInheritUserID, "B");
- std::unique_ptr<Connection> connection_b = ConnectTo(identity_b);
std::string instance_b;
test::mojom::ConnectTestServicePtr service_b;
{
- connection_b->GetInterface(&service_b);
+ connector()->BindInterface(identity_b, &service_b);
base::RunLoop loop;
service_b->GetInstance(base::Bind(&ReceiveOneString, &instance_b, &loop));
loop.Run();
@@ -212,10 +213,9 @@
// BlockedInterface should not be exposed to this application because it is not
// in our CapabilityFilter whitelist.
TEST_F(ConnectTest, BlockedInterface) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName);
base::RunLoop run_loop;
test::mojom::BlockedInterfacePtr blocked;
- connection->GetInterface(&blocked);
+ connector()->BindInterface(kTestAppName, &blocked);
blocked.set_connection_error_handler(base::Bind(&QuitLoop, &run_loop));
std::string title = "unchanged";
blocked->GetTitleBlocked(base::Bind(&ReceiveOneString, &title, &run_loop));
@@ -225,16 +225,18 @@
// Connects to an app provided by a package.
TEST_F(ConnectTest, PackagedApp) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppAName);
test::mojom::ConnectTestServicePtr service_a;
- connection->GetInterface(&service_a);
+ connector()->BindInterface(kTestAppAName, &service_a);
+ Connector::TestApi test_api(connector());
+ Identity resolved_identity;
+ test_api.SetStartServiceCallback(
+ base::Bind(&StartServiceResponse, nullptr, nullptr, &resolved_identity));
base::RunLoop run_loop;
std::string a_name;
service_a->GetTitle(base::Bind(&ReceiveOneString, &a_name, &run_loop));
run_loop.Run();
EXPECT_EQ("A", a_name);
- EXPECT_FALSE(connection->IsPending());
- EXPECT_EQ(connection->GetRemoteIdentity().name(), kTestAppAName);
+ EXPECT_EQ(resolved_identity.name(), kTestAppAName);
}
// Ask the target application to attempt to connect to a third application
@@ -243,9 +245,8 @@
// allowed regardless of the target's CapabilityFilter with respect to the
// package.
TEST_F(ConnectTest, BlockedPackage) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName);
test::mojom::StandaloneAppPtr standalone_app;
- connection->GetInterface(&standalone_app);
+ connector()->BindInterface(kTestAppName, &standalone_app);
base::RunLoop run_loop;
std::string title;
standalone_app->ConnectToAllowedAppInBlockedPackage(
@@ -257,10 +258,9 @@
// BlockedInterface should not be exposed to this application because it is not
// in our CapabilityFilter whitelist.
TEST_F(ConnectTest, PackagedApp_BlockedInterface) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppAName);
base::RunLoop run_loop;
test::mojom::BlockedInterfacePtr blocked;
- connection->GetInterface(&blocked);
+ connector()->BindInterface(kTestAppAName, &blocked);
blocked.set_connection_error_handler(base::Bind(&QuitLoop, &run_loop));
run_loop.Run();
}
@@ -268,20 +268,21 @@
// Connection to another application provided by the same package, blocked
// because it's not in the capability filter whitelist.
TEST_F(ConnectTest, BlockedPackagedApplication) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppBName);
test::mojom::ConnectTestServicePtr service_b;
- connection->GetInterface(&service_b);
+ connector()->BindInterface(kTestAppBName, &service_b);
+ Connector::TestApi test_api(connector());
+ mojom::ConnectResult result;
+ test_api.SetStartServiceCallback(
+ base::Bind(&StartServiceResponse, nullptr, &result, nullptr));
base::RunLoop run_loop;
- connection->SetConnectionLostClosure(base::Bind(&QuitLoop, &run_loop));
+ service_b.set_connection_error_handler(run_loop.QuitClosure());
run_loop.Run();
- EXPECT_FALSE(connection->IsPending());
- EXPECT_EQ(mojom::ConnectResult::ACCESS_DENIED, connection->GetResult());
+ EXPECT_EQ(mojom::ConnectResult::ACCESS_DENIED, result);
}
TEST_F(ConnectTest, CapabilityClasses) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName);
test::mojom::StandaloneAppPtr standalone_app;
- connection->GetInterface(&standalone_app);
+ connector()->BindInterface(kTestAppName, &standalone_app);
std::string string1, string2;
base::RunLoop loop;
standalone_app->ConnectToClassInterface(
@@ -295,19 +296,16 @@
// We not be able to bind a ClassInterfacePtr since the connect_unittest app
// does not explicitly request the "class" capability from
// connect_test_class_app. This test will hang if it is bound.
- std::unique_ptr<Connection> connection =
- connector()->Connect(kTestClassAppName);
test::mojom::ClassInterfacePtr class_interface;
- connection->GetInterface(&class_interface);
+ connector()->BindInterface(kTestClassAppName, &class_interface);
base::RunLoop loop;
class_interface.set_connection_error_handler(base::Bind(&QuitLoop, &loop));
loop.Run();
}
TEST_F(ConnectTest, ConnectAsDifferentUser_Allowed) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName);
test::mojom::UserIdTestPtr user_id_test;
- connection->GetInterface(&user_id_test);
+ connector()->BindInterface(kTestAppName, &user_id_test);
mojom::ConnectResult result;
Identity target(kTestClassAppName, base::GenerateGUID());
Identity result_identity;
@@ -323,9 +321,8 @@
}
TEST_F(ConnectTest, ConnectAsDifferentUser_Blocked) {
- std::unique_ptr<Connection> connection = connector()->Connect(kTestAppAName);
test::mojom::UserIdTestPtr user_id_test;
- connection->GetInterface(&user_id_test);
+ connector()->BindInterface(kTestAppAName, &user_id_test);
mojom::ConnectResult result;
Identity target(kTestClassAppName, base::GenerateGUID());
Identity result_identity;
@@ -345,7 +342,7 @@
// process specifications. This is the only one for blocking.
TEST_F(ConnectTest, ConnectToClientProcess_Blocked) {
base::Process process;
- std::unique_ptr<service_manager::Connection> connection =
+ mojom::ConnectResult result =
service_manager::test::LaunchAndConnectToProcess(
#if defined(OS_WIN)
"connect_test_exe.exe",
@@ -355,7 +352,7 @@
service_manager::Identity("connect_test_exe",
service_manager::mojom::kInheritUserID),
connector(), &process);
- EXPECT_EQ(connection->GetResult(), mojom::ConnectResult::ACCESS_DENIED);
+ EXPECT_EQ(result, mojom::ConnectResult::ACCESS_DENIED);
}
// Verifies that a client with the "all_users" capability class can receive
@@ -367,25 +364,28 @@
// synthetic user id for all-user singleton instances).
const std::string singleton_userid = base::GenerateGUID();
Identity singleton_id(kTestSingletonAppName, singleton_userid);
- std::unique_ptr<Connection> connection = connector()->Connect(singleton_id);
+ connector()->StartService(singleton_id);
+ Identity first_resolved_identity;
{
base::RunLoop loop;
- connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
+ Connector::TestApi test_api(connector());
+ test_api.SetStartServiceCallback(base::Bind(
+ &StartServiceResponse, &loop, nullptr, &first_resolved_identity));
loop.Run();
- EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid);
+ EXPECT_NE(first_resolved_identity.user_id(), singleton_userid);
}
// This connects using the current client's user_id. It should be bound to the
// same service started above, with the same service manager-generated user
// id.
- std::unique_ptr<Connection> inherit_connection =
- connector()->Connect(kTestSingletonAppName);
+ connector()->StartService(kTestSingletonAppName);
{
base::RunLoop loop;
- inherit_connection->AddConnectionCompletedClosure(
- base::Bind(&QuitLoop, &loop));
+ Connector::TestApi test_api(connector());
+ Identity resolved_identity;
+ test_api.SetStartServiceCallback(
+ base::Bind(&StartServiceResponse, &loop, nullptr, &resolved_identity));
loop.Run();
- EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(),
- connection->GetRemoteIdentity().user_id());
+ EXPECT_EQ(resolved_identity.user_id(), first_resolved_identity.user_id());
}
}
diff --git a/services/service_manager/tests/lifecycle/app_client.cc b/services/service_manager/tests/lifecycle/app_client.cc
index 5e9467e..1ec9b3b 100644
--- a/services/service_manager/tests/lifecycle/app_client.cc
+++ b/services/service_manager/tests/lifecycle/app_client.cc
@@ -5,20 +5,22 @@
#include "services/service_manager/tests/lifecycle/app_client.h"
#include "base/macros.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_context.h"
namespace service_manager {
namespace test {
-AppClient::AppClient() {}
+AppClient::AppClient() {
+ registry_.AddInterface<mojom::LifecycleControl>(this);
+}
AppClient::~AppClient() {}
-bool AppClient::OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) {
- registry->AddInterface<mojom::LifecycleControl>(this);
- return true;
+void AppClient::OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
bool AppClient::OnServiceManagerConnectionLost() {
diff --git a/services/service_manager/tests/lifecycle/app_client.h b/services/service_manager/tests/lifecycle/app_client.h
index 9d8baad..34100bf 100644
--- a/services/service_manager/tests/lifecycle/app_client.h
+++ b/services/service_manager/tests/lifecycle/app_client.h
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_runner.h"
@@ -29,8 +30,9 @@
void set_runner(ServiceRunner* runner) { runner_ = runner; }
// Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override;
bool OnServiceManagerConnectionLost() override;
// InterfaceFactory<LifecycleControl>:
@@ -49,6 +51,7 @@
void BindingLost();
ServiceRunner* runner_ = nullptr;
+ BinderRegistry registry_;
mojo::BindingSet<mojom::LifecycleControl> bindings_;
DISALLOW_COPY_AND_ASSIGN(AppClient);
diff --git a/services/service_manager/tests/service_manager/service_manager_unittest.cc b/services/service_manager/tests/service_manager/service_manager_unittest.cc
index 08b3e94..bf79e683 100644
--- a/services/service_manager/tests/service_manager/service_manager_unittest.cc
+++ b/services/service_manager/tests/service_manager/service_manager_unittest.cc
@@ -24,8 +24,8 @@
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/public/cpp/bindings/binding_set.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_test.h"
#include "services/service_manager/public/interfaces/constants.mojom.h"
@@ -43,7 +43,9 @@
public test::mojom::CreateInstanceTest {
public:
explicit ServiceManagerTestClient(test::ServiceTest* test)
- : test::ServiceTestClient(test), binding_(this) {}
+ : test::ServiceTestClient(test), binding_(this) {
+ registry_.AddInterface<test::mojom::CreateInstanceTest>(this);
+ }
~ServiceManagerTestClient() override {}
const Identity& target_identity() const { return target_identity_; }
@@ -55,10 +57,11 @@
private:
// test::ServiceTestClient:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<test::mojom::CreateInstanceTest>(this);
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<test::mojom::CreateInstanceTest>:
@@ -79,6 +82,7 @@
service_manager::Identity target_identity_;
std::unique_ptr<base::RunLoop> wait_for_target_identity_loop_;
+ BinderRegistry registry_;
mojo::Binding<test::mojom::CreateInstanceTest> binding_;
DISALLOW_COPY_AND_ASSIGN(ServiceManagerTestClient);
@@ -187,11 +191,9 @@
service_manager::mojom::kInheritUserID);
connector()->StartService(target, std::move(client),
MakeRequest(&receiver));
- std::unique_ptr<service_manager::Connection> connection =
- connector()->Connect(target);
- connection->AddConnectionCompletedClosure(
- base::Bind(&ServiceManagerTest::OnConnectionCompleted,
- base::Unretained(this)));
+ Connector::TestApi test_api(connector());
+ test_api.SetStartServiceCallback(base::Bind(
+ &ServiceManagerTest::OnConnectionCompleted, base::Unretained(this)));
base::LaunchOptions options;
#if defined(OS_WIN)
@@ -255,7 +257,7 @@
}
}
- void OnConnectionCompleted() {}
+ void OnConnectionCompleted(mojom::ConnectResult, const Identity&) {}
ServiceManagerTestClient* service_;
mojo::Binding<mojom::ServiceManagerListener> binding_;
@@ -333,11 +335,9 @@
&OnServiceFailedToStartCallback,
&failed_to_start, loop.QuitClosure()));
- std::unique_ptr<Connection> embedder_connection =
- connector()->Connect("service_manager_unittest_embedder");
+ connector()->StartService("service_manager_unittest_embedder");
loop.Run();
EXPECT_FALSE(failed_to_start);
- EXPECT_FALSE(embedder_connection->IsPending());
EXPECT_EQ(1, start_count);
EXPECT_EQ("service_manager_unittest_embedder", service_name);
}
@@ -355,11 +355,9 @@
&failed_to_start, loop.QuitClosure()));
// Connect to the packaged singleton service.
- std::unique_ptr<Connection> singleton_connection =
- connector()->Connect("service_manager_unittest_singleton");
+ connector()->StartService("service_manager_unittest_singleton");
loop.Run();
EXPECT_FALSE(failed_to_start);
- EXPECT_FALSE(singleton_connection->IsPending());
EXPECT_EQ(1, start_count);
EXPECT_EQ("service_manager_unittest_singleton", service_name);
}
diff --git a/services/service_manager/tests/service_manager/target.cc b/services/service_manager/tests/service_manager/target.cc
index bbfd5e7..509c893 100644
--- a/services/service_manager/tests/service_manager/target.cc
+++ b/services/service_manager/tests/service_manager/target.cc
@@ -7,7 +7,6 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "services/service_manager/public/c/main.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
diff --git a/services/service_manager/tests/shutdown/shutdown_client_app.cc b/services/service_manager/tests/shutdown/shutdown_client_app.cc
index 9dd6942..bdac97a8 100644
--- a/services/service_manager/tests/shutdown/shutdown_client_app.cc
+++ b/services/service_manager/tests/shutdown/shutdown_client_app.cc
@@ -6,9 +6,9 @@
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/c/main.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_runner.h"
@@ -22,15 +22,18 @@
public mojom::ShutdownTestClientController,
public mojom::ShutdownTestClient {
public:
- ShutdownClientApp() {}
+ ShutdownClientApp() {
+ registry_.AddInterface<mojom::ShutdownTestClientController>(this);
+ }
~ShutdownClientApp() override {}
private:
// service_manager::Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<mojom::ShutdownTestClientController>(this);
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<mojom::ShutdownTestClientController>:
@@ -60,6 +63,7 @@
callback.Run();
}
+ BinderRegistry registry_;
mojo::BindingSet<mojom::ShutdownTestClientController> bindings_;
DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp);
diff --git a/services/service_manager/tests/shutdown/shutdown_service_app.cc b/services/service_manager/tests/shutdown/shutdown_service_app.cc
index 95134f7..1e1c8c7 100644
--- a/services/service_manager/tests/shutdown/shutdown_service_app.cc
+++ b/services/service_manager/tests/shutdown/shutdown_service_app.cc
@@ -5,9 +5,10 @@
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/service_manager/public/c/main.h"
+#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_factory.h"
-#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service.h"
+#include "services/service_manager/public/cpp/service_info.h"
#include "services/service_manager/public/cpp/service_runner.h"
#include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h"
@@ -21,15 +22,18 @@
public InterfaceFactory<mojom::ShutdownTestService>,
public mojom::ShutdownTestService {
public:
- ShutdownServiceApp() {}
+ ShutdownServiceApp() {
+ registry_.AddInterface<mojom::ShutdownTestService>(this);
+ }
~ShutdownServiceApp() override {}
private:
// service_manager::Service:
- bool OnConnect(const ServiceInfo& remote_info,
- InterfaceRegistry* registry) override {
- registry->AddInterface<mojom::ShutdownTestService>(this);
- return true;
+ void OnBindInterface(const ServiceInfo& source_info,
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) override {
+ registry_.BindInterface(source_info.identity, interface_name,
+ std::move(interface_pipe));
}
// InterfaceFactory<mojom::ShutdownTestService>:
@@ -42,6 +46,7 @@
void SetClient(mojom::ShutdownTestClientPtr client) override {}
void ShutDown() override { g_app->Quit(); }
+ BinderRegistry registry_;
mojo::BindingSet<mojom::ShutdownTestService> bindings_;
DISALLOW_COPY_AND_ASSIGN(ShutdownServiceApp);
diff --git a/services/service_manager/tests/util.cc b/services/service_manager/tests/util.cc
index 081ce6c..b881f17 100644
--- a/services/service_manager/tests/util.cc
+++ b/services/service_manager/tests/util.cc
@@ -17,7 +17,6 @@
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
#include "services/service_manager/public/interfaces/service_factory.mojom.h"
@@ -28,13 +27,17 @@
namespace {
-void QuitLoop(base::RunLoop* loop) {
+void GrabConnectResult(base::RunLoop* loop,
+ mojom::ConnectResult* out_result,
+ mojom::ConnectResult result,
+ const Identity& resolved_identity) {
loop->Quit();
+ *out_result = result;
}
} // namespace
-std::unique_ptr<Connection> LaunchAndConnectToProcess(
+mojom::ConnectResult LaunchAndConnectToProcess(
const std::string& target_exe_name,
const Identity& target,
service_manager::Connector* connector,
@@ -70,11 +73,12 @@
service_manager::mojom::PIDReceiverPtr receiver;
connector->StartService(target, std::move(client), MakeRequest(&receiver));
- std::unique_ptr<service_manager::Connection> connection =
- connector->Connect(target);
+ mojom::ConnectResult result;
{
base::RunLoop loop;
- connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
+ Connector::TestApi test_api(connector);
+ test_api.SetStartServiceCallback(
+ base::Bind(&GrabConnectResult, &loop, &result));
base::MessageLoop::ScopedNestableTaskAllower allow(
base::MessageLoop::current());
loop.Run();
@@ -92,7 +96,7 @@
pending_process.Connect(
process->Handle(),
mojo::edk::ConnectionParams(platform_channel_pair.PassServerHandle()));
- return connection;
+ return result;
}
} // namespace test
diff --git a/services/service_manager/tests/util.h b/services/service_manager/tests/util.h
index 6fe6bc3..e11c18b 100644
--- a/services/service_manager/tests/util.h
+++ b/services/service_manager/tests/util.h
@@ -8,22 +8,23 @@
#include <memory>
#include <string>
+#include "services/service_manager/public/interfaces/connector.mojom.h"
+
namespace base {
class Process;
}
namespace service_manager {
-class Connection;
class Connector;
class Identity;
namespace test {
// Starts the process @ |target_exe_name| and connects to it as |target| using
-// |connector|, returning the connection & the process.
+// |connector|, returning a ConnectResult for the StartService() call.
// This blocks until the connection is established/rejected by the service
// manager.
-std::unique_ptr<Connection> LaunchAndConnectToProcess(
+service_manager::mojom::ConnectResult LaunchAndConnectToProcess(
const std::string& target_exe_name,
const Identity& target,
service_manager::Connector* connector,
diff --git a/services/tracing/public/cpp/provider.cc b/services/tracing/public/cpp/provider.cc
index 12e27bb..c89aed2 100644
--- a/services/tracing/public/cpp/provider.cc
+++ b/services/tracing/public/cpp/provider.cc
@@ -17,7 +17,6 @@
#include "base/time/time.h"
#include "base/trace_event/trace_config.h"
#include "base/trace_event/trace_event.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/tracing/public/cpp/switches.h"
#include "services/tracing/public/interfaces/constants.mojom.h"
diff --git a/services/ui/demo/mus_demo_unittests.cc b/services/ui/demo/mus_demo_unittests.cc
index 9fdb810..e89c167f 100644
--- a/services/ui/demo/mus_demo_unittests.cc
+++ b/services/ui/demo/mus_demo_unittests.cc
@@ -40,7 +40,7 @@
} // namespace
TEST_F(MusDemoTest, CheckMusDemoDraws) {
- connector()->Connect("mus_demo");
+ connector()->StartService("mus_demo");
::ui::mojom::WindowServerTestPtr test_interface;
connector()->BindInterface(ui::mojom::kServiceName, &test_interface);
diff --git a/services/ui/display/output_protection.h b/services/ui/display/output_protection.h
index 48185289..eafd2cb 100644
--- a/services/ui/display/output_protection.h
+++ b/services/ui/display/output_protection.h
@@ -8,7 +8,6 @@
#include <stdint.h>
#include "base/macros.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/ui/public/interfaces/display/output_protection.mojom.h"
diff --git a/services/ui/display/screen_manager_ozone_internal.h b/services/ui/display/screen_manager_ozone_internal.h
index 7032bdbb..61c9920 100644
--- a/services/ui/display/screen_manager_ozone_internal.h
+++ b/services/ui/display/screen_manager_ozone_internal.h
@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/ui/display/screen_manager.h"
#include "services/ui/display/viewport_metrics.h"
diff --git a/services/ui/ime/ime_server_impl.cc b/services/ui/ime/ime_server_impl.cc
index 19c89b5..7d26f0e 100644
--- a/services/ui/ime/ime_server_impl.cc
+++ b/services/ui/ime/ime_server_impl.cc
@@ -17,7 +17,7 @@
void IMEServerImpl::Init(service_manager::Connector* connector,
bool is_test_config) {
if (is_test_config)
- connector->Connect("test_ime_driver");
+ connector->StartService("test_ime_driver");
// For non test configs we assume a client registers with us.
}
diff --git a/services/ui/ime/ime_unittest.cc b/services/ui/ime/ime_unittest.cc
index 582521f..f33275a6 100644
--- a/services/ui/ime/ime_unittest.cc
+++ b/services/ui/ime/ime_unittest.cc
@@ -56,7 +56,7 @@
void SetUp() override {
ServiceTest::SetUp();
// test_ime_driver will register itself as the current IMEDriver.
- connector()->Connect("test_ime_driver");
+ connector()->StartService("test_ime_driver");
connector()->BindInterface(ui::mojom::kServiceName, &ime_server_);
}
diff --git a/services/ui/input_devices/input_device_server.h b/services/ui/input_devices/input_device_server.h
index 0e858b4..1e7d91c 100644
--- a/services/ui/input_devices/input_device_server.h
+++ b/services/ui/input_devices/input_device_server.h
@@ -8,7 +8,6 @@
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/interface_factory.h"
#include "services/ui/public/interfaces/input_devices/input_device_server.mojom.h"
#include "ui/events/devices/device_data_manager.h"
diff --git a/services/ui/service.cc b/services/ui/service.cc
index aa4aa441..b7ff9691 100644
--- a/services/ui/service.cc
+++ b/services/ui/service.cc
@@ -18,7 +18,6 @@
#include "services/catalog/public/cpp/resource_loader.h"
#include "services/catalog/public/interfaces/constants.mojom.h"
#include "services/service_manager/public/c/main.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_registry.h"
#include "services/service_manager/public/cpp/service_context.h"
@@ -58,7 +57,6 @@
#include "ui/ozone/public/ozone_platform.h"
#endif
-using service_manager::Connection;
using mojo::InterfaceRequest;
using ui::mojom::WindowServerTest;
using ui::mojom::WindowTreeHostFactory;
diff --git a/services/ui/ws/gpu_host.cc b/services/ui/ws/gpu_host.cc
index db35498e..85ac3aa 100644
--- a/services/ui/ws/gpu_host.cc
+++ b/services/ui/ws/gpu_host.cc
@@ -14,7 +14,6 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/platform_handle.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/ui/common/server_gpu_memory_buffer_manager.h"
#include "services/ui/ws/gpu_client.h"
#include "services/ui/ws/gpu_host_delegate.h"
diff --git a/services/ui/ws/window_server.cc b/services/ui/ws/window_server.cc
index b47276b..d012b886 100644
--- a/services/ui/ws/window_server.cc
+++ b/services/ui/ws/window_server.cc
@@ -10,7 +10,6 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/ui/ws/display.h"
#include "services/ui/ws/display_manager.h"
#include "services/ui/ws/frame_generator.h"
diff --git a/services/ui/ws/window_server_service_test_base.h b/services/ui/ws/window_server_service_test_base.h
index e6be41d..8cff44c 100644
--- a/services/ui/ws/window_server_service_test_base.h
+++ b/services/ui/ws/window_server_service_test_base.h
@@ -6,7 +6,6 @@
#define SERVICES_UI_WS_WINDOW_SERVER_SERVICE_TEST_BASE_H_
#include "base/macros.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/service_test.h"
namespace ui {
diff --git a/services/ui/ws/window_tree_client_unittest.cc b/services/ui/ws/window_tree_client_unittest.cc
index d70250c..06f6762 100644
--- a/services/ui/ws/window_tree_client_unittest.cc
+++ b/services/ui/ws/window_tree_client_unittest.cc
@@ -24,7 +24,6 @@
#include "services/ui/ws/test_change_tracker.h"
#include "services/ui/ws/window_server_service_test_base.h"
-using service_manager::Connection;
using mojo::InterfaceRequest;
using service_manager::Service;
using ui::mojom::WindowDataPtr;
diff --git a/ui/ozone/platform/drm/gpu/drm_thread.cc b/ui/ozone/platform/drm/gpu/drm_thread.cc
index 8faec76..06bec8a9 100644
--- a/ui/ozone/platform/drm/gpu/drm_thread.cc
+++ b/ui/ozone/platform/drm/gpu/drm_thread.cc
@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/threading/thread_task_runner_handle.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_buffer.h"
#include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
diff --git a/ui/ozone/platform/drm/gpu/drm_thread.h b/ui/ozone/platform/drm/gpu/drm_thread.h
index fe3864e..be12617 100644
--- a/ui/ozone/platform/drm/gpu/drm_thread.h
+++ b/ui/ozone/platform/drm/gpu/drm_thread.h
@@ -14,7 +14,6 @@
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "mojo/public/cpp/bindings/binding_set.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "ui/gfx/native_pixmap_handle.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/vsync_provider.h"
diff --git a/ui/views/mus/mus_client.cc b/ui/views/mus/mus_client.cc
index ee16fd9..136424b6 100644
--- a/ui/views/mus/mus_client.cc
+++ b/ui/views/mus/mus_client.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/threading/thread.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/ui/public/cpp/gpu/gpu.h"
#include "services/ui/public/cpp/property_type_converters.h"
diff --git a/ui/views/mus/screen_mus.cc b/ui/views/mus/screen_mus.cc
index a8790496..8618d1b 100644
--- a/ui/views/mus/screen_mus.cc
+++ b/ui/views/mus/screen_mus.cc
@@ -8,7 +8,6 @@
#include "ui/views/mus/screen_mus.h"
-#include "services/service_manager/public/cpp/connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "ui/aura/env.h"
diff --git a/ui/views/mus/views_mus_test_suite.cc b/ui/views/mus/views_mus_test_suite.cc
index 8483a258..1773510 100644
--- a/ui/views/mus/views_mus_test_suite.cc
+++ b/ui/views/mus/views_mus_test_suite.cc
@@ -205,7 +205,7 @@
// ui/views/mus requires a WindowManager running, so launch test_wm.
service_manager::Connector* connector = context_->connector();
- connector->Connect("test_wm");
+ connector->StartService("test_wm");
service_manager_connector_ = connector->Clone();
service_manager_identity_ = context_->identity();
wait->Signal();