summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authoryzshen <yzshen@chromium.org>2016-03-08 15:48:49 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-08 23:50:50 +0000
commitb92c3dd75843e7603892e997a80dcdba5102ce07 (patch)
tree07fb889c003760df4da61fdd4bde82107fa128ea /mojo
parentbd736b069b320a18476b30aea47639fb25f50110 (diff)
downloadchromium_src-b92c3dd75843e7603892e997a80dcdba5102ce07.zip
chromium_src-b92c3dd75843e7603892e997a80dcdba5102ce07.tar.gz
chromium_src-b92c3dd75843e7603892e997a80dcdba5102ce07.tar.bz2
Mojo C++ bindings: remove the concept of "GenericInterface".
Previously, if a variant Foo1 was generated for mojom interface Foo. Foo1::GenericInterface was defined as a typedef of the non-variant version Foo. This required the non-variant version to be generated and depended on by all variants. The purpose was to make different variants use the same [Associated]Interface{PtrInfo,Request} types. In fact, this is not very useful in real-world use cases. It should be very rare that users need to deal with multiple variants of the same mojom interface in a single same app. This change removes GenericInterface and makes [Associated]Interface{PtrInfo, Request} directly use Foo1 instead of Foo1::GenericInterface. BUG=590329 Review URL: https://codereview.chromium.org/1775613003 Cr-Commit-Position: refs/heads/master@{#379970}
Diffstat (limited to 'mojo')
-rw-r--r--mojo/mojo_public.gyp1
-rw-r--r--mojo/public/cpp/bindings/associated_binding.h14
-rw-r--r--mojo/public/cpp/bindings/associated_interface_ptr.h14
-rw-r--r--mojo/public/cpp/bindings/binding.h8
-rw-r--r--mojo/public/cpp/bindings/binding_set.h8
-rw-r--r--mojo/public/cpp/bindings/interface_ptr.h6
-rw-r--r--mojo/public/cpp/bindings/interface_request.h9
-rw-r--r--mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h8
-rw-r--r--mojo/public/cpp/bindings/lib/binding_state.h16
-rw-r--r--mojo/public/cpp/bindings/lib/interface_ptr_state.h16
-rw-r--r--mojo/public/cpp/bindings/tests/pickle_unittest.cc124
-rw-r--r--mojo/public/cpp/bindings/tests/struct_traits_unittest.cc34
-rw-r--r--mojo/public/interfaces/bindings/tests/BUILD.gn1
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl2
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl3
15 files changed, 135 insertions, 129 deletions
diff --git a/mojo/mojo_public.gyp b/mojo/mojo_public.gyp
index e72ce0b..d090dc3 100644
--- a/mojo/mojo_public.gyp
+++ b/mojo/mojo_public.gyp
@@ -371,7 +371,6 @@
'public/interfaces/bindings/tests/scoping.mojom',
'public/interfaces/bindings/tests/serialization_test_structs.mojom',
'public/interfaces/bindings/tests/test_constants.mojom',
- 'public/interfaces/bindings/tests/test_native_types.mojom',
'public/interfaces/bindings/tests/test_structs.mojom',
'public/interfaces/bindings/tests/test_sync_methods.mojom',
'public/interfaces/bindings/tests/test_unions.mojom',
diff --git a/mojo/public/cpp/bindings/associated_binding.h b/mojo/public/cpp/bindings/associated_binding.h
index 6af95cc..37f22bd 100644
--- a/mojo/public/cpp/bindings/associated_binding.h
+++ b/mojo/public/cpp/bindings/associated_binding.h
@@ -23,8 +23,6 @@ namespace mojo {
template <typename Interface>
class AssociatedBinding {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
// Constructs an incomplete associated binding that will use the
// implementation |impl|. It may be completed with a subsequent call to the
// |Bind| method. Does not take ownership of |impl|, which must outlive this
@@ -38,7 +36,7 @@ class AssociatedBinding {
// |associated_group| to setup the corresponding asssociated interface
// pointer. |impl| must outlive this object.
AssociatedBinding(Interface* impl,
- AssociatedInterfacePtrInfo<GenericInterface>* ptr_info,
+ AssociatedInterfacePtrInfo<Interface>* ptr_info,
AssociatedGroup* associated_group)
: AssociatedBinding(impl) {
Bind(ptr_info, associated_group);
@@ -47,7 +45,7 @@ class AssociatedBinding {
// Constructs a completed associated binding of |impl|. |impl| must outlive
// the binding.
AssociatedBinding(Interface* impl,
- AssociatedInterfaceRequest<GenericInterface> request)
+ AssociatedInterfaceRequest<Interface> request)
: AssociatedBinding(impl) {
Bind(std::move(request));
}
@@ -58,7 +56,7 @@ class AssociatedBinding {
// implementation side. The output |ptr_info| should be passed through the
// message pipe endpoint referred to by |associated_group| to setup the
// corresponding asssociated interface pointer.
- void Bind(AssociatedInterfacePtrInfo<GenericInterface>* ptr_info,
+ void Bind(AssociatedInterfacePtrInfo<Interface>* ptr_info,
AssociatedGroup* associated_group) {
AssociatedInterfaceRequest<Interface> request;
associated_group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_PTR,
@@ -67,7 +65,7 @@ class AssociatedBinding {
}
// Sets up this object as the implementation side of an associated interface.
- void Bind(AssociatedInterfaceRequest<GenericInterface> request) {
+ void Bind(AssociatedInterfaceRequest<Interface> request) {
internal::ScopedInterfaceEndpointHandle handle =
internal::AssociatedInterfaceRequestHelper::PassHandle(&request);
@@ -100,10 +98,10 @@ class AssociatedBinding {
// Unbinds and returns the associated interface request so it can be
// used in another context, such as on another thread or with a different
// implementation. Puts this object into a state where it can be rebound.
- AssociatedInterfaceRequest<GenericInterface> Unbind() {
+ AssociatedInterfaceRequest<Interface> Unbind() {
DCHECK(endpoint_client_);
- AssociatedInterfaceRequest<GenericInterface> request;
+ AssociatedInterfaceRequest<Interface> request;
internal::AssociatedInterfaceRequestHelper::SetHandle(
&request, endpoint_client_->PassHandle());
diff --git a/mojo/public/cpp/bindings/associated_interface_ptr.h b/mojo/public/cpp/bindings/associated_interface_ptr.h
index f683637..d3a848a 100644
--- a/mojo/public/cpp/bindings/associated_interface_ptr.h
+++ b/mojo/public/cpp/bindings/associated_interface_ptr.h
@@ -25,8 +25,6 @@ class AssociatedInterfacePtr {
DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtr)
public:
- using GenericInterface = typename Interface::GenericInterface;
-
// Constructs an unbound AssociatedInterfacePtr.
AssociatedInterfacePtr() {}
AssociatedInterfacePtr(decltype(nullptr)) {}
@@ -57,7 +55,7 @@ class AssociatedInterfacePtr {
// NOTE: Please see the comments of
// AssociatedGroup.CreateAssociatedInterface() about when you can use this
// object to make calls.
- void Bind(AssociatedInterfacePtrInfo<GenericInterface> info) {
+ void Bind(AssociatedInterfacePtrInfo<Interface> info) {
reset();
bool is_local =
@@ -125,7 +123,7 @@ class AssociatedInterfacePtr {
// It is an error to call PassInterface() while there are pending responses.
// TODO: fix this restriction, it's not always obvious when there is a
// pending response.
- AssociatedInterfacePtrInfo<GenericInterface> PassInterface() {
+ AssociatedInterfacePtrInfo<Interface> PassInterface() {
DCHECK(!internal_state_.has_pending_callbacks());
State state;
internal_state_.Swap(&state);
@@ -178,16 +176,16 @@ class AssociatedInterfacePtr {
// as soon as the request is sent, |ptr| is usable. There is no need to wait
// until the request is bound to an implementation at the remote side.
template <typename Interface>
-AssociatedInterfaceRequest<typename Interface::GenericInterface> GetProxy(
+AssociatedInterfaceRequest<Interface> GetProxy(
AssociatedInterfacePtr<Interface>* ptr,
AssociatedGroup* group) {
- AssociatedInterfaceRequest<typename Interface::GenericInterface> request;
- AssociatedInterfacePtrInfo<typename Interface::GenericInterface> ptr_info;
+ AssociatedInterfaceRequest<Interface> request;
+ AssociatedInterfacePtrInfo<Interface> ptr_info;
group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST,
&ptr_info, &request);
ptr->Bind(std::move(ptr_info));
- return std::move(request);
+ return request;
}
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/binding.h b/mojo/public/cpp/bindings/binding.h
index 3739331..68dd322 100644
--- a/mojo/public/cpp/bindings/binding.h
+++ b/mojo/public/cpp/bindings/binding.h
@@ -55,8 +55,6 @@ class AssociatedGroup;
template <typename Interface>
class Binding {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
// Constructs an incomplete binding that will use the implementation |impl|.
// The binding may be completed with a subsequent call to the |Bind| method.
// Does not take ownership of |impl|, which must outlive the binding.
@@ -80,7 +78,7 @@ class Binding {
// Constructs a completed binding of |impl| to the message pipe endpoint in
// |request|, taking ownership of the endpoint. Does not take ownership of
// |impl|, which must outlive the binding.
- Binding(Interface* impl, InterfaceRequest<GenericInterface> request)
+ Binding(Interface* impl, InterfaceRequest<Interface> request)
: Binding(impl) {
Bind(request.PassMessagePipe());
}
@@ -119,7 +117,7 @@ class Binding {
// Completes a binding that was constructed with only an interface
// implementation by removing the message pipe endpoint from |request| and
// binding it to the previously specified implementation.
- void Bind(InterfaceRequest<GenericInterface> request) {
+ void Bind(InterfaceRequest<Interface> request) {
Bind(request.PassMessagePipe());
}
@@ -172,7 +170,7 @@ class Binding {
// on to associated interface endpoint handles at both sides of the
// message pipe in order to call this method. We need a way to forcefully
// invalidate associated interface endpoint handles.
- InterfaceRequest<GenericInterface> Unbind() {
+ InterfaceRequest<Interface> Unbind() {
CHECK(!HasAssociatedInterfaces());
return internal_state_.Unbind();
}
diff --git a/mojo/public/cpp/bindings/binding_set.h b/mojo/public/cpp/bindings/binding_set.h
index 3bbdb7e..f2c9480 100644
--- a/mojo/public/cpp/bindings/binding_set.h
+++ b/mojo/public/cpp/bindings/binding_set.h
@@ -20,8 +20,6 @@ namespace mojo {
template <typename Interface>
class BindingSet {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
BindingSet() {}
~BindingSet() { CloseAllBindings(); }
@@ -29,7 +27,7 @@ class BindingSet {
error_handler_ = error_handler;
}
- void AddBinding(Interface* impl, InterfaceRequest<GenericInterface> request) {
+ void AddBinding(Interface* impl, InterfaceRequest<Interface> request) {
auto binding = new Element(impl, std::move(request));
binding->set_connection_error_handler([this]() { OnConnectionError(); });
bindings_.push_back(binding->GetWeakPtr());
@@ -58,9 +56,7 @@ class BindingSet {
private:
class Element {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
- Element(Interface* impl, InterfaceRequest<GenericInterface> request)
+ Element(Interface* impl, InterfaceRequest<Interface> request)
: binding_(impl, std::move(request)), weak_ptr_factory_(this) {
binding_.set_connection_error_handler([this]() { OnConnectionError(); });
}
diff --git a/mojo/public/cpp/bindings/interface_ptr.h b/mojo/public/cpp/bindings/interface_ptr.h
index 4aba1ff..9b005ee 100644
--- a/mojo/public/cpp/bindings/interface_ptr.h
+++ b/mojo/public/cpp/bindings/interface_ptr.h
@@ -36,8 +36,6 @@ class InterfacePtr {
DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(InterfacePtr);
public:
- using GenericInterface = typename Interface::GenericInterface;
-
// Constructs an unbound InterfacePtr.
InterfacePtr() {}
InterfacePtr(decltype(nullptr)) {}
@@ -70,7 +68,7 @@ class InterfacePtr {
// Calling with an invalid |info| (containing an invalid message pipe handle)
// has the same effect as reset(). In this case, the InterfacePtr is not
// considered as bound.
- void Bind(InterfacePtrInfo<GenericInterface> info) {
+ void Bind(InterfacePtrInfo<Interface> info) {
reset();
if (info.is_valid())
internal_state_.Bind(std::move(info));
@@ -158,7 +156,7 @@ class InterfacePtr {
// on to associated interface endpoint handles at both sides of the
// message pipe in order to call this method. We need a way to forcefully
// invalidate associated interface endpoint handles.
- InterfacePtrInfo<GenericInterface> PassInterface() {
+ InterfacePtrInfo<Interface> PassInterface() {
CHECK(!HasAssociatedInterfaces());
CHECK(!internal_state_.has_pending_callbacks());
State state;
diff --git a/mojo/public/cpp/bindings/interface_request.h b/mojo/public/cpp/bindings/interface_request.h
index a2b617b..f67566d 100644
--- a/mojo/public/cpp/bindings/interface_request.h
+++ b/mojo/public/cpp/bindings/interface_request.h
@@ -111,13 +111,10 @@ InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) {
// CreateSource(std::move(source_request)); // Create implementation locally.
//
template <typename Interface>
-InterfaceRequest<typename Interface::GenericInterface>
-GetProxy(InterfacePtr<Interface>* ptr) {
+InterfaceRequest<Interface> GetProxy(InterfacePtr<Interface>* ptr) {
MessagePipe pipe;
- ptr->Bind(InterfacePtrInfo<typename Interface::GenericInterface>(
- std::move(pipe.handle0), 0u));
- return MakeRequest<typename Interface::GenericInterface>(
- std::move(pipe.handle1));
+ ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u));
+ return MakeRequest<Interface>(std::move(pipe.handle1));
}
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h b/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h
index caa4ce8..f792884 100644
--- a/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h
+++ b/mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h
@@ -26,8 +26,6 @@ namespace internal {
template <typename Interface>
class AssociatedInterfacePtrState {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
AssociatedInterfacePtrState() : version_(0u) {}
~AssociatedInterfacePtrState() {
@@ -73,7 +71,7 @@ class AssociatedInterfacePtrState {
swap(other->version_, version_);
}
- void Bind(AssociatedInterfacePtrInfo<GenericInterface> info) {
+ void Bind(AssociatedInterfacePtrInfo<Interface> info) {
DCHECK(!endpoint_client_);
DCHECK(!proxy_);
DCHECK_EQ(0u, version_);
@@ -89,12 +87,12 @@ class AssociatedInterfacePtrState {
// After this method is called, the object is in an invalid state and
// shouldn't be reused.
- AssociatedInterfacePtrInfo<GenericInterface> PassInterface() {
+ AssociatedInterfacePtrInfo<Interface> PassInterface() {
ScopedInterfaceEndpointHandle handle = endpoint_client_->PassHandle();
endpoint_client_.reset();
proxy_.reset();
- AssociatedInterfacePtrInfo<GenericInterface> result;
+ AssociatedInterfacePtrInfo<Interface> result;
result.set_version(version_);
AssociatedInterfacePtrInfoHelper::SetHandle(&result, std::move(handle));
return result;
diff --git a/mojo/public/cpp/bindings/lib/binding_state.h b/mojo/public/cpp/bindings/lib/binding_state.h
index 84a8a36..feef835 100644
--- a/mojo/public/cpp/bindings/lib/binding_state.h
+++ b/mojo/public/cpp/bindings/lib/binding_state.h
@@ -38,8 +38,6 @@ class BindingState;
template <typename Interface>
class BindingState<Interface, false> {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
explicit BindingState(Interface* impl) : impl_(impl) {
stub_.set_sink(impl_);
}
@@ -85,9 +83,9 @@ class BindingState<Interface, false> {
DestroyRouter();
}
- InterfaceRequest<GenericInterface> Unbind() {
- InterfaceRequest<GenericInterface> request =
- MakeRequest<GenericInterface>(router_->PassMessagePipe());
+ InterfaceRequest<Interface> Unbind() {
+ InterfaceRequest<Interface> request =
+ MakeRequest<Interface>(router_->PassMessagePipe());
DestroyRouter();
return std::move(request);
}
@@ -134,8 +132,6 @@ class BindingState<Interface, false> {
template <typename Interface>
class BindingState<Interface, true> {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
explicit BindingState(Interface* impl) : impl_(impl) {
stub_.set_sink(impl_);
}
@@ -186,10 +182,10 @@ class BindingState<Interface, true> {
connection_error_handler_.reset();
}
- InterfaceRequest<GenericInterface> Unbind() {
+ InterfaceRequest<Interface> Unbind() {
endpoint_client_.reset();
- InterfaceRequest<GenericInterface> request =
- MakeRequest<GenericInterface>(router_->PassMessagePipe());
+ InterfaceRequest<Interface> request =
+ MakeRequest<Interface>(router_->PassMessagePipe());
router_ = nullptr;
connection_error_handler_.reset();
return request;
diff --git a/mojo/public/cpp/bindings/lib/interface_ptr_state.h b/mojo/public/cpp/bindings/lib/interface_ptr_state.h
index 4f505d1..d772e21 100644
--- a/mojo/public/cpp/bindings/lib/interface_ptr_state.h
+++ b/mojo/public/cpp/bindings/lib/interface_ptr_state.h
@@ -38,8 +38,6 @@ class InterfacePtrState;
template <typename Interface>
class InterfacePtrState<Interface, false> {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
InterfacePtrState() : proxy_(nullptr), router_(nullptr), version_(0u) {}
~InterfacePtrState() {
@@ -94,7 +92,7 @@ class InterfacePtrState<Interface, false> {
swap(other->version_, version_);
}
- void Bind(InterfacePtrInfo<GenericInterface> info) {
+ void Bind(InterfacePtrInfo<Interface> info) {
DCHECK(!proxy_);
DCHECK(!router_);
DCHECK(!handle_.is_valid());
@@ -116,8 +114,8 @@ class InterfacePtrState<Interface, false> {
// After this method is called, the object is in an invalid state and
// shouldn't be reused.
- InterfacePtrInfo<GenericInterface> PassInterface() {
- return InterfacePtrInfo<GenericInterface>(
+ InterfacePtrInfo<Interface> PassInterface() {
+ return InterfacePtrInfo<Interface>(
router_ ? router_->PassMessagePipe() : std::move(handle_), version_);
}
@@ -186,8 +184,6 @@ class InterfacePtrState<Interface, false> {
template <typename Interface>
class InterfacePtrState<Interface, true> {
public:
- using GenericInterface = typename Interface::GenericInterface;
-
InterfacePtrState() : version_(0u) {}
~InterfacePtrState() {
@@ -243,7 +239,7 @@ class InterfacePtrState<Interface, true> {
swap(other->version_, version_);
}
- void Bind(InterfacePtrInfo<GenericInterface> info) {
+ void Bind(InterfacePtrInfo<Interface> info) {
DCHECK(!router_);
DCHECK(!endpoint_client_);
DCHECK(!proxy_);
@@ -268,10 +264,10 @@ class InterfacePtrState<Interface, true> {
// After this method is called, the object is in an invalid state and
// shouldn't be reused.
- InterfacePtrInfo<GenericInterface> PassInterface() {
+ InterfacePtrInfo<Interface> PassInterface() {
endpoint_client_.reset();
proxy_.reset();
- return InterfacePtrInfo<GenericInterface>(
+ return InterfacePtrInfo<Interface>(
router_ ? router_->PassMessagePipe() : std::move(handle_), version_);
}
diff --git a/mojo/public/cpp/bindings/tests/pickle_unittest.cc b/mojo/public/cpp/bindings/tests/pickle_unittest.cc
index 33961b4..bc77298 100644
--- a/mojo/public/cpp/bindings/tests/pickle_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/pickle_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string.h>
+
#include <string>
#include "base/bind.h"
@@ -15,13 +17,25 @@
#include "mojo/public/cpp/bindings/tests/pickled_struct_chromium.h"
#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h"
#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-chromium.h"
-#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace test {
namespace {
+// Converts a request of Interface1 to a request of Interface0. Interface0 and
+// Interface1 are expected to be two variants of the same mojom interface.
+// In real-world use cases, users shouldn't need to worry about this. Because it
+// is rare to deal with two variants of the same interface in the same app.
+template <typename Interface0, typename Interface1>
+InterfaceRequest<Interface0> ConvertInterfaceRequest(
+ InterfaceRequest<Interface1> request) {
+ DCHECK_EQ(0, strcmp(Interface0::Name_, Interface1::Name_));
+ InterfaceRequest<Interface0> result;
+ result.Bind(request.PassMessagePipe());
+ return result;
+}
+
template <typename T>
void DoExpectResult(int foo,
int bar,
@@ -70,14 +84,13 @@ class ChromiumPicklePasserImpl : public chromium::PicklePasser {
callback.Run(std::move(container));
}
- void PassPickles(mojo::Array<PickledStructChromium> pickles,
+ void PassPickles(Array<PickledStructChromium> pickles,
const PassPicklesCallback& callback) override {
callback.Run(std::move(pickles));
}
- void PassPickleArrays(
- mojo::Array<mojo::Array<PickledStructChromium>> pickle_arrays,
- const PassPickleArraysCallback& callback) override {
+ void PassPickleArrays(Array<Array<PickledStructChromium>> pickle_arrays,
+ const PassPickleArraysCallback& callback) override {
callback.Run(std::move(pickle_arrays));
}
};
@@ -99,14 +112,13 @@ class BlinkPicklePasserImpl : public blink::PicklePasser {
callback.Run(std::move(container));
}
- void PassPickles(mojo::Array<PickledStructBlink> pickles,
+ void PassPickles(Array<PickledStructBlink> pickles,
const PassPicklesCallback& callback) override {
callback.Run(std::move(pickles));
}
- void PassPickleArrays(
- mojo::Array<mojo::Array<PickledStructBlink>> pickle_arrays,
- const PassPickleArraysCallback& callback) override {
+ void PassPickleArrays(Array<Array<PickledStructBlink>> pickle_arrays,
+ const PassPickleArraysCallback& callback) override {
callback.Run(std::move(pickle_arrays));
}
};
@@ -118,25 +130,31 @@ class PickleTest : public testing::Test {
PickleTest() {}
template <typename ProxyType = chromium::PicklePasser>
- mojo::InterfacePtr<ProxyType> ConnectToChromiumService() {
- mojo::InterfacePtr<ProxyType> proxy;
- chromium_bindings_.AddBinding(&chromium_service_, GetProxy(&proxy));
+ InterfacePtr<ProxyType> ConnectToChromiumService() {
+ InterfacePtr<ProxyType> proxy;
+ InterfaceRequest<ProxyType> request = GetProxy(&proxy);
+ chromium_bindings_.AddBinding(
+ &chromium_service_,
+ ConvertInterfaceRequest<chromium::PicklePasser>(std::move(request)));
return proxy;
}
template <typename ProxyType = blink::PicklePasser>
- mojo::InterfacePtr<ProxyType> ConnectToBlinkService() {
- mojo::InterfacePtr<ProxyType> proxy;
- blink_bindings_.AddBinding(&blink_service_, GetProxy(&proxy));
+ InterfacePtr<ProxyType> ConnectToBlinkService() {
+ InterfacePtr<ProxyType> proxy;
+ InterfaceRequest<ProxyType> request = GetProxy(&proxy);
+ blink_bindings_.AddBinding(
+ &blink_service_,
+ ConvertInterfaceRequest<blink::PicklePasser>(std::move(request)));
return proxy;
}
private:
base::MessageLoop loop_;
ChromiumPicklePasserImpl chromium_service_;
- mojo::BindingSet<chromium::PicklePasser> chromium_bindings_;
+ BindingSet<chromium::PicklePasser> chromium_bindings_;
BlinkPicklePasserImpl blink_service_;
- mojo::BindingSet<blink::PicklePasser> blink_bindings_;
+ BindingSet<blink::PicklePasser> blink_bindings_;
};
} // namespace
@@ -211,7 +229,7 @@ TEST_F(PickleTest, BlinkProxyToChromiumService) {
TEST_F(PickleTest, PickleArray) {
auto proxy = ConnectToChromiumService();
- auto pickles = mojo::Array<PickledStructChromium>::New(2);
+ auto pickles = Array<PickledStructChromium>::New(2);
pickles[0].set_foo(1);
pickles[0].set_bar(2);
pickles[0].set_baz(100);
@@ -224,28 +242,27 @@ TEST_F(PickleTest, PickleArray) {
// deserialized intact. This ensures that the ParamTraits are actually used
// rather than doing a byte-for-byte copy of the element data, beacuse the
// |baz| field should never be serialized.
- proxy->PassPickles(
- std::move(pickles),
- [&](mojo::Array<PickledStructChromium> passed) {
- ASSERT_FALSE(passed.is_null());
- ASSERT_EQ(2u, passed.size());
- EXPECT_EQ(1, passed[0].foo());
- EXPECT_EQ(2, passed[0].bar());
- EXPECT_EQ(0, passed[0].baz());
- EXPECT_EQ(3, passed[1].foo());
- EXPECT_EQ(4, passed[1].bar());
- EXPECT_EQ(0, passed[1].baz());
- run_loop.Quit();
- });
+ proxy->PassPickles(std::move(pickles),
+ [&](Array<PickledStructChromium> passed) {
+ ASSERT_FALSE(passed.is_null());
+ ASSERT_EQ(2u, passed.size());
+ EXPECT_EQ(1, passed[0].foo());
+ EXPECT_EQ(2, passed[0].bar());
+ EXPECT_EQ(0, passed[0].baz());
+ EXPECT_EQ(3, passed[1].foo());
+ EXPECT_EQ(4, passed[1].bar());
+ EXPECT_EQ(0, passed[1].baz());
+ run_loop.Quit();
+ });
run_loop.Run();
}
}
TEST_F(PickleTest, PickleArrayArray) {
auto proxy = ConnectToChromiumService();
- auto pickle_arrays = mojo::Array<mojo::Array<PickledStructChromium>>::New(2);
+ auto pickle_arrays = Array<Array<PickledStructChromium>>::New(2);
for (size_t i = 0; i < 2; ++i)
- pickle_arrays[i] = mojo::Array<PickledStructChromium>::New(2);
+ pickle_arrays[i] = Array<PickledStructChromium>::New(2);
pickle_arrays[0][0].set_foo(1);
pickle_arrays[0][0].set_bar(2);
@@ -262,27 +279,26 @@ TEST_F(PickleTest, PickleArrayArray) {
{
base::RunLoop run_loop;
// Verify that the array-of-arrays serializes and deserializes properly.
- proxy->PassPickleArrays(
- std::move(pickle_arrays),
- [&](mojo::Array<mojo::Array<PickledStructChromium>> passed) {
- ASSERT_FALSE(passed.is_null());
- ASSERT_EQ(2u, passed.size());
- ASSERT_EQ(2u, passed[0].size());
- ASSERT_EQ(2u, passed[1].size());
- EXPECT_EQ(1, passed[0][0].foo());
- EXPECT_EQ(2, passed[0][0].bar());
- EXPECT_EQ(0, passed[0][0].baz());
- EXPECT_EQ(3, passed[0][1].foo());
- EXPECT_EQ(4, passed[0][1].bar());
- EXPECT_EQ(0, passed[0][1].baz());
- EXPECT_EQ(5, passed[1][0].foo());
- EXPECT_EQ(6, passed[1][0].bar());
- EXPECT_EQ(0, passed[1][0].baz());
- EXPECT_EQ(7, passed[1][1].foo());
- EXPECT_EQ(8, passed[1][1].bar());
- EXPECT_EQ(0, passed[1][1].baz());
- run_loop.Quit();
- });
+ proxy->PassPickleArrays(std::move(pickle_arrays),
+ [&](Array<Array<PickledStructChromium>> passed) {
+ ASSERT_FALSE(passed.is_null());
+ ASSERT_EQ(2u, passed.size());
+ ASSERT_EQ(2u, passed[0].size());
+ ASSERT_EQ(2u, passed[1].size());
+ EXPECT_EQ(1, passed[0][0].foo());
+ EXPECT_EQ(2, passed[0][0].bar());
+ EXPECT_EQ(0, passed[0][0].baz());
+ EXPECT_EQ(3, passed[0][1].foo());
+ EXPECT_EQ(4, passed[0][1].bar());
+ EXPECT_EQ(0, passed[0][1].baz());
+ EXPECT_EQ(5, passed[1][0].foo());
+ EXPECT_EQ(6, passed[1][0].bar());
+ EXPECT_EQ(0, passed[1][0].baz());
+ EXPECT_EQ(7, passed[1][1].foo());
+ EXPECT_EQ(8, passed[1][1].bar());
+ EXPECT_EQ(0, passed[1][1].baz());
+ run_loop.Quit();
+ });
run_loop.Run();
}
}
diff --git a/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc b/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
index b4c3e49..e1ffacb 100644
--- a/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/struct_traits_unittest.cc
@@ -15,13 +15,25 @@
#include "mojo/public/interfaces/bindings/tests/struct_with_traits.mojom.h"
#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h"
#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-chromium.h"
-#include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace test {
namespace {
+// Converts a request of Interface1 to a request of Interface0. Interface0 and
+// Interface1 are expected to be two variants of the same mojom interface.
+// In real-world use cases, users shouldn't need to worry about this. Because it
+// is rare to deal with two variants of the same interface in the same app.
+template <typename Interface0, typename Interface1>
+InterfaceRequest<Interface0> ConvertInterfaceRequest(
+ InterfaceRequest<Interface1> request) {
+ DCHECK_EQ(0, strcmp(Interface0::Name_, Interface1::Name_));
+ InterfaceRequest<Interface0> result;
+ result.Bind(request.PassMessagePipe());
+ return result;
+}
+
template <typename T>
void DoExpectResult(const T& expected,
const base::Closure& callback,
@@ -103,13 +115,23 @@ class StructTraitsTest : public testing::Test,
StructTraitsTest() {}
protected:
- void BindToChromiumService(mojo::InterfaceRequest<RectService> request) {
+ void BindToChromiumService(chromium::RectServiceRequest request) {
chromium_bindings_.AddBinding(&chromium_service_, std::move(request));
}
+ void BindToChromiumService(blink::RectServiceRequest request) {
+ chromium_bindings_.AddBinding(
+ &chromium_service_,
+ ConvertInterfaceRequest<chromium::RectService>(std::move(request)));
+ }
- void BindToBlinkService(mojo::InterfaceRequest<RectService> request) {
+ void BindToBlinkService(blink::RectServiceRequest request) {
blink_bindings_.AddBinding(&blink_service_, std::move(request));
}
+ void BindToBlinkService(chromium::RectServiceRequest request) {
+ blink_bindings_.AddBinding(
+ &blink_service_,
+ ConvertInterfaceRequest<blink::RectService>(std::move(request)));
+ }
TraitsTestServicePtr GetTraitsTestProxy() {
return traits_test_bindings_.CreateInterfacePtrAndBind(this);
@@ -126,12 +148,12 @@ class StructTraitsTest : public testing::Test,
base::MessageLoop loop_;
ChromiumRectServiceImpl chromium_service_;
- mojo::BindingSet<chromium::RectService> chromium_bindings_;
+ BindingSet<chromium::RectService> chromium_bindings_;
BlinkRectServiceImpl blink_service_;
- mojo::BindingSet<blink::RectService> blink_bindings_;
+ BindingSet<blink::RectService> blink_bindings_;
- mojo::BindingSet<TraitsTestService> traits_test_bindings_;
+ BindingSet<TraitsTestService> traits_test_bindings_;
};
} // namespace
diff --git a/mojo/public/interfaces/bindings/tests/BUILD.gn b/mojo/public/interfaces/bindings/tests/BUILD.gn
index dddb522..464566c 100644
--- a/mojo/public/interfaces/bindings/tests/BUILD.gn
+++ b/mojo/public/interfaces/bindings/tests/BUILD.gn
@@ -20,7 +20,6 @@ mojom("test_interfaces") {
"scoping.mojom",
"serialization_test_structs.mojom",
"test_constants.mojom",
- "test_native_types.mojom",
"test_structs.mojom",
"test_sync_methods.mojom",
"validation_test_interfaces.mojom",
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
index 2f0c60e..dddbbd3 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
@@ -14,8 +14,6 @@ class {{interface.name}} {
static const bool PassesAssociatedKinds_ = {% if interface|passes_associated_kinds %}true{% else %}false{% endif %};
static const bool HasSyncMethods_ = {% if interface|has_sync_methods %}true{% else %}false{% endif %};
- using GenericInterface = {{interface|get_qualified_name_for_kind}};
-
using Proxy_ = {{interface.name}}Proxy;
using Stub_ = {{interface.name}}Stub;
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
index 91a4473..af93b84 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl
@@ -39,9 +39,6 @@
{%- for import in imports %}
#include "{{import.module.path}}.h"
{%- endfor %}
-{%- if variant %}
-#include "{{module.path}}.h"
-{%- endif %}
{%- for namespace in namespaces_as_array %}
namespace {{namespace}} {