summaryrefslogtreecommitdiffstats
path: root/mojo/public/cpp/application
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/public/cpp/application')
-rw-r--r--mojo/public/cpp/application/BUILD.gn91
-rw-r--r--mojo/public/cpp/application/DEPS11
-rw-r--r--mojo/public/cpp/application/application_connection.h82
-rw-r--r--mojo/public/cpp/application/application_delegate.h40
-rw-r--r--mojo/public/cpp/application/application_impl.h119
-rw-r--r--mojo/public/cpp/application/application_runner.h44
-rw-r--r--mojo/public/cpp/application/application_test_base.h65
-rw-r--r--mojo/public/cpp/application/connect.h22
-rw-r--r--mojo/public/cpp/application/interface_factory.h31
-rw-r--r--mojo/public/cpp/application/interface_factory_impl.h49
-rw-r--r--mojo/public/cpp/application/lazy_interface_ptr.h44
-rw-r--r--mojo/public/cpp/application/lib/DEPS3
-rw-r--r--mojo/public/cpp/application/lib/application_connection.cc12
-rw-r--r--mojo/public/cpp/application/lib/application_delegate.cc27
-rw-r--r--mojo/public/cpp/application/lib/application_impl.cc117
-rw-r--r--mojo/public/cpp/application/lib/application_runner.cc39
-rw-r--r--mojo/public/cpp/application/lib/application_test_base.cc129
-rw-r--r--mojo/public/cpp/application/lib/application_test_main.cc14
-rw-r--r--mojo/public/cpp/application/lib/service_connector.cc18
-rw-r--r--mojo/public/cpp/application/lib/service_connector.h55
-rw-r--r--mojo/public/cpp/application/lib/service_provider_impl.cc69
-rw-r--r--mojo/public/cpp/application/lib/service_registry.cc91
-rw-r--r--mojo/public/cpp/application/lib/service_registry.h64
-rw-r--r--mojo/public/cpp/application/lib/weak_service_provider.cc36
-rw-r--r--mojo/public/cpp/application/lib/weak_service_provider.h41
-rw-r--r--mojo/public/cpp/application/service_provider_impl.h66
-rw-r--r--mojo/public/cpp/application/tests/BUILD.gn23
-rw-r--r--mojo/public/cpp/application/tests/service_registry_unittest.cc65
28 files changed, 0 insertions, 1467 deletions
diff --git a/mojo/public/cpp/application/BUILD.gn b/mojo/public/cpp/application/BUILD.gn
deleted file mode 100644
index 1c8842d..0000000
--- a/mojo/public/cpp/application/BUILD.gn
+++ /dev/null
@@ -1,91 +0,0 @@
-# Copyright 2014 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.
-
-import("../../mojo_sdk.gni")
-
-# GYP version: mojo/public/mojo_public.gyp:mojo_application_base
-mojo_sdk_source_set("application") {
- sources = [
- "application_connection.h",
- "application_delegate.h",
- "application_impl.h",
- "connect.h",
- "service_provider_impl.h",
- "interface_factory.h",
- "interface_factory_impl.h",
- "lib/application_connection.cc",
- "lib/application_delegate.cc",
- "lib/application_impl.cc",
- "lib/service_provider_impl.cc",
- "lib/service_connector.cc",
- "lib/service_connector.h",
- "lib/service_registry.cc",
- "lib/service_registry.h",
- "lib/weak_service_provider.cc",
- "lib/weak_service_provider.h",
- ]
-
- mojo_sdk_deps = [
- "mojo/public/cpp/bindings",
- "mojo/public/cpp/environment",
- "mojo/public/cpp/system",
- "mojo/public/interfaces/application",
- ]
-}
-
-# GYP version: mojo/public/mojo_public.gyp:mojo_application_standalone
-mojo_sdk_source_set("standalone") {
- sources = [
- "lib/application_runner.cc",
- ]
-
- public_deps = [
- ":application",
- ]
-
- mojo_sdk_deps = [
- "mojo/public/cpp/environment:standalone",
- "mojo/public/cpp/utility",
- ]
-}
-
-mojo_sdk_source_set("test_support") {
- testonly = true
- sources = [
- "application_test_base.h",
- "lib/application_test_base.cc",
- ]
-
- deps = [
- ":application",
- "//testing/gtest",
- ]
-
- mojo_sdk_deps = [
- "mojo/public/cpp/bindings",
- "mojo/public/cpp/environment",
- "mojo/public/cpp/system",
- ]
-}
-
-mojo_sdk_source_set("test_support_standalone") {
- testonly = true
- sources = [
- "lib/application_test_main.cc",
- ]
-
- public_deps = [
- ":test_support",
- ]
-
- deps = [
- ":application",
- ]
-
- mojo_sdk_deps = [
- "mojo/public/cpp/environment:standalone",
- "mojo/public/cpp/system",
- "mojo/public/cpp/utility",
- ]
-}
diff --git a/mojo/public/cpp/application/DEPS b/mojo/public/cpp/application/DEPS
deleted file mode 100644
index 503eebc..0000000
--- a/mojo/public/cpp/application/DEPS
+++ /dev/null
@@ -1,11 +0,0 @@
-include_rules = [
- "+mojo/public/cpp/bindings",
- "+mojo/public/cpp/environment",
- "+mojo/public/interfaces/application",
- "+mojo/public/interfaces/service_provider",
-]
-specific_include_rules = {
- r"application_test_base\.h": [
- "+testing/gtest/include/gtest",
- ],
-} \ No newline at end of file
diff --git a/mojo/public/cpp/application/application_connection.h b/mojo/public/cpp/application/application_connection.h
deleted file mode 100644
index d5d6dde..0000000
--- a/mojo/public/cpp/application/application_connection.h
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2014 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_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
-#define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
-
-#include <string>
-
-#include "mojo/public/cpp/application/lib/service_connector.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-
-// An instance of this class is passed to
-// ApplicationDelegate's ConfigureIncomingConnection() method each time a
-// connection is made to this app, and to ApplicationDelegate's
-// ConfigureOutgoingConnection() method when the app connects to
-// another.
-//
-// To use define a class that implements your specific service api, e.g. FooImpl
-// to implement a service named Foo.
-// That class must subclass an InterfaceImpl specialization.
-//
-// Then implement an InterfaceFactory<Foo> that binds instances of FooImpl to
-// InterfaceRequest<Foo>s and register that on the connection.
-//
-// connection->AddService(&factory);
-//
-// Or if you have multiple factories implemented by the same type, explicitly
-// specify the interface to register the factory for:
-//
-// connection->AddService<Foo>(&my_foo_and_bar_factory_);
-// connection->AddService<Bar>(&my_foo_and_bar_factory_);
-//
-// The InterfaceFactory must outlive the ApplicationConnection.
-class ApplicationConnection {
- public:
- virtual ~ApplicationConnection();
-
- template <typename Interface>
- void AddService(InterfaceFactory<Interface>* factory) {
- AddServiceConnector(
- new internal::InterfaceFactoryConnector<Interface>(factory));
- }
-
- // Connect to the service implementing |Interface|.
- template <typename Interface>
- void ConnectToService(InterfacePtr<Interface>* ptr) {
- MessagePipe pipe;
- ptr->Bind(pipe.handle0.Pass());
- GetServiceProvider()->ConnectToService(Interface::Name_,
- pipe.handle1.Pass());
- }
-
- // The url identifying the application on the other end of this connection.
- virtual const std::string& GetRemoteApplicationURL() = 0;
-
- // Establishes a new connection to an application.
- // TODO(davemoore): Would it be better to expose the ApplicationImpl?
- virtual ApplicationConnection* ConnectToApplication(
- const std::string& url) = 0;
-
- // Connect to application identified by |application_url| and connect to
- // the service implementation of the interface identified by |Interface|.
- template <typename Interface>
- void ConnectToService(const std::string& application_url,
- InterfacePtr<Interface>* ptr) {
- ConnectToApplication(application_url)->ConnectToService(ptr);
- }
-
- // Raw ServiceProvider interface to remote application.
- virtual ServiceProvider* GetServiceProvider() = 0;
-
- private:
- virtual void AddServiceConnector(
- internal::ServiceConnectorBase* service_connector) = 0;
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
diff --git a/mojo/public/cpp/application/application_delegate.h b/mojo/public/cpp/application/application_delegate.h
deleted file mode 100644
index b0f2916..0000000
--- a/mojo/public/cpp/application/application_delegate.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2014 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_PUBLIC_APPLICATION_APPLICATION_DELEGATE_H_
-#define MOJO_PUBLIC_APPLICATION_APPLICATION_DELEGATE_H_
-
-#include <string>
-
-#include "mojo/public/cpp/system/macros.h"
-
-namespace mojo {
-
-class ApplicationConnection;
-class ApplicationImpl;
-
-class ApplicationDelegate {
- public:
- ApplicationDelegate();
- virtual ~ApplicationDelegate();
-
- virtual void Initialize(ApplicationImpl* app);
-
- // Override this method to configure what services a connection supports when
- // being connected to from an app.
- // return false to reject the connection entirely.
- virtual bool ConfigureIncomingConnection(ApplicationConnection* connection);
-
- // Override this method to configure what services a connection supports when
- // connecting to another app.
- // return false to reject the connection entirely.
- virtual bool ConfigureOutgoingConnection(ApplicationConnection* connection);
-
- private:
- MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationDelegate);
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_DELEGATE_H_
diff --git a/mojo/public/cpp/application/application_impl.h b/mojo/public/cpp/application/application_impl.h
deleted file mode 100644
index 0ea22c9..0000000
--- a/mojo/public/cpp/application/application_impl.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2014 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_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
-#define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
-#include <vector>
-
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/lib/service_connector.h"
-#include "mojo/public/cpp/application/lib/service_registry.h"
-#include "mojo/public/cpp/system/core.h"
-#include "mojo/public/interfaces/application/application.mojom.h"
-#include "mojo/public/interfaces/application/shell.mojom.h"
-
-namespace mojo {
-
-class ApplicationDelegate;
-
-// Utility class for communicating with the Shell, and providing Services
-// to clients.
-//
-// To use define a class that implements your specific server api, e.g. FooImpl
-// to implement a service named Foo.
-// That class must subclass an InterfaceImpl specialization.
-//
-// If there is context that is to be shared amongst all instances, define a
-// constructor with that class as its only argument, otherwise define an empty
-// constructor.
-//
-// class FooImpl : public InterfaceImpl<Foo> {
-// public:
-// FooImpl(ApplicationContext* app_context) {}
-// };
-//
-// or
-//
-// class BarImpl : public InterfaceImpl<Bar> {
-// public:
-// // contexts will remain valid for the lifetime of BarImpl.
-// BarImpl(ApplicationContext* app_context, BarContext* service_context)
-// : app_context_(app_context), servicecontext_(context) {}
-//
-// Create an ApplicationImpl instance that collects any service implementations.
-//
-// ApplicationImpl app(service_provider_handle);
-// app.AddService<FooImpl>();
-//
-// BarContext context;
-// app.AddService<BarImpl>(&context);
-//
-//
-class ApplicationImpl : public InterfaceImpl<Application> {
- public:
- ApplicationImpl(ApplicationDelegate* delegate,
- ScopedMessagePipeHandle shell_handle);
- ApplicationImpl(ApplicationDelegate* delegate, MojoHandle shell_handle);
- ~ApplicationImpl() override;
-
- Shell* shell() const { return shell_.get(); }
-
- // Returns any initial configuration arguments, passed by the Shell.
- const std::vector<std::string>& args() const { return args_; }
- bool HasArg(const std::string& arg) const;
-
- // Establishes a new connection to an application. Caller does not own.
- ApplicationConnection* ConnectToApplication(const String& application_url);
-
- // Connect to application identified by |application_url| and connect to the
- // service implementation of the interface identified by |Interface|.
- template <typename Interface>
- void ConnectToService(const std::string& application_url,
- InterfacePtr<Interface>* ptr) {
- ConnectToApplication(application_url)->ConnectToService(ptr);
- }
-
- // Wait for the ShellPtr's Initialize message.
- bool WaitForInitialize();
-
- // Unbind the shell from this application and return its handle.
- ScopedMessagePipeHandle UnbindShell();
-
- // Application implementation.
- void Initialize(Array<String> args) override;
-
- // Quits the main run loop for this application.
- static void Terminate();
-
- private:
- class ShellPtrWatcher;
-
- void BindShell(ScopedMessagePipeHandle shell_handle);
- void ClearConnections();
- void OnShellError() {
- ClearConnections();
- Terminate();
- }
-
- // Application implementation.
- void AcceptConnection(const String& requestor_url,
- InterfaceRequest<ServiceProvider> services,
- ServiceProviderPtr exposed_services) override;
-
- typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList;
-
- bool initialized_;
- ServiceRegistryList incoming_service_registries_;
- ServiceRegistryList outgoing_service_registries_;
- ApplicationDelegate* delegate_;
- ShellPtr shell_;
- ShellPtrWatcher* shell_watch_;
- std::vector<std::string> args_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
diff --git a/mojo/public/cpp/application/application_runner.h b/mojo/public/cpp/application/application_runner.h
deleted file mode 100644
index b88ec8e..0000000
--- a/mojo/public/cpp/application/application_runner.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2014 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_PUBLIC_APPLICATION_APPLICATION_RUNNER_H_
-#define MOJO_PUBLIC_APPLICATION_APPLICATION_RUNNER_H_
-
-#include "mojo/public/cpp/system/core.h"
-
-namespace mojo {
-
-class ApplicationDelegate;
-
-// A utility for running an Application. The typical use case is to use
-// when writing your MojoMain:
-//
-// MojoResult MojoMain(MojoHandle shell_handle) {
-// mojo::ApplicationRunner runner(new MyApplicationDelegate());
-// return runner.Run(shell_handle);
-// }
-//
-// ApplicationRunner takes care of mojo environment initialization and
-// shutdown, and starting a RunLoop from which your application can run and
-// ultimately Quit().
-class ApplicationRunner {
- public:
- // Takes ownership of |delegate|.
- explicit ApplicationRunner(ApplicationDelegate* delegate);
- ~ApplicationRunner();
-
- // Once the various parameters have been set above, use Run to initialize an
- // ApplicationImpl wired to the provided delegate, and run a RunLoop until
- // the application exits.
- MojoResult Run(MojoHandle shell_handle);
-
- private:
- ApplicationDelegate* delegate_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationRunner);
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_RUNNER_H_
diff --git a/mojo/public/cpp/application/application_test_base.h b/mojo/public/cpp/application/application_test_base.h
deleted file mode 100644
index bdf2f8b..0000000
--- a/mojo/public/cpp/application/application_test_base.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_APPLICATION_TEST_BASE_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_TEST_BASE_H_
-
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/bindings/array.h"
-#include "mojo/public/cpp/bindings/string.h"
-#include "mojo/public/cpp/system/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-
-class ApplicationImpl;
-
-namespace test {
-
-// Access the command line arguments passed to the application test.
-const Array<String>& Args();
-
-// Run all application tests. This must be called after the environment is
-// initialized, to support construction of a default run loop.
-MojoResult RunAllTests(MojoHandle shell_handle);
-
-// A GTEST base class for application testing executed in mojo_shell.
-class ApplicationTestBase : public testing::Test {
- public:
- ApplicationTestBase();
- ~ApplicationTestBase() override;
-
- protected:
- ApplicationImpl* application_impl() { return application_impl_; }
-
- // Get the ApplicationDelegate for the application to be tested.
- virtual ApplicationDelegate* GetApplicationDelegate();
-
- // A testing::Test::SetUp helper to override the application command
- // line arguments.
- void SetUpWithArgs(const Array<String>& args);
-
- // testing::Test:
- void SetUp() override;
- void TearDown() override;
-
- // True by default, which indicates a MessageLoop will automatically be
- // created for the application. Tests may override this function to prevent
- // a default loop from being created.
- virtual bool ShouldCreateDefaultRunLoop();
-
- private:
- // The application implementation instance, reconstructed for each test.
- ApplicationImpl* application_impl_;
- // The application delegate used if GetApplicationDelegate is not overridden.
- ApplicationDelegate default_application_delegate_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase);
-};
-
-} // namespace test
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_TEST_BASE_H_
diff --git a/mojo/public/cpp/application/connect.h b/mojo/public/cpp/application/connect.h
deleted file mode 100644
index a41c028..0000000
--- a/mojo/public/cpp/application/connect.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_CONNECT_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_
-
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-
-template <typename Interface>
-inline void ConnectToService(ServiceProvider* service_provider,
- InterfacePtr<Interface>* ptr) {
- MessagePipe pipe;
- ptr->Bind(pipe.handle0.Pass());
- service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass());
-}
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_
diff --git a/mojo/public/cpp/application/interface_factory.h b/mojo/public/cpp/application/interface_factory.h
deleted file mode 100644
index 8840fcb..0000000
--- a/mojo/public/cpp/application/interface_factory.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_INTERFACE_FACTORY_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_INTERFACE_FACTORY_H_
-
-#include "mojo/public/cpp/bindings/interface_impl.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-
-namespace mojo {
-
-class ApplicationConnection;
-template <typename Interface>
-class InterfaceRequest;
-
-// Implement this class to provide implementations of a given interface and
-// bind them to incoming requests. The implementation of this class is
-// responsible for managing the lifetime of the implementations of the
-// interface.
-template <typename Interface>
-class InterfaceFactory {
- public:
- virtual ~InterfaceFactory() {}
- virtual void Create(ApplicationConnection* connection,
- InterfaceRequest<Interface> request) = 0;
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_INTERFACE_FACTORY_H_
diff --git a/mojo/public/cpp/application/interface_factory_impl.h b/mojo/public/cpp/application/interface_factory_impl.h
deleted file mode 100644
index 72d3254..0000000
--- a/mojo/public/cpp/application/interface_factory_impl.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_INTERFACE_FACTORY_IMPL_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_INTERFACE_FACTORY_IMPL_H_
-
-#include "mojo/public/cpp/application/interface_factory.h"
-
-namespace mojo {
-
-// Use this class to allocate and bind instances of Impl to interface requests.
-// The lifetime of the constructed Impl is bound to the pipe.
-template <typename Impl,
- typename Interface = typename Impl::ImplementedInterface>
-class InterfaceFactoryImpl : public InterfaceFactory<Interface> {
- public:
- virtual ~InterfaceFactoryImpl() {}
-
- virtual void Create(ApplicationConnection* connection,
- InterfaceRequest<Interface> request) override {
- BindToRequest(new Impl(), &request);
- }
-};
-
-// Use this class to allocate and bind instances of Impl constructed with a
-// context parameter to interface requests. The lifetime of the constructed
-// Impl is bound to the pipe.
-template <typename Impl,
- typename Context,
- typename Interface = typename Impl::ImplementedInterface>
-class InterfaceFactoryImplWithContext : public InterfaceFactory<Interface> {
- public:
- explicit InterfaceFactoryImplWithContext(Context* context)
- : context_(context) {}
- virtual ~InterfaceFactoryImplWithContext() {}
-
- virtual void Create(ApplicationConnection* connection,
- InterfaceRequest<Interface> request) override {
- BindToRequest(new Impl(context_), &request);
- }
-
- private:
- Context* context_;
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_INTERFACE_FACTORY_IMPL_H_
diff --git a/mojo/public/cpp/application/lazy_interface_ptr.h b/mojo/public/cpp/application/lazy_interface_ptr.h
deleted file mode 100644
index a9b57db..0000000
--- a/mojo/public/cpp/application/lazy_interface_ptr.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
-
-#include "mojo/public/cpp/application/connect.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-
-template <typename Interface>
-class LazyInterfacePtr : public InterfacePtr<Interface> {
- public:
- LazyInterfacePtr() : service_provider_(nullptr) {}
-
- LazyInterfacePtr(ServiceProvider* service_provider)
- : service_provider_(service_provider) {}
-
- void set_service_provider(ServiceProvider* service_provider) {
- if (service_provider != service_provider_) {
- InterfacePtr<Interface>::reset();
- }
- service_provider_ = service_provider;
- }
-
- Interface* get() const {
- if (!InterfacePtr<Interface>::get() && service_provider_) {
- mojo::ConnectToService<Interface>(
- service_provider_, const_cast<LazyInterfacePtr<Interface>*>(this));
- }
- return InterfacePtr<Interface>::get();
- }
- Interface* operator->() const { return get(); }
- Interface& operator*() const { return *get(); }
-
- private:
- ServiceProvider* service_provider_;
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_LAZY_INTERFACE_PTR_H_
diff --git a/mojo/public/cpp/application/lib/DEPS b/mojo/public/cpp/application/lib/DEPS
deleted file mode 100644
index a04ed0f..0000000
--- a/mojo/public/cpp/application/lib/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+mojo/public/cpp/utility",
-]
diff --git a/mojo/public/cpp/application/lib/application_connection.cc b/mojo/public/cpp/application/lib/application_connection.cc
deleted file mode 100644
index d557817..0000000
--- a/mojo/public/cpp/application/lib/application_connection.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2014 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/public/cpp/application/application_connection.h"
-
-namespace mojo {
-
-ApplicationConnection::~ApplicationConnection() {
-}
-
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/application_delegate.cc b/mojo/public/cpp/application/lib/application_delegate.cc
deleted file mode 100644
index bd6aebd..0000000
--- a/mojo/public/cpp/application/lib/application_delegate.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2014 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/public/cpp/application/application_delegate.h"
-
-namespace mojo {
-
-ApplicationDelegate::ApplicationDelegate() {
-}
-ApplicationDelegate::~ApplicationDelegate() {
-}
-
-void ApplicationDelegate::Initialize(ApplicationImpl* app) {
-}
-
-bool ApplicationDelegate::ConfigureIncomingConnection(
- ApplicationConnection* connection) {
- return true;
-}
-
-bool ApplicationDelegate::ConfigureOutgoingConnection(
- ApplicationConnection* connection) {
- return true;
-}
-
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/application_impl.cc b/mojo/public/cpp/application/lib/application_impl.cc
deleted file mode 100644
index 6677003..0000000
--- a/mojo/public/cpp/application/lib/application_impl.cc
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2014 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/public/cpp/application/application_impl.h"
-
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/lib/service_registry.h"
-#include "mojo/public/cpp/bindings/interface_ptr.h"
-#include "mojo/public/cpp/environment/logging.h"
-
-namespace mojo {
-
-class ApplicationImpl::ShellPtrWatcher : public ErrorHandler {
- public:
- ShellPtrWatcher(ApplicationImpl* impl) : impl_(impl) {}
-
- ~ShellPtrWatcher() override {}
-
- void OnConnectionError() override { impl_->OnShellError(); }
-
- private:
- ApplicationImpl* impl_;
- MOJO_DISALLOW_COPY_AND_ASSIGN(ShellPtrWatcher);
-};
-
-ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate,
- ScopedMessagePipeHandle shell_handle)
- : initialized_(false), delegate_(delegate), shell_watch_(nullptr) {
- BindShell(shell_handle.Pass());
-}
-
-ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate,
- MojoHandle shell_handle)
- : initialized_(false), delegate_(delegate), shell_watch_(nullptr) {
- BindShell(MakeScopedHandle(MessagePipeHandle(shell_handle)));
-}
-
-bool ApplicationImpl::HasArg(const std::string& arg) const {
- return std::find(args_.begin(), args_.end(), arg) != args_.end();
-}
-
-void ApplicationImpl::ClearConnections() {
- for (ServiceRegistryList::iterator i(incoming_service_registries_.begin());
- i != incoming_service_registries_.end();
- ++i)
- delete *i;
- for (ServiceRegistryList::iterator i(outgoing_service_registries_.begin());
- i != outgoing_service_registries_.end();
- ++i)
- delete *i;
- incoming_service_registries_.clear();
- outgoing_service_registries_.clear();
-}
-
-ApplicationImpl::~ApplicationImpl() {
- ClearConnections();
- delete shell_watch_;
-}
-
-ApplicationConnection* ApplicationImpl::ConnectToApplication(
- const String& application_url) {
- MOJO_CHECK(initialized_);
- ServiceProviderPtr local_services;
- InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services);
- ServiceProviderPtr remote_services;
- shell_->ConnectToApplication(application_url, GetProxy(&remote_services),
- local_services.Pass());
- internal::ServiceRegistry* registry = new internal::ServiceRegistry(
- this, application_url, remote_services.Pass(), local_request.Pass());
- if (!delegate_->ConfigureOutgoingConnection(registry)) {
- delete registry;
- return nullptr;
- }
- outgoing_service_registries_.push_back(registry);
- return registry;
-}
-
-bool ApplicationImpl::WaitForInitialize() {
- MOJO_CHECK(!initialized_);
- bool result = shell_.WaitForIncomingMethodCall();
- MOJO_CHECK(initialized_ || !result);
- return result;
-}
-
-ScopedMessagePipeHandle ApplicationImpl::UnbindShell() {
- return shell_.PassMessagePipe();
-}
-
-void ApplicationImpl::Initialize(Array<String> args) {
- MOJO_CHECK(!initialized_);
- initialized_ = true;
- args_ = args.To<std::vector<std::string>>();
- delegate_->Initialize(this);
-}
-
-void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) {
- shell_watch_ = new ShellPtrWatcher(this);
- shell_.Bind(shell_handle.Pass());
- shell_.set_client(this);
- shell_.set_error_handler(shell_watch_);
-}
-
-void ApplicationImpl::AcceptConnection(
- const String& requestor_url,
- InterfaceRequest<ServiceProvider> services,
- ServiceProviderPtr exposed_services) {
- internal::ServiceRegistry* registry = new internal::ServiceRegistry(
- this, requestor_url, exposed_services.Pass(), services.Pass());
- if (!delegate_->ConfigureIncomingConnection(registry)) {
- delete registry;
- return;
- }
- incoming_service_registries_.push_back(registry);
-}
-
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/application_runner.cc b/mojo/public/cpp/application/lib/application_runner.cc
deleted file mode 100644
index dec74489..0000000
--- a/mojo/public/cpp/application/lib/application_runner.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 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/public/cpp/application/application_runner.h"
-
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/environment/environment.h"
-#include "mojo/public/cpp/utility/run_loop.h"
-
-namespace mojo {
-
-// static
-void ApplicationImpl::Terminate() {
- RunLoop::current()->Quit();
-}
-
-ApplicationRunner::ApplicationRunner(ApplicationDelegate* delegate)
- : delegate_(delegate) {
-}
-ApplicationRunner::~ApplicationRunner() {
- assert(!delegate_);
-}
-
-MojoResult ApplicationRunner::Run(MojoHandle shell_handle) {
- Environment env;
- {
- RunLoop loop;
- ApplicationImpl app(delegate_, shell_handle);
- loop.Run();
- }
-
- delete delegate_;
- delegate_ = nullptr;
- return MOJO_RESULT_OK;
-}
-
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/application_test_base.cc b/mojo/public/cpp/application/lib/application_test_base.cc
deleted file mode 100644
index 20a60a1..0000000
--- a/mojo/public/cpp/application/lib/application_test_base.cc
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2014 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/public/cpp/application/application_test_base.h"
-
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/environment/environment.h"
-#include "mojo/public/cpp/system/message_pipe.h"
-
-namespace mojo {
-namespace test {
-
-namespace {
-
-// This shell handle is shared by multiple test application instances.
-MessagePipeHandle g_shell_handle;
-// Share the application command-line arguments with multiple application tests.
-Array<String> g_args;
-
-ScopedMessagePipeHandle PassShellHandle() {
- MOJO_CHECK(g_shell_handle.is_valid());
- ScopedMessagePipeHandle scoped_handle(g_shell_handle);
- g_shell_handle = MessagePipeHandle();
- return scoped_handle.Pass();
-}
-
-void SetShellHandle(ScopedMessagePipeHandle handle) {
- MOJO_CHECK(handle.is_valid());
- MOJO_CHECK(!g_shell_handle.is_valid());
- g_shell_handle = handle.release();
-}
-
-void InitializeArgs(int argc, std::vector<const char*> argv) {
- MOJO_CHECK(g_args.is_null());
- for (const char* arg : argv) {
- if (arg)
- g_args.push_back(arg);
- }
-}
-
-} // namespace
-
-const Array<String>& Args() {
- return g_args;
-}
-
-MojoResult RunAllTests(MojoHandle shell_handle) {
- {
- // This loop is used for init, and then destroyed before running tests.
- Environment::InstantiateDefaultRunLoop();
-
- // Construct an ApplicationImpl just for the GTEST commandline arguments.
- // GTEST command line arguments are supported amid application arguments:
- // $ mojo_shell mojo:example_apptests
- // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2'
- mojo::ApplicationDelegate dummy_application_delegate;
- mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
- MOJO_CHECK(app.WaitForInitialize());
-
- // InitGoogleTest expects (argc + 1) elements, including a terminating null.
- // It also removes GTEST arguments from |argv| and updates the |argc| count.
- const std::vector<std::string>& args = app.args();
- MOJO_CHECK(args.size() <
- static_cast<size_t>(std::numeric_limits<int>::max()));
- int argc = static_cast<int>(args.size());
- std::vector<const char*> argv(argc + 1);
- for (int i = 0; i < argc; ++i)
- argv[i] = args[i].c_str();
- argv[argc] = nullptr;
-
- testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
- SetShellHandle(app.UnbindShell());
- InitializeArgs(argc, argv);
-
- Environment::DestroyDefaultRunLoop();
- }
-
- int result = RUN_ALL_TESTS();
-
- shell_handle = mojo::test::PassShellHandle().release().value();
- MojoResult close_result = MojoClose(shell_handle);
- MOJO_CHECK(close_result == MOJO_RESULT_OK);
-
- return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
-}
-
-ApplicationTestBase::ApplicationTestBase() : application_impl_(nullptr) {
-}
-
-ApplicationTestBase::~ApplicationTestBase() {
-}
-
-ApplicationDelegate* ApplicationTestBase::GetApplicationDelegate() {
- return &default_application_delegate_;
-}
-
-void ApplicationTestBase::SetUpWithArgs(const Array<String>& args) {
- // A run loop is recommended for ApplicationImpl initialization and
- // communication.
- if (ShouldCreateDefaultRunLoop())
- Environment::InstantiateDefaultRunLoop();
-
- // New applications are constructed for each test to avoid persisting state.
- application_impl_ = new ApplicationImpl(GetApplicationDelegate(),
- PassShellHandle());
-
- // Fake application initialization with the given command line arguments.
- application_impl_->Initialize(args.Clone());
-}
-
-void ApplicationTestBase::SetUp() {
- SetUpWithArgs(Args());
-}
-
-void ApplicationTestBase::TearDown() {
- SetShellHandle(application_impl_->UnbindShell());
- delete application_impl_;
- if (ShouldCreateDefaultRunLoop())
- Environment::DestroyDefaultRunLoop();
-}
-
-bool ApplicationTestBase::ShouldCreateDefaultRunLoop() {
- return true;
-}
-
-} // namespace test
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/application_test_main.cc b/mojo/public/cpp/application/lib/application_test_main.cc
deleted file mode 100644
index 47f36e9..0000000
--- a/mojo/public/cpp/application/lib/application_test_main.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2014 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/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_test_base.h"
-#include "mojo/public/cpp/environment/environment.h"
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- // An Environment instance is needed to construct run loops.
- mojo::Environment environment;
-
- return mojo::test::RunAllTests(shell_handle);
-}
diff --git a/mojo/public/cpp/application/lib/service_connector.cc b/mojo/public/cpp/application/lib/service_connector.cc
deleted file mode 100644
index ada5d9c..0000000
--- a/mojo/public/cpp/application/lib/service_connector.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2014 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/public/cpp/application/lib/service_connector.h"
-
-namespace mojo {
-namespace internal {
-
-ServiceConnectorBase::ServiceConnectorBase(const std::string& name)
- : name_(name), application_connection_(nullptr) {
-}
-
-ServiceConnectorBase::~ServiceConnectorBase() {
-}
-
-} // namespace internal
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/service_connector.h b/mojo/public/cpp/application/lib/service_connector.h
deleted file mode 100644
index 70c1380..0000000
--- a/mojo/public/cpp/application/lib/service_connector.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
-
-#include "mojo/public/cpp/application/interface_factory.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-
-namespace mojo {
-class ApplicationConnection;
-
-namespace internal {
-
-class ServiceConnectorBase {
- public:
- ServiceConnectorBase(const std::string& name);
- virtual ~ServiceConnectorBase();
- virtual void ConnectToService(const std::string& name,
- ScopedMessagePipeHandle client_handle) = 0;
- std::string name() const { return name_; }
- void set_application_connection(ApplicationConnection* connection) {
- application_connection_ = connection;
- }
-
- protected:
- std::string name_;
- ApplicationConnection* application_connection_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorBase);
-};
-
-template <typename Interface>
-class InterfaceFactoryConnector : public ServiceConnectorBase {
- public:
- explicit InterfaceFactoryConnector(InterfaceFactory<Interface>* factory)
- : ServiceConnectorBase(Interface::Name_), factory_(factory) {}
- virtual ~InterfaceFactoryConnector() {}
-
- virtual void ConnectToService(const std::string& name,
- ScopedMessagePipeHandle client_handle) {
- factory_->Create(application_connection_,
- MakeRequest<Interface>(client_handle.Pass()));
- }
-
- private:
- InterfaceFactory<Interface>* factory_;
- MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceFactoryConnector);
-};
-
-} // namespace internal
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
diff --git a/mojo/public/cpp/application/lib/service_provider_impl.cc b/mojo/public/cpp/application/lib/service_provider_impl.cc
deleted file mode 100644
index 08a0648..0000000
--- a/mojo/public/cpp/application/lib/service_provider_impl.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2014 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/public/cpp/application/service_provider_impl.h"
-
-#include "mojo/public/cpp/application/lib/service_connector.h"
-#include "mojo/public/cpp/application/lib/weak_service_provider.h"
-#include "mojo/public/cpp/environment/logging.h"
-
-namespace mojo {
-
-ServiceProviderImpl::ServiceProviderImpl() : remote_(nullptr) {
-}
-
-ServiceProviderImpl::~ServiceProviderImpl() {
-}
-
-ServiceProvider* ServiceProviderImpl::CreateRemoteServiceProvider() {
- // TODO(beng): it sure would be nice if this method could return a scoped_ptr.
- MOJO_DCHECK(!remote_);
- remote_ = new internal::WeakServiceProvider(this, client());
- return remote_;
-}
-
-void ServiceProviderImpl::ConnectToService(
- const String& service_name,
- ScopedMessagePipeHandle client_handle) {
- if (service_connectors_.find(service_name) == service_connectors_.end()) {
- client_handle.reset();
- return;
- }
-
- internal::ServiceConnectorBase* service_connector =
- service_connectors_[service_name];
- return service_connector->ConnectToService(service_name,
- client_handle.Pass());
-}
-
-void ServiceProviderImpl::OnConnectionError() {
- ClearRemote();
-}
-
-void ServiceProviderImpl::AddServiceConnector(
- internal::ServiceConnectorBase* service_connector) {
- RemoveServiceConnector(service_connector);
- service_connectors_[service_connector->name()] = service_connector;
- // TODO(beng): perhaps take app connection thru ctor??
- service_connector->set_application_connection(nullptr);
-}
-
-void ServiceProviderImpl::RemoveServiceConnector(
- internal::ServiceConnectorBase* service_connector) {
- NameToServiceConnectorMap::iterator it =
- service_connectors_.find(service_connector->name());
- if (it == service_connectors_.end())
- return;
- delete it->second;
- service_connectors_.erase(it);
-}
-
-void ServiceProviderImpl::ClearRemote() {
- if (remote_) {
- remote_->Clear();
- remote_ = nullptr;
- }
-}
-
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/service_registry.cc b/mojo/public/cpp/application/lib/service_registry.cc
deleted file mode 100644
index d934a16..0000000
--- a/mojo/public/cpp/application/lib/service_registry.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2014 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/public/cpp/application/lib/service_registry.h"
-
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/lib/service_connector.h"
-
-namespace mojo {
-namespace internal {
-
-ServiceRegistry::ServiceRegistry(
- ApplicationImpl* application_impl,
- const std::string& url,
- ServiceProviderPtr remote_services,
- InterfaceRequest<ServiceProvider> local_services)
- : application_impl_(application_impl),
- url_(url),
- local_binding_(this, local_services.Pass()),
- remote_service_provider_(remote_services.Pass()) {
-}
-
-ServiceRegistry::ServiceRegistry()
- : application_impl_(nullptr), local_binding_(this) {
-}
-
-ServiceRegistry::~ServiceRegistry() {
- for (NameToServiceConnectorMap::iterator i =
- name_to_service_connector_.begin();
- i != name_to_service_connector_.end();
- ++i) {
- delete i->second;
- }
- name_to_service_connector_.clear();
-}
-
-void ServiceRegistry::AddServiceConnector(
- ServiceConnectorBase* service_connector) {
- RemoveServiceConnectorInternal(service_connector);
- name_to_service_connector_[service_connector->name()] = service_connector;
- service_connector->set_application_connection(this);
-}
-
-void ServiceRegistry::RemoveServiceConnector(
- ServiceConnectorBase* service_connector) {
- RemoveServiceConnectorInternal(service_connector);
- if (name_to_service_connector_.empty())
- remote_service_provider_.reset();
-}
-
-bool ServiceRegistry::RemoveServiceConnectorInternal(
- ServiceConnectorBase* service_connector) {
- NameToServiceConnectorMap::iterator it =
- name_to_service_connector_.find(service_connector->name());
- if (it == name_to_service_connector_.end())
- return false;
- delete it->second;
- name_to_service_connector_.erase(it);
- return true;
-}
-
-const std::string& ServiceRegistry::GetRemoteApplicationURL() {
- return url_;
-}
-
-ServiceProvider* ServiceRegistry::GetServiceProvider() {
- return remote_service_provider_.get();
-}
-
-ApplicationConnection* ServiceRegistry::ConnectToApplication(
- const std::string& url) {
- return application_impl_->ConnectToApplication(url);
-}
-
-void ServiceRegistry::ConnectToService(const mojo::String& service_name,
- ScopedMessagePipeHandle client_handle) {
- if (name_to_service_connector_.find(service_name) ==
- name_to_service_connector_.end()) {
- client_handle.reset();
- return;
- }
- internal::ServiceConnectorBase* service_connector =
- name_to_service_connector_[service_name];
- return service_connector->ConnectToService(service_name,
- client_handle.Pass());
-}
-
-} // namespace internal
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/service_registry.h b/mojo/public/cpp/application/lib/service_registry.h
deleted file mode 100644
index af1613b..0000000
--- a/mojo/public/cpp/application/lib/service_registry.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2014 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_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
-#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
-
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-
-class Application;
-class ApplicationImpl;
-
-namespace internal {
-
-class ServiceConnectorBase;
-
-// A ServiceRegistry represents each half of a connection between two
-// applications, allowing customization of which services are published to the
-// other.
-class ServiceRegistry : public ServiceProvider, public ApplicationConnection {
- public:
- ServiceRegistry();
- ServiceRegistry(ApplicationImpl* application_impl,
- const std::string& url,
- ServiceProviderPtr remote_services,
- InterfaceRequest<ServiceProvider> local_services);
- ~ServiceRegistry() override;
-
- // ApplicationConnection overrides.
- void AddServiceConnector(ServiceConnectorBase* service_connector) override;
- const std::string& GetRemoteApplicationURL() override;
- ApplicationConnection* ConnectToApplication(const std::string& url) override;
- ServiceProvider* GetServiceProvider() override;
-
- virtual void RemoveServiceConnector(ServiceConnectorBase* service_connector);
-
- private:
- // ServiceProvider method.
- void ConnectToService(const mojo::String& service_name,
- ScopedMessagePipeHandle client_handle) override;
-
- ApplicationImpl* application_impl_;
- const std::string url_;
-
- private:
- bool RemoveServiceConnectorInternal(ServiceConnectorBase* service_connector);
-
- Application* application_;
- typedef std::map<std::string, ServiceConnectorBase*>
- NameToServiceConnectorMap;
- NameToServiceConnectorMap name_to_service_connector_;
- Binding<ServiceProvider> local_binding_;
- ServiceProviderPtr remote_service_provider_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceRegistry);
-};
-
-} // namespace internal
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
diff --git a/mojo/public/cpp/application/lib/weak_service_provider.cc b/mojo/public/cpp/application/lib/weak_service_provider.cc
deleted file mode 100644
index de0cb6c..0000000
--- a/mojo/public/cpp/application/lib/weak_service_provider.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 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/public/cpp/application/lib/weak_service_provider.h"
-
-#include "mojo/public/cpp/application/service_provider_impl.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-namespace internal {
-
-WeakServiceProvider::WeakServiceProvider(ServiceProviderImpl* creator,
- ServiceProvider* service_provider)
- : creator_(creator), service_provider_(service_provider) {
-}
-
-WeakServiceProvider::~WeakServiceProvider() {
- if (creator_)
- creator_->ClearRemote();
-}
-
-void WeakServiceProvider::Clear() {
- creator_ = nullptr;
- service_provider_ = nullptr;
-}
-
-void WeakServiceProvider::ConnectToService(
- const String& service_name,
- ScopedMessagePipeHandle client_handle) {
- if (service_provider_)
- service_provider_->ConnectToService(service_name, client_handle.Pass());
-}
-
-} // namespace internal
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/weak_service_provider.h b/mojo/public/cpp/application/lib/weak_service_provider.h
deleted file mode 100644
index 3d959d1..0000000
--- a/mojo/public/cpp/application/lib/weak_service_provider.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2014 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_PUBLIC_APPLICATION_LIB_WEAK_SERVICE_PROVIDER_H_
-#define MOJO_PUBLIC_APPLICATION_LIB_WEAK_SERVICE_PROVIDER_H_
-
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-class ServiceProviderImpl;
-namespace internal {
-class ServiceConnectorBase;
-
-// Implements a weak pointer to a ServiceProvider. Necessary as the lifetime of
-// the ServiceProviderImpl is bound to that of its pipe, but code may continue
-// to reference a remote service provider beyond the lifetime of said pipe.
-// Calls to ConnectToService() are silently dropped when the pipe is closed.
-class WeakServiceProvider : public ServiceProvider {
- public:
- WeakServiceProvider(ServiceProviderImpl* creator,
- ServiceProvider* service_provider);
- ~WeakServiceProvider() override;
-
- void Clear();
-
- private:
- // Overridden from ServiceProvider:
- void ConnectToService(const String& service_name,
- ScopedMessagePipeHandle client_handle) override;
-
- ServiceProviderImpl* creator_;
- ServiceProvider* service_provider_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(WeakServiceProvider);
-};
-
-} // namespace internal
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_LIB_WEAK_SERVICE_PROVIDER_H_
diff --git a/mojo/public/cpp/application/service_provider_impl.h b/mojo/public/cpp/application/service_provider_impl.h
deleted file mode 100644
index 45ad7b8..0000000
--- a/mojo/public/cpp/application/service_provider_impl.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2014 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_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_
-#define MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_
-
-#include "mojo/public/cpp/application/lib/service_connector.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-namespace internal {
-class WeakServiceProvider;
-class ServiceConnectorBase;
-}
-
-// Implements a registry that can be used to expose services to another app.
-class ServiceProviderImpl : public InterfaceImpl<ServiceProvider> {
- public:
- ServiceProviderImpl();
- ~ServiceProviderImpl() override;
-
- template <typename Interface>
- void AddService(InterfaceFactory<Interface>* factory) {
- AddServiceConnector(
- new internal::InterfaceFactoryConnector<Interface>(factory));
- }
-
- // Returns an instance of a ServiceProvider that weakly wraps this impl's
- // connection to some other app. Whereas the lifetime of an instance of
- // ServiceProviderImpl is bound to the lifetime of the pipe it
- // encapsulates, the lifetime of the ServiceProvider instance returned by this
- // method is assumed by the caller. After the pipe is closed
- // ConnectToService() calls on this object will be silently dropped.
- // This method must only be called once per ServiceProviderImpl.
- ServiceProvider* CreateRemoteServiceProvider();
-
- private:
- typedef std::map<std::string, internal::ServiceConnectorBase*>
- NameToServiceConnectorMap;
-
- friend class internal::WeakServiceProvider;
-
- // Overridden from ServiceProvider:
- void ConnectToService(const String& service_name,
- ScopedMessagePipeHandle client_handle) override;
-
- // Overridden from InterfaceImpl:
- void OnConnectionError() override;
-
- void AddServiceConnector(internal::ServiceConnectorBase* service_connector);
- void RemoveServiceConnector(
- internal::ServiceConnectorBase* service_connector);
-
- void ClearRemote();
-
- NameToServiceConnectorMap service_connectors_;
-
- internal::WeakServiceProvider* remote_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl);
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_
diff --git a/mojo/public/cpp/application/tests/BUILD.gn b/mojo/public/cpp/application/tests/BUILD.gn
deleted file mode 100644
index 7766a7d..0000000
--- a/mojo/public/cpp/application/tests/BUILD.gn
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright 2014 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.
-
-import("../../../mojo_sdk.gni")
-
-mojo_sdk_source_set("tests") {
- testonly = true
-
- sources = [
- "service_registry_unittest.cc",
- ]
-
- deps = [
- "//testing/gtest",
- ]
-
- mojo_sdk_deps = [
- "mojo/public/cpp/application:standalone",
- "mojo/public/cpp/environment:standalone",
- "mojo/public/cpp/utility",
- ]
-}
diff --git a/mojo/public/cpp/application/tests/service_registry_unittest.cc b/mojo/public/cpp/application/tests/service_registry_unittest.cc
deleted file mode 100644
index 283bf14..0000000
--- a/mojo/public/cpp/application/tests/service_registry_unittest.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2014 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/public/cpp/application/lib/service_registry.h"
-
-#include "mojo/public/cpp/application/lib/service_connector.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace internal {
-namespace {
-
-class TestConnector : public ServiceConnectorBase {
- public:
- TestConnector(const std::string& name, int* delete_count)
- : ServiceConnectorBase(name), delete_count_(delete_count) {}
- ~TestConnector() override { (*delete_count_)++; }
- void ConnectToService(const std::string& name,
- ScopedMessagePipeHandle client_handle) override {}
-
- private:
- int* delete_count_;
-};
-
-TEST(ServiceRegistryTest, Ownership) {
- int delete_count = 0;
-
- // Destruction.
- {
- ServiceRegistry registry;
- registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
- }
- EXPECT_EQ(1, delete_count);
-
- // Removal.
- {
- ServiceRegistry registry;
- ServiceConnectorBase* c = new TestConnector("TC1", &delete_count);
- registry.AddServiceConnector(c);
- registry.RemoveServiceConnector(c);
- EXPECT_EQ(2, delete_count);
- }
-
- // Multiple.
- {
- ServiceRegistry registry;
- registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
- registry.AddServiceConnector(new TestConnector("TC2", &delete_count));
- }
- EXPECT_EQ(4, delete_count);
-
- // Re-addition.
- {
- ServiceRegistry registry;
- registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
- registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
- EXPECT_EQ(5, delete_count);
- }
- EXPECT_EQ(6, delete_count);
-}
-
-} // namespace
-} // namespace internal
-} // namespace mojo