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

Unified Diff: mojo/service_manager/service_manager_unittest.cc

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: convert everything over, remove ApplicationConnection::AddService Created 6 years, 5 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: mojo/service_manager/service_manager_unittest.cc
diff --git a/mojo/service_manager/service_manager_unittest.cc b/mojo/service_manager/service_manager_unittest.cc
index f485600541283c60a77092b43a426b4572f74135..d3b8af76be165dde3b666def8fde45f95529e5c3 100644
--- a/mojo/service_manager/service_manager_unittest.cc
+++ b/mojo/service_manager/service_manager_unittest.cc
@@ -44,8 +44,7 @@ class QuitMessageLoopErrorHandler : public ErrorHandler {
class TestServiceImpl : public InterfaceImpl<TestService> {
public:
- explicit TestServiceImpl(ApplicationConnection* connection,
- TestContext* context) : context_(context) {
+ explicit TestServiceImpl(TestContext* context) : context_(context) {
++context_->num_impls;
}
@@ -98,7 +97,8 @@ class TestClientImpl : public TestClient {
};
class TestServiceLoader : public ServiceLoader,
- public ApplicationDelegate {
+ public ApplicationDelegate,
+ public InterfaceFactory<TestService> {
public:
TestServiceLoader()
: context_(NULL),
@@ -129,10 +129,15 @@ class TestServiceLoader : public ServiceLoader,
virtual bool ConfigureIncomingConnection(
ApplicationConnection* connection) OVERRIDE {
- connection->AddService<TestServiceImpl>(context_);
+ connection->AddServiceFactory(this);
return true;
}
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<TestService> request) OVERRIDE {
+ mojo::BindToRequest(new TestServiceImpl(context_), &request);
+ }
+
scoped_ptr<ApplicationImpl> test_app_;
TestContext* context_;
int num_loads_;
@@ -160,8 +165,7 @@ struct TesterContext {
// Used to test that the requestor url will be correctly passed.
class TestAImpl : public InterfaceImpl<TestA> {
public:
- explicit TestAImpl(ApplicationConnection* connection,
- TesterContext* test_context)
+ TestAImpl(ApplicationConnection* connection, TesterContext* test_context)
: test_context_(test_context) {
connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_);
}
@@ -187,8 +191,7 @@ class TestAImpl : public InterfaceImpl<TestA> {
class TestBImpl : public InterfaceImpl<TestB> {
public:
- explicit TestBImpl(ApplicationConnection* connection,
- TesterContext* test_context)
+ TestBImpl(ApplicationConnection* connection, TesterContext* test_context)
: test_context_(test_context) {
connection->ConnectToService(&c_);
}
@@ -217,10 +220,8 @@ class TestBImpl : public InterfaceImpl<TestB> {
class TestCImpl : public InterfaceImpl<TestC> {
public:
- explicit TestCImpl(ApplicationConnection* connection,
- TesterContext* test_context)
- : test_context_(test_context) {
- }
+ TestCImpl(ApplicationConnection* connection, TesterContext* test_context)
+ : test_context_(test_context) {}
virtual ~TestCImpl() { test_context_->num_c_deletes++; }
@@ -232,7 +233,11 @@ class TestCImpl : public InterfaceImpl<TestC> {
TesterContext* test_context_;
};
-class Tester : public ApplicationDelegate, public ServiceLoader {
+class Tester : public ApplicationDelegate,
+ public ServiceLoader,
+ public InterfaceFactory<TestA>,
+ public InterfaceFactory<TestB>,
+ public InterfaceFactory<TestC> {
public:
Tester(TesterContext* context, const std::string& requestor_url)
: context_(context),
@@ -260,9 +265,9 @@ class Tester : public ApplicationDelegate, public ServiceLoader {
}
// If we're coming from A, then add B, otherwise A.
if (connection->GetRemoteApplicationURL() == kTestAURLString)
- connection->AddService<TestBImpl>(context_);
+ connection->AddServiceFactory<TestB>(this);
else
- connection->AddService<TestAImpl>(context_);
+ connection->AddServiceFactory<TestA>(this);
return true;
}
@@ -270,10 +275,25 @@ class Tester : public ApplicationDelegate, public ServiceLoader {
ApplicationConnection* connection) OVERRIDE {
// If we're connecting to B, then add C.
if (connection->GetRemoteApplicationURL() == kTestBURLString)
- connection->AddService<TestCImpl>(context_);
+ connection->AddServiceFactory<TestC>(this);
return true;
}
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<TestA> request) OVERRIDE {
+ mojo::BindToRequest(new TestAImpl(connection, context_), &request);
+ }
+
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<TestB> request) OVERRIDE {
+ mojo::BindToRequest(new TestBImpl(connection, context_), &request);
+ }
+
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<TestC> request) OVERRIDE {
+ mojo::BindToRequest(new TestCImpl(connection, context_), &request);
+ }
+
TesterContext* context_;
scoped_ptr<ApplicationImpl> app_;
std::string requestor_url_;

Powered by Google App Engine
This is Rietveld 408576698