summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 21:57:02 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 21:57:02 +0000
commit8fc44a9f0c97c5f2e61fc8125a4822a057c67446 (patch)
tree0e3745a55a87d85cc5463b4a157aadccd0713c45
parentcf0c55a04cc3cb7e996d823eaf574e70d305a303 (diff)
downloadchromium_src-8fc44a9f0c97c5f2e61fc8125a4822a057c67446.zip
chromium_src-8fc44a9f0c97c5f2e61fc8125a4822a057c67446.tar.gz
chromium_src-8fc44a9f0c97c5f2e61fc8125a4822a057c67446.tar.bz2
Split ServiceProvider into 3
BUG= R=darin@chromium.org, qsr@chromium.org Review URL: https://codereview.chromium.org/347333002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279830 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/dbus/dbus_external_service.cc1
-rw-r--r--mojo/dbus/dbus_external_service.h16
-rw-r--r--mojo/examples/aura_demo/aura_demo.cc15
-rw-r--r--mojo/examples/aura_demo/view_manager_init.cc11
-rw-r--r--mojo/examples/browser/browser.cc23
-rw-r--r--mojo/examples/compositor_app/compositor_app.cc12
-rw-r--r--mojo/examples/dbus_echo/dbus_echo_app.cc13
-rw-r--r--mojo/examples/demo_launcher/demo_launcher.cc19
-rw-r--r--mojo/examples/embedded_app/embedded_app.cc28
-rw-r--r--mojo/examples/html_viewer/blink_platform_impl.cc6
-rw-r--r--mojo/examples/html_viewer/blink_platform_impl.h4
-rw-r--r--mojo/examples/html_viewer/html_viewer.cc25
-rw-r--r--mojo/examples/keyboard/keyboard.cc22
-rw-r--r--mojo/examples/media_viewer/media_viewer.cc32
-rw-r--r--mojo/examples/nesting_app/nesting_app.cc31
-rw-r--r--mojo/examples/pepper_container_app/pepper_container_app.cc14
-rw-r--r--mojo/examples/png_viewer/png_viewer.cc21
-rw-r--r--mojo/examples/sample_app/sample_app.cc12
-rw-r--r--mojo/examples/wget/wget.cc11
-rw-r--r--mojo/examples/window_manager/window_manager.cc45
-rw-r--r--mojo/mojo_public.gypi6
-rw-r--r--mojo/public/cpp/application/application.h121
-rw-r--r--mojo/public/cpp/application/application_connection.h106
-rw-r--r--mojo/public/cpp/application/application_delegate.h44
-rw-r--r--mojo/public/cpp/application/application_impl.h111
-rw-r--r--mojo/public/cpp/application/connect.h4
-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
-rw-r--r--mojo/public/cpp/application/tests/service_registry_unittest.cc9
-rw-r--r--mojo/public/interfaces/service_provider/service_provider.mojom25
-rw-r--r--mojo/service_manager/background_service_loader.cc12
-rw-r--r--mojo/service_manager/background_service_loader.h4
-rw-r--r--mojo/service_manager/service_loader.h13
-rw-r--r--mojo/service_manager/service_manager.cc150
-rw-r--r--mojo/service_manager/service_manager.h48
-rw-r--r--mojo/service_manager/service_manager_unittest.cc301
-rw-r--r--mojo/service_manager/test.mojom10
-rw-r--r--mojo/services/dbus_echo/dbus_echo_service.cc2
-rw-r--r--mojo/services/launcher/launcher.cc24
-rw-r--r--mojo/services/native_viewport/native_viewport_service.cc27
-rw-r--r--mojo/services/native_viewport/native_viewport_service.h4
-rw-r--r--mojo/services/network/main.cc41
-rw-r--r--mojo/services/network/network_service_impl.cc6
-rw-r--r--mojo/services/network/network_service_impl.h4
-rw-r--r--mojo/services/profile/profile_service_impl.cc2
-rw-r--r--mojo/services/profile/profile_service_impl.h4
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc15
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h4
-rw-r--r--mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc23
-rw-r--r--mojo/services/public/cpp/view_manager/view_manager.h5
-rw-r--r--mojo/services/test_service/test_service_application.cc9
-rw-r--r--mojo/services/test_service/test_service_application.h8
-rw-r--r--mojo/services/test_service/test_service_impl.cc3
-rw-r--r--mojo/services/test_service/test_service_impl.h4
-rw-r--r--mojo/services/view_manager/main.cc13
-rw-r--r--mojo/services/view_manager/root_node_manager.cc16
-rw-r--r--mojo/services/view_manager/root_node_manager.h6
-rw-r--r--mojo/services/view_manager/root_view_manager.cc9
-rw-r--r--mojo/services/view_manager/root_view_manager.h4
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.cc6
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.h3
-rw-r--r--mojo/services/view_manager/view_manager_unittest.cc28
-rw-r--r--mojo/shell/android/mojo_main.cc1
-rw-r--r--mojo/shell/context.cc8
-rw-r--r--mojo/shell/dbus_service_loader_linux.cc4
-rw-r--r--mojo/shell/dbus_service_loader_linux.h2
-rw-r--r--mojo/shell/dynamic_service_loader.cc10
-rw-r--r--mojo/shell/profile_service_loader.cc18
-rw-r--r--mojo/shell/profile_service_loader.h13
-rw-r--r--mojo/shell/run.cc19
-rw-r--r--mojo/shell/shell_test_base.cc12
-rw-r--r--mojo/shell/shell_test_base.h6
-rw-r--r--mojo/shell/shell_test_base_unittest.cc18
-rw-r--r--mojo/shell/shell_test_helper.cc19
-rw-r--r--mojo/shell/shell_test_helper.h15
-rw-r--r--mojo/shell/view_manager_loader.cc16
-rw-r--r--mojo/shell/view_manager_loader.h9
-rw-r--r--mojo/spy/spy.cc13
86 files changed, 1320 insertions, 771 deletions
diff --git a/mojo/dbus/dbus_external_service.cc b/mojo/dbus/dbus_external_service.cc
index a0b8981..fad451c 100644
--- a/mojo/dbus/dbus_external_service.cc
+++ b/mojo/dbus/dbus_external_service.cc
@@ -15,7 +15,6 @@
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "mojo/embedder/channel_init.h"
-#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/bindings/error_handler.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/shell/external_service.mojom.h"
diff --git a/mojo/dbus/dbus_external_service.h b/mojo/dbus/dbus_external_service.h
index 213c074..77e9e4b 100644
--- a/mojo/dbus/dbus_external_service.h
+++ b/mojo/dbus/dbus_external_service.h
@@ -8,7 +8,9 @@
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "mojo/embedder/channel_init.h"
-#include "mojo/public/cpp/application/application.h"
+#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/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/shell/external_service.mojom.h"
@@ -48,13 +50,20 @@ class DBusExternalServiceBase {
};
template <class ServiceImpl>
-class DBusExternalService : public DBusExternalServiceBase {
+class DBusExternalService : public DBusExternalServiceBase,
+ public ApplicationDelegate {
public:
explicit DBusExternalService(const std::string& service_name)
: DBusExternalServiceBase(service_name) {
}
virtual ~DBusExternalService() {}
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ connection->AddService<ServiceImpl>();
+ return true;
+ }
+
protected:
virtual void Connect(ScopedMessagePipeHandle client_handle) OVERRIDE {
external_service_.reset(BindToPipe(new Impl(this), client_handle.Pass()));
@@ -74,8 +83,7 @@ class DBusExternalService : public DBusExternalServiceBase {
}
virtual void Activate(ScopedMessagePipeHandle service_provider_handle)
OVERRIDE {
- app_.reset(new Application(service_provider_handle.Pass()));
- app_->AddService<ServiceImpl>();
+ app_.reset(new ApplicationImpl(service_, service_provider_handle.Pass()));
}
private:
DBusExternalService* service_;
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
index de005a7..4f88dfb 100644
--- a/mojo/examples/aura_demo/aura_demo.cc
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -10,7 +10,7 @@
#include "mojo/aura/screen_mojo.h"
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/aura/window_tree_host_mojo_delegate.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/node.h"
@@ -103,7 +103,7 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
};
-class AuraDemo : public Application,
+class AuraDemo : public ApplicationDelegate,
public WindowTreeHostMojoDelegate,
public view_manager::ViewManagerDelegate {
public:
@@ -112,7 +112,6 @@ class AuraDemo : public Application,
window2_(NULL),
window21_(NULL),
view_(NULL) {
- view_manager::ViewManager::Create(this, this);
}
virtual ~AuraDemo() {}
@@ -159,7 +158,7 @@ class AuraDemo : public Application,
view_->SetContents(bitmap);
}
- virtual void Initialize() OVERRIDE {
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
aura::Env::CreateInstance(true);
context_factory_.reset(new ContextFactoryMojo);
aura::Env::GetInstance()->set_context_factory(context_factory_.get());
@@ -167,6 +166,12 @@ class AuraDemo : public Application,
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
}
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
+ }
+
scoped_ptr<DemoWindowTreeClient> window_tree_client_;
scoped_ptr<ui::ContextFactory> context_factory_;
@@ -191,7 +196,7 @@ class AuraDemo : public Application,
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::AuraDemo();
}
diff --git a/mojo/examples/aura_demo/view_manager_init.cc b/mojo/examples/aura_demo/view_manager_init.cc
index 7a558d3..4130193 100644
--- a/mojo/examples/aura_demo/view_manager_init.cc
+++ b/mojo/examples/aura_demo/view_manager_init.cc
@@ -4,7 +4,8 @@
#include "base/basictypes.h"
#include "base/bind.h"
-#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/services/public/interfaces/view_manager/view_manager.mojom.h"
namespace mojo {
@@ -12,13 +13,13 @@ namespace examples {
// ViewManagerInit is responsible for establishing the initial connection to
// the view manager. When established it loads |mojo_aura_demo|.
-class ViewManagerInit : public Application {
+class ViewManagerInit : public ApplicationDelegate {
public:
ViewManagerInit() {}
virtual ~ViewManagerInit() {}
- virtual void Initialize() OVERRIDE {
- ConnectTo("mojo:mojo_view_manager", &view_manager_init_);
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_view_manager", &view_manager_init_);
view_manager_init_->EmbedRoot("mojo:mojo_aura_demo",
base::Bind(&ViewManagerInit::DidConnect,
base::Unretained(this)));
@@ -38,7 +39,7 @@ class ViewManagerInit : public Application {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::ViewManagerInit();
}
diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc
index fed88b5..edc565c 100644
--- a/mojo/examples/browser/browser.cc
+++ b/mojo/examples/browser/browser.cc
@@ -6,7 +6,9 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -112,7 +114,7 @@ class KeyboardManager : public views::FocusChangeListener,
// This is the basics of creating a views widget with a textfield.
// TODO: cleanup!
-class Browser : public Application,
+class Browser : public ApplicationDelegate,
public view_manager::ViewManagerDelegate,
public views::TextfieldController,
public view_manager::NodeObserver {
@@ -123,12 +125,17 @@ class Browser : public Application,
}
private:
- // Overridden from Application:
- virtual void Initialize() MOJO_OVERRIDE {
+ // Overridden from ApplicationDelegate:
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
views_init_.reset(new ViewsInit);
- view_manager::ViewManager::Create(this, this);
- ConnectTo("mojo:mojo_window_manager", &navigator_host_);
- ConnectTo("mojo:mojo_window_manager", &window_manager_);
+ app->ConnectToService("mojo:mojo_window_manager", &navigator_host_);
+ app->ConnectToService("mojo:mojo_window_manager", &window_manager_);
+ }
+
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
}
void CreateWidget(view_manager::Node* node) {
@@ -206,7 +213,7 @@ class Browser : public Application,
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::Browser;
}
diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc
index 31752bd..6a5a8c4 100644
--- a/mojo/examples/compositor_app/compositor_app.cc
+++ b/mojo/examples/compositor_app/compositor_app.cc
@@ -7,7 +7,8 @@
#include "base/macros.h"
#include "mojo/examples/compositor_app/compositor_host.h"
-#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/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
@@ -18,15 +19,14 @@
namespace mojo {
namespace examples {
-class SampleApp : public Application, public NativeViewportClient {
+class SampleApp : public ApplicationDelegate, public NativeViewportClient {
public:
SampleApp() {}
virtual ~SampleApp() {}
- virtual void Initialize() OVERRIDE {
- ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
+ virtual void Initialize(ApplicationImpl* app) OVERRIDE {
+ app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
viewport_.set_client(this);
-
viewport_->Create(Rect::From(gfx::Rect(10, 10, 800, 600)));
viewport_->Show();
@@ -62,7 +62,7 @@ class SampleApp : public Application, public NativeViewportClient {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::SampleApp();
}
diff --git a/mojo/examples/dbus_echo/dbus_echo_app.cc b/mojo/examples/dbus_echo/dbus_echo_app.cc
index 5a9b80f..948ad8c 100644
--- a/mojo/examples/dbus_echo/dbus_echo_app.cc
+++ b/mojo/examples/dbus_echo/dbus_echo_app.cc
@@ -7,7 +7,8 @@
#include "base/bind.h"
#include "base/logging.h"
-#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/system/core.h"
#include "mojo/public/cpp/system/macros.h"
@@ -17,14 +18,14 @@
namespace mojo {
namespace examples {
-class DBusEchoApp : public Application {
+class DBusEchoApp : public ApplicationDelegate {
public:
DBusEchoApp() {}
virtual ~DBusEchoApp() {}
- virtual void Initialize() MOJO_OVERRIDE {
- ConnectTo("dbus:org.chromium.EchoService/org/chromium/MojoImpl",
- &echo_service_);
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService(
+ "dbus:org.chromium.EchoService/org/chromium/MojoImpl", &echo_service_);
echo_service_->Echo(
String::From("who"),
@@ -44,7 +45,7 @@ class DBusEchoApp : public Application {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::DBusEchoApp();
}
diff --git a/mojo/examples/demo_launcher/demo_launcher.cc b/mojo/examples/demo_launcher/demo_launcher.cc
index 141a49a..d6a3712 100644
--- a/mojo/examples/demo_launcher/demo_launcher.cc
+++ b/mojo/examples/demo_launcher/demo_launcher.cc
@@ -5,25 +5,30 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/run_loop.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/public/interfaces/view_manager/view_manager.mojom.h"
namespace mojo {
namespace examples {
-class DemoLauncher : public Application {
+class DemoLauncher : public ApplicationDelegate {
public:
DemoLauncher() {}
virtual ~DemoLauncher() {}
private:
- // Overridden from Application:
- virtual void Initialize() MOJO_OVERRIDE {
- ConnectTo<view_manager::ViewManagerInitService>("mojo:mojo_view_manager",
- &view_manager_init_);
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_view_manager", &view_manager_init_);
+ }
+
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
view_manager_init_->EmbedRoot("mojo:mojo_window_manager",
base::Bind(&DemoLauncher::OnConnect,
base::Unretained(this)));
+ return true;
}
void OnConnect(bool success) {}
@@ -36,7 +41,7 @@ class DemoLauncher : public Application {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::DemoLauncher;
}
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
index de8b00b..9a0144d 100644
--- a/mojo/examples/embedded_app/embedded_app.cc
+++ b/mojo/examples/embedded_app/embedded_app.cc
@@ -7,7 +7,9 @@
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/node_observer.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -29,7 +31,7 @@ using mojo::view_manager::ViewObserver;
namespace mojo {
namespace examples {
-class EmbeddedApp : public Application,
+class EmbeddedApp : public ApplicationDelegate,
public ViewManagerDelegate,
public ViewObserver,
public NodeObserver {
@@ -47,7 +49,8 @@ class EmbeddedApp : public Application,
private:
class Navigator : public InterfaceImpl<navigation::Navigator> {
public:
- explicit Navigator(EmbeddedApp* app) : app_(app) {}
+ Navigator(ApplicationConnection* connection,
+ EmbeddedApp* app) : app_(app) {}
private:
virtual void Navigate(
uint32 node_id,
@@ -70,15 +73,20 @@ class EmbeddedApp : public Application,
DISALLOW_COPY_AND_ASSIGN(Navigator);
};
- // Overridden from Application:
- virtual void Initialize() MOJO_OVERRIDE {
- ViewManager::Create(this, this);
+ // Overridden from ApplicationDelegate:
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
// TODO(aa): Weird for embeddee to talk to embedder by URL. Seems like
// embedder should be able to specify the SP embeddee receives, then
// communication can be anonymous.
- ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
- ConnectTo("mojo:mojo_window_manager", &navigator_host_);
- AddService<Navigator>(this);
+ app->ConnectToService("mojo:mojo_window_manager", &window_manager_);
+ app->ConnectToService("mojo:mojo_window_manager", &navigator_host_);
+ }
+
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ ViewManager::ConfigureIncomingConnection(connection, this);
+ connection->AddService<Navigator>(this);
+ return true;
}
// Overridden from ViewManagerDelegate:
@@ -160,7 +168,7 @@ class EmbeddedApp : public Application,
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::EmbeddedApp;
}
diff --git a/mojo/examples/html_viewer/blink_platform_impl.cc b/mojo/examples/html_viewer/blink_platform_impl.cc
index 3128d43..f629b9c 100644
--- a/mojo/examples/html_viewer/blink_platform_impl.cc
+++ b/mojo/examples/html_viewer/blink_platform_impl.cc
@@ -12,7 +12,7 @@
#include "base/time/time.h"
#include "mojo/examples/html_viewer/webthread_impl.h"
#include "mojo/examples/html_viewer/weburlloader_impl.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_impl.h"
#include "net/base/data_url.h"
#include "net/base/mime_util.h"
#include "net/base/net_errors.h"
@@ -46,14 +46,14 @@ class WebWaitableEventImpl : public blink::WebWaitableEvent {
} // namespace
-BlinkPlatformImpl::BlinkPlatformImpl(Application* app)
+BlinkPlatformImpl::BlinkPlatformImpl(ApplicationImpl* app)
: main_loop_(base::MessageLoop::current()),
shared_timer_func_(NULL),
shared_timer_fire_time_(0.0),
shared_timer_fire_time_was_set_while_suspended_(false),
shared_timer_suspended_(0),
current_thread_slot_(&DestroyCurrentThread) {
- app->ConnectTo("mojo:mojo_network_service", &network_service_);
+ app->ConnectToService("mojo:mojo_network_service", &network_service_);
}
BlinkPlatformImpl::~BlinkPlatformImpl() {
diff --git a/mojo/examples/html_viewer/blink_platform_impl.h b/mojo/examples/html_viewer/blink_platform_impl.h
index dfe7744..e24f17e 100644
--- a/mojo/examples/html_viewer/blink_platform_impl.h
+++ b/mojo/examples/html_viewer/blink_platform_impl.h
@@ -14,13 +14,13 @@
#include "third_party/WebKit/public/platform/WebThemeEngine.h"
namespace mojo {
-class Application;
+class ApplicationImpl;
namespace examples {
class BlinkPlatformImpl : public blink::Platform {
public:
- explicit BlinkPlatformImpl(Application* app);
+ explicit BlinkPlatformImpl(ApplicationImpl* app);
virtual ~BlinkPlatformImpl();
// blink::Platform methods:
diff --git a/mojo/examples/html_viewer/html_viewer.cc b/mojo/examples/html_viewer/html_viewer.cc
index 05bd7b5..ad9bb8f 100644
--- a/mojo/examples/html_viewer/html_viewer.cc
+++ b/mojo/examples/html_viewer/html_viewer.cc
@@ -4,7 +4,9 @@
#include "mojo/examples/html_viewer/blink_platform_impl.h"
#include "mojo/examples/html_viewer/html_document_view.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -20,7 +22,8 @@ class HTMLViewer;
class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
public:
- explicit NavigatorImpl(HTMLViewer* viewer) : viewer_(viewer) {}
+ explicit NavigatorImpl(ApplicationConnection* connection,
+ HTMLViewer* viewer) : viewer_(viewer) {}
virtual ~NavigatorImpl() {}
private:
@@ -35,7 +38,7 @@ class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
-class HTMLViewer : public Application,
+class HTMLViewer : public ApplicationDelegate,
public view_manager::ViewManagerDelegate {
public:
HTMLViewer() : document_view_(NULL) {
@@ -53,13 +56,17 @@ class HTMLViewer : public Application,
}
private:
- // Overridden from Application:
- virtual void Initialize() OVERRIDE {
- blink_platform_impl_.reset(new BlinkPlatformImpl(this));
+ // Overridden from ApplicationDelegate:
+ virtual void Initialize(ApplicationImpl* app) OVERRIDE {
+ blink_platform_impl_.reset(new BlinkPlatformImpl(app));
blink::initialize(blink_platform_impl_.get());
+ }
- AddService<NavigatorImpl>(this);
- view_manager::ViewManager::Create(this, this);
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ OVERRIDE {
+ connection->AddService<NavigatorImpl>(this);
+ view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
}
// Overridden from view_manager::ViewManagerDelegate:
@@ -98,7 +105,7 @@ void NavigatorImpl::Navigate(
}
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::HTMLViewer;
}
diff --git a/mojo/examples/keyboard/keyboard.cc b/mojo/examples/keyboard/keyboard.cc
index ae6d8c9..0941d05 100644
--- a/mojo/examples/keyboard/keyboard.cc
+++ b/mojo/examples/keyboard/keyboard.cc
@@ -8,7 +8,8 @@
#include "mojo/examples/keyboard/keyboard.mojom.h"
#include "mojo/examples/keyboard/keyboard_delegate.h"
#include "mojo/examples/keyboard/keyboard_view.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
@@ -32,7 +33,7 @@ class Keyboard;
class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> {
public:
- KeyboardServiceImpl(Keyboard* keyboard);
+ KeyboardServiceImpl(ApplicationConnection* connection, Keyboard* keyboard);
virtual ~KeyboardServiceImpl() {}
// KeyboardService:
@@ -44,7 +45,7 @@ class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> {
DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl);
};
-class Keyboard : public Application,
+class Keyboard : public ApplicationDelegate,
public view_manager::ViewManagerDelegate,
public KeyboardDelegate {
public:
@@ -60,11 +61,13 @@ class Keyboard : public Application,
}
private:
- // Overridden from Application:
- virtual void Initialize() MOJO_OVERRIDE {
+ // Overridden from ApplicationDelegate:
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
views_init_.reset(new ViewsInit);
- view_manager::ViewManager::Create(this, this);
- AddService<KeyboardServiceImpl>(this);
+ view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
+ connection->AddService<KeyboardServiceImpl>(this);
+ return true;
}
void CreateWidget(view_manager::Node* node) {
@@ -110,7 +113,8 @@ class Keyboard : public Application,
DISALLOW_COPY_AND_ASSIGN(Keyboard);
};
-KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard)
+KeyboardServiceImpl::KeyboardServiceImpl(ApplicationConnection* connection,
+ Keyboard* keyboard)
: keyboard_(keyboard) {
keyboard_->set_keyboard_service(this);
}
@@ -122,7 +126,7 @@ void KeyboardServiceImpl::SetTarget(uint32_t node_id) {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::Keyboard;
}
diff --git a/mojo/examples/media_viewer/media_viewer.cc b/mojo/examples/media_viewer/media_viewer.cc
index 29d4b06..b727b59 100644
--- a/mojo/examples/media_viewer/media_viewer.cc
+++ b/mojo/examples/media_viewer/media_viewer.cc
@@ -7,7 +7,9 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-#include "mojo/public/cpp/application/application.h"
+#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/bindings/interface_impl.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -23,7 +25,8 @@ class MediaViewer;
class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
public:
- explicit NavigatorImpl(MediaViewer* viewer) : viewer_(viewer) {}
+ explicit NavigatorImpl(ApplicationConnection* connection,
+ MediaViewer* viewer) : viewer_(viewer) {}
virtual ~NavigatorImpl() {}
private:
@@ -38,10 +41,11 @@ class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
-class MediaViewer : public Application,
+class MediaViewer : public ApplicationDelegate,
public view_manager::ViewManagerDelegate {
public:
- MediaViewer() : content_node_(NULL),
+ MediaViewer() : app_(NULL),
+ content_node_(NULL),
view_manager_(NULL) {
handler_map_["image/png"] = "mojo:mojo_png_viewer";
}
@@ -72,7 +76,7 @@ class MediaViewer : public Application,
if (navigation_details) {
navigation::NavigatorPtr navigator;
- ConnectTo(handler, &navigator);
+ app_->ConnectToService(handler, &navigator);
navigator->Navigate(content_node_->id(), navigation_details.Pass(),
response_details.Pass());
}
@@ -87,10 +91,17 @@ class MediaViewer : public Application,
navigation::ResponseDetailsPtr response_details;
};
- // Overridden from Application:
- virtual void Initialize() OVERRIDE {
- AddService<NavigatorImpl>(this);
- view_manager::ViewManager::Create(this, this);
+
+ // Overridden from ApplicationDelegate:
+ virtual void Initialize(ApplicationImpl* app) OVERRIDE {
+ app_ = app;
+ }
+
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ OVERRIDE {
+ connection->AddService<NavigatorImpl>(this);
+ view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
}
// Overridden from view_manager::ViewManagerDelegate:
@@ -117,6 +128,7 @@ class MediaViewer : public Application,
return it != handler_map_.end() ? it->second : std::string();
}
+ ApplicationImpl* app_;
view_manager::Node* content_node_;
view_manager::ViewManager* view_manager_;
HandlerMap handler_map_;
@@ -136,7 +148,7 @@ void NavigatorImpl::Navigate(
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::MediaViewer;
}
diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
index 7eccc72..8e66736 100644
--- a/mojo/examples/nesting_app/nesting_app.cc
+++ b/mojo/examples/nesting_app/nesting_app.cc
@@ -6,7 +6,8 @@
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/node_observer.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -32,7 +33,8 @@ const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app";
}
// An app that embeds another app.
-class NestingApp : public Application,
+// TODO(davemoore): Is this the right name?
+class NestingApp : public ApplicationDelegate,
public ViewManagerDelegate,
public ViewObserver,
public NodeObserver {
@@ -43,7 +45,8 @@ class NestingApp : public Application,
private:
class Navigator : public InterfaceImpl<navigation::Navigator> {
public:
- explicit Navigator(NestingApp* app) : app_(app) {}
+ explicit Navigator(ApplicationConnection* connection,
+ NestingApp* app) : app_(app) {}
private:
virtual void Navigate(
uint32 node_id,
@@ -61,11 +64,18 @@ class NestingApp : public Application,
DISALLOW_COPY_AND_ASSIGN(Navigator);
};
- // Overridden from Application:
- virtual void Initialize() MOJO_OVERRIDE {
- ViewManager::Create(this, this);
- ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
- AddService<Navigator>(this);
+ // Overridden from ApplicationImpl:
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ ViewManager::ConfigureIncomingConnection(connection, this);
+ connection->ConnectToService(&window_manager_);
+ connection->AddService<Navigator>(this);
+ // TODO(davemoore): Is this ok?
+ if (!navigator_.get()) {
+ connection->ConnectToApplication(
+ kEmbeddedAppURL)->ConnectToService(&navigator_);
+ }
+ return true;
}
// Overridden from ViewManagerDelegate:
@@ -82,9 +92,6 @@ class NestingApp : public Application,
nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
nested_->Embed(kEmbeddedAppURL);
- if (!navigator_.get())
- ConnectTo(kEmbeddedAppURL, &navigator_);
-
NavigateChild();
}
@@ -129,7 +136,7 @@ class NestingApp : public Application,
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::NestingApp;
}
diff --git a/mojo/examples/pepper_container_app/pepper_container_app.cc b/mojo/examples/pepper_container_app/pepper_container_app.cc
index 3c6cf76..dc4a9ce 100644
--- a/mojo/examples/pepper_container_app/pepper_container_app.cc
+++ b/mojo/examples/pepper_container_app/pepper_container_app.cc
@@ -11,7 +11,8 @@
#include "mojo/examples/pepper_container_app/plugin_instance.h"
#include "mojo/examples/pepper_container_app/plugin_module.h"
#include "mojo/examples/pepper_container_app/type_converters.h"
-#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/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
@@ -22,19 +23,18 @@
namespace mojo {
namespace examples {
-class PepperContainerApp: public Application,
+class PepperContainerApp: public ApplicationDelegate,
public NativeViewportClient,
public MojoPpapiGlobals::Delegate {
public:
explicit PepperContainerApp()
- : Application(),
- ppapi_globals_(this),
+ : ppapi_globals_(this),
plugin_module_(new PluginModule) {}
virtual ~PepperContainerApp() {}
- virtual void Initialize() MOJO_OVERRIDE {
- ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
viewport_.set_client(this);
RectPtr rect(Rect::New());
@@ -103,7 +103,7 @@ class PepperContainerApp: public Application,
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::PepperContainerApp();
}
diff --git a/mojo/examples/png_viewer/png_viewer.cc b/mojo/examples/png_viewer/png_viewer.cc
index 8faed24..6a7218a 100644
--- a/mojo/examples/png_viewer/png_viewer.cc
+++ b/mojo/examples/png_viewer/png_viewer.cc
@@ -5,7 +5,8 @@
#include <algorithm>
#include "base/strings/string_tokenizer.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/view.h"
@@ -22,7 +23,8 @@ class PNGViewer;
class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
public:
- explicit NavigatorImpl(PNGViewer* viewer) : viewer_(viewer) {}
+ explicit NavigatorImpl(ApplicationConnection* connection,
+ PNGViewer* viewer) : viewer_(viewer) {}
virtual ~NavigatorImpl() {}
private:
@@ -84,7 +86,8 @@ class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
-class PNGViewer : public Application, public view_manager::ViewManagerDelegate {
+class PNGViewer : public ApplicationDelegate,
+ public view_manager::ViewManagerDelegate {
public:
PNGViewer() : content_view_(NULL) {}
virtual ~PNGViewer() {}
@@ -95,10 +98,12 @@ class PNGViewer : public Application, public view_manager::ViewManagerDelegate {
}
private:
- // Overridden from Application:
- virtual void Initialize() OVERRIDE {
- AddService<NavigatorImpl>(this);
- view_manager::ViewManager::Create(this, this);
+ // Overridden from ApplicationDelegate:
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ connection->AddService<NavigatorImpl>(this);
+ view_manager::ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
}
// Overridden from view_manager::ViewManagerDelegate:
@@ -130,7 +135,7 @@ void NavigatorImpl::UpdateView(view_manager::Id node_id,
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::PNGViewer;
}
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index b6a20b7..c5a57ab 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -6,7 +6,9 @@
#include <string>
#include "mojo/examples/sample_app/gles2_client_impl.h"
-#include "mojo/public/cpp/application/application.h"
+#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/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"
@@ -17,7 +19,7 @@
namespace mojo {
namespace examples {
-class SampleApp : public Application, public NativeViewportClient {
+class SampleApp : public ApplicationDelegate, public NativeViewportClient {
public:
SampleApp() {}
@@ -26,8 +28,8 @@ class SampleApp : public Application, public NativeViewportClient {
MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
}
- virtual void Initialize() MOJO_OVERRIDE {
- ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
viewport_.set_client(this);
RectPtr rect(Rect::New());
@@ -77,7 +79,7 @@ class SampleApp : public Application, public NativeViewportClient {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::SampleApp();
}
diff --git a/mojo/examples/wget/wget.cc b/mojo/examples/wget/wget.cc
index 8a0ad5e..8fabbe6 100644
--- a/mojo/examples/wget/wget.cc
+++ b/mojo/examples/wget/wget.cc
@@ -4,17 +4,18 @@
#include <stdio.h>
-#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/services/public/interfaces/network/network_service.mojom.h"
#include "mojo/services/public/interfaces/network/url_loader.mojom.h"
namespace mojo {
namespace examples {
-class WGetApp : public Application, public URLLoaderClient {
+class WGetApp : public ApplicationDelegate, public URLLoaderClient {
public:
- virtual void Initialize() MOJO_OVERRIDE {
- ConnectTo("mojo:mojo_network_service", &network_service_);
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_network_service", &network_service_);
Start();
}
@@ -109,7 +110,7 @@ class WGetApp : public Application, public URLLoaderClient {
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::WGetApp();
}
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 28178ba..d6c2082 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -7,7 +7,9 @@
#include "base/strings/stringprintf.h"
#include "mojo/examples/keyboard/keyboard.mojom.h"
#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#include "mojo/services/public/cpp/view_manager/node.h"
@@ -54,7 +56,8 @@ const int kTextfieldHeight = 25;
class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
public:
- explicit WindowManagerConnection(WindowManager* window_manager)
+ explicit WindowManagerConnection(ApplicationConnection* connection,
+ WindowManager* window_manager)
: window_manager_(window_manager) {}
virtual ~WindowManagerConnection() {}
@@ -71,7 +74,8 @@ class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
class NavigatorHost : public InterfaceImpl<navigation::NavigatorHost> {
public:
- explicit NavigatorHost(WindowManager* window_manager)
+ explicit NavigatorHost(ApplicationConnection* connection,
+ WindowManager* window_manager)
: window_manager_(window_manager) {
}
virtual ~NavigatorHost() {
@@ -96,7 +100,7 @@ class KeyboardManager : public KeyboardClient {
Node* node() { return node_; }
- void Init(Application* application,
+ void Init(ApplicationImpl* application,
ViewManager* view_manager,
Node* parent,
const gfx::Rect& bounds) {
@@ -105,7 +109,7 @@ class KeyboardManager : public KeyboardClient {
parent->AddChild(node_);
node_->SetBounds(bounds);
node_->Embed("mojo:mojo_keyboard");
- application->ConnectTo("mojo:mojo_keyboard", &keyboard_service_);
+ application->ConnectToService("mojo:mojo_keyboard", &keyboard_service_);
keyboard_service_.set_client(this);
}
@@ -151,13 +155,12 @@ class KeyboardManager : public KeyboardClient {
DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
};
-class WindowManager : public Application,
+class WindowManager : public ApplicationDelegate,
public ViewObserver,
public ViewManagerDelegate,
public ViewEventDispatcher {
public:
- WindowManager() : launcher_ui_(NULL), view_manager_(NULL) {
- }
+ WindowManager() : launcher_ui_(NULL), view_manager_(NULL), app_(NULL) {}
virtual ~WindowManager() {}
void CloseWindow(Id node_id) {
@@ -176,7 +179,7 @@ class WindowManager : public Application,
// this really owns |view_id|.
if (!keyboard_manager_) {
keyboard_manager_.reset(new KeyboardManager);
- keyboard_manager_->Init(this, view_manager_,
+ keyboard_manager_->Init(app_, view_manager_,
view_manager_->GetRoots().back(),
gfx::Rect(0, 400, 400, 200));
}
@@ -193,8 +196,6 @@ class WindowManager : public Application,
uint32 source_node_id,
navigation::Target target,
navigation::NavigationDetailsPtr nav_details) {
- if (!launcher_.get())
- ConnectTo("mojo:mojo_launcher", &launcher_);
launcher_->Launch(nav_details->url,
base::Bind(&WindowManager::OnLaunch,
base::Unretained(this),
@@ -203,11 +204,18 @@ class WindowManager : public Application,
}
private:
- // Overridden from Application:
- virtual void Initialize() MOJO_OVERRIDE {
- AddService<WindowManagerConnection>(this);
- AddService<NavigatorHost>(this);
- ViewManager::Create(this, this);
+ // Overridden from ApplicationDelegate:
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app_ = app;
+ app->ConnectToService("mojo:mojo_launcher", &launcher_);
+ }
+
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ connection->AddService<WindowManagerConnection>(this);
+ connection->AddService<NavigatorHost>(this);
+ ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
}
// Overridden from ViewObserver:
@@ -328,7 +336,7 @@ class WindowManager : public Application,
node->Embed(app_url);
if (nav_details.get()) {
navigation::NavigatorPtr navigator;
- ConnectTo(app_url, &navigator);
+ app_->ConnectToService(app_url, &navigator);
navigator->Navigate(node->id(), nav_details.Pass(), response.Pass());
}
}
@@ -347,6 +355,7 @@ class WindowManager : public Application,
Id content_node_id_;
scoped_ptr<KeyboardManager> keyboard_manager_;
+ ApplicationImpl* app_;
DISALLOW_COPY_AND_ASSIGN(WindowManager);
};
@@ -373,7 +382,7 @@ void NavigatorHost::RequestNavigate(
} // namespace examples
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::WindowManager;
}
diff --git a/mojo/mojo_public.gypi b/mojo/mojo_public.gypi
index 77b755d..36842c3 100644
--- a/mojo/mojo_public.gypi
+++ b/mojo/mojo_public.gypi
@@ -413,11 +413,13 @@
'target_name': 'mojo_application',
'type': 'static_library',
'sources': [
- 'public/cpp/application/application.h',
+ 'public/cpp/application/application_impl.h',
'public/cpp/application/connect.h',
- 'public/cpp/application/lib/application.cc',
+ 'public/cpp/application/lib/application_impl.cc',
'public/cpp/application/lib/service_connector.cc',
'public/cpp/application/lib/service_connector.h',
+ 'public/cpp/application/lib/application_connection.cc',
+ 'public/cpp/application/lib/application_delegate.cc',
'public/cpp/application/lib/service_registry.cc',
'public/cpp/application/lib/service_registry.h',
],
diff --git a/mojo/public/cpp/application/application.h b/mojo/public/cpp/application/application.h
deleted file mode 100644
index da7a0ed..0000000
--- a/mojo/public/cpp/application/application.h
+++ /dev/null
@@ -1,121 +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_H_
-#define MOJO_PUBLIC_APPLICATION_APPLICATION_H_
-#include <vector>
-
-#include "mojo/public/cpp/application/connect.h"
-#include "mojo/public/cpp/application/lib/service_connector.h"
-#include "mojo/public/cpp/system/core.h"
-#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
-
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define APPLICATION_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define APPLICATION_EXPORT __attribute__((visibility("default")))
-#endif
-
-// DSOs can either implement MojoMain directly or include
-// mojo_main_{standalone|chromium}.cc in their project and implement
-// Application::Create();
-// TODO(davemoore): Establish this as part of our SDK for third party mojo
-// application writers.
-extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle);
-
-namespace mojo {
-
-// Utility class for creating ServiceProviders that vend service instances.
-// 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() {}
-// };
-//
-// or
-//
-// class BarImpl : public InterfaceImpl<Bar> {
-// public:
-// // context will remain valid for the lifetime of BarImpl.
-// BarImpl(BarContext* context) : context_(context) {}
-// private:
-// BarContext* context;
-// };
-//
-// Create an Application instance that collects any service implementations.
-//
-// Application app(service_provider_handle);
-// app.AddService<FooImpl>();
-//
-// BarContext context;
-// app.AddService<BarImpl>(&context);
-//
-//
-class Application {
- public:
- Application();
- explicit Application(ScopedMessagePipeHandle service_provider_handle);
- explicit Application(MojoHandle service_provider_handle);
- virtual ~Application();
-
- // Override this method to control what urls are allowed to connect to a
- // service.
- virtual bool AllowIncomingConnection(const mojo::String& service_name,
- const mojo::String& requestor_url);
-
- template <typename Impl, typename Context>
- void AddService(Context* context) {
- service_registry_.AddServiceConnector(
- new internal::ServiceConnector<Impl, Context>(Impl::Name_, context));
- }
-
- template <typename Impl>
- void AddService() {
- service_registry_.AddServiceConnector(
- new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL));
- }
-
- template <typename Interface>
- void ConnectTo(const std::string& url, InterfacePtr<Interface>* ptr) {
- mojo::ConnectToService(service_provider(), url, ptr);
- }
-
- ServiceProvider* service_provider() {
- return service_registry_.remote_service_provider();
- }
-
- void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle);
-
- protected:
- // Override this to do any necessary initialization. There's no need to call
- // Application's implementation.
- // The service_provider will be bound to its pipe before this is called.
- virtual void Initialize();
-
- private:
- friend MojoResult (::MojoMain)(MojoHandle);
-
- // Implement this method to create the specific subclass of Application.
- static Application* Create();
-
- internal::ServiceRegistry service_registry_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(Application);
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_
diff --git a/mojo/public/cpp/application/application_connection.h b/mojo/public/cpp/application/application_connection.h
new file mode 100644
index 0000000..2044af1
--- /dev/null
+++ b/mojo/public/cpp/application/application_connection.h
@@ -0,0 +1,106 @@
+// 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"
+
+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.
+//
+// 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:
+// explicit FooImpl(ApplicationConnnection* connection) {}
+// };
+//
+// or
+//
+// class BarImpl : public InterfaceImpl<Bar> {
+// public:
+// // contexts will remain valid for the lifetime of BarImpl.
+// BarImpl(ApplicationConnnection* connection, BarContext* service_context)
+// : connection_(connection), servicecontext_(context) {}
+//
+// Create an ApplicationDelegate instance and pass it to the constructor
+// of an ApplicationImpl. The delegate will be called when new connections are
+// made to other applications.
+//
+// connection->AddService<FooImpl>();
+//
+// BarContext context;
+// connection->AddService<BarImpl>(&context);
+class ApplicationConnection {
+ public:
+ virtual ~ApplicationConnection();
+
+ // Impl’s constructor will receive two arguments:
+ // Impl::Impl(Application::Context* app_context,
+ // ServiceContext* svc_context)
+ template <typename Impl, typename ServiceContext>
+ void AddService(ServiceContext* context) {
+ AddServiceConnector(
+ new internal::ServiceConnector<Impl, ServiceContext>(Impl::Name_,
+ context));
+ }
+
+ // Impl’s constructor will receive one argument:
+ // Impl::Impl(Application::Context* app_context)
+ template <typename Impl>
+ void AddService() {
+ AddServiceConnector(
+ new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL));
+ }
+
+ // 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
new file mode 100644
index 0000000..cb67308
--- /dev/null
+++ b/mojo/public/cpp/application/application_delegate.h
@@ -0,0 +1,44 @@
+// 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();
+
+ // Implement this method to create the specific subclass of
+ // ApplicationDelegate. Ownership is taken by the caller. It will be deleted.
+ static ApplicationDelegate* Create();
+
+ 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
new file mode 100644
index 0000000..8f7a842
--- /dev/null
+++ b/mojo/public/cpp/application/application_impl.h
@@ -0,0 +1,111 @@
+// 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/service_provider/service_provider.mojom.h"
+
+#if defined(WIN32)
+#if !defined(CDECL)
+#define CDECL __cdecl
+#endif
+#define APPLICATION_EXPORT __declspec(dllexport)
+#else
+#define CDECL
+#define APPLICATION_EXPORT __attribute__((visibility("default")))
+#endif
+
+// DSOs can either implement MojoMain directly or include
+// mojo_main_{standalone|chromium}.cc in their project and implement
+// ApplicationImpl::Create();
+// TODO(davemoore): Establish this as part of our SDK for third party mojo
+// application writers.
+extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
+ MojoHandle service_provider_handle);
+
+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 ApplicationDele 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:
+ explicit ApplicationImpl(ApplicationDelegate* delegate);
+ ApplicationImpl(ApplicationDelegate* delegate,
+ ScopedMessagePipeHandle shell_handle);
+ ApplicationImpl(ApplicationDelegate* delegate,
+ MojoHandle shell_handle);
+ virtual ~ApplicationImpl();
+
+ // 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
+ // an 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);
+ }
+
+ private:
+ friend MojoResult (::MojoMain)(MojoHandle);
+
+ void BindShell(ScopedMessagePipeHandle shell_handle);
+ void BindShell(MojoHandle shell_handle);
+
+ // Application implementation.
+ virtual void AcceptConnection(const String& requestor_url,
+ ServiceProviderPtr provider) MOJO_OVERRIDE;
+
+ typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList;
+ ServiceRegistryList incoming_service_registries_;
+ ServiceRegistryList outgoing_service_registries_;
+ ApplicationDelegate* delegate_;
+ ShellPtr shell_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_
diff --git a/mojo/public/cpp/application/connect.h b/mojo/public/cpp/application/connect.h
index e4ba641..7160316 100644
--- a/mojo/public/cpp/application/connect.h
+++ b/mojo/public/cpp/application/connect.h
@@ -11,12 +11,10 @@ namespace mojo {
template <typename Interface>
inline void ConnectToService(ServiceProvider* service_provider,
- const std::string& url,
InterfacePtr<Interface>* ptr) {
MessagePipe pipe;
ptr->Bind(pipe.handle0.Pass());
- service_provider->ConnectToService(
- url, Interface::Name_, pipe.handle1.Pass(), std::string());
+ service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass());
}
} // namespace mojo
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);
diff --git a/mojo/public/cpp/application/tests/service_registry_unittest.cc b/mojo/public/cpp/application/tests/service_registry_unittest.cc
index 586dff8..9749ae4 100644
--- a/mojo/public/cpp/application/tests/service_registry_unittest.cc
+++ b/mojo/public/cpp/application/tests/service_registry_unittest.cc
@@ -17,7 +17,6 @@ class TestConnector : public ServiceConnectorBase {
: ServiceConnectorBase(name), delete_count_(delete_count) {}
virtual ~TestConnector() { (*delete_count_)++; }
virtual void ConnectToService(
- const std::string& url,
const std::string& name,
ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE {}
private:
@@ -29,14 +28,14 @@ TEST(ServiceRegistryTest, Ownership) {
// Destruction.
{
- ServiceRegistry registry(NULL);
+ ServiceRegistry registry;
registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
}
EXPECT_EQ(1, delete_count);
// Removal.
{
- ServiceRegistry registry(NULL);
+ ServiceRegistry registry;
ServiceConnectorBase* c = new TestConnector("TC1", &delete_count);
registry.AddServiceConnector(c);
registry.RemoveServiceConnector(c);
@@ -45,7 +44,7 @@ TEST(ServiceRegistryTest, Ownership) {
// Multiple.
{
- ServiceRegistry registry(NULL);
+ ServiceRegistry registry;
registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
registry.AddServiceConnector(new TestConnector("TC2", &delete_count));
}
@@ -53,7 +52,7 @@ TEST(ServiceRegistryTest, Ownership) {
// Re-addition.
{
- ServiceRegistry registry(NULL);
+ ServiceRegistry registry;
registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
registry.AddServiceConnector(new TestConnector("TC1", &delete_count));
EXPECT_EQ(5, delete_count);
diff --git a/mojo/public/interfaces/service_provider/service_provider.mojom b/mojo/public/interfaces/service_provider/service_provider.mojom
index 190c85c..de7ddf5 100644
--- a/mojo/public/interfaces/service_provider/service_provider.mojom
+++ b/mojo/public/interfaces/service_provider/service_provider.mojom
@@ -2,18 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// Quick definitions:
+// The Shell is the finder and launcher of Applications.
+// Applications vend Services through the ServiceProvider interface.
+// Services implement Interfaces.
+// An Application uses it's Shell interface to connect to other Applications.
module mojo {
[Client=ServiceProvider]
interface ServiceProvider {
+ // Loads url. mojo:{service} will result in the the value of the
+ // --origin flag to the shell being used.
+ ConnectToService(string interface_name, handle<message_pipe> client_handle);
+};
+
+// TODO(davemore): Break Application & Shell into their own files.
+[Client=Application]
+interface Shell {
// Loads url. mojo:{service} will result in the user of the value of the
// --origin flag to the shell being used.
- ConnectToService(string service_url,
- string service_name,
- handle<message_pipe> client_handle,
- // ignored for client making request, filled in by system for
- // implementor.
- string requestor_url);
+ ConnectToApplication(string application_url, ServiceProvider& provider);
+};
+
+[Client=Shell]
+interface Application {
+ AcceptConnection(string requestor_url, ServiceProvider provider);
};
}
diff --git a/mojo/service_manager/background_service_loader.cc b/mojo/service_manager/background_service_loader.cc
index 96a2c43..15e8c32 100644
--- a/mojo/service_manager/background_service_loader.cc
+++ b/mojo/service_manager/background_service_loader.cc
@@ -16,8 +16,8 @@ class BackgroundServiceLoader::BackgroundLoader {
void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_provider_handle) {
- loader_->LoadService(manager, url, service_provider_handle.Pass());
+ ScopedMessagePipeHandle shell_handle) {
+ loader_->LoadService(manager, url, shell_handle.Pass());
}
void OnServiceError(ServiceManager* manager, const GURL& url) {
@@ -54,7 +54,7 @@ BackgroundServiceLoader::~BackgroundServiceLoader() {
void BackgroundServiceLoader::LoadService(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) {
+ ScopedMessagePipeHandle shell_handle) {
const int kDefaultStackSize = 0;
if (!thread_.IsRunning())
thread_.StartWithOptions(
@@ -64,7 +64,7 @@ void BackgroundServiceLoader::LoadService(
base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread,
base::Unretained(this), manager, url,
base::Owned(
- new ScopedMessagePipeHandle(service_handle.Pass()))));
+ new ScopedMessagePipeHandle(shell_handle.Pass()))));
}
void BackgroundServiceLoader::OnServiceError(ServiceManager* manager,
@@ -80,11 +80,11 @@ void BackgroundServiceLoader::OnServiceError(ServiceManager* manager,
void BackgroundServiceLoader::LoadServiceOnBackgroundThread(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle* service_provider_handle) {
+ ScopedMessagePipeHandle* shell_handle) {
if (!background_loader_)
background_loader_ = new BackgroundLoader(loader_.get());
background_loader_->LoadService(
- manager, url, service_provider_handle->Pass());
+ manager, url, shell_handle->Pass());
}
void BackgroundServiceLoader::OnServiceErrorOnBackgroundThread(
diff --git a/mojo/service_manager/background_service_loader.h b/mojo/service_manager/background_service_loader.h
index 59dbc0f..253637a 100644
--- a/mojo/service_manager/background_service_loader.h
+++ b/mojo/service_manager/background_service_loader.h
@@ -27,7 +27,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader
// ServiceLoader overrides:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) OVERRIDE;
+ ScopedMessagePipeHandle shell_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE;
@@ -41,7 +41,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader
void LoadServiceOnBackgroundThread(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle* service_provider_handle);
+ ScopedMessagePipeHandle* shell_handle);
void OnServiceErrorOnBackgroundThread(ServiceManager* manager,
const GURL& url);
void ShutdownOnBackgroundThread();
diff --git a/mojo/service_manager/service_loader.h b/mojo/service_manager/service_loader.h
index 32c15cc..e69e0fd 100644
--- a/mojo/service_manager/service_loader.h
+++ b/mojo/service_manager/service_loader.h
@@ -6,6 +6,7 @@
#define MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_
#include "mojo/public/cpp/system/core.h"
+#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/service_manager/service_manager_export.h"
#include "url/gurl.h"
@@ -13,14 +14,20 @@ namespace mojo {
class ServiceManager;
-// Interface to allowing default loading behavior to be overridden for a
-// specific url.
+// Interface to allowing loading behavior to be established for schemes,
+// specific urls or as the default.
+// A ServiceLoader is responsible to using whatever mechanism is appropriate
+// to load the application at url.
+// TODO(davemoore): change name to ApplicationLoader.
+// The handle to the shell is passed to that application so it can bind it to
+// a Shell instance. This will give the Application a way to connect to other
+// apps and services.
class MOJO_SERVICE_MANAGER_EXPORT ServiceLoader {
public:
virtual ~ServiceLoader() {}
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) = 0;
+ ScopedMessagePipeHandle shell_handle) = 0;
virtual void OnServiceError(ServiceManager* manager, const GURL& url) = 0;
protected:
diff --git a/mojo/service_manager/service_manager.cc b/mojo/service_manager/service_manager.cc
index 060ca4f..65a93bd 100644
--- a/mojo/service_manager/service_manager.cc
+++ b/mojo/service_manager/service_manager.cc
@@ -17,76 +17,59 @@ namespace mojo {
namespace {
// Used by TestAPI.
bool has_created_instance = false;
+
+class StubServiceProvider : public InterfaceImpl<ServiceProvider> {
+ public:
+ ServiceProvider* GetRemoteServiceProvider() {
+ return client();
+ }
+
+ private:
+ virtual void ConnectToService(
+ const String& service_name,
+ ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE {}
+};
+
}
-class ServiceManager::ServiceFactory : public InterfaceImpl<ServiceProvider> {
+class ServiceManager::ShellImpl : public InterfaceImpl<Shell> {
public:
- ServiceFactory(ServiceManager* manager, const GURL& url)
+ ShellImpl(ServiceManager* manager, const GURL& url)
: manager_(manager),
url_(url) {
}
- virtual ~ServiceFactory() {
+ virtual ~ShellImpl() {
}
- void ConnectToClient(const std::string& service_name,
- ScopedMessagePipeHandle handle,
- const GURL& requestor_url) {
- if (handle.is_valid()) {
- client()->ConnectToService(
- url_.spec(), service_name, handle.Pass(), requestor_url.spec());
- }
+ void ConnectToClient(const GURL& requestor_url,
+ ServiceProviderPtr service_provider) {
+ client()->AcceptConnection(requestor_url.spec(), service_provider.Pass());
}
// ServiceProvider implementation:
- virtual void ConnectToService(const String& service_url,
- const String& service_name,
- ScopedMessagePipeHandle client_pipe,
- const String& requestor_url) OVERRIDE {
- // Ignore provided requestor_url and use url from connection.
- manager_->ConnectToService(
- GURL(service_url), service_name, client_pipe.Pass(), url_);
+ virtual void ConnectToApplication(
+ const String& app_url,
+ InterfaceRequest<ServiceProvider> in_service_provider) OVERRIDE {
+ ServiceProviderPtr out_service_provider;
+ out_service_provider.Bind(in_service_provider.PassMessagePipe());
+ manager_->ConnectToApplication(
+ GURL(app_url),
+ url_,
+ out_service_provider.Pass());
}
const GURL& url() const { return url_; }
private:
virtual void OnConnectionError() OVERRIDE {
- manager_->OnServiceFactoryError(this);
+ manager_->OnShellImplError(this);
}
ServiceManager* const manager_;
const GURL url_;
- DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
-};
-
-class ServiceManager::TestAPI::TestServiceProviderConnection
- : public InterfaceImpl<ServiceProvider> {
- public:
- explicit TestServiceProviderConnection(ServiceManager* manager)
- : manager_(manager) {}
- virtual ~TestServiceProviderConnection() {}
-
- virtual void OnConnectionError() OVERRIDE {
- // TODO(darin): How should we handle this error?
- }
-
- // ServiceProvider:
- virtual void ConnectToService(const String& service_url,
- const String& service_name,
- ScopedMessagePipeHandle client_pipe,
- const String& requestor_url) OVERRIDE {
- manager_->ConnectToService(GURL(service_url),
- service_name,
- client_pipe.Pass(),
- GURL(requestor_url));
- }
-
- private:
- ServiceManager* manager_;
-
- DISALLOW_COPY_AND_ASSIGN(TestServiceProviderConnection);
+ DISALLOW_COPY_AND_ASSIGN(ShellImpl);
};
// static
@@ -100,25 +83,16 @@ bool ServiceManager::TestAPI::HasCreatedInstance() {
return has_created_instance;
}
-ScopedMessagePipeHandle ServiceManager::TestAPI::GetServiceProviderHandle() {
- MessagePipe pipe;
- service_provider_.reset(
- BindToPipe(new TestServiceProviderConnection(manager_),
- pipe.handle0.Pass()));
- return pipe.handle1.Pass();
-}
-
bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
- return manager_->url_to_service_factory_.find(url) !=
- manager_->url_to_service_factory_.end();
+ return manager_->url_to_shell_impl_.find(url) !=
+ manager_->url_to_shell_impl_.end();
}
-ServiceManager::ServiceManager()
- : interceptor_(NULL) {
+ServiceManager::ServiceManager() : interceptor_(NULL) {
}
ServiceManager::~ServiceManager() {
- STLDeleteValues(&url_to_service_factory_);
+ STLDeleteValues(&url_to_shell_impl_);
STLDeleteValues(&url_to_loader_);
STLDeleteValues(&scheme_to_loader_);
}
@@ -131,31 +105,25 @@ ServiceManager* ServiceManager::GetInstance() {
return &instance.Get();
}
-void ServiceManager::ConnectToService(const GURL& url,
- const std::string& name,
- ScopedMessagePipeHandle client_handle,
- const GURL& requestor_url) {
- URLToServiceFactoryMap::const_iterator service_it =
- url_to_service_factory_.find(url);
- ServiceFactory* service_factory;
- if (service_it != url_to_service_factory_.end()) {
- service_factory = service_it->second;
+void ServiceManager::ConnectToApplication(const GURL& url,
+ const GURL& requestor_url,
+ ServiceProviderPtr service_provider) {
+ URLToShellImplMap::const_iterator shell_it = url_to_shell_impl_.find(url);
+ ShellImpl* shell_impl;
+ if (shell_it != url_to_shell_impl_.end()) {
+ shell_impl = shell_it->second;
} else {
MessagePipe pipe;
GetLoaderForURL(url)->LoadService(this, url, pipe.handle0.Pass());
-
- service_factory =
- BindToPipe(new ServiceFactory(this, url), pipe.handle1.Pass());
-
- url_to_service_factory_[url] = service_factory;
+ shell_impl = BindToPipe(new ShellImpl(this, url), pipe.handle1.Pass());
+ url_to_shell_impl_[url] = shell_impl;
}
if (interceptor_) {
- service_factory->ConnectToClient(
- name,
- interceptor_->OnConnectToClient(url, client_handle.Pass()),
- requestor_url);
+ shell_impl->ConnectToClient(
+ requestor_url,
+ interceptor_->OnConnectToClient(url, service_provider.Pass()));
} else {
- service_factory->ConnectToClient(name, client_handle.Pass(), requestor_url);
+ shell_impl->ConnectToClient(requestor_url, service_provider.Pass());
}
}
@@ -191,16 +159,28 @@ ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& url) {
return default_loader_.get();
}
-void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) {
- // Called from ~ServiceFactory, so we do not need to call Destroy here.
- const GURL url = service_factory->url();
- URLToServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
- DCHECK(it != url_to_service_factory_.end());
+void ServiceManager::OnShellImplError(ShellImpl* shell_impl) {
+ // Called from ~ShellImpl, so we do not need to call Destroy here.
+ const GURL url = shell_impl->url();
+ URLToShellImplMap::iterator it = url_to_shell_impl_.find(url);
+ DCHECK(it != url_to_shell_impl_.end());
delete it->second;
- url_to_service_factory_.erase(it);
+ url_to_shell_impl_.erase(it);
ServiceLoader* loader = GetLoaderForURL(url);
if (loader)
loader->OnServiceError(this, url);
}
+ScopedMessagePipeHandle ServiceManager::ConnectToServiceByName(
+ const GURL& application_url,
+ const std::string& interface_name) {
+ StubServiceProvider* stub_sp = new StubServiceProvider;
+ ServiceProviderPtr spp;
+ BindToProxy(stub_sp, &spp);
+ ConnectToApplication(GURL(application_url), GURL(), spp.Pass());
+ MessagePipe pipe;
+ stub_sp->GetRemoteServiceProvider()->ConnectToService(
+ interface_name, pipe.handle1.Pass());
+ return pipe.handle0.Pass();
+}
} // namespace mojo
diff --git a/mojo/service_manager/service_manager.h b/mojo/service_manager/service_manager.h
index 170e3b7..97c260e 100644
--- a/mojo/service_manager/service_manager.h
+++ b/mojo/service_manager/service_manager.h
@@ -25,19 +25,13 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
explicit TestAPI(ServiceManager* manager);
~TestAPI();
- // Returns a handle to a unique ServiceProvider instance.
- ScopedMessagePipeHandle GetServiceProviderHandle();
-
// Returns true if the shared instance has been created.
static bool HasCreatedInstance();
- // Returns true if there is a ServiceFactory for this URL.
+ // Returns true if there is a ShellImpl for this URL.
bool HasFactoryForURL(const GURL& url) const;
private:
- class TestServiceProviderConnection;
-
ServiceManager* manager_;
- scoped_ptr<TestServiceProviderConnection> service_provider_;
DISALLOW_COPY_AND_ASSIGN(TestAPI);
};
@@ -47,8 +41,8 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
public:
virtual ~Interceptor() {}
// Called when ServiceManager::Connect is called.
- virtual ScopedMessagePipeHandle OnConnectToClient(
- const GURL& url, ScopedMessagePipeHandle handle) = 0;
+ virtual ServiceProviderPtr OnConnectToClient(
+ const GURL& url, ServiceProviderPtr service_provider) = 0;
};
ServiceManager();
@@ -58,23 +52,22 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
static ServiceManager* GetInstance();
// Loads a service if necessary and establishes a new client connection.
- void ConnectToService(const GURL& service_url,
- const std::string& service_name,
- ScopedMessagePipeHandle client_handle,
- const GURL& requestor_url);
+ void ConnectToApplication(const GURL& application_url,
+ const GURL& requestor_url,
+ ServiceProviderPtr service_provider);
template <typename Interface>
- void ConnectTo(const GURL& service_url,
- InterfacePtr<Interface>* ptr,
- const GURL& requestor_url) {
- MessagePipe pipe;
- ptr->Bind(pipe.handle0.Pass());
- ConnectToService(service_url,
- Interface::Name_,
- pipe.handle1.Pass(),
- requestor_url);
+ inline void ConnectToService(const GURL& application_url,
+ InterfacePtr<Interface>* ptr) {
+ ScopedMessagePipeHandle service_handle =
+ ConnectToServiceByName(application_url, Interface::Name_);
+ ptr->Bind(service_handle.Pass());
}
+ ScopedMessagePipeHandle ConnectToServiceByName(
+ const GURL& application_url,
+ const std::string& interface_name);
+
// Sets the default Loader to be used if not overridden by SetLoaderForURL()
// or SetLoaderForScheme().
void set_default_loader(scoped_ptr<ServiceLoader> loader) {
@@ -89,18 +82,18 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
void SetInterceptor(Interceptor* interceptor);
private:
- class ServiceFactory;
+ class ShellImpl;
typedef std::map<std::string, ServiceLoader*> SchemeToLoaderMap;
typedef std::map<GURL, ServiceLoader*> URLToLoaderMap;
- typedef std::map<GURL, ServiceFactory*> URLToServiceFactoryMap;
+ typedef std::map<GURL, ShellImpl*> URLToShellImplMap;
// Returns the Loader to use for a url (using default if not overridden.)
// The preference is to use a loader that's been specified for an url first,
// then one that's been specified for a scheme, then the default.
ServiceLoader* GetLoaderForURL(const GURL& url);
- // Removes a ServiceFactory when it encounters an error.
- void OnServiceFactoryError(ServiceFactory* service_factory);
+ // Removes a ShellImpl when it encounters an error.
+ void OnShellImplError(ShellImpl* shell_impl);
// Loader management.
URLToLoaderMap url_to_loader_;
@@ -108,7 +101,8 @@ class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
scoped_ptr<ServiceLoader> default_loader_;
Interceptor* interceptor_;
- URLToServiceFactoryMap url_to_service_factory_;
+ URLToShellImplMap url_to_shell_impl_;
+
DISALLOW_COPY_AND_ASSIGN(ServiceManager);
};
diff --git a/mojo/service_manager/service_manager_unittest.cc b/mojo/service_manager/service_manager_unittest.cc
index a212201..f485600 100644
--- a/mojo/service_manager/service_manager_unittest.cc
+++ b/mojo/service_manager/service_manager_unittest.cc
@@ -3,8 +3,11 @@
// found in the LICENSE file.
#include "base/at_exit.h"
+#include "base/bind.h"
#include "base/message_loop/message_loop.h"
-#include "mojo/public/cpp/application/application.h"
+#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/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/service_manager/service_loader.h"
#include "mojo/service_manager/service_manager.h"
@@ -41,7 +44,8 @@ class QuitMessageLoopErrorHandler : public ErrorHandler {
class TestServiceImpl : public InterfaceImpl<TestService> {
public:
- explicit TestServiceImpl(TestContext* context) : context_(context) {
+ explicit TestServiceImpl(ApplicationConnection* connection,
+ TestContext* context) : context_(context) {
++context_->num_impls;
}
@@ -50,6 +54,8 @@ class TestServiceImpl : public InterfaceImpl<TestService> {
}
virtual void OnConnectionError() OVERRIDE {
+ if (!base::MessageLoop::current()->is_running())
+ return;
base::MessageLoop::current()->Quit();
}
@@ -71,7 +77,9 @@ class TestClientImpl : public TestClient {
service_.set_client(this);
}
- virtual ~TestClientImpl() {}
+ virtual ~TestClientImpl() {
+ service_.reset();
+ }
virtual void AckTest() OVERRIDE {
if (quit_after_ack_)
@@ -89,7 +97,8 @@ class TestClientImpl : public TestClient {
DISALLOW_COPY_AND_ASSIGN(TestClientImpl);
};
-class TestServiceLoader : public ServiceLoader {
+class TestServiceLoader : public ServiceLoader,
+ public ApplicationDelegate {
public:
TestServiceLoader()
: context_(NULL),
@@ -111,86 +120,174 @@ class TestServiceLoader : public ServiceLoader {
const GURL& url,
ScopedMessagePipeHandle service_provider_handle) OVERRIDE {
++num_loads_;
- test_app_.reset(new Application(service_provider_handle.Pass()));
- test_app_->AddService<TestServiceImpl>(context_);
+ test_app_.reset(new ApplicationImpl(this, service_provider_handle.Pass()));
}
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE {
}
- scoped_ptr<Application> test_app_;
+ virtual bool ConfigureIncomingConnection(
+ ApplicationConnection* connection) OVERRIDE {
+ connection->AddService<TestServiceImpl>(context_);
+ return true;
+ }
+
+ scoped_ptr<ApplicationImpl> test_app_;
TestContext* context_;
int num_loads_;
DISALLOW_COPY_AND_ASSIGN(TestServiceLoader);
};
+struct TesterContext {
+ TesterContext()
+ : num_b_calls(0),
+ num_c_calls(0),
+ num_a_deletes(0),
+ num_b_deletes(0),
+ num_c_deletes(0),
+ tester_called_quit(false),
+ a_called_quit(false) {}
+ int num_b_calls;
+ int num_c_calls;
+ int num_a_deletes;
+ int num_b_deletes;
+ int num_c_deletes;
+ bool tester_called_quit;
+ bool a_called_quit;
+};
+
// Used to test that the requestor url will be correctly passed.
class TestAImpl : public InterfaceImpl<TestA> {
public:
- explicit TestAImpl(Application* app) : app_(app) {}
-
- virtual void LoadB() OVERRIDE {
- TestBPtr b;
- app_->ConnectTo(kTestBURLString, &b);
- b->Test();
+ explicit TestAImpl(ApplicationConnection* connection,
+ TesterContext* test_context)
+ : test_context_(test_context) {
+ connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_);
}
+ virtual ~TestAImpl() { test_context_->num_a_deletes++; }
private:
- Application* app_;
+ virtual void CallB() OVERRIDE {
+ b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
+ }
+
+ virtual void CallCFromB() OVERRIDE {
+ b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
+ }
+
+ void Quit() {
+ test_context_->a_called_quit = true;
+ base::MessageLoop::current()->Quit();
+ }
+
+ TesterContext* test_context_;
+ TestBPtr b_;
};
class TestBImpl : public InterfaceImpl<TestB> {
public:
- virtual void Test() OVERRIDE {
+ explicit TestBImpl(ApplicationConnection* connection,
+ TesterContext* test_context)
+ : test_context_(test_context) {
+ connection->ConnectToService(&c_);
+ }
+
+ virtual ~TestBImpl() {
+ test_context_->num_b_deletes++;
+ if (!base::MessageLoop::current()->is_running())
+ return;
base::MessageLoop::current()->Quit();
}
+
+ private:
+ virtual void B(const mojo::Callback<void()>& callback) OVERRIDE {
+ ++test_context_->num_b_calls;
+ callback.Run();
+ }
+
+ virtual void CallC(const mojo::Callback<void()>& callback) OVERRIDE {
+ ++test_context_->num_b_calls;
+ c_->C(callback);
+ }
+
+ TesterContext* test_context_;
+ TestCPtr c_;
};
-class TestApp : public Application, public ServiceLoader {
+class TestCImpl : public InterfaceImpl<TestC> {
public:
- explicit TestApp(std::string requestor_url)
- : requestor_url_(requestor_url),
- num_connects_(0) {
+ explicit TestCImpl(ApplicationConnection* connection,
+ TesterContext* test_context)
+ : test_context_(test_context) {
+ }
+
+ virtual ~TestCImpl() { test_context_->num_c_deletes++; }
+
+ private:
+ virtual void C(const mojo::Callback<void()>& callback) OVERRIDE {
+ ++test_context_->num_c_calls;
+ callback.Run();
}
+ TesterContext* test_context_;
+};
- int num_connects() const { return num_connects_; }
+class Tester : public ApplicationDelegate, public ServiceLoader {
+ public:
+ Tester(TesterContext* context, const std::string& requestor_url)
+ : context_(context),
+ requestor_url_(requestor_url) {}
+ virtual ~Tester() {}
private:
virtual void LoadService(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_provider_handle) OVERRIDE {
- BindServiceProvider(service_provider_handle.Pass());
+ ScopedMessagePipeHandle shell_handle) OVERRIDE {
+ app_.reset(new ApplicationImpl(this, shell_handle.Pass()));
}
- virtual bool AllowIncomingConnection(const mojo::String& service_name,
- const mojo::String& requestor_url)
- MOJO_OVERRIDE {
- if (requestor_url_.empty() || requestor_url_ == requestor_url) {
- ++num_connects_;
- return true;
- } else {
+ virtual void OnServiceError(ServiceManager* manager,
+ const GURL& url) OVERRIDE {}
+
+ virtual bool ConfigureIncomingConnection(
+ ApplicationConnection* connection) OVERRIDE {
+ if (!requestor_url_.empty() &&
+ requestor_url_ != connection->GetRemoteApplicationURL()) {
+ context_->tester_called_quit = true;
base::MessageLoop::current()->Quit();
return false;
}
+ // If we're coming from A, then add B, otherwise A.
+ if (connection->GetRemoteApplicationURL() == kTestAURLString)
+ connection->AddService<TestBImpl>(context_);
+ else
+ connection->AddService<TestAImpl>(context_);
+ return true;
}
- virtual void OnServiceError(ServiceManager* manager,
- const GURL& url) OVERRIDE {}
+ virtual bool ConfigureOutgoingConnection(
+ ApplicationConnection* connection) OVERRIDE {
+ // If we're connecting to B, then add C.
+ if (connection->GetRemoteApplicationURL() == kTestBURLString)
+ connection->AddService<TestCImpl>(context_);
+ return true;
+ }
+
+ TesterContext* context_;
+ scoped_ptr<ApplicationImpl> app_;
std::string requestor_url_;
- int num_connects_;
};
class TestServiceInterceptor : public ServiceManager::Interceptor {
public:
TestServiceInterceptor() : call_count_(0) {}
- virtual ScopedMessagePipeHandle OnConnectToClient(
- const GURL& url, ScopedMessagePipeHandle handle) OVERRIDE {
+ virtual ServiceProviderPtr OnConnectToClient(
+ const GURL& url, ServiceProviderPtr service_provider) OVERRIDE {
++call_count_;
url_ = url;
- return handle.Pass();
+ return service_provider.Pass();
}
std::string url_spec() const {
@@ -218,20 +315,15 @@ class ServiceManagerTest : public testing::Test {
virtual ~ServiceManagerTest() {}
virtual void SetUp() OVERRIDE {
- GURL test_url(kTestURLString);
service_manager_.reset(new ServiceManager);
-
- MessagePipe pipe;
- TestServicePtr service_proxy = MakeProxy<TestService>(pipe.handle0.Pass());
- test_client_.reset(new TestClientImpl(service_proxy.Pass()));
-
TestServiceLoader* default_loader = new TestServiceLoader;
default_loader->set_context(&context_);
service_manager_->set_default_loader(
scoped_ptr<ServiceLoader>(default_loader));
- service_manager_->ConnectToService(
- test_url, TestService::Name_, pipe.handle1.Pass(), GURL());
+ TestServicePtr service_proxy;
+ service_manager_->ConnectToService(GURL(kTestURLString), &service_proxy);
+ test_client_.reset(new TestClientImpl(service_proxy.Pass()));
}
virtual void TearDown() OVERRIDE {
@@ -306,19 +398,19 @@ TEST_F(ServiceManagerTest, SetLoaders) {
// test::test1 should go to url_loader.
TestServicePtr test_service;
- sm.ConnectTo(GURL("test:test1"), &test_service, GURL());
+ sm.ConnectToService(GURL("test:test1"), &test_service);
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(0, scheme_loader->num_loads());
EXPECT_EQ(0, default_loader->num_loads());
// test::test2 should go to scheme loader.
- sm.ConnectTo(GURL("test:test2"), &test_service, GURL());
+ sm.ConnectToService(GURL("test:test2"), &test_service);
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(1, scheme_loader->num_loads());
EXPECT_EQ(0, default_loader->num_loads());
// http::test1 should go to default loader.
- sm.ConnectTo(GURL("http:test1"), &test_service, GURL());
+ sm.ConnectToService(GURL("http:test1"), &test_service);
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(1, scheme_loader->num_loads());
EXPECT_EQ(1, default_loader->num_loads());
@@ -326,66 +418,122 @@ TEST_F(ServiceManagerTest, SetLoaders) {
// Confirm that the url of a service is correctly passed to another service that
// it loads.
-TEST_F(ServiceManagerTest, ALoadB) {
+TEST_F(ServiceManagerTest, ACallB) {
+ TesterContext context;
ServiceManager sm;
// Any url can load a.
- TestApp* a_app = new TestApp(std::string());
- a_app->AddService<TestAImpl>(a_app);
- sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(a_app), GURL(kTestAURLString));
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(new Tester(&context, std::string())),
+ GURL(kTestAURLString));
// Only a can load b.
- TestApp* b_app = new TestApp(kTestAURLString);
- b_app->AddService<TestBImpl>();
- sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(b_app), GURL(kTestBURLString));
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(
+ new Tester(&context, kTestAURLString)),
+ GURL(kTestBURLString));
TestAPtr a;
- sm.ConnectTo(GURL(kTestAURLString), &a, GURL());
- a->LoadB();
+ sm.ConnectToService(GURL(kTestAURLString), &a);
+ a->CallB();
loop_.Run();
- EXPECT_EQ(1, b_app->num_connects());
+ EXPECT_EQ(1, context.num_b_calls);
+ EXPECT_TRUE(context.a_called_quit);
+}
+
+// A calls B which calls C.
+TEST_F(ServiceManagerTest, BCallC) {
+ TesterContext context;
+ ServiceManager sm;
+
+ // Any url can load a.
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(new Tester(&context, std::string())),
+ GURL(kTestAURLString));
+
+ // Only a can load b.
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(
+ new Tester(&context, kTestAURLString)),
+ GURL(kTestBURLString));
+
+ TestAPtr a;
+ sm.ConnectToService(GURL(kTestAURLString), &a);
+ a->CallCFromB();
+ loop_.Run();
+
+ EXPECT_EQ(1, context.num_b_calls);
+ EXPECT_EQ(1, context.num_c_calls);
+ EXPECT_TRUE(context.a_called_quit);
+}
+
+// Confirm that a service impl will be deleted if the app that connected to
+// it goes away.
+TEST_F(ServiceManagerTest, BDeleted) {
+ TesterContext context;
+ ServiceManager sm;
+
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(new Tester(&context, std::string())),
+ GURL(kTestAURLString));
+
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>( new Tester(&context, std::string())),
+ GURL(kTestBURLString));
+
+ TestAPtr a;
+ sm.ConnectToService(GURL(kTestAURLString), &a);
+
+ a->CallB();
+ loop_.Run();
+
+ // Kills the a app.
+ sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(), GURL(kTestAURLString));
+ loop_.Run();
+ EXPECT_EQ(1, context.num_b_deletes);
}
// Confirm that the url of a service is correctly passed to another service that
// it loads, and that it can be rejected.
TEST_F(ServiceManagerTest, ANoLoadB) {
+ TesterContext context;
ServiceManager sm;
// Any url can load a.
- TestApp* a_app = new TestApp(std::string());
- a_app->AddService<TestAImpl>(a_app);
- sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(a_app), GURL(kTestAURLString));
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(new Tester(&context, std::string())),
+ GURL(kTestAURLString));
// Only c can load b, so this will fail.
- TestApp* b_app = new TestApp("test:TestC");
- b_app->AddService<TestBImpl>();
- sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(b_app), GURL(kTestBURLString));
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(new Tester(&context, "test:TestC")),
+ GURL(kTestBURLString));
TestAPtr a;
- sm.ConnectTo(GURL(kTestAURLString), &a, GURL());
- a->LoadB();
+ sm.ConnectToService(GURL(kTestAURLString), &a);
+ a->CallB();
loop_.Run();
- EXPECT_EQ(0, b_app->num_connects());
+ EXPECT_EQ(0, context.num_b_calls);
+ EXPECT_TRUE(context.tester_called_quit);
}
TEST_F(ServiceManagerTest, NoServiceNoLoad) {
+ TesterContext context;
ServiceManager sm;
- TestApp* b_app = new TestApp(std::string());
- b_app->AddService<TestBImpl>();
- sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(b_app), GURL(kTestBURLString));
+ sm.SetLoaderForURL(
+ scoped_ptr<ServiceLoader>(new Tester(&context, std::string())),
+ GURL(kTestAURLString));
- // There is no TestA service implementation registered with ServiceManager,
+ // There is no TestC service implementation registered with ServiceManager,
// so this cannot succeed (but also shouldn't crash).
- TestAPtr a;
- sm.ConnectTo(GURL(kTestBURLString), &a, GURL());
+ TestCPtr c;
+ sm.ConnectToService(GURL(kTestAURLString), &c);
QuitMessageLoopErrorHandler quitter;
- a.set_error_handler(&quitter);
- a->LoadB();
+ c.set_error_handler(&quitter);
loop_.Run();
- EXPECT_TRUE(a.encountered_error());
- EXPECT_EQ(0, b_app->num_connects());
+ EXPECT_TRUE(c.encountered_error());
}
TEST_F(ServiceManagerTest, Interceptor) {
@@ -397,7 +545,8 @@ TEST_F(ServiceManagerTest, Interceptor) {
std::string url("test:test3");
TestServicePtr test_service;
- sm.ConnectTo(GURL(url), &test_service, GURL());
+ sm.ConnectToService(GURL(url), &test_service);
+
EXPECT_EQ(1, interceptor.call_count());
EXPECT_EQ(url, interceptor.url_spec());
EXPECT_EQ(1, default_loader->num_loads());
diff --git a/mojo/service_manager/test.mojom b/mojo/service_manager/test.mojom
index 47921cd..868a4d3 100644
--- a/mojo/service_manager/test.mojom
+++ b/mojo/service_manager/test.mojom
@@ -14,11 +14,17 @@ interface TestClient {
};
interface TestA {
- LoadB();
+ CallB();
+ CallCFromB();
};
interface TestB {
- Test();
+ B() => ();
+ CallC() => ();
+};
+
+interface TestC {
+ C() => ();
};
}
diff --git a/mojo/services/dbus_echo/dbus_echo_service.cc b/mojo/services/dbus_echo/dbus_echo_service.cc
index ae8029f..5243c42 100644
--- a/mojo/services/dbus_echo/dbus_echo_service.cc
+++ b/mojo/services/dbus_echo/dbus_echo_service.cc
@@ -18,7 +18,7 @@
namespace {
class EchoServiceImpl : public mojo::InterfaceImpl<mojo::EchoService> {
public:
- EchoServiceImpl() {}
+ explicit EchoServiceImpl(mojo::ApplicationConnection* connection) {}
virtual ~EchoServiceImpl() {}
protected:
diff --git a/mojo/services/launcher/launcher.cc b/mojo/services/launcher/launcher.cc
index 4a453e0..60c3303 100644
--- a/mojo/services/launcher/launcher.cc
+++ b/mojo/services/launcher/launcher.cc
@@ -5,7 +5,9 @@
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_tokenizer.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
#include "mojo/services/public/interfaces/network/network_service.mojom.h"
@@ -26,7 +28,8 @@ class LauncherApp;
class LauncherConnection : public InterfaceImpl<Launcher> {
public:
- explicit LauncherConnection(LauncherApp* app) : app_(app) {}
+ LauncherConnection(ApplicationConnection* connection, LauncherApp* app)
+ : app_(app) {}
virtual ~LauncherConnection() {}
private:
@@ -91,7 +94,7 @@ class LaunchInstance : public URLLoaderClient {
DISALLOW_COPY_AND_ASSIGN(LaunchInstance);
};
-class LauncherApp : public Application {
+class LauncherApp : public ApplicationDelegate {
public:
LauncherApp() {
handler_map_["text/html"] = "mojo:mojo_html_viewer";
@@ -113,10 +116,15 @@ class LauncherApp : public Application {
private:
typedef std::map<std::string, std::string> HandlerMap;
- // Overridden from Application:
- virtual void Initialize() OVERRIDE {
- AddService<LauncherConnection>(this);
- ConnectTo("mojo:mojo_network_service", &network_service_);
+ // Overridden from ApplicationDelegate:
+ virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
+ app->ConnectToService("mojo:mojo_network_service", &network_service_);
+ }
+
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
+ connection->AddService<LauncherConnection>(this);
+ return true;
}
HandlerMap handler_map_;
@@ -177,7 +185,7 @@ void LaunchInstance::OnReceivedResponse(URLResponsePtr response) {
} // namespace launcher
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new launcher::LauncherApp;
}
diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc
index 886c4dc..9b63c48 100644
--- a/mojo/services/native_viewport/native_viewport_service.cc
+++ b/mojo/services/native_viewport/native_viewport_service.cc
@@ -8,6 +8,7 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/gles2/command_buffer_impl.h"
#include "mojo/services/native_viewport/native_viewport.h"
@@ -32,7 +33,8 @@ class NativeViewportImpl
: public InterfaceImpl<mojo::NativeViewport>,
public NativeViewportDelegate {
public:
- NativeViewportImpl(shell::Context* context)
+ NativeViewportImpl(ApplicationConnection* connection,
+ shell::Context* context)
: context_(context),
widget_(gfx::kNullAcceleratedWidget),
waiting_for_event_ack_(false),
@@ -150,16 +152,31 @@ class NativeViewportImpl
base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
};
+class NVSDelegate : public ApplicationDelegate {
+ public:
+ NVSDelegate(shell::Context* context) : context_(context) {}
+ virtual ~NVSDelegate() {}
+
+ virtual bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
+ connection->AddService<NativeViewportImpl>(context_);
+ return true;
+ }
+
+ private:
+ mojo::shell::Context* context_;
+};
+
+
} // namespace services
} // namespace mojo
-MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
+MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl*
CreateNativeViewportService(
mojo::shell::Context* context,
mojo::ScopedMessagePipeHandle service_provider_handle) {
- mojo::Application* app = new mojo::Application(
- service_provider_handle.Pass());
- app->AddService<mojo::services::NativeViewportImpl>(context);
+ mojo::ApplicationImpl* app = new mojo::ApplicationImpl(
+ new mojo::services::NVSDelegate(context), service_provider_handle.Pass());
return app;
}
diff --git a/mojo/services/native_viewport/native_viewport_service.h b/mojo/services/native_viewport/native_viewport_service.h
index 99b455c..1e6cde8 100644
--- a/mojo/services/native_viewport/native_viewport_service.h
+++ b/mojo/services/native_viewport/native_viewport_service.h
@@ -6,11 +6,11 @@
#define MOJO_SERVICES_NATIVE_VIEWPORT_SERVICE_H_
#include "base/memory/scoped_vector.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/services/native_viewport/native_viewport_export.h"
#include "mojo/shell/context.h"
-MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
+MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl*
CreateNativeViewportService(
mojo::shell::Context* context,
mojo::ScopedMessagePipeHandle service_provider_handle);
diff --git a/mojo/services/network/main.cc b/mojo/services/network/main.cc
index 99b62c5..72943ff 100644
--- a/mojo/services/network/main.cc
+++ b/mojo/services/network/main.cc
@@ -8,7 +8,9 @@
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "mojo/public/cpp/application/application.h"
+#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/bindings/interface_ptr.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
@@ -41,13 +43,14 @@ scoped_ptr<mojo::NetworkContext> CreateContext(
// when http://crbug.com/386485 is implemented.
// Temporarly bind the handle to a service provider to retrieve a profile
// service.
+ mojo::InterfacePtr<mojo::Shell> shell;
+ shell.Bind(handle->Pass());
mojo::InterfacePtr<mojo::ServiceProvider> service_provider;
- service_provider.Bind(handle->Pass());
+ shell->ConnectToApplication("mojo:profile_service", Get(&service_provider));
mojo::InterfacePtr<mojo::ProfileService> profile_service;
- ConnectToService(
- service_provider.get(), "mojo:profile_service", &profile_service);
+ ConnectToService(service_provider.get(), &profile_service);
// Unbind the handle to prevent any message to be read.
- *handle = service_provider.PassMessagePipe();
+ *handle = shell.PassMessagePipe();
// Use a nested message loop to synchronously call a method on the profile
// service.
@@ -66,22 +69,36 @@ scoped_ptr<mojo::NetworkContext> CreateContext(
} // namespace
+class Delegate : public mojo::ApplicationDelegate {
+ public:
+ Delegate(scoped_ptr<mojo::NetworkContext> context)
+ : context_(context.Pass()) {}
+
+ virtual bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
+ connection->AddService<mojo::NetworkServiceImpl>(context_.get());
+ return true;
+ }
+
+ private:
+ scoped_ptr<mojo::NetworkContext> context_;
+};
+
extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
+ MojoHandle shell_handle) {
base::CommandLine::Init(0, NULL);
base::AtExitManager at_exit;
// The IO message loop allows us to use net::URLRequest on this thread.
base::MessageLoopForIO loop;
- mojo::ScopedMessagePipeHandle scoped_service_provider_handle =
- mojo::MakeScopedHandle(mojo::MessagePipeHandle(service_provider_handle));
+ mojo::ScopedMessagePipeHandle scoped_shell_handle =
+ mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle));
scoped_ptr<mojo::NetworkContext> context =
- CreateContext(&scoped_service_provider_handle);
+ CreateContext(&scoped_shell_handle);
- mojo::Application app;
- app.BindServiceProvider(scoped_service_provider_handle.Pass());
- app.AddService<mojo::NetworkServiceImpl>(context.get());
+ Delegate delegate(context.Pass());
+ mojo::ApplicationImpl app(&delegate, scoped_shell_handle.Pass());
loop.Run();
return MOJO_RESULT_OK;
diff --git a/mojo/services/network/network_service_impl.cc b/mojo/services/network/network_service_impl.cc
index a216738..e7da48e 100644
--- a/mojo/services/network/network_service_impl.cc
+++ b/mojo/services/network/network_service_impl.cc
@@ -8,15 +8,15 @@
namespace mojo {
-NetworkServiceImpl::NetworkServiceImpl(NetworkContext* context)
+NetworkServiceImpl::NetworkServiceImpl(ApplicationConnection* connection,
+ NetworkContext* context)
: context_(context) {
}
NetworkServiceImpl::~NetworkServiceImpl() {
}
-void NetworkServiceImpl::CreateURLLoader(
- InterfaceRequest<URLLoader> loader) {
+void NetworkServiceImpl::CreateURLLoader(InterfaceRequest<URLLoader> loader) {
BindToRequest(new URLLoaderImpl(context_), &loader);
}
diff --git a/mojo/services/network/network_service_impl.h b/mojo/services/network/network_service_impl.h
index 32d1713..668569b 100644
--- a/mojo/services/network/network_service_impl.h
+++ b/mojo/services/network/network_service_impl.h
@@ -10,11 +10,13 @@
#include "mojo/services/public/interfaces/network/network_service.mojom.h"
namespace mojo {
+class ApplicationConnection;
class NetworkContext;
class NetworkServiceImpl : public InterfaceImpl<NetworkService> {
public:
- explicit NetworkServiceImpl(NetworkContext* context);
+ NetworkServiceImpl(ApplicationConnection* connection,
+ NetworkContext* context);
virtual ~NetworkServiceImpl();
// NetworkService methods:
diff --git a/mojo/services/profile/profile_service_impl.cc b/mojo/services/profile/profile_service_impl.cc
index 2fe52ac..6af6a6b 100644
--- a/mojo/services/profile/profile_service_impl.cc
+++ b/mojo/services/profile/profile_service_impl.cc
@@ -23,7 +23,7 @@ int BaseKeyForMojoKey(mojo::ProfileService::PathKey key) {
namespace mojo {
-ProfileServiceImpl::ProfileServiceImpl(void* context) {
+ProfileServiceImpl::ProfileServiceImpl(ApplicationConnection* connection) {
}
ProfileServiceImpl::~ProfileServiceImpl() {
diff --git a/mojo/services/profile/profile_service_impl.h b/mojo/services/profile/profile_service_impl.h
index 7a0d03b..b10f18a 100644
--- a/mojo/services/profile/profile_service_impl.h
+++ b/mojo/services/profile/profile_service_impl.h
@@ -11,9 +11,11 @@
namespace mojo {
+class ApplicationConnection;
+
class ProfileServiceImpl : public InterfaceImpl<ProfileService> {
public:
- ProfileServiceImpl(void* context);
+ ProfileServiceImpl(ApplicationConnection* connection);
virtual ~ProfileServiceImpl();
// |ProfileService| methods:
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
index 7575060..d82c8ec 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/lib/node_private.h"
@@ -522,7 +522,8 @@ class SetVisibleTransaction : public ViewManagerTransaction {
DISALLOW_COPY_AND_ASSIGN(SetVisibleTransaction);
};
-ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate)
+ViewManagerClientImpl::ViewManagerClientImpl(ApplicationConnection* connection,
+ ViewManagerDelegate* delegate)
: connected_(false),
connection_id_(0),
next_id_(1),
@@ -644,7 +645,8 @@ void ViewManagerClientImpl::SetVisible(Id node_id, bool visible) {
void ViewManagerClientImpl::Embed(const String& url, Id node_id) {
DCHECK(connected_);
- pending_transactions_.push_back(new EmbedTransaction(url, node_id, this));
+ pending_transactions_.push_back(
+ new EmbedTransaction(url, node_id, this));
Sync();
}
@@ -890,9 +892,10 @@ void ViewManagerClientImpl::RemoveRoot(Node* root) {
// ViewManager, public:
// static
-void ViewManager::Create(Application* application,
- ViewManagerDelegate* delegate) {
- application->AddService<ViewManagerClientImpl>(delegate);
+void ViewManager::ConfigureIncomingConnection(
+ ApplicationConnection* connection,
+ ViewManagerDelegate* delegate) {
+ connection->AddService<ViewManagerClientImpl>(delegate);
}
} // namespace view_manager
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
index 425c0ef..e1b14f29 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
@@ -18,6 +18,7 @@
class SkBitmap;
namespace mojo {
+class ApplicationConnection;
namespace view_manager {
class ViewEventDispatcher;
@@ -28,7 +29,8 @@ class ViewManagerTransaction;
class ViewManagerClientImpl : public ViewManager,
public InterfaceImpl<ViewManagerClient> {
public:
- explicit ViewManagerClientImpl(ViewManagerDelegate* delegate);
+ explicit ViewManagerClientImpl(ApplicationConnection* connection,
+ ViewManagerDelegate* delegate);
virtual ~ViewManagerClientImpl();
bool connected() const { return connected_; }
diff --git a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
index eb98fc7..c9316ea 100644
--- a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
+++ b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
@@ -7,7 +7,9 @@
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/logging.h"
-#include "mojo/public/cpp/application/application.h"
+#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/service_manager/service_manager.h"
#include "mojo/services/public/cpp/view_manager/lib/node_private.h"
#include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
@@ -46,6 +48,7 @@ void WaitForAllChangesToBeAcked(ViewManagerClientImpl* client) {
}
class ConnectServiceLoader : public ServiceLoader,
+ public ApplicationDelegate,
public ViewManagerDelegate {
public:
typedef base::Callback<void(ViewManager*, Node*)> LoadedCallback;
@@ -60,21 +63,28 @@ class ConnectServiceLoader : public ServiceLoader,
virtual void LoadService(ServiceManager* manager,
const GURL& url,
ScopedMessagePipeHandle shell_handle) OVERRIDE {
- scoped_ptr<Application> app(new Application(shell_handle.Pass()));
- ViewManager::Create(app.get(), this);
+ scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this,
+ shell_handle.Pass()));
apps_.push_back(app.release());
}
+
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE {
}
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ OVERRIDE {
+ ViewManager::ConfigureIncomingConnection(connection, this);
+ return true;
+ }
+
// Overridden from ViewManagerDelegate:
virtual void OnRootAdded(ViewManager* view_manager,
Node* root) OVERRIDE {
callback_.Run(view_manager, root);
}
- ScopedVector<Application> apps_;
+ ScopedVector<ApplicationImpl> apps_;
LoadedCallback callback_;
DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader);
@@ -373,9 +383,8 @@ class ViewManagerTest : public testing::Test {
scoped_ptr<ServiceLoader>(new ConnectServiceLoader(ready_callback)),
GURL(kEmbeddedApp1URL));
- ConnectToService(test_helper_.service_provider(),
- "mojo:mojo_view_manager",
- &view_manager_init_);
+ test_helper_.service_manager()->ConnectToService(
+ GURL("mojo:mojo_view_manager"), &view_manager_init_);
ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kWindowManagerURL));
}
diff --git a/mojo/services/public/cpp/view_manager/view_manager.h b/mojo/services/public/cpp/view_manager/view_manager.h
index 9b46387..3c55e307 100644
--- a/mojo/services/public/cpp/view_manager/view_manager.h
+++ b/mojo/services/public/cpp/view_manager/view_manager.h
@@ -12,7 +12,7 @@
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
namespace mojo {
-class Application;
+class ApplicationConnection;
namespace view_manager {
class Node;
@@ -23,7 +23,8 @@ class ViewManagerDelegate;
class ViewManager {
public:
// Delegate is owned by the caller.
- static void Create(Application* application, ViewManagerDelegate* delegate);
+ static void ConfigureIncomingConnection(ApplicationConnection* connection,
+ ViewManagerDelegate* delegate);
// Sets the event dispatcher. Can only be called by the app rendering to the
// root Node of the hierarchy.
diff --git a/mojo/services/test_service/test_service_application.cc b/mojo/services/test_service/test_service_application.cc
index 3737823..5b64973 100644
--- a/mojo/services/test_service/test_service_application.cc
+++ b/mojo/services/test_service/test_service_application.cc
@@ -6,6 +6,7 @@
#include <assert.h>
+#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/services/test_service/test_service_impl.h"
@@ -18,8 +19,10 @@ TestServiceApplication::TestServiceApplication() : ref_count_(0) {
TestServiceApplication::~TestServiceApplication() {
}
-void TestServiceApplication::Initialize() {
- AddService<TestServiceImpl>(this);
+bool TestServiceApplication::ConfigureIncomingConnection(
+ ApplicationConnection* connection) {
+ connection->AddService<TestServiceImpl>(this);
+ return true;
}
void TestServiceApplication::AddRef() {
@@ -37,7 +40,7 @@ void TestServiceApplication::ReleaseRef() {
} // namespace test
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new mojo::test::TestServiceApplication();
}
diff --git a/mojo/services/test_service/test_service_application.h b/mojo/services/test_service/test_service_application.h
index 9f042c1..8892f30 100644
--- a/mojo/services/test_service/test_service_application.h
+++ b/mojo/services/test_service/test_service_application.h
@@ -5,18 +5,20 @@
#ifndef MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_APPLICATION_H_
#define MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_APPLICATION_H_
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
+class ApplicationConnection;
namespace test {
-class TestServiceApplication : public Application {
+class TestServiceApplication : public ApplicationDelegate {
public:
TestServiceApplication();
virtual ~TestServiceApplication();
- virtual void Initialize() MOJO_OVERRIDE;
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE;
void AddRef();
void ReleaseRef();
diff --git a/mojo/services/test_service/test_service_impl.cc b/mojo/services/test_service/test_service_impl.cc
index a38d619..ec65200 100644
--- a/mojo/services/test_service/test_service_impl.cc
+++ b/mojo/services/test_service/test_service_impl.cc
@@ -9,7 +9,8 @@
namespace mojo {
namespace test {
-TestServiceImpl::TestServiceImpl(TestServiceApplication* application)
+TestServiceImpl::TestServiceImpl(ApplicationConnection* connection,
+ TestServiceApplication* application)
: application_(application) {
}
diff --git a/mojo/services/test_service/test_service_impl.h b/mojo/services/test_service/test_service_impl.h
index df2d4a1..c8e272a 100644
--- a/mojo/services/test_service/test_service_impl.h
+++ b/mojo/services/test_service/test_service_impl.h
@@ -9,13 +9,15 @@
#include "mojo/services/test_service/test_service.mojom.h"
namespace mojo {
+class ApplicationConnection;
namespace test {
class TestServiceApplication;
class TestServiceImpl : public InterfaceImpl<ITestService> {
public:
- explicit TestServiceImpl(TestServiceApplication* application);
+ explicit TestServiceImpl(ApplicationConnection* connection,
+ TestServiceApplication* application);
virtual ~TestServiceImpl();
// |ITestService| methods:
diff --git a/mojo/services/view_manager/main.cc b/mojo/services/view_manager/main.cc
index de0a768..d511505 100644
--- a/mojo/services/view_manager/main.cc
+++ b/mojo/services/view_manager/main.cc
@@ -2,22 +2,25 @@
// 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_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/services/view_manager/view_manager_init_service_impl.h"
namespace mojo {
namespace view_manager {
namespace service {
-class ViewManagerApp : public Application {
+class ViewManagerApp : public ApplicationDelegate {
public:
ViewManagerApp() {}
virtual ~ViewManagerApp() {}
- virtual void Initialize() MOJO_OVERRIDE {
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE {
// TODO(sky): this needs some sort of authentication as well as making sure
// we only ever have one active at a time.
- AddService<ViewManagerInitServiceImpl>(service_provider());
+ connection->AddService<ViewManagerInitServiceImpl>();
+ return true;
}
private:
@@ -28,7 +31,7 @@ class ViewManagerApp : public Application {
} // namespace view_manager
// static
-Application* Application::Create() {
+ApplicationDelegate* ApplicationDelegate::Create() {
return new mojo::view_manager::service::ViewManagerApp();
}
diff --git a/mojo/services/view_manager/root_node_manager.cc b/mojo/services/view_manager/root_node_manager.cc
index 10a699c..45df25d 100644
--- a/mojo/services/view_manager/root_node_manager.cc
+++ b/mojo/services/view_manager/root_node_manager.cc
@@ -5,6 +5,7 @@
#include "mojo/services/view_manager/root_node_manager.h"
#include "base/logging.h"
+#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
#include "mojo/services/view_manager/view.h"
@@ -41,12 +42,12 @@ RootNodeManager::Context::~Context() {
aura::Env::DeleteInstance();
}
-RootNodeManager::RootNodeManager(ServiceProvider* service_provider,
+RootNodeManager::RootNodeManager(ApplicationConnection* app_connection,
RootViewManagerDelegate* view_manager_delegate)
- : service_provider_(service_provider),
+ : app_connection_(app_connection),
next_connection_id_(1),
next_server_change_id_(1),
- root_view_manager_(service_provider, this, view_manager_delegate),
+ root_view_manager_(app_connection, this, view_manager_delegate),
root_(this, RootNodeId()),
current_change_(NULL) {
}
@@ -235,11 +236,12 @@ ViewManagerServiceImpl* RootNodeManager::EmbedImpl(
const String& url,
const Array<Id>& node_ids) {
MessagePipe pipe;
- service_provider_->ConnectToService(
- url,
+
+ ServiceProvider* service_provider =
+ app_connection_->ConnectToApplication(url)->GetServiceProvider();
+ service_provider->ConnectToService(
ViewManagerServiceImpl::Client::Name_,
- pipe.handle1.Pass(),
- String());
+ pipe.handle1.Pass());
std::string creator_url;
ConnectionMap::const_iterator it = connection_map_.find(creator_id);
diff --git a/mojo/services/view_manager/root_node_manager.h b/mojo/services/view_manager/root_node_manager.h
index b5098fd..86afa83 100644
--- a/mojo/services/view_manager/root_node_manager.h
+++ b/mojo/services/view_manager/root_node_manager.h
@@ -23,7 +23,7 @@ class Event;
namespace mojo {
-class ServiceProvider;
+class ApplicationConnection;
namespace view_manager {
namespace service {
@@ -81,7 +81,7 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
DISALLOW_COPY_AND_ASSIGN(ScopedChange);
};
- RootNodeManager(ServiceProvider* service_provider,
+ RootNodeManager(ApplicationConnection* app_connection,
RootViewManagerDelegate* view_manager_delegate);
virtual ~RootNodeManager();
@@ -198,7 +198,7 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
Context context_;
- ServiceProvider* service_provider_;
+ ApplicationConnection* app_connection_;
// ID to use for next ViewManagerServiceImpl.
ConnectionSpecificId next_connection_id_;
diff --git a/mojo/services/view_manager/root_view_manager.cc b/mojo/services/view_manager/root_view_manager.cc
index 3f432de..6e7baf0 100644
--- a/mojo/services/view_manager/root_view_manager.cc
+++ b/mojo/services/view_manager/root_view_manager.cc
@@ -6,7 +6,7 @@
#include "base/auto_reset.h"
#include "base/scoped_observer.h"
-#include "mojo/public/cpp/application/connect.h"
+#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/root_view_manager_delegate.h"
#include "mojo/services/view_manager/screen_impl.h"
@@ -116,7 +116,7 @@ class WindowTreeClientImpl : public aura::client::WindowTreeClient {
DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl);
};
-RootViewManager::RootViewManager(ServiceProvider* service_provider,
+RootViewManager::RootViewManager(ApplicationConnection* app_connection,
RootNodeManager* root_node,
RootViewManagerDelegate* delegate)
: delegate_(delegate),
@@ -125,9 +125,8 @@ RootViewManager::RootViewManager(ServiceProvider* service_provider,
screen_.reset(ScreenImpl::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
NativeViewportPtr viewport;
- ConnectToService(service_provider,
- "mojo:mojo_native_viewport_service",
- &viewport);
+ app_connection->ConnectToService(
+ "mojo:mojo_native_viewport_service", &viewport);
window_tree_host_.reset(new WindowTreeHostImpl(
viewport.Pass(),
gfx::Rect(800, 600),
diff --git a/mojo/services/view_manager/root_view_manager.h b/mojo/services/view_manager/root_view_manager.h
index cfec229..8eb3eb5 100644
--- a/mojo/services/view_manager/root_view_manager.h
+++ b/mojo/services/view_manager/root_view_manager.h
@@ -26,7 +26,7 @@ class Screen;
namespace mojo {
-class ServiceProvider;
+class ApplicationConnection;
namespace view_manager {
namespace service {
@@ -37,7 +37,7 @@ class RootViewManagerDelegate;
// RootViewManager binds the root node to an actual display.
class MOJO_VIEW_MANAGER_EXPORT RootViewManager {
public:
- RootViewManager(ServiceProvider* service_provider,
+ RootViewManager(ApplicationConnection* app_connection,
RootNodeManager* root_node,
RootViewManagerDelegate* delegate);
virtual ~RootViewManager();
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.cc b/mojo/services/view_manager/view_manager_init_service_impl.cc
index be2ce15..28c7beb 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_init_service_impl.cc
@@ -9,6 +9,7 @@
#include "mojo/services/view_manager/view_manager_service_impl.h"
namespace mojo {
+class ApplicationConnection;
namespace view_manager {
namespace service {
@@ -17,9 +18,8 @@ ViewManagerInitServiceImpl::ConnectParams::ConnectParams() {}
ViewManagerInitServiceImpl::ConnectParams::~ConnectParams() {}
ViewManagerInitServiceImpl::ViewManagerInitServiceImpl(
- ServiceProvider* service_provider)
- : service_provider_(service_provider),
- root_node_manager_(service_provider, this),
+ ApplicationConnection* connection)
+ : root_node_manager_(connection, this),
is_tree_host_ready_(false) {
}
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.h b/mojo/services/view_manager/view_manager_init_service_impl.h
index 59d438e..b3a0964 100644
--- a/mojo/services/view_manager/view_manager_init_service_impl.h
+++ b/mojo/services/view_manager/view_manager_init_service_impl.h
@@ -16,6 +16,7 @@
namespace mojo {
+class ApplicationConnection;
class ServiceProvider;
namespace view_manager {
@@ -34,7 +35,7 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceImpl
: public InterfaceImpl<ViewManagerInitService>,
public RootViewManagerDelegate {
public:
- explicit ViewManagerInitServiceImpl(ServiceProvider* service_provider);
+ explicit ViewManagerInitServiceImpl(ApplicationConnection* connection);
virtual ~ViewManagerInitServiceImpl();
private:
diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc
index 1e48459..52bcf9e 100644
--- a/mojo/services/view_manager/view_manager_unittest.cc
+++ b/mojo/services/view_manager/view_manager_unittest.cc
@@ -14,7 +14,9 @@
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "mojo/common/common_type_converters.h"
-#include "mojo/public/cpp/application/application.h"
+#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/bindings/lib/router.h"
#include "mojo/service_manager/service_manager.h"
@@ -284,7 +286,8 @@ bool ViewManagerProxy::in_embed_ = false;
class TestViewManagerClientConnection
: public InterfaceImpl<ViewManagerClient> {
public:
- TestViewManagerClientConnection() : connection_(&tracker_) {
+ TestViewManagerClientConnection(ApplicationConnection* app_connection) :
+ connection_(&tracker_) {
tracker_.set_delegate(&connection_);
}
@@ -361,7 +364,7 @@ class TestViewManagerClientConnection
// Used with ViewManagerService::Embed(). Creates a
// TestViewManagerClientConnection, which creates and owns the ViewManagerProxy.
-class EmbedServiceLoader : public ServiceLoader {
+class EmbedServiceLoader : public ServiceLoader, ApplicationDelegate {
public:
EmbedServiceLoader() {}
virtual ~EmbedServiceLoader() {}
@@ -370,16 +373,23 @@ class EmbedServiceLoader : public ServiceLoader {
virtual void LoadService(ServiceManager* manager,
const GURL& url,
ScopedMessagePipeHandle shell_handle) OVERRIDE {
- scoped_ptr<Application> app(new Application(shell_handle.Pass()));
- app->AddService<TestViewManagerClientConnection>();
+ scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this,
+ shell_handle.Pass()));
apps_.push_back(app.release());
}
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE {
}
+ // ApplicationDelegate
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ OVERRIDE {
+ connection->AddService<TestViewManagerClientConnection>();
+ return true;
+ }
+
private:
- ScopedVector<Application> apps_;
+ ScopedVector<ApplicationImpl> apps_;
DISALLOW_COPY_AND_ASSIGN(EmbedServiceLoader);
};
@@ -432,9 +442,9 @@ class ViewManagerTest : public testing::Test {
scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
GURL(kTestServiceURL));
- ConnectToService(test_helper_.service_provider(),
- "mojo:mojo_view_manager",
- &view_manager_init_);
+ test_helper_.service_manager()->ConnectToService(
+ GURL("mojo:mojo_view_manager"),
+ &view_manager_init_);
ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL));
connection_ = ViewManagerProxy::WaitForInstance();
diff --git a/mojo/shell/android/mojo_main.cc b/mojo/shell/android/mojo_main.cc
index c265632..9a574b8 100644
--- a/mojo/shell/android/mojo_main.cc
+++ b/mojo/shell/android/mojo_main.cc
@@ -13,7 +13,6 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "jni/MojoMain_jni.h"
-#include "mojo/public/cpp/application/application.h"
#include "mojo/service_manager/service_loader.h"
#include "mojo/service_manager/service_manager.h"
#include "mojo/shell/context.h"
diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc
index 8fc8aaf..b4fe829 100644
--- a/mojo/shell/context.cc
+++ b/mojo/shell/context.cc
@@ -10,7 +10,7 @@
#include "base/memory/scoped_vector.h"
#include "mojo/embedder/embedder.h"
#include "mojo/gles2/gles2_support_impl.h"
-#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/service_manager/background_service_loader.h"
#include "mojo/service_manager/service_loader.h"
#include "mojo/service_manager/service_manager.h"
@@ -67,8 +67,8 @@ class Context::NativeViewportServiceLoader : public ServiceLoader {
private:
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) OVERRIDE {
- app_.reset(::CreateNativeViewportService(context_, service_handle.Pass()));
+ ScopedMessagePipeHandle shell_handle) OVERRIDE {
+ app_.reset(::CreateNativeViewportService(context_, shell_handle.Pass()));
}
virtual void OnServiceError(ServiceManager* manager,
@@ -76,7 +76,7 @@ class Context::NativeViewportServiceLoader : public ServiceLoader {
}
Context* context_;
- scoped_ptr<Application> app_;
+ scoped_ptr<ApplicationImpl> app_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader);
};
diff --git a/mojo/shell/dbus_service_loader_linux.cc b/mojo/shell/dbus_service_loader_linux.cc
index bd4255c..dfad95f 100644
--- a/mojo/shell/dbus_service_loader_linux.cc
+++ b/mojo/shell/dbus_service_loader_linux.cc
@@ -152,11 +152,11 @@ DBusServiceLoader::~DBusServiceLoader() {
void DBusServiceLoader::LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) {
+ ScopedMessagePipeHandle shell_handle) {
DCHECK(url.SchemeIs("dbus"));
DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end());
url_to_load_context_[url] =
- new LoadContext(this, bus_, url, service_handle.Pass());
+ new LoadContext(this, bus_, url, shell_handle.Pass());
}
void DBusServiceLoader::OnServiceError(ServiceManager* manager,
diff --git a/mojo/shell/dbus_service_loader_linux.h b/mojo/shell/dbus_service_loader_linux.h
index 5bc24ca..a24af5f 100644
--- a/mojo/shell/dbus_service_loader_linux.h
+++ b/mojo/shell/dbus_service_loader_linux.h
@@ -63,7 +63,7 @@ class DBusServiceLoader : public ServiceLoader {
// "/org/chromium/MojoImpl".
virtual void LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) OVERRIDE;
+ ScopedMessagePipeHandle shell_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager, const GURL& url)
OVERRIDE;
diff --git a/mojo/shell/dynamic_service_loader.cc b/mojo/shell/dynamic_service_loader.cc
index 9def450..994e318 100644
--- a/mojo/shell/dynamic_service_loader.cc
+++ b/mojo/shell/dynamic_service_loader.cc
@@ -152,7 +152,7 @@ DynamicServiceLoader::~DynamicServiceLoader() {
void DynamicServiceLoader::LoadService(ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_handle) {
+ ScopedMessagePipeHandle shell_handle) {
scoped_ptr<DynamicServiceRunner> runner = runner_factory_->Create(context_);
GURL resolved_url;
@@ -167,13 +167,13 @@ void DynamicServiceLoader::LoadService(ServiceManager* manager,
loader = new LocalLoader(runner.Pass());
} else {
if (!network_service_.get()) {
- context_->service_manager()->ConnectTo(GURL("mojo:mojo_network_service"),
- &network_service_,
- GURL());
+ context_->service_manager()->ConnectToService(
+ GURL("mojo:mojo_network_service"),
+ &network_service_);
}
loader = new NetworkLoader(runner.Pass(), network_service_.get());
}
- loader->Start(resolved_url, service_handle.Pass(), context_);
+ loader->Start(resolved_url, shell_handle.Pass(), context_);
}
void DynamicServiceLoader::OnServiceError(ServiceManager* manager,
diff --git a/mojo/shell/profile_service_loader.cc b/mojo/shell/profile_service_loader.cc
index 217fa4f..741d2f2 100644
--- a/mojo/shell/profile_service_loader.cc
+++ b/mojo/shell/profile_service_loader.cc
@@ -4,7 +4,9 @@
#include "mojo/shell/profile_service_loader.h"
-#include "mojo/public/cpp/application/application.h"
+#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/services/profile/profile_service_impl.h"
namespace mojo {
@@ -19,13 +21,11 @@ ProfileServiceLoader::~ProfileServiceLoader() {
void ProfileServiceLoader::LoadService(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_provider_handle) {
+ ScopedMessagePipeHandle shell_handle) {
uintptr_t key = reinterpret_cast<uintptr_t>(manager);
if (apps_.find(key) == apps_.end()) {
- scoped_ptr<Application> app(
- new Application(service_provider_handle.Pass()));
- app->AddService<ProfileServiceImpl>(
- app->service_provider());
+ scoped_ptr<ApplicationImpl> app(
+ new ApplicationImpl(this, shell_handle.Pass()));
apps_.add(key, app.Pass());
}
}
@@ -35,5 +35,11 @@ void ProfileServiceLoader::OnServiceError(ServiceManager* manager,
apps_.erase(reinterpret_cast<uintptr_t>(manager));
}
+bool ProfileServiceLoader::ConfigureIncomingConnection(
+ ApplicationConnection* connection) {
+ connection->AddService<ProfileServiceImpl>();
+ return true;
+}
+
} // namespace shell
} // namespace mojo
diff --git a/mojo/shell/profile_service_loader.h b/mojo/shell/profile_service_loader.h
index d6d38c7..bbb5d82 100644
--- a/mojo/shell/profile_service_loader.h
+++ b/mojo/shell/profile_service_loader.h
@@ -9,16 +9,17 @@
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/scoped_ptr.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/service_manager/service_loader.h"
namespace mojo {
-class Application;
+class ApplicationImpl;
namespace shell {
// ServiceLoader responsible for creating connections to the ProfileService.
-class ProfileServiceLoader : public ServiceLoader {
+class ProfileServiceLoader : public ServiceLoader, public ApplicationDelegate {
public:
ProfileServiceLoader();
virtual ~ProfileServiceLoader();
@@ -28,11 +29,15 @@ class ProfileServiceLoader : public ServiceLoader {
virtual void LoadService(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_provider_handle) OVERRIDE;
+ ScopedMessagePipeHandle shell_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE;
- base::ScopedPtrHashMap<uintptr_t, Application> apps_;
+ // ApplicationDelegate overrides.
+ virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
+ MOJO_OVERRIDE;
+
+ base::ScopedPtrHashMap<uintptr_t, ApplicationImpl> apps_;
DISALLOW_COPY_AND_ASSIGN(ProfileServiceLoader);
};
diff --git a/mojo/shell/run.cc b/mojo/shell/run.cc
index 3d68404..7cd1200 100644
--- a/mojo/shell/run.cc
+++ b/mojo/shell/run.cc
@@ -12,6 +12,15 @@
namespace mojo {
namespace shell {
+class StubServiceProvider : public InterfaceImpl<ServiceProvider> {
+ private:
+ virtual void ConnectToService(const mojo::String& service_name,
+ ScopedMessagePipeHandle client_handle)
+ MOJO_OVERRIDE {
+ }
+};
+
+
void Run(Context* context, const std::vector<GURL>& app_urls) {
KeepAlive keep_alive(context);
@@ -23,9 +32,13 @@ void Run(Context* context, const std::vector<GURL>& app_urls) {
for (std::vector<GURL>::const_iterator it = app_urls.begin();
it != app_urls.end();
++it) {
- ScopedMessagePipeHandle no_handle;
- context->service_manager()->ConnectToService(
- *it, std::string(), no_handle.Pass(), GURL());
+ // TODO(davemoore): These leak...need refs to them.
+ StubServiceProvider* stub_sp = new StubServiceProvider;
+ ServiceProviderPtr spp;
+ BindToProxy(stub_sp, &spp);
+
+ context->service_manager()->ConnectToApplication(
+ *it, GURL(), spp.Pass());
}
}
diff --git a/mojo/shell/shell_test_base.cc b/mojo/shell/shell_test_base.cc
index e83f746..53747be 100644
--- a/mojo/shell/shell_test_base.cc
+++ b/mojo/shell/shell_test_base.cc
@@ -23,10 +23,12 @@ ShellTestBase::ShellTestBase() {
ShellTestBase::~ShellTestBase() {
}
-void ShellTestBase::LaunchServiceInProcess(
+ScopedMessagePipeHandle ShellTestBase::LaunchServiceInProcess(
const GURL& service_url,
- const std::string& service_name,
- ScopedMessagePipeHandle client_handle) {
+ const std::string& service_name) {
+ base::FilePath base_dir;
+ CHECK(PathService::Get(base::DIR_EXE, &base_dir));
+ // On android, the library is bundled with the app.
#if defined(OS_ANDROID)
// On Android, the library is bundled with the app.
base::FilePath service_dir;
@@ -39,8 +41,8 @@ void ShellTestBase::LaunchServiceInProcess(
shell_context_.mojo_url_resolver()->set_origin(
net::FilePathToFileURL(service_dir).spec());
- shell_context_.service_manager()->ConnectToService(
- service_url, service_name, client_handle.Pass(), GURL());
+ return shell_context_.service_manager()->ConnectToServiceByName(
+ service_url, service_name).Pass();
}
} // namespace test
diff --git a/mojo/shell/shell_test_base.h b/mojo/shell/shell_test_base.h
index 57e2cf7..69cc2c6 100644
--- a/mojo/shell/shell_test_base.h
+++ b/mojo/shell/shell_test_base.h
@@ -26,9 +26,9 @@ class ShellTestBase : public testing::Test {
// Launches the given service in-process; |service_url| should typically be a
// mojo: URL (the origin will be set to an "appropriate" file: URL).
- void LaunchServiceInProcess(const GURL& service_url,
- const std::string& service_name,
- ScopedMessagePipeHandle client_handle);
+ ScopedMessagePipeHandle LaunchServiceInProcess(
+ const GURL& service_url,
+ const std::string& service_name);
base::MessageLoop* message_loop() { return &message_loop_; }
Context* shell_context() { return &shell_context_; }
diff --git a/mojo/shell/shell_test_base_unittest.cc b/mojo/shell/shell_test_base_unittest.cc
index 3a0d132..4b861f9 100644
--- a/mojo/shell/shell_test_base_unittest.cc
+++ b/mojo/shell/shell_test_base_unittest.cc
@@ -45,11 +45,10 @@ TEST_F(ShellTestBaseTest, LaunchServiceInProcess) {
InterfacePtr<mojo::test::ITestService> test_service;
{
- MessagePipe mp;
- test_service.Bind(mp.handle0.Pass());
- LaunchServiceInProcess(GURL("mojo:mojo_test_service"),
- mojo::test::ITestService::Name_,
- mp.handle1.Pass());
+ ScopedMessagePipeHandle service_handle =
+ LaunchServiceInProcess(GURL("mojo:mojo_test_service"),
+ mojo::test::ITestService::Name_);
+ test_service.Bind(service_handle.Pass());
}
bool was_run = false;
@@ -73,11 +72,10 @@ TEST_F(ShellTestBaseTest, LaunchServiceInProcessInvalidService) {
InterfacePtr<mojo::test::ITestService> test_service;
{
- MessagePipe mp;
- test_service.Bind(mp.handle0.Pass());
- LaunchServiceInProcess(GURL("mojo:non_existent_service"),
- mojo::test::ITestService::Name_,
- mp.handle1.Pass());
+ ScopedMessagePipeHandle service_handle =
+ LaunchServiceInProcess(GURL("mojo:non_existent_service"),
+ mojo::test::ITestService::Name_);
+ test_service.Bind(service_handle.Pass());
}
bool was_run = false;
diff --git a/mojo/shell/shell_test_helper.cc b/mojo/shell/shell_test_helper.cc
index cec75ce..5bf83ab 100644
--- a/mojo/shell/shell_test_helper.cc
+++ b/mojo/shell/shell_test_helper.cc
@@ -11,22 +11,6 @@
namespace mojo {
namespace shell {
-class ShellTestHelper::TestServiceProvider : public ServiceProvider {
- public:
- TestServiceProvider() {}
- virtual ~TestServiceProvider() {}
-
- // ServiceProvider:
- virtual void ConnectToService(
- const mojo::String& service_url,
- const mojo::String& service_name,
- ScopedMessagePipeHandle client_handle,
- const mojo::String& requestor_url) OVERRIDE {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestServiceProvider);
-};
-
ShellTestHelper::ShellTestHelper() {
base::CommandLine::Init(0, NULL);
mojo::shell::InitializeLogging();
@@ -38,9 +22,6 @@ ShellTestHelper::~ShellTestHelper() {
void ShellTestHelper::Init() {
context_.reset(new Context);
test_api_.reset(new ServiceManager::TestAPI(context_->service_manager()));
- local_service_provider_.reset(new TestServiceProvider);
- service_provider_.Bind(test_api_->GetServiceProviderHandle().Pass());
- service_provider_.set_client(local_service_provider_.get());
}
void ShellTestHelper::SetLoaderForURL(scoped_ptr<ServiceLoader> loader,
diff --git a/mojo/shell/shell_test_helper.h b/mojo/shell/shell_test_helper.h
index ef8af89..6d8953c 100644
--- a/mojo/shell/shell_test_helper.h
+++ b/mojo/shell/shell_test_helper.h
@@ -30,28 +30,17 @@ class ShellTestHelper {
void Init();
- // Returns a handle to the ServiceProvider. ShellTestHelper owns the
+ // Returns a handle to the ServiceManager. ShellTestHelper owns the
// ServiceProvider.
- ServiceProvider* service_provider() { return service_provider_.get(); }
+ ServiceManager* service_manager() { return context_->service_manager(); }
// Sets a ServiceLoader for the specified URL. |loader| is ultimately used on
// the thread this class spawns.
void SetLoaderForURL(scoped_ptr<ServiceLoader> loader, const GURL& url);
private:
- class TestServiceProvider;
-
scoped_ptr<Context> context_;
-
scoped_ptr<ServiceManager::TestAPI> test_api_;
-
- // ScopedMessagePipeHandle service_provider_handle_;
-
- // Client interface for the shell.
- scoped_ptr<TestServiceProvider> local_service_provider_;
-
- ServiceProviderPtr service_provider_;
-
DISALLOW_COPY_AND_ASSIGN(ShellTestHelper);
};
diff --git a/mojo/shell/view_manager_loader.cc b/mojo/shell/view_manager_loader.cc
index 278ab81..e41a874 100644
--- a/mojo/shell/view_manager_loader.cc
+++ b/mojo/shell/view_manager_loader.cc
@@ -4,7 +4,8 @@
#include "mojo/shell/view_manager_loader.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/services/view_manager/view_manager_init_service_impl.h"
namespace mojo {
@@ -19,12 +20,11 @@ ViewManagerLoader::~ViewManagerLoader() {
void ViewManagerLoader::LoadService(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_provider_handle) {
+ ScopedMessagePipeHandle shell_handle) {
// TODO(sky): this needs some sort of authentication as well as making sure
// we only ever have one active at a time.
- scoped_ptr<Application> app(new Application(service_provider_handle.Pass()));
- app->AddService<view_manager::service::ViewManagerInitServiceImpl>(
- app->service_provider());
+ scoped_ptr<ApplicationImpl> app(
+ new ApplicationImpl(this, shell_handle.Pass()));
apps_.push_back(app.release());
}
@@ -32,5 +32,11 @@ void ViewManagerLoader::OnServiceError(ServiceManager* manager,
const GURL& url) {
}
+bool ViewManagerLoader::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ connection->AddService<view_manager::service::ViewManagerInitServiceImpl>();
+ return true;
+}
+
} // namespace shell
} // namespace mojo
diff --git a/mojo/shell/view_manager_loader.h b/mojo/shell/view_manager_loader.h
index 8bebc57..85454e2 100644
--- a/mojo/shell/view_manager_loader.h
+++ b/mojo/shell/view_manager_loader.h
@@ -7,6 +7,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
+#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/service_manager/service_loader.h"
namespace mojo {
@@ -16,7 +17,7 @@ class Application;
namespace shell {
// ServiceLoader responsible for creating connections to the ViewManager.
-class ViewManagerLoader : public ServiceLoader {
+class ViewManagerLoader : public ServiceLoader, public ApplicationDelegate {
public:
ViewManagerLoader();
virtual ~ViewManagerLoader();
@@ -26,10 +27,14 @@ class ViewManagerLoader : public ServiceLoader {
virtual void LoadService(
ServiceManager* manager,
const GURL& url,
- ScopedMessagePipeHandle service_provider_handle) OVERRIDE;
+ ScopedMessagePipeHandle shell_handle) OVERRIDE;
virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE;
+ // ApplicationDelegate overrides.
+ virtual bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) MOJO_OVERRIDE;
+
ScopedVector<Application> apps_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerLoader);
diff --git a/mojo/spy/spy.cc b/mojo/spy/spy.cc
index 3fcc49c..38310ec 100644
--- a/mojo/spy/spy.cc
+++ b/mojo/spy/spy.cc
@@ -126,14 +126,14 @@ class MessageProcessor :
// In charge of intercepting access to the service manager.
class SpyInterceptor : public mojo::ServiceManager::Interceptor {
private:
- virtual mojo::ScopedMessagePipeHandle OnConnectToClient(
- const GURL& url, mojo::ScopedMessagePipeHandle real_client) OVERRIDE {
+ virtual mojo::ServiceProviderPtr OnConnectToClient(
+ const GURL& url, mojo::ServiceProviderPtr real_client) OVERRIDE {
if (!MustIntercept(url))
return real_client.Pass();
// You can get an invalid handle if the app (or service) is
// created by unconventional means, for example the command line.
- if (!real_client.is_valid())
+ if (!real_client.get())
return real_client.Pass();
mojo::ScopedMessagePipeHandle faux_client;
@@ -141,14 +141,17 @@ class SpyInterceptor : public mojo::ServiceManager::Interceptor {
CreateMessagePipe(NULL, &faux_client, &interceptor);
scoped_refptr<MessageProcessor> processor = new MessageProcessor();
+ mojo::ScopedMessagePipeHandle real_handle = real_client.PassMessagePipe();
base::WorkerPool::PostTask(
FROM_HERE,
base::Bind(&MessageProcessor::Start,
processor,
- base::Passed(&real_client), base::Passed(&interceptor)),
+ base::Passed(&real_handle), base::Passed(&interceptor)),
true);
- return faux_client.Pass();
+ mojo::ServiceProviderPtr faux_provider;
+ faux_provider.Bind(faux_client.Pass());
+ return faux_provider.Pass();
}
bool MustIntercept(const GURL& url) {