summaryrefslogtreecommitdiffstats
path: root/mojo/public/cpp/application/lib
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/public/cpp/application/lib')
-rw-r--r--mojo/public/cpp/application/lib/application.cc34
-rw-r--r--mojo/public/cpp/application/lib/application_connection.cc12
-rw-r--r--mojo/public/cpp/application/lib/application_delegate.cc24
-rw-r--r--mojo/public/cpp/application/lib/application_impl.cc74
-rw-r--r--mojo/public/cpp/application/lib/mojo_main_chromium.cc14
-rw-r--r--mojo/public/cpp/application/lib/mojo_main_standalone.cc19
-rw-r--r--mojo/public/cpp/application/lib/service_connector.cc2
-rw-r--r--mojo/public/cpp/application/lib/service_connector.h36
-rw-r--r--mojo/public/cpp/application/lib/service_registry.cc54
-rw-r--r--mojo/public/cpp/application/lib/service_registry.h44
10 files changed, 201 insertions, 112 deletions
diff --git a/mojo/public/cpp/application/lib/application.cc b/mojo/public/cpp/application/lib/application.cc
deleted file mode 100644
index 78f5a8b..0000000
--- a/mojo/public/cpp/application/lib/application.cc
+++ /dev/null
@@ -1,34 +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.h"
-
-namespace mojo {
-
-Application::Application() : service_registry_(this) {}
-
-Application::Application(ScopedMessagePipeHandle service_provider_handle)
- : service_registry_(this, service_provider_handle.Pass()) {}
-
-Application::Application(MojoHandle service_provider_handle)
- : service_registry_(
- this,
- mojo::MakeScopedHandle(
- MessagePipeHandle(service_provider_handle)).Pass()) {}
-
-Application::~Application() {}
-
-bool Application::AllowIncomingConnection(const mojo::String& service_name,
- const mojo::String& requestor_url) {
- return true;
-}
-
-void Application::BindServiceProvider(
- ScopedMessagePipeHandle service_provider_handle) {
- service_registry_.BindRemoteServiceProvider(service_provider_handle.Pass());
-}
-
-void Application::Initialize() {}
-
-} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/application_connection.cc b/mojo/public/cpp/application/lib/application_connection.cc
new file mode 100644
index 0000000..4978a35
--- /dev/null
+++ b/mojo/public/cpp/application/lib/application_connection.cc
@@ -0,0 +1,12 @@
+// 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
new file mode 100644
index 0000000..715daa0
--- /dev/null
+++ b/mojo/public/cpp/application/lib/application_delegate.cc
@@ -0,0 +1,24 @@
+// 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
new file mode 100644
index 0000000..f5831aa
--- /dev/null
+++ b/mojo/public/cpp/application/lib/application_impl.cc
@@ -0,0 +1,74 @@
+// 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"
+
+namespace mojo {
+
+ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate)
+ : delegate_(delegate) {}
+
+ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate,
+ ScopedMessagePipeHandle shell_handle)
+ : delegate_(delegate) {
+ BindShell(shell_handle.Pass());
+}
+
+ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate,
+ MojoHandle shell_handle)
+ : delegate_(delegate) {
+ BindShell(shell_handle);
+}
+
+ApplicationImpl::~ApplicationImpl() {
+ 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;
+}
+
+ApplicationConnection* ApplicationImpl::ConnectToApplication(
+ const String& application_url) {
+ ServiceProviderPtr out_service_provider;
+ shell_->ConnectToApplication(application_url, Get(&out_service_provider));
+ internal::ServiceRegistry* registry = new internal::ServiceRegistry(
+ this,
+ application_url,
+ out_service_provider.Pass());
+ if (!delegate_->ConfigureOutgoingConnection(registry)) {
+ delete registry;
+ return NULL;
+ }
+ outgoing_service_registries_.push_back(registry);
+ return registry;
+}
+
+void ApplicationImpl::BindShell(ScopedMessagePipeHandle shell_handle) {
+ shell_.Bind(shell_handle.Pass());
+ shell_.set_client(this);
+ delegate_->Initialize(this);
+}
+
+void ApplicationImpl::BindShell(MojoHandle shell_handle) {
+ BindShell(mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)));
+}
+
+void ApplicationImpl::AcceptConnection(const String& requestor_url,
+ ServiceProviderPtr service_provider) {
+ internal::ServiceRegistry* registry = new internal::ServiceRegistry(
+ this, requestor_url, service_provider.Pass());
+ if (!delegate_->ConfigureIncomingConnection(registry)) {
+ delete registry;
+ return;
+ }
+ incoming_service_registries_.push_back(registry);
+}
+
+} // namespace mojo
diff --git a/mojo/public/cpp/application/lib/mojo_main_chromium.cc b/mojo/public/cpp/application/lib/mojo_main_chromium.cc
index cda7cd0..6eb0c63 100644
--- a/mojo/public/cpp/application/lib/mojo_main_chromium.cc
+++ b/mojo/public/cpp/application/lib/mojo_main_chromium.cc
@@ -5,18 +5,18 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_impl.h"
extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
+ MojoHandle shell_handle) {
base::CommandLine::Init(0, NULL);
base::AtExitManager at_exit;
base::MessageLoop loop;
-
- scoped_ptr<mojo::Application> app(mojo::Application::Create());
- app->BindServiceProvider(
- mojo::MakeScopedHandle(mojo::MessagePipeHandle(service_provider_handle)));
- app->Initialize();
+ scoped_ptr<mojo::ApplicationDelegate> delegate(
+ mojo::ApplicationDelegate::Create());
+ mojo::ApplicationImpl app(delegate.get());
+ app.BindShell(shell_handle);
loop.Run();
return MOJO_RESULT_OK;
diff --git a/mojo/public/cpp/application/lib/mojo_main_standalone.cc b/mojo/public/cpp/application/lib/mojo_main_standalone.cc
index 05825aa..0ba078b 100644
--- a/mojo/public/cpp/application/lib/mojo_main_standalone.cc
+++ b/mojo/public/cpp/application/lib/mojo_main_standalone.cc
@@ -2,21 +2,22 @@
// 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.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"
extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
+ MojoHandle shell_handle) {
mojo::Environment env;
mojo::RunLoop loop;
-
- mojo::Application* app = mojo::Application::Create();
- app->BindServiceProvider(
- mojo::MakeScopedHandle(mojo::MessagePipeHandle(service_provider_handle)));
- app->Initialize();
- loop.Run();
- delete app;
+ mojo::ApplicationDelegate* delegate = mojo::ApplicationDelegate::Create();
+ {
+ mojo::ApplicationImpl app(delegate);
+ app.BindShell(shell_handle);
+ loop.Run();
+ }
+ delete delegate;
return MOJO_RESULT_OK;
}
diff --git a/mojo/public/cpp/application/lib/service_connector.cc b/mojo/public/cpp/application/lib/service_connector.cc
index 5cc4421..1a52b62 100644
--- a/mojo/public/cpp/application/lib/service_connector.cc
+++ b/mojo/public/cpp/application/lib/service_connector.cc
@@ -9,7 +9,7 @@ namespace internal {
ServiceConnectorBase::ServiceConnectorBase(const std::string& name)
: name_(name),
- registry_(NULL) {
+ application_connection_(NULL) {
}
ServiceConnectorBase::~ServiceConnectorBase() {}
diff --git a/mojo/public/cpp/application/lib/service_connector.h b/mojo/public/cpp/application/lib/service_connector.h
index 30786ad..d2de48b 100644
--- a/mojo/public/cpp/application/lib/service_connector.h
+++ b/mojo/public/cpp/application/lib/service_connector.h
@@ -9,10 +9,11 @@
#include <vector>
-#include "mojo/public/cpp/application/lib/service_registry.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
namespace mojo {
+class ApplicationConnection;
+
namespace internal {
template <class ServiceImpl, typename Context>
@@ -24,8 +25,10 @@ class ServiceConnector;
template <class ServiceImpl, typename Context>
class ServiceConnection : public ServiceImpl {
public:
- ServiceConnection() : ServiceImpl() {}
- ServiceConnection(Context* context) : ServiceImpl(context) {}
+ explicit ServiceConnection(ApplicationConnection* connection)
+ : ServiceImpl(connection) {}
+ ServiceConnection(ApplicationConnection* connection,
+ Context* context) : ServiceImpl(connection, context) {}
virtual void OnConnectionError() MOJO_OVERRIDE {
service_connector_->RemoveConnection(static_cast<ServiceImpl*>(this));
@@ -48,16 +51,21 @@ private:
template <typename ServiceImpl, typename Context>
struct ServiceConstructor {
- static ServiceConnection<ServiceImpl, Context>* New(Context* context) {
- return new ServiceConnection<ServiceImpl, Context>(context);
+ static ServiceConnection<ServiceImpl, Context>* New(
+ ApplicationConnection* connection,
+ Context* context) {
+ return new ServiceConnection<ServiceImpl, Context>(
+ connection, context);
}
};
template <typename ServiceImpl>
struct ServiceConstructor<ServiceImpl, void> {
public:
- static ServiceConnection<ServiceImpl, void>* New(void* context) {
- return new ServiceConnection<ServiceImpl, void>();
+ static ServiceConnection<ServiceImpl, void>* New(
+ ApplicationConnection* connection,
+ void* context) {
+ return new ServiceConnection<ServiceImpl, void>(connection);
}
};
@@ -65,15 +73,15 @@ class ServiceConnectorBase {
public:
ServiceConnectorBase(const std::string& name);
virtual ~ServiceConnectorBase();
- virtual void ConnectToService(const std::string& url,
- const std::string& name,
+ virtual void ConnectToService(const std::string& name,
ScopedMessagePipeHandle client_handle) = 0;
std::string name() const { return name_; }
- void set_registry(ServiceRegistry* registry) { registry_ = registry; }
+ void set_application_connection(ApplicationConnection* connection) {
+ application_connection_ = connection; }
protected:
std::string name_;
- ServiceRegistry* registry_;
+ ApplicationConnection* application_connection_;
MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorBase);
};
@@ -94,11 +102,11 @@ class ServiceConnector : public internal::ServiceConnectorBase {
assert(connections_.empty()); // No one should have added more!
}
- virtual void ConnectToService(const std::string& url,
- const std::string& name,
+ virtual void ConnectToService(const std::string& name,
ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
ServiceConnection<ServiceImpl, Context>* impl =
- ServiceConstructor<ServiceImpl, Context>::New(context_);
+ ServiceConstructor<ServiceImpl, Context>::New(application_connection_,
+ context_);
impl->set_service_connector(this);
BindToPipe(impl, handle.Pass());
diff --git a/mojo/public/cpp/application/lib/service_registry.cc b/mojo/public/cpp/application/lib/service_registry.cc
index 44b51ef..1bb061b 100644
--- a/mojo/public/cpp/application/lib/service_registry.cc
+++ b/mojo/public/cpp/application/lib/service_registry.cc
@@ -4,24 +4,24 @@
#include "mojo/public/cpp/application/lib/service_registry.h"
-#include "mojo/public/cpp/application/application.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(Application* application)
- : application_(application) {
-}
-
-ServiceRegistry::ServiceRegistry(
- Application* application,
- ScopedMessagePipeHandle service_provider_handle)
- : application_(application) {
- remote_service_provider_.Bind(service_provider_handle.Pass());
+ServiceRegistry::ServiceRegistry(ApplicationImpl* application_impl,
+ const std::string& url,
+ ServiceProviderPtr service_provider)
+ : application_impl_(application_impl),
+ url_(url),
+ remote_service_provider_(service_provider.Pass()) {
remote_service_provider_.set_client(this);
}
+ServiceRegistry::ServiceRegistry() : application_impl_(NULL) {}
+
ServiceRegistry::~ServiceRegistry() {
for (NameToServiceConnectorMap::iterator i =
name_to_service_connector_.begin();
@@ -35,7 +35,7 @@ void ServiceRegistry::AddServiceConnector(
ServiceConnectorBase* service_connector) {
RemoveServiceConnectorInternal(service_connector);
name_to_service_connector_[service_connector->name()] = service_connector;
- service_connector->set_registry(this);
+ service_connector->set_application_connection(this);
}
void ServiceRegistry::RemoveServiceConnector(
@@ -56,30 +56,30 @@ bool ServiceRegistry::RemoveServiceConnectorInternal(
return true;
}
-void ServiceRegistry::BindRemoteServiceProvider(
- ScopedMessagePipeHandle service_provider_handle) {
- remote_service_provider_.Bind(service_provider_handle.Pass());
- remote_service_provider_.set_client(this);
+const std::string& ServiceRegistry::GetRemoteApplicationURL() {
+ return url_;
}
-void ServiceRegistry::ConnectToService(const mojo::String& service_url,
- const mojo::String& service_name,
- ScopedMessagePipeHandle client_handle,
- const mojo::String& requestor_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() ||
- !application_->AllowIncomingConnection(service_name, requestor_url)) {
+ name_to_service_connector_.end()) {
client_handle.reset();
return;
}
-
internal::ServiceConnectorBase* service_connector =
name_to_service_connector_[service_name];
- assert(service_connector);
- // requestor_url is ignored because the service_connector stores the url
- // of the requestor safely.
- return service_connector->ConnectToService(
- service_url, service_name, client_handle.Pass());
+ return service_connector->ConnectToService(service_name,
+ client_handle.Pass());
}
} // namespace internal
diff --git a/mojo/public/cpp/application/lib/service_registry.h b/mojo/public/cpp/application/lib/service_registry.h
index a2f23cd..8f77259 100644
--- a/mojo/public/cpp/application/lib/service_registry.h
+++ b/mojo/public/cpp/application/lib/service_registry.h
@@ -5,43 +5,47 @@
#ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
-#include <map>
-#include <string>
-
+#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
namespace mojo {
-class Application;
+class ApplicationImpl;
namespace internal {
class ServiceConnectorBase;
-class ServiceRegistry : public ServiceProvider {
+// 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(Application* application);
- ServiceRegistry(Application* application,
- ScopedMessagePipeHandle service_provider_handle);
+ ServiceRegistry();
+ ServiceRegistry(ApplicationImpl* application_impl,
+ const std::string& url,
+ ServiceProviderPtr service_provider);
virtual ~ServiceRegistry();
- void AddServiceConnector(ServiceConnectorBase* service_connector);
- void RemoveServiceConnector(ServiceConnectorBase* service_connector);
-
- ServiceProvider* remote_service_provider() {
- return remote_service_provider_.get();
- }
+ // ApplicationConnection overrides.
+ virtual void AddServiceConnector(ServiceConnectorBase* service_connector)
+ MOJO_OVERRIDE;
+ virtual const std::string& GetRemoteApplicationURL() MOJO_OVERRIDE;
+ virtual ApplicationConnection* ConnectToApplication(
+ const std::string& url) MOJO_OVERRIDE;
+ virtual ServiceProvider* GetServiceProvider() MOJO_OVERRIDE;
- void BindRemoteServiceProvider(
- ScopedMessagePipeHandle service_provider_handle);
+ virtual void RemoveServiceConnector(ServiceConnectorBase* service_connector);
+ private:
// ServiceProvider method.
- virtual void ConnectToService(const mojo::String& service_url,
- const mojo::String& service_name,
- ScopedMessagePipeHandle client_handle,
- const mojo::String& requestor_url)
+ virtual void ConnectToService(const mojo::String& service_name,
+ ScopedMessagePipeHandle client_handle)
MOJO_OVERRIDE;
+ ApplicationImpl* application_impl_;
+ const std::string url_;
+
private:
bool RemoveServiceConnectorInternal(
ServiceConnectorBase* service_connector);