summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mojo/examples/aura_demo/aura_demo.cc44
-rw-r--r--mojo/examples/compositor_app/compositor_app.cc33
-rw-r--r--mojo/examples/dbus_echo/dbus_echo_app.cc36
-rw-r--r--mojo/examples/pepper_container_app/pepper_container_app.cc38
-rw-r--r--mojo/examples/sample_app/sample_app.cc44
-rw-r--r--mojo/examples/sample_view_manager_app/sample_view_manager_app.cc35
-rw-r--r--mojo/mojo_examples.gypi14
-rw-r--r--mojo/mojo_public.gypi26
-rw-r--r--mojo/mojo_services.gypi6
-rw-r--r--mojo/public/cpp/application/DEPS10
-rw-r--r--mojo/public/cpp/application/application.h33
-rw-r--r--mojo/public/cpp/application/lib/application.cc10
-rw-r--r--mojo/public/cpp/application/lib/mojo_main_chromium.cc25
-rw-r--r--mojo/public/cpp/application/lib/mojo_main_standalone.cc22
-rw-r--r--mojo/public/cpp/application/lib/service_connector.cc2
-rw-r--r--mojo/public/cpp/application/lib/service_connector.h3
-rw-r--r--mojo/services/view_manager/main.cc53
17 files changed, 237 insertions, 197 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
index 7e4ec8c..062800c 100644
--- a/mojo/examples/aura_demo/aura_demo.cc
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -5,9 +5,6 @@
#include <stdio.h>
#include <string>
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "mojo/aura/screen_mojo.h"
#include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/public/cpp/application/application.h"
@@ -24,16 +21,6 @@
#include "ui/base/hit_test.h"
#include "ui/gfx/canvas.h"
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define AURA_DEMO_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define AURA_DEMO_EXPORT __attribute__((visibility("default")))
-#endif
-
namespace mojo {
namespace examples {
@@ -105,7 +92,6 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
private:
aura::Window* window_;
-
scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
@@ -113,8 +99,11 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
class AuraDemo : public Application {
public:
- explicit AuraDemo(MojoHandle service_provider_handle)
- : Application(service_provider_handle) {
+ AuraDemo() {}
+ virtual ~AuraDemo() {}
+
+ virtual void Initialize() OVERRIDE {
+ aura::Env::CreateInstance(true);
screen_.reset(ScreenMojo::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
@@ -158,6 +147,7 @@ class AuraDemo : public Application {
window_tree_host_->Show();
}
+ mojo::GLES2Initializer gles2;
scoped_ptr<ScreenMojo> screen_;
scoped_ptr<DemoWindowTreeClient> window_tree_client_;
@@ -171,24 +161,16 @@ class AuraDemo : public Application {
aura::Window* window21_;
scoped_ptr<aura::WindowTreeHost> window_tree_host_;
+
+ DISALLOW_COPY_AND_ASSIGN(AuraDemo);
};
} // namespace examples
-} // namespace mojo
-extern "C" AURA_DEMO_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- base::CommandLine::Init(0, NULL);
- base::AtExitManager at_exit;
- base::MessageLoop loop;
- mojo::GLES2Initializer gles2;
+// static
+Application* Application::Create() {
+ return new examples::AuraDemo();
+}
- // TODO(beng): This crashes in a DCHECK on X11 because this thread's
- // MessageLoop is not of TYPE_UI. I think we need a way to build
- // Aura that doesn't define platform-specific stuff.
- aura::Env::CreateInstance(true);
- mojo::examples::AuraDemo app(service_provider_handle);
- loop.Run();
+} // namespace mojo
- return MOJO_RESULT_OK;
-}
diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc
index 583f4e9..db6e4e2 100644
--- a/mojo/examples/compositor_app/compositor_app.cc
+++ b/mojo/examples/compositor_app/compositor_app.cc
@@ -6,7 +6,6 @@
#include <string>
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
#include "mojo/examples/compositor_app/compositor_host.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
@@ -17,23 +16,15 @@
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "ui/gfx/rect.h"
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define SAMPLE_APP_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
-#endif
-
namespace mojo {
namespace examples {
class SampleApp : public Application, public NativeViewportClient {
public:
- explicit SampleApp(MojoHandle service_provider_handle)
- : Application(service_provider_handle) {
+ SampleApp() {}
+ virtual ~SampleApp() {}
+
+ virtual void Initialize() OVERRIDE {
AllocationScope scope;
ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
@@ -64,19 +55,17 @@ class SampleApp : public Application, public NativeViewportClient {
}
private:
+ mojo::GLES2Initializer gles2;
NativeViewportPtr viewport_;
scoped_ptr<CompositorHost> host_;
+ DISALLOW_COPY_AND_ASSIGN(SampleApp);
};
} // namespace examples
-} // namespace mojo
-extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- base::MessageLoop loop;
- mojo::GLES2Initializer gles2;
-
- mojo::examples::SampleApp app(service_provider_handle);
- loop.Run();
- return MOJO_RESULT_OK;
+// static
+Application* Application::Create() {
+ return new examples::SampleApp();
}
+
+} // namespace mojo
diff --git a/mojo/examples/dbus_echo/dbus_echo_app.cc b/mojo/examples/dbus_echo/dbus_echo_app.cc
index f9b9433..0ccccc6 100644
--- a/mojo/examples/dbus_echo/dbus_echo_app.cc
+++ b/mojo/examples/dbus_echo/dbus_echo_app.cc
@@ -12,27 +12,18 @@
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"
-#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/dbus_echo/echo.mojom.h"
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define DBUS_ECHO_APP_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define DBUS_ECHO_APP_EXPORT __attribute__((visibility("default")))
-#endif
-
namespace mojo {
namespace examples {
class DBusEchoApp : public Application {
public:
- explicit DBusEchoApp(MojoHandle service_provider_handle)
- : Application(service_provider_handle) {
+ DBusEchoApp() {}
+ virtual ~DBusEchoApp() {}
+
+ virtual void Initialize() MOJO_OVERRIDE {
ConnectTo("dbus:org.chromium.EchoService/org/chromium/MojoImpl",
&echo_service_);
@@ -41,26 +32,21 @@ class DBusEchoApp : public Application {
base::Unretained(this)));
}
- virtual ~DBusEchoApp() {
- }
-
private:
void OnEcho(const String& echoed) {
LOG(INFO) << "echo'd " << echoed.To<std::string>();
}
EchoServicePtr echo_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(DBusEchoApp);
};
} // namespace examples
-} // namespace mojo
-
-extern "C" DBUS_ECHO_APP_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- mojo::Environment env;
- mojo::RunLoop loop;
- mojo::examples::DBusEchoApp app(service_provider_handle);
- loop.Run();
- return MOJO_RESULT_OK;
+// static
+Application* Application::Create() {
+ return new examples::DBusEchoApp();
}
+
+} // namespace mojo
diff --git a/mojo/examples/pepper_container_app/pepper_container_app.cc b/mojo/examples/pepper_container_app/pepper_container_app.cc
index e678613..3d5bf31 100644
--- a/mojo/examples/pepper_container_app/pepper_container_app.cc
+++ b/mojo/examples/pepper_container_app/pepper_container_app.cc
@@ -13,7 +13,6 @@
#include "mojo/examples/pepper_container_app/type_converters.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/environment/environment.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"
@@ -21,16 +20,6 @@
#include "ppapi/c/pp_rect.h"
#include "ppapi/shared_impl/proxy_lock.h"
-#if defined(OS_WIN)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define PEPPER_CONTAINER_APP_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define PEPPER_CONTAINER_APP_EXPORT __attribute__((visibility("default")))
-#endif
-
namespace mojo {
namespace examples {
@@ -38,10 +27,14 @@ class PepperContainerApp: public Application,
public NativeViewportClient,
public MojoPpapiGlobals::Delegate {
public:
- explicit PepperContainerApp(MojoHandle service_provider_handle)
- : Application(service_provider_handle),
+ explicit PepperContainerApp()
+ : Application(),
ppapi_globals_(this),
- plugin_module_(new PluginModule) {
+ plugin_module_(new PluginModule) {}
+
+ virtual ~PepperContainerApp() {}
+
+ virtual void Initialize() MOJO_OVERRIDE {
mojo::AllocationScope scope;
ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
@@ -60,8 +53,6 @@ class PepperContainerApp: public Application,
viewport_->Show();
}
- virtual ~PepperContainerApp() {}
-
// NativeViewportClient implementation.
virtual void OnCreated() OVERRIDE {
ppapi::ProxyAutoLock lock;
@@ -117,15 +108,10 @@ class PepperContainerApp: public Application,
};
} // namespace examples
-} // namespace mojo
-
-extern "C" PEPPER_CONTAINER_APP_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- mojo::Environment env;
- mojo::GLES2Initializer gles2;
- base::MessageLoop run_loop;
- mojo::examples::PepperContainerApp app(service_provider_handle);
- run_loop.Run();
- return MOJO_RESULT_OK;
+// static
+Application* Application::Create() {
+ return new examples::PepperContainerApp();
}
+
+} // namespace mojo
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index 74b9d99..1be8073 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -8,7 +8,6 @@
#include "mojo/examples/sample_app/gles2_client_impl.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/bindings/allocation_scope.h"
-#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"
@@ -16,23 +15,19 @@
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/native_viewport/native_viewport.mojom.h"
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define SAMPLE_APP_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
-#endif
-
namespace mojo {
namespace examples {
class SampleApp : public Application, public NativeViewportClient {
public:
- explicit SampleApp(MojoHandle service_provider_handle)
- : Application(service_provider_handle) {
+ SampleApp() {}
+
+ virtual ~SampleApp() {
+ // TODO(darin): Fix shutdown so we don't need to leak this.
+ MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
+ }
+
+ virtual void Initialize() MOJO_OVERRIDE {
ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
viewport_.set_client(this);
@@ -55,11 +50,6 @@ class SampleApp : public Application, public NativeViewportClient {
gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass()));
}
- virtual ~SampleApp() {
- // TODO(darin): Fix shutdown so we don't need to leak this.
- MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
- }
-
virtual void OnCreated() MOJO_OVERRIDE {
}
@@ -79,20 +69,18 @@ class SampleApp : public Application, public NativeViewportClient {
}
private:
+ mojo::GLES2Initializer gles2;
scoped_ptr<GLES2ClientImpl> gles2_client_;
NativeViewportPtr viewport_;
+
+ DISALLOW_COPY_AND_ASSIGN(SampleApp);
};
} // namespace examples
-} // namespace mojo
-extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- mojo::Environment env;
- mojo::RunLoop loop;
- mojo::GLES2Initializer gles2;
-
- mojo::examples::SampleApp app(service_provider_handle);
- loop.Run();
- return MOJO_RESULT_OK;
+// static
+Application* Application::Create() {
+ return new examples::SampleApp();
}
+
+} // namespace mojo
diff --git a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
index 0188fb2..1ae5b90 100644
--- a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
+++ b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
@@ -4,35 +4,24 @@
#include "base/at_exit.h"
#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"
-#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
#include "ui/gfx/canvas.h"
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl
-#endif
-#define SAMPLE_APP_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
-#endif
-
namespace mojo {
namespace examples {
class SampleApp : public Application {
public:
- explicit SampleApp(MojoHandle service_provider_handle)
- : Application(service_provider_handle) {
+ SampleApp() {}
+ virtual ~SampleApp() {}
+
+ virtual void Initialize() MOJO_OVERRIDE {
view_manager_.reset(new view_manager::ViewManager(service_provider()));
view_manager_->Init();
view_manager::ViewTreeNode* node1 =
@@ -53,9 +42,6 @@ class SampleApp : public Application {
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
}
- virtual ~SampleApp() {
- }
-
private:
// SampleApp creates a ViewManager and a trivial node hierarchy.
scoped_ptr<view_manager::ViewManager> view_manager_;
@@ -64,13 +50,10 @@ class SampleApp : public Application {
};
} // namespace examples
-} // namespace mojo
-
-extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- base::MessageLoop loop;
- mojo::examples::SampleApp app(service_provider_handle);
- loop.Run();
- return MOJO_RESULT_OK;
+// static
+Application* Application::Create() {
+ return new examples::SampleApp();
}
+
+} // namespace mojo
diff --git a/mojo/mojo_examples.gypi b/mojo/mojo_examples.gypi
index df6b6e0..d99bf5a 100644
--- a/mojo/mojo_examples.gypi
+++ b/mojo/mojo_examples.gypi
@@ -15,8 +15,8 @@
'mojo_environment_standalone',
'mojo_geometry_bindings',
'mojo_gles2',
+ 'mojo_main_standalone',
'mojo_native_viewport_bindings',
- 'mojo_application',
'mojo_system',
'mojo_utility',
],
@@ -49,8 +49,8 @@
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_gles2',
+ 'mojo_main_chromium',
'mojo_native_viewport_bindings',
- 'mojo_application',
'mojo_system_impl',
],
'sources': [
@@ -80,8 +80,8 @@
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_gles2',
+ 'mojo_main_chromium',
'mojo_native_viewport_bindings',
- 'mojo_application',
'mojo_system_impl',
],
'defines': [
@@ -181,7 +181,7 @@
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_gles2',
- 'mojo_application',
+ 'mojo_main_chromium',
'mojo_system_impl'
],
'sources': [
@@ -224,6 +224,7 @@
'../ui/views/views.gyp:views',
'../ui/wm/wm.gyp:wm',
'../url/url.gyp:url_lib',
+ 'mojo_application',
'mojo_aura_support',
'mojo_common_lib',
'mojo_environment_chromium',
@@ -231,7 +232,6 @@
'mojo_geometry_lib',
'mojo_gles2',
'mojo_launcher_bindings',
- 'mojo_application',
'mojo_system_impl',
],
'sources': [
@@ -258,8 +258,8 @@
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_gles2',
+ 'mojo_main_chromium',
'mojo_view_manager_lib',
- 'mojo_application',
'mojo_system_impl',
'mojo_utility',
],
@@ -279,7 +279,7 @@
'mojo_cpp_bindings',
'mojo_environment_standalone',
'mojo_echo_bindings',
- 'mojo_application',
+ 'mojo_main_standalone',
'mojo_system',
'mojo_utility',
],
diff --git a/mojo/mojo_public.gypi b/mojo/mojo_public.gypi
index a5929df..22e208b 100644
--- a/mojo/mojo_public.gypi
+++ b/mojo/mojo_public.gypi
@@ -379,6 +379,32 @@
'mojo_service_provider_bindings',
],
},
+ {
+ 'target_name': 'mojo_main_standalone',
+ 'type': 'static_library',
+ 'sources': [
+ 'public/cpp/application/lib/mojo_main_standalone.cc',
+ ],
+ 'dependencies': [
+ 'mojo_application',
+ ],
+ 'export_dependent_settings': [
+ 'mojo_application',
+ ],
+ },
+ {
+ 'target_name': 'mojo_main_chromium',
+ 'type': 'static_library',
+ 'sources': [
+ 'public/cpp/application/lib/mojo_main_chromium.cc',
+ ],
+ 'dependencies': [
+ 'mojo_application',
+ ],
+ 'export_dependent_settings': [
+ 'mojo_application',
+ ],
+ },
],
'conditions': [
['OS == "android"', {
diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi
index 1a4419f..112893f 100644
--- a/mojo/mojo_services.gypi
+++ b/mojo/mojo_services.gypi
@@ -123,13 +123,13 @@
'../ui/events/events.gyp:events',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
+ 'mojo_application',
'mojo_common_lib',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_gles2_service',
'mojo_native_viewport_bindings',
- 'mojo_application',
'mojo_system_impl',
],
'defines': [
@@ -270,8 +270,8 @@
'mojo_geometry_lib',
'mojo_gles2',
'mojo_launcher_bindings',
+ 'mojo_main_chromium',
'mojo_native_viewport_bindings',
- 'mojo_application',
'mojo_system_impl',
'mojo_view_manager_bindings',
'mojo_view_manager_common',
@@ -356,11 +356,11 @@
'../base/base.gyp:base',
'../build/linux/system.gyp:dbus',
'../dbus/dbus.gyp:dbus',
+ 'mojo_application',
'mojo_common_lib',
'mojo_dbus_service',
'mojo_echo_bindings',
'mojo_environment_chromium',
- 'mojo_application',
'mojo_system_impl',
],
'sources': [
diff --git a/mojo/public/cpp/application/DEPS b/mojo/public/cpp/application/DEPS
index a0e2b06..e808b79 100644
--- a/mojo/public/cpp/application/DEPS
+++ b/mojo/public/cpp/application/DEPS
@@ -2,3 +2,13 @@ include_rules = [
"+mojo/public/cpp/bindings",
"+mojo/public/interfaces/service_provider",
]
+
+specific_include_rules = {
+ "mojo_main_chromium.cc": [
+ "+base",
+ "+mojo/public/cpp"
+ ],
+ "mojo_main_standalone.cc": [
+ "+mojo/public/cpp"
+ ],
+}
diff --git a/mojo/public/cpp/application/application.h b/mojo/public/cpp/application/application.h
index 58e9d05..9f426b7 100644
--- a/mojo/public/cpp/application/application.h
+++ b/mojo/public/cpp/application/application.h
@@ -4,7 +4,6 @@
#ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_H_
#define MOJO_PUBLIC_APPLICATION_APPLICATION_H_
-
#include <vector>
#include "mojo/public/cpp/application/connect.h"
@@ -12,6 +11,24 @@
#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 utilize the
+// mojo_main_{standalone|chromium} gyp targets 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.
@@ -49,10 +66,16 @@ namespace mojo {
//
class Application : public internal::ServiceConnectorBase::Owner {
public:
+ Application();
explicit Application(ScopedMessagePipeHandle service_provider_handle);
explicit Application(MojoHandle service_provider_handle);
virtual ~Application();
+ // 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();
+
template <typename Impl, typename Context>
void AddService(Context* context) {
AddServiceConnector(new internal::ServiceConnector<Impl, Context>(context));
@@ -69,6 +92,9 @@ class Application : public internal::ServiceConnectorBase::Owner {
mojo::ConnectToService(service_provider(), url, ptr);
}
+ ServiceProvider* service_provider() { return service_provider_.get(); }
+ void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle);
+
protected:
// ServiceProvider methods.
// Override this to dispatch to correct service when there's more than one.
@@ -78,6 +104,11 @@ class Application : public internal::ServiceConnectorBase::Owner {
MOJO_OVERRIDE;
private:
+ friend MojoResult (::MojoMain)(MojoHandle);
+
+ // Implement this method to create the specific subclass of Application.
+ static Application* Create();
+
// internal::ServiceConnectorBase::Owner methods.
// Takes ownership of |service_connector|.
virtual void AddServiceConnector(
diff --git a/mojo/public/cpp/application/lib/application.cc b/mojo/public/cpp/application/lib/application.cc
index 72ce5802..6cc988d 100644
--- a/mojo/public/cpp/application/lib/application.cc
+++ b/mojo/public/cpp/application/lib/application.cc
@@ -6,6 +6,8 @@
namespace mojo {
+Application::Application() {}
+
Application::Application(ScopedMessagePipeHandle service_provider_handle)
: internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) {
}
@@ -22,6 +24,8 @@ Application::~Application() {
}
}
+void Application::Initialize() {}
+
void Application::AddServiceConnector(
internal::ServiceConnectorBase* service_connector) {
service_connectors_.push_back(service_connector);
@@ -42,6 +46,12 @@ void Application::RemoveServiceConnector(
service_provider_.reset();
}
+void Application::BindServiceProvider(
+ ScopedMessagePipeHandle service_provider_handle) {
+ service_provider_.Bind(service_provider_handle.Pass());
+ service_provider_.set_client(this);
+}
+
void Application::ConnectToService(const mojo::String& url,
ScopedMessagePipeHandle client_handle) {
// TODO(davemoore): This method must be overridden by an Application subclass
diff --git a/mojo/public/cpp/application/lib/mojo_main_chromium.cc b/mojo/public/cpp/application/lib/mojo_main_chromium.cc
new file mode 100644
index 0000000..7f9f133
--- /dev/null
+++ b/mojo/public/cpp/application/lib/mojo_main_chromium.cc
@@ -0,0 +1,25 @@
+// 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 "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/environment/environment.h"
+#include "mojo/public/cpp/utility/run_loop.h"
+
+extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
+ MojoHandle service_provider_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();
+ 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
new file mode 100644
index 0000000..05825aa
--- /dev/null
+++ b/mojo/public/cpp/application/lib/mojo_main_standalone.cc
@@ -0,0 +1,22 @@
+// 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"
+#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) {
+ 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;
+
+ 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 10bda99..3c53be0 100644
--- a/mojo/public/cpp/application/lib/service_connector.cc
+++ b/mojo/public/cpp/application/lib/service_connector.cc
@@ -7,6 +7,8 @@
namespace mojo {
namespace internal {
+ServiceConnectorBase::Owner::Owner() {}
+
ServiceConnectorBase::Owner::Owner(
ScopedMessagePipeHandle service_provider_handle) {
service_provider_.Bind(service_provider_handle.Pass());
diff --git a/mojo/public/cpp/application/lib/service_connector.h b/mojo/public/cpp/application/lib/service_connector.h
index 8dda334..136aabd 100644
--- a/mojo/public/cpp/application/lib/service_connector.h
+++ b/mojo/public/cpp/application/lib/service_connector.h
@@ -63,9 +63,9 @@ class ServiceConnectorBase {
public:
class Owner : public ServiceProvider {
public:
+ Owner();
Owner(ScopedMessagePipeHandle service_provider_handle);
virtual ~Owner();
- ServiceProvider* service_provider() { return service_provider_.get(); }
virtual void AddServiceConnector(
internal::ServiceConnectorBase* service_connector) = 0;
virtual void RemoveServiceConnector(
@@ -80,7 +80,6 @@ class ServiceConnectorBase {
};
ServiceConnectorBase() : owner_(NULL) {}
virtual ~ServiceConnectorBase();
- ServiceProvider* service_provider() { return owner_->service_provider(); }
virtual void ConnectToService(const std::string& url,
ScopedMessagePipeHandle client_handle) = 0;
diff --git a/mojo/services/view_manager/main.cc b/mojo/services/view_manager/main.cc
index 95c74ef..4acd992 100644
--- a/mojo/services/view_manager/main.cc
+++ b/mojo/services/view_manager/main.cc
@@ -2,34 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#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/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/view_manager_connection.h"
-#if defined(WIN32)
-#if !defined(CDECL)
-#define CDECL __cdecl)
-#endif
-#define VIEW_MANAGER_EXPORT __declspec(dllexport)
-#else
-#define CDECL
-#define VIEW_MANAGER_EXPORT __attribute__((visibility("default")))
-#endif
-
-extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain(
- MojoHandle service_provider_handle) {
- base::CommandLine::Init(0, NULL);
- base::AtExitManager at_exit;
- base::MessageLoop loop;
- mojo::Application app(service_provider_handle);
- mojo::view_manager::service::RootNodeManager root_node_manager(
- app.service_provider());
- app.AddService<mojo::view_manager::service::ViewManagerConnection>(
- &root_node_manager);
- loop.Run();
-
- return MOJO_RESULT_OK;
+namespace mojo {
+namespace view_manager {
+namespace service {
+
+class ViewManagerApp : public Application {
+ public:
+ ViewManagerApp() {}
+ virtual ~ViewManagerApp() {}
+
+ virtual void Initialize() MOJO_OVERRIDE {
+ root_node_manager_.reset(new RootNodeManager(service_provider()));
+ AddService<ViewManagerConnection>(root_node_manager_.get());
+ }
+
+ private:
+ scoped_ptr<RootNodeManager> root_node_manager_;
+ DISALLOW_COPY_AND_ASSIGN(ViewManagerApp);
+};
+
+}
+}
+
+// static
+Application* Application::Create() {
+ return new mojo::view_manager::service::ViewManagerApp();
+}
+
}