Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Unified Diff: services/service_manager/tests/connect/connect_test_app.cc

Issue 2804373002: Eliminate Connector::Connect(), Connection, etc. (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/service_manager/tests/connect/connect_test_app.cc
diff --git a/services/service_manager/tests/connect/connect_test_app.cc b/services/service_manager/tests/connect/connect_test_app.cc
index ad0a26e621c870345a6e6fccf9fd0fc3c5653597..62034155c026b0e31a755c2b22697adf63019d50 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 service_manager {
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 @@ class ConnectTestApp : public Service,
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 @@ class ConnectTestApp : public Service,
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 @@ class ConnectTestApp : public Service,
}
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 @@ class ConnectTestApp : public Service,
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 @@ class ConnectTestApp : public Service,
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 @@ class ConnectTestApp : public Service,
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_;
« no previous file with comments | « services/service_manager/standalone/context.cc ('k') | services/service_manager/tests/connect/connect_test_class_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698