ConnectToApplicationDeprecated() conversion/removal, part 3.
The last use of ConnectToApplicationDeprecated() is complicated, since
both ServiceProvider directions are used.
We hang on to ServiceProviderImpls (which are bound to requests whose
corresponding handles were sent over ConnectToApplication()) and keep
them alive (and of course service them), so that the TestB that we
connected to can make requests on us.
Instead of passing the ApplicationConnect* to the TestAImpl, we just
pass it the ServiceProvider handle ("pointer"), so that the TestAImpl
can connect to the TestB services.
R=vardhan@google.com
Review URL: https://codereview.chromium.org/1924673002 .
diff --git a/shell/application_manager/application_manager_unittest.cc b/shell/application_manager/application_manager_unittest.cc
index bbf84bb..de9fa14 100644
--- a/shell/application_manager/application_manager_unittest.cc
+++ b/shell/application_manager/application_manager_unittest.cc
@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "shell/application_manager/application_manager.h"
+
+#include <utility>
+
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/macros.h"
@@ -10,11 +14,12 @@
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/application/interface_factory.h"
+#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "shell/application_manager/application_loader.h"
-#include "shell/application_manager/application_manager.h"
#include "shell/application_manager/test.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -241,11 +246,12 @@
// Used to test that the requestor url will be correctly passed.
class TestAImpl : public TestA {
public:
- TestAImpl(ApplicationConnection* b_connection,
+ TestAImpl(mojo::InterfaceHandle<mojo::ServiceProvider> b_sp_handle,
TesterContext* test_context,
InterfaceRequest<TestA> request)
: test_context_(test_context), binding_(this, request.Pass()) {
- b_connection->ConnectToService(&b_);
+ auto b_sp = mojo::ServiceProviderPtr::Create(b_sp_handle.Pass());
+ mojo::ConnectToService(b_sp.get(), GetProxy(&b_));
}
~TestAImpl() override {
@@ -359,11 +365,19 @@
void Create(ApplicationConnection* connection,
InterfaceRequest<TestA> request) override {
- ApplicationConnection* b_connection =
- app_->ConnectToApplicationDeprecated(kTestBURLString);
- b_connection->AddService<TestC>(this);
+ mojo::InterfaceHandle<mojo::ServiceProvider> incoming_sp_handle;
+ mojo::InterfaceHandle<mojo::ServiceProvider> outgoing_sp_handle;
+ mojo::InterfaceRequest<mojo::ServiceProvider> outgoing_sp_request =
+ GetProxy(&outgoing_sp_handle);
+ app_->shell()->ConnectToApplication(kTestBURLString,
+ GetProxy(&incoming_sp_handle),
+ outgoing_sp_handle.Pass());
+ std::unique_ptr<mojo::ServiceProviderImpl> outgoing_sp_impl(
+ new mojo::ServiceProviderImpl(outgoing_sp_request.Pass()));
+ outgoing_sp_impl->AddService<TestC>(this);
+ outgoing_sp_impls_for_b_.push_back(std::move(outgoing_sp_impl));
a_bindings_.push_back(
- new TestAImpl(b_connection, context_, request.Pass()));
+ new TestAImpl(incoming_sp_handle.Pass(), context_, request.Pass()));
}
void Create(ApplicationConnection* connection,
@@ -379,6 +393,8 @@
TesterContext* context_;
scoped_ptr<ApplicationImpl> app_;
std::string requestor_url_;
+ std::vector<std::unique_ptr<mojo::ServiceProviderImpl>>
+ outgoing_sp_impls_for_b_;
ScopedVector<TestAImpl> a_bindings_;
};