summaryrefslogtreecommitdiffstats
path: root/mojo/shell/public
diff options
context:
space:
mode:
authorben <ben@chromium.org>2016-02-12 00:26:42 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-12 08:27:53 +0000
commite83e09a1f670d57be60d75453dfa5be32f02d47d (patch)
tree805ac1c3362fb076438b5f873655a8be42f458d2 /mojo/shell/public
parent9fc9177179ed5c6bc5e9824c669199c8b15b56e3 (diff)
downloadchromium_src-e83e09a1f670d57be60d75453dfa5be32f02d47d.zip
chromium_src-e83e09a1f670d57be60d75453dfa5be32f02d47d.tar.gz
chromium_src-e83e09a1f670d57be60d75453dfa5be32f02d47d.tar.bz2
Extracts InterfaceRegistry from ConnectionImpl.
For most existing Mojo uses outside of Chrome, we have been relying on Connection::AddService<T>() as the means of exposing interfaces to other applications, because primarily we have been doing this via the InterfaceProviders exchanged @ Shell::ConnectToApplication. However there have been times in the past and are likely to be again in the future where we will want to pass an InterfaceProvider to another method, so having a canonical implementation of an InterfaceRegistry seems useful. I pulled all the relevant bits out of ConnectionImpl into this utility and then made ConnectionImpl wrap it. I suspect in time we could replace some of the custom InterfaceProvider impls currently in Content with this. R=rockot@chromium.org BUG= Review URL: https://codereview.chromium.org/1681933005 Cr-Commit-Position: refs/heads/master@{#375146}
Diffstat (limited to 'mojo/shell/public')
-rw-r--r--mojo/shell/public/cpp/BUILD.gn2
-rw-r--r--mojo/shell/public/cpp/connection.h62
-rw-r--r--mojo/shell/public/cpp/interface_registry.h109
-rw-r--r--mojo/shell/public/cpp/lib/connection_impl.cc80
-rw-r--r--mojo/shell/public/cpp/lib/connection_impl.h41
-rw-r--r--mojo/shell/public/cpp/lib/interface_registry.cc69
-rw-r--r--mojo/shell/public/cpp/tests/BUILD.gn2
-rw-r--r--mojo/shell/public/cpp/tests/interface_registry_unittest.cc (renamed from mojo/shell/public/cpp/tests/connection_impl_unittest.cc)27
8 files changed, 239 insertions, 153 deletions
diff --git a/mojo/shell/public/cpp/BUILD.gn b/mojo/shell/public/cpp/BUILD.gn
index 5f59c60..b368a50 100644
--- a/mojo/shell/public/cpp/BUILD.gn
+++ b/mojo/shell/public/cpp/BUILD.gn
@@ -27,10 +27,12 @@ source_set("sources") {
"interface_binder.h",
"interface_factory.h",
"interface_factory_impl.h",
+ "interface_registry.h",
"lib/application_runner.cc",
"lib/connection_impl.cc",
"lib/connection_impl.h",
"lib/interface_factory_binder.h",
+ "lib/interface_registry.cc",
"lib/shell_client.cc",
"lib/shell_connection.cc",
"shell.h",
diff --git a/mojo/shell/public/cpp/connection.h b/mojo/shell/public/cpp/connection.h
index ddae4fc..84f428b 100644
--- a/mojo/shell/public/cpp/connection.h
+++ b/mojo/shell/public/cpp/connection.h
@@ -11,7 +11,8 @@
#include <utility>
#include "base/memory/weak_ptr.h"
-#include "mojo/shell/public/cpp/lib/interface_factory_binder.h"
+#include "mojo/shell/public/cpp/connect.h"
+#include "mojo/shell/public/cpp/interface_registry.h"
#include "mojo/shell/public/interfaces/interface_provider.mojom.h"
namespace mojo {
@@ -22,24 +23,13 @@ class InterfaceBinder;
// returned from Shell's ConnectToApplication(), and passed to ShellClient's
// AcceptConnection() each time an incoming connection is received.
//
-// To use, define a class that implements your specific interface. Then
-// implement an InterfaceFactory<Foo> that binds instances of FooImpl to
-// InterfaceRequest<Foo>s and register that on the connection like this:
+// Call AddService<T>(factory) to expose an interface to the remote application,
+// and GetInterface(&interface_ptr) to consume an interface exposed by the
+// remote application.
//
-// connection->AddInterface(&factory);
-//
-// Or, if you have multiple factories implemented by the same type, explicitly
-// specify the interface to register the factory for:
-//
-// connection->AddInterface<Foo>(&my_foo_and_bar_factory_);
-// connection->AddInterface<Bar>(&my_foo_and_bar_factory_);
-//
-// The InterfaceFactory must outlive the Connection.
-//
-// Additionally you may specify a default InterfaceBinder to handle requests for
-// interfaces unhandled by any registered InterfaceFactory. Just as with
-// InterfaceFactory, the default InterfaceBinder supplied must outlive
-// Connection.
+// Internally, this class wraps an InterfaceRegistry that accepts interfaces
+// that may be exposed to a remote application. See documentation in
+// interface_registry.h for more information.
//
// A Connection returned via Shell::ConnectToApplication() is owned by the
// caller.
@@ -60,18 +50,13 @@ class Connection {
Connection* connection_;
};
- // See class description for details.
- virtual void SetDefaultInterfaceBinder(InterfaceBinder* binder) = 0;
-
// Allow the remote application to request instances of Interface.
// |factory| will create implementations of Interface on demand.
// Returns true if the interface was exposed, false if capability filtering
// from the shell prevented the interface from being exposed.
template <typename Interface>
bool AddInterface(InterfaceFactory<Interface>* factory) {
- return SetInterfaceBinderForName(
- new internal::InterfaceFactoryBinder<Interface>(factory),
- Interface::Name_);
+ return GetLocalRegistry()->AddInterface<Interface>(factory);
}
// Binds |ptr| to an implemention of Interface in the remote application.
@@ -79,11 +64,7 @@ class Connection {
// interface.
template <typename Interface>
void GetInterface(InterfacePtr<Interface>* ptr) {
- if (shell::mojom::InterfaceProvider* ip = GetRemoteInterfaces()) {
- MessagePipe pipe;
- ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u));
- ip->GetInterface(Interface::Name_, std::move(pipe.handle1));
- }
+ mojo::GetInterface(GetRemoteInterfaces(), ptr);
}
// Returns the URL that was used by the source application to establish a
@@ -101,15 +82,6 @@ class Connection {
// Returns the URL identifying the remote application on this connection.
virtual const std::string& GetRemoteApplicationURL() = 0;
- // Returns the raw proxy to the remote application's InterfaceProvider
- // interface. Most applications will just use GetInterface() instead.
- // Caller does not take ownership.
- virtual shell::mojom::InterfaceProvider* GetRemoteInterfaces() = 0;
-
- // Returns the local application's InterfaceProvider interface. The return
- // value is owned by this connection.
- virtual shell::mojom::InterfaceProvider* GetLocalInterfaces() = 0;
-
// Register a handler to receive an error notification on the pipe to the
// remote application's InterfaceProvider.
virtual void SetRemoteInterfaceProviderConnectionErrorHandler(
@@ -134,11 +106,17 @@ class Connection {
// the ids are available, |callback| is run immediately.
virtual void AddRemoteIDCallback(const Closure& callback) = 0;
+ // Returns true if the Shell allows |interface_name| to be exposed to the
+ // remote application.
+ virtual bool AllowsInterface(const std::string& interface_name) const = 0;
+
+ // Returns the raw proxy to the remote application's InterfaceProvider
+ // interface. Most applications will just use GetInterface() instead.
+ // Caller does not take ownership.
+ virtual shell::mojom::InterfaceProvider* GetRemoteInterfaces() = 0;
+
protected:
- // Returns true if the binder was set, false if it was not set (e.g. by
- // some filtering policy preventing this interface from being exposed).
- virtual bool SetInterfaceBinderForName(InterfaceBinder* binder,
- const std::string& name) = 0;
+ virtual InterfaceRegistry* GetLocalRegistry() = 0;
virtual base::WeakPtr<Connection> GetWeakPtr() = 0;
};
diff --git a/mojo/shell/public/cpp/interface_registry.h b/mojo/shell/public/cpp/interface_registry.h
new file mode 100644
index 0000000..ea0b984
--- /dev/null
+++ b/mojo/shell/public/cpp/interface_registry.h
@@ -0,0 +1,109 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_
+#define MOJO_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_
+
+#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/shell/public/cpp/lib/interface_factory_binder.h"
+#include "mojo/shell/public/interfaces/interface_provider.mojom.h"
+
+namespace mojo {
+
+class InterfaceBinder;
+
+// An implementation of shell::mojom::InterfaceProvider that allows the user to
+// register services to be exposed to another application.
+//
+// To use, define a class that implements your specific interface. Then
+// implement an InterfaceFactory<Foo> that binds instances of FooImpl to
+// InterfaceRequest<Foo>s and register that on the registry like this:
+//
+// registry.AddInterface(&factory);
+//
+// Or, if you have multiple factories implemented by the same type, explicitly
+// specify the interface to register the factory for:
+//
+// registry.AddInterface<Foo>(&my_foo_and_bar_factory_);
+// registry.AddInterface<Bar>(&my_foo_and_bar_factory_);
+//
+// The InterfaceFactory must outlive the InterfaceRegistry.
+//
+// Additionally you may specify a default InterfaceBinder to handle requests for
+// interfaces unhandled by any registered InterfaceFactory. Just as with
+// InterfaceFactory, the default InterfaceBinder supplied must outlive
+// InterfaceRegistry.
+//
+class InterfaceRegistry : public shell::mojom::InterfaceProvider {
+ public:
+ class TestApi {
+ public:
+ explicit TestApi(InterfaceRegistry* registry) : registry_(registry) {}
+ ~TestApi() {}
+
+ void SetInterfaceBinderForName(InterfaceBinder* binder,
+ const std::string& interface_name) {
+ registry_->SetInterfaceBinderForName(binder, interface_name);
+ }
+ void RemoveInterfaceBinderForName(const std::string& interface_name) {
+ registry_->RemoveInterfaceBinderForName(interface_name);
+ }
+
+ private:
+ InterfaceRegistry* registry_;
+ DISALLOW_COPY_AND_ASSIGN(TestApi);
+ };
+
+ // Construct with a Connection (which may be null), and create an
+ // InterfaceProvider pipe, the client end of which may be obtained by calling
+ // TakeClientHandle(). If |connection| is non-null, the Mojo Shell's
+ // rules filtering which interfaces are allowed to be exposed to clients are
+ // imposed on this registry. If null, they are not.
+ explicit InterfaceRegistry(Connection* connection);
+ // Construct with an InterfaceProviderRequest and a Connection (which may be
+ // null, see note above about filtering).
+ InterfaceRegistry(shell::mojom::InterfaceProviderRequest request,
+ Connection* connection);
+ ~InterfaceRegistry() override;
+
+ // Takes the client end of the InterfaceProvider pipe created in the
+ // constructor.
+ shell::mojom::InterfaceProviderPtr TakeClientHandle();
+
+ template <typename Interface>
+ bool AddInterface(InterfaceFactory<Interface>* factory) {
+ return SetInterfaceBinderForName(
+ new internal::InterfaceFactoryBinder<Interface>(factory),
+ Interface::Name_);
+ }
+
+ void set_default_binder(InterfaceBinder* binder) { default_binder_ = binder; }
+
+ private:
+ using NameToInterfaceBinderMap = std::map<std::string, InterfaceBinder*>;
+
+ // shell::mojom::InterfaceProvider:
+ void GetInterface(const String& interface_name,
+ ScopedMessagePipeHandle handle) override;
+
+ // Returns true if the binder was set, false if it was not set (e.g. by
+ // some filtering policy preventing this interface from being exposed).
+ bool SetInterfaceBinderForName(InterfaceBinder* binder,
+ const std::string& name);
+
+ void RemoveInterfaceBinderForName(const std::string& interface_name);
+
+ shell::mojom::InterfaceProviderPtr client_handle_;
+ Binding<shell::mojom::InterfaceProvider> binding_;
+ Connection* connection_;
+
+ InterfaceBinder* default_binder_;
+ NameToInterfaceBinderMap name_to_binder_;
+
+ DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry);
+};
+
+} // namespace mojo
+
+#endif // MOJO_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_
diff --git a/mojo/shell/public/cpp/lib/connection_impl.cc b/mojo/shell/public/cpp/lib/connection_impl.cc
index bc66e70..8f41dcb 100644
--- a/mojo/shell/public/cpp/lib/connection_impl.cc
+++ b/mojo/shell/public/cpp/lib/connection_impl.cc
@@ -31,32 +31,22 @@ ConnectionImpl::ConnectionImpl(
remote_id_(remote_id),
content_handler_id_(0u),
remote_ids_valid_(false),
- local_binding_(this),
+ local_registry_(std::move(local_interfaces), this),
remote_interfaces_(std::move(remote_interfaces)),
allowed_interfaces_(allowed_interfaces),
allow_all_interfaces_(allowed_interfaces_.size() == 1 &&
allowed_interfaces_.count("*") == 1),
- default_binder_(nullptr),
- weak_factory_(this) {
- if (local_interfaces.is_pending())
- local_binding_.Bind(std::move(local_interfaces));
-}
+ weak_factory_(this) {}
ConnectionImpl::ConnectionImpl()
: remote_id_(shell::mojom::Shell::kInvalidApplicationID),
content_handler_id_(shell::mojom::Shell::kInvalidApplicationID),
remote_ids_valid_(false),
- local_binding_(this),
+ local_registry_(shell::mojom::InterfaceProviderRequest(), this),
allow_all_interfaces_(true),
- default_binder_(nullptr),
- weak_factory_(this) {
-}
+ weak_factory_(this) {}
-ConnectionImpl::~ConnectionImpl() {
- for (auto& i : name_to_binder_)
- delete i.second;
- name_to_binder_.clear();
-}
+ConnectionImpl::~ConnectionImpl() {}
shell::mojom::Shell::ConnectToApplicationCallback
ConnectionImpl::GetConnectToApplicationCallback() {
@@ -67,25 +57,6 @@ ConnectionImpl::GetConnectToApplicationCallback() {
////////////////////////////////////////////////////////////////////////////////
// ConnectionImpl, Connection implementation:
-void ConnectionImpl::SetDefaultInterfaceBinder(InterfaceBinder* binder) {
- default_binder_ = binder;
-}
-
-bool ConnectionImpl::SetInterfaceBinderForName(
- InterfaceBinder* binder,
- const std::string& interface_name) {
- if (allow_all_interfaces_ ||
- allowed_interfaces_.count(interface_name)) {
- RemoveInterfaceBinderForName(interface_name);
- name_to_binder_[interface_name] = binder;
- return true;
- }
- LOG(WARNING) << "CapabilityFilter prevented connection to interface: "
- << interface_name << " connection_url:" << connection_url_
- << " remote_url:" << remote_url_;
- return false;
-}
-
const std::string& ConnectionImpl::GetConnectionURL() {
return connection_url_;
}
@@ -94,14 +65,6 @@ const std::string& ConnectionImpl::GetRemoteApplicationURL() {
return remote_url_;
}
-shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
- return remote_interfaces_.get();
-}
-
-shell::mojom::InterfaceProvider* ConnectionImpl::GetLocalInterfaces() {
- return this;
-}
-
void ConnectionImpl::SetRemoteInterfaceProviderConnectionErrorHandler(
const Closure& handler) {
remote_interfaces_.set_connection_error_handler(handler);
@@ -132,34 +95,25 @@ void ConnectionImpl::AddRemoteIDCallback(const Closure& callback) {
remote_id_callbacks_.push_back(callback);
}
-base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
- return weak_factory_.GetWeakPtr();
+bool ConnectionImpl::AllowsInterface(const std::string& interface_name) const {
+ return allow_all_interfaces_ || allowed_interfaces_.count(interface_name);
}
-////////////////////////////////////////////////////////////////////////////////
-// ConnectionImpl, shell::mojom::InterfaceProvider implementation:
-
-void ConnectionImpl::GetInterface(const mojo::String& interface_name,
- ScopedMessagePipeHandle handle) {
- auto iter = name_to_binder_.find(interface_name);
- InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second :
- default_binder_;
- if (binder)
- binder->BindInterface(this, interface_name, std::move(handle));
+shell::mojom::InterfaceProvider* ConnectionImpl::GetRemoteInterfaces() {
+ return remote_interfaces_.get();
}
-////////////////////////////////////////////////////////////////////////////////
-// ConnectionImpl, private:
+InterfaceRegistry* ConnectionImpl::GetLocalRegistry() {
+ return &local_registry_;
+}
-void ConnectionImpl::RemoveInterfaceBinderForName(
- const std::string& interface_name) {
- NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name);
- if (it == name_to_binder_.end())
- return;
- delete it->second;
- name_to_binder_.erase(it);
+base::WeakPtr<Connection> ConnectionImpl::GetWeakPtr() {
+ return weak_factory_.GetWeakPtr();
}
+////////////////////////////////////////////////////////////////////////////////
+// ConnectionImpl, private:
+
void ConnectionImpl::OnGotRemoteIDs(uint32_t target_application_id,
uint32_t content_handler_id) {
DCHECK(!remote_ids_valid_);
diff --git a/mojo/shell/public/cpp/lib/connection_impl.h b/mojo/shell/public/cpp/lib/connection_impl.h
index 86ca3a7..7d9c55e 100644
--- a/mojo/shell/public/cpp/lib/connection_impl.h
+++ b/mojo/shell/public/cpp/lib/connection_impl.h
@@ -21,27 +21,8 @@ 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 shell::mojom::InterfaceProvider {
+class ConnectionImpl : public Connection {
public:
- class TestApi {
- public:
- explicit TestApi(ConnectionImpl* impl) : impl_(impl) {}
- ~TestApi() {}
-
- void SetInterfaceBinderForName(InterfaceBinder* binder,
- const std::string& interface_name) {
- impl_->SetInterfaceBinderForName(binder, interface_name);
- }
- void RemoveInterfaceBinderForName(const std::string& interface_name) {
- impl_->RemoveInterfaceBinderForName(interface_name);
- }
-
- private:
- ConnectionImpl* impl_;
- DISALLOW_COPY_AND_ASSIGN(TestApi);
- };
-
ConnectionImpl();
// |allowed_interfaces| are the set of interfaces that the shell has allowed
// an application to expose to another application. If this set contains only
@@ -58,28 +39,19 @@ class ConnectionImpl : public Connection,
GetConnectToApplicationCallback();
private:
- using NameToInterfaceBinderMap = std::map<std::string, InterfaceBinder*>;
-
// Connection:
- void SetDefaultInterfaceBinder(InterfaceBinder* binder) override;
- bool SetInterfaceBinderForName(InterfaceBinder* binder,
- const std::string& interface_name) override;
const std::string& GetConnectionURL() override;
const std::string& GetRemoteApplicationURL() override;
- shell::mojom::InterfaceProvider* GetRemoteInterfaces() override;
- shell::mojom::InterfaceProvider* GetLocalInterfaces() override;
void SetRemoteInterfaceProviderConnectionErrorHandler(
const Closure& handler) override;
bool GetRemoteApplicationID(uint32_t* remote_id) const override;
bool GetRemoteContentHandlerID(uint32_t* content_handler_id) const override;
void AddRemoteIDCallback(const Closure& callback) override;
+ bool AllowsInterface(const std::string& interface_name) const override;
+ shell::mojom::InterfaceProvider* GetRemoteInterfaces() override;
+ InterfaceRegistry* GetLocalRegistry() override;
base::WeakPtr<Connection> GetWeakPtr() override;
- // InterfaceProvider:
- void GetInterface(const mojo::String& interface_name,
- ScopedMessagePipeHandle handle) override;
-
- void RemoveInterfaceBinderForName(const std::string& interface_name);
void OnGotRemoteIDs(uint32_t target_application_id,
uint32_t content_handler_id);
@@ -93,15 +65,12 @@ class ConnectionImpl : public Connection,
bool remote_ids_valid_;
std::vector<Closure> remote_id_callbacks_;
- Binding<shell::mojom::InterfaceProvider> local_binding_;
+ InterfaceRegistry local_registry_;
shell::mojom::InterfaceProviderPtr remote_interfaces_;
const std::set<std::string> allowed_interfaces_;
const bool allow_all_interfaces_;
- InterfaceBinder* default_binder_;
- NameToInterfaceBinderMap name_to_binder_;
-
base::WeakPtrFactory<ConnectionImpl> weak_factory_;
MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionImpl);
diff --git a/mojo/shell/public/cpp/lib/interface_registry.cc b/mojo/shell/public/cpp/lib/interface_registry.cc
new file mode 100644
index 0000000..ee14f5a
--- /dev/null
+++ b/mojo/shell/public/cpp/lib/interface_registry.cc
@@ -0,0 +1,69 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/public/cpp/interface_registry.h"
+
+#include "mojo/shell/public/cpp/connection.h"
+
+namespace mojo {
+
+InterfaceRegistry::InterfaceRegistry(Connection* connection)
+ : InterfaceRegistry(GetProxy(&client_handle_), connection) {}
+
+InterfaceRegistry::InterfaceRegistry(
+ shell::mojom::InterfaceProviderRequest request,
+ Connection* connection)
+ : binding_(this),
+ connection_(connection),
+ default_binder_(nullptr) {
+ if (request.is_pending())
+ binding_.Bind(std::move(request));
+}
+
+InterfaceRegistry::~InterfaceRegistry() {
+ for (auto& i : name_to_binder_)
+ delete i.second;
+ name_to_binder_.clear();
+}
+
+shell::mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() {
+ return std::move(client_handle_);
+}
+
+// shell::mojom::InterfaceProvider:
+void InterfaceRegistry::GetInterface(const String& interface_name,
+ ScopedMessagePipeHandle handle) {
+ auto iter = name_to_binder_.find(interface_name);
+ InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second :
+ default_binder_;
+ if (binder)
+ binder->BindInterface(connection_, interface_name, std::move(handle));
+}
+
+bool InterfaceRegistry::SetInterfaceBinderForName(
+ InterfaceBinder* binder,
+ const std::string& interface_name) {
+ if (!connection_ ||
+ (connection_ && connection_->AllowsInterface(interface_name))) {
+ RemoveInterfaceBinderForName(interface_name);
+ name_to_binder_[interface_name] = binder;
+ return true;
+ }
+ LOG(WARNING) << "Connection CapabilityFilter prevented binding to interface: "
+ << interface_name << " connection_url:"
+ << connection_->GetConnectionURL() << " remote_url:"
+ << connection_->GetRemoteApplicationURL();
+ return false;
+}
+
+void InterfaceRegistry::RemoveInterfaceBinderForName(
+ const std::string& interface_name) {
+ NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name);
+ if (it == name_to_binder_.end())
+ return;
+ delete it->second;
+ name_to_binder_.erase(it);
+}
+
+} // namespace mojo
diff --git a/mojo/shell/public/cpp/tests/BUILD.gn b/mojo/shell/public/cpp/tests/BUILD.gn
index ef9bbbd..7df8e36 100644
--- a/mojo/shell/public/cpp/tests/BUILD.gn
+++ b/mojo/shell/public/cpp/tests/BUILD.gn
@@ -6,7 +6,7 @@ import("//testing/test.gni")
test("mojo_public_application_unittests") {
sources = [
- "connection_impl_unittest.cc",
+ "interface_registry_unittest.cc",
]
deps = [
diff --git a/mojo/shell/public/cpp/tests/connection_impl_unittest.cc b/mojo/shell/public/cpp/tests/interface_registry_unittest.cc
index d93da43..d93f63c 100644
--- a/mojo/shell/public/cpp/tests/connection_impl_unittest.cc
+++ b/mojo/shell/public/cpp/tests/interface_registry_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/shell/public/cpp/lib/connection_impl.h"
+#include "mojo/shell/public/cpp/interface_registry.h"
#include "base/memory/scoped_ptr.h"
#include "mojo/shell/public/cpp/interface_binder.h"
@@ -24,32 +24,36 @@ class TestBinder : public InterfaceBinder {
int* delete_count_;
};
-TEST(ConnectionImplTest, Ownership) {
+TEST(InterfaceRegistryTest, Ownership) {
int delete_count = 0;
// Destruction.
{
- ConnectionImpl connection;
- ConnectionImpl::TestApi test_api(&connection);
+ shell::mojom::InterfaceProviderRequest ir;
+ InterfaceRegistry registry(std::move(ir), nullptr);
+ InterfaceRegistry::TestApi test_api(&registry);
test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
}
EXPECT_EQ(1, delete_count);
// Removal.
{
- scoped_ptr<ConnectionImpl> connection(new ConnectionImpl);
+ shell::mojom::InterfaceProviderRequest ir;
+ scoped_ptr<InterfaceRegistry> registry(
+ new InterfaceRegistry(std::move(ir), nullptr));
InterfaceBinder* b = new TestBinder(&delete_count);
- ConnectionImpl::TestApi test_api(connection.get());
+ InterfaceRegistry::TestApi test_api(registry.get());
test_api.SetInterfaceBinderForName(b, "TC1");
test_api.RemoveInterfaceBinderForName("TC1");
- connection.reset();
+ registry.reset();
EXPECT_EQ(2, delete_count);
}
// Multiple.
{
- ConnectionImpl connection;
- ConnectionImpl::TestApi test_api(&connection);
+ shell::mojom::InterfaceProviderRequest ir;
+ InterfaceRegistry registry(std::move(ir), nullptr);
+ InterfaceRegistry::TestApi test_api(&registry);
test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2");
}
@@ -57,8 +61,9 @@ TEST(ConnectionImplTest, Ownership) {
// Re-addition.
{
- ConnectionImpl connection;
- ConnectionImpl::TestApi test_api(&connection);
+ shell::mojom::InterfaceProviderRequest ir;
+ InterfaceRegistry registry(std::move(ir), nullptr);
+ InterfaceRegistry::TestApi test_api(&registry);
test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
EXPECT_EQ(5, delete_count);