diff options
-rw-r--r-- | mojo/application/public/cpp/application_impl.h | 33 | ||||
-rw-r--r-- | mojo/application/public/cpp/lib/application_impl.cc | 19 | ||||
-rw-r--r-- | mojo/application/public/cpp/lib/application_test_base.cc | 8 |
3 files changed, 34 insertions, 26 deletions
diff --git a/mojo/application/public/cpp/application_impl.h b/mojo/application/public/cpp/application_impl.h index e05e741..b2e9675 100644 --- a/mojo/application/public/cpp/application_impl.h +++ b/mojo/application/public/cpp/application_impl.h @@ -56,6 +56,20 @@ namespace mojo { // class ApplicationImpl : public Application { public: + class TestApi { + public: + explicit TestApi(ApplicationImpl* application) + : application_(application) {} + + void UnbindConnections(InterfaceRequest<Application>* application_request, + ShellPtr* shell) { + application_->UnbindConnections(application_request, shell); + } + + private: + ApplicationImpl* application_; + }; + // Does not take ownership of |delegate|, which must remain valid for the // lifetime of ApplicationImpl. ApplicationImpl(ApplicationDelegate* delegate, @@ -98,24 +112,13 @@ class ApplicationImpl : public Application { connection->ConnectToService(ptr); } - // Application implementation. - void Initialize(ShellPtr shell, const mojo::String& url) override; - - // Block until the Application is initialized, if it is not already. - void WaitForInitialize(); - - // Unbinds the Shell and Application connections. Can be used to re-bind the - // handles to another implementation of ApplicationImpl, for instance when - // running apptests. - void UnbindConnections(InterfaceRequest<Application>* application_request, - ShellPtr* shell); - // Initiate shutdown of this application. This may involve a round trip to the // Shell to ensure there are no inbound service requests. void Quit(); private: // Application implementation. + void Initialize(ShellPtr shell, const mojo::String& url) override; void AcceptConnection(const String& requestor_url, InterfaceRequest<ServiceProvider> services, ServiceProviderPtr exposed_services, @@ -129,6 +132,12 @@ class ApplicationImpl : public Application { // from Quit() once the Shell has OK'ed shutdown. void QuitNow(); + // Unbinds the Shell and Application connections. Can be used to re-bind the + // handles to another implementation of ApplicationImpl, for instance when + // running apptests. + void UnbindConnections(InterfaceRequest<Application>* application_request, + ShellPtr* shell); + // We track the lifetime of incoming connection registries as it more // convenient for the client. ScopedVector<ApplicationConnection> incoming_connections_; diff --git a/mojo/application/public/cpp/lib/application_impl.cc b/mojo/application/public/cpp/lib/application_impl.cc index 9f2c419..aafd458 100644 --- a/mojo/application/public/cpp/lib/application_impl.cc +++ b/mojo/application/public/cpp/lib/application_impl.cc @@ -90,18 +90,6 @@ void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) { delegate_->Initialize(this); } -void ApplicationImpl::WaitForInitialize() { - if (!shell_) - binding_.WaitForIncomingMethodCall(); -} - -void ApplicationImpl::UnbindConnections( - InterfaceRequest<Application>* application_request, - ShellPtr* shell) { - *application_request = binding_.Unbind(); - shell->Bind(shell_.PassInterface()); -} - void ApplicationImpl::Quit() { // We can't quit immediately, since there could be in-flight requests from the // shell. So check with it first. @@ -162,4 +150,11 @@ void ApplicationImpl::QuitNow() { termination_closure_.Run(); } +void ApplicationImpl::UnbindConnections( + InterfaceRequest<Application>* application_request, + ShellPtr* shell) { + *application_request = binding_.Unbind(); + shell->Bind(shell_.PassInterface()); +} + } // namespace mojo diff --git a/mojo/application/public/cpp/lib/application_test_base.cc b/mojo/application/public/cpp/lib/application_test_base.cc index 3b4a30e..e5d1aa5 100644 --- a/mojo/application/public/cpp/lib/application_test_base.cc +++ b/mojo/application/public/cpp/lib/application_test_base.cc @@ -130,14 +130,18 @@ void ApplicationTestBase::SetUp() { g_application_request.Pass()); // Fake application initialization. - application_impl_->Initialize(g_shell.Pass(), g_url); + Application* application = application_impl_; + application->Initialize(g_shell.Pass(), g_url); } void ApplicationTestBase::TearDown() { MOJO_CHECK(!g_application_request.is_pending()); MOJO_CHECK(!g_shell); - application_impl_->UnbindConnections(&g_application_request, &g_shell); + { + ApplicationImpl::TestApi test_api(application_impl_); + test_api.UnbindConnections(&g_application_request, &g_shell); + } delete application_impl_; if (ShouldCreateDefaultRunLoop()) Environment::DestroyDefaultRunLoop(); |