summaryrefslogtreecommitdiffstats
path: root/mojo/examples
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-13 17:54:29 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-13 17:54:29 +0000
commit06863b392d7cf2165ac9cd5b1bb8a4df8d55dc97 (patch)
treebdc44af44c5270128e7cf7906eec6598f5756cee /mojo/examples
parent58712c69eaff92ebf41d44757c93ac453d195ed5 (diff)
downloadchromium_src-06863b392d7cf2165ac9cd5b1bb8a4df8d55dc97.zip
chromium_src-06863b392d7cf2165ac9cd5b1bb8a4df8d55dc97.tar.gz
chromium_src-06863b392d7cf2165ac9cd5b1bb8a4df8d55dc97.tar.bz2
Change mojo demo apps to use Application.
BUG=None R=darin@chromium.org, ben Review URL: https://codereview.chromium.org/162213002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples')
-rw-r--r--mojo/examples/aura_demo/aura_demo.cc20
-rw-r--r--mojo/examples/compositor_app/compositor_app.cc85
-rw-r--r--mojo/examples/launcher/launcher.cc19
-rw-r--r--mojo/examples/sample_app/sample_app.cc4
-rw-r--r--mojo/examples/view_manager/view_manager.cc31
5 files changed, 58 insertions, 101 deletions
diff --git a/mojo/examples/aura_demo/aura_demo.cc b/mojo/examples/aura_demo/aura_demo.cc
index 618d4c3..f22d964 100644
--- a/mojo/examples/aura_demo/aura_demo.cc
+++ b/mojo/examples/aura_demo/aura_demo.cc
@@ -11,8 +11,8 @@
#include "mojo/examples/aura_demo/demo_screen.h"
#include "mojo/examples/aura_demo/root_window_host_mojo.h"
#include "mojo/public/bindings/allocation_scope.h"
-#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/gles2/gles2_cpp.h"
+#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojom/native_viewport.h"
@@ -115,29 +115,23 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
};
-class AuraDemo : public ShellClient {
+class AuraDemo : public Application {
public:
- explicit AuraDemo(ScopedShellHandle shell_handle)
- : shell_(shell_handle.Pass(), this) {
+ explicit AuraDemo(MojoHandle shell_handle) : Application(shell_handle) {
screen_.reset(DemoScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
InterfacePipe<NativeViewport, AnyInterface> pipe;
mojo::AllocationScope scope;
- shell_->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
+ shell()->Connect("mojo:mojo_native_viewport_service",
+ pipe.handle_to_peer.Pass());
root_window_host_.reset(new WindowTreeHostMojo(
pipe.handle_to_self.Pass(),
gfx::Rect(800, 600),
base::Bind(&AuraDemo::HostContextCreated, base::Unretained(this))));
}
- virtual void AcceptConnection(const mojo::String& url,
- ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
- NOTREACHED() << "AuraDemo can't be connected to.";
- }
-
private:
void HostContextCreated() {
aura::RootWindow::CreateParams params(
@@ -185,7 +179,6 @@ class AuraDemo : public ShellClient {
aura::Window* window2_;
aura::Window* window21_;
- RemotePtr<Shell> shell_;
scoped_ptr<WindowTreeHostMojo> root_window_host_;
scoped_ptr<aura::RootWindow> root_window_;
};
@@ -204,8 +197,7 @@ extern "C" AURA_DEMO_EXPORT MojoResult CDECL MojoMain(
// 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();
- mojo::examples::AuraDemo app(
- mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
+ mojo::examples::AuraDemo app(shell_handle);
loop.Run();
return MOJO_RESULT_OK;
diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc
index dce027c..05ffa71 100644
--- a/mojo/examples/compositor_app/compositor_app.cc
+++ b/mojo/examples/compositor_app/compositor_app.cc
@@ -10,6 +10,7 @@
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/gles2/gles2_cpp.h"
+#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojo/services/native_viewport/geometry_conversions.h"
@@ -30,67 +31,46 @@
namespace mojo {
namespace examples {
-class SampleApp : public ShellClient {
+class SampleApp : public Application, public NativeViewportClient {
public:
- explicit SampleApp(ScopedShellHandle shell_handle)
- : shell_(shell_handle.Pass(), this) {
- InterfacePipe<NativeViewport, AnyInterface> pipe;
+ explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
+ InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
AllocationScope scope;
- shell_->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
-
- native_viewport_client_.reset(
- new NativeViewportClientImpl(pipe.handle_to_self.Pass()));
+ shell()->Connect("mojo:mojo_native_viewport_service",
+ viewport_pipe.handle_to_peer.Pass());
+
+ viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
+ viewport_->Create(gfx::Rect(10, 10, 800, 600));
+ viewport_->Show();
+ ScopedMessagePipeHandle gles2_handle;
+ ScopedMessagePipeHandle gles2_client_handle;
+ CreateMessagePipe(&gles2_handle, &gles2_client_handle);
+
+ viewport_->CreateGLES2Context(gles2_client_handle.Pass());
+ host_.reset(new CompositorHost(gles2_handle.Pass()));
}
- virtual void AcceptConnection(const mojo::String& url,
- ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
- NOTREACHED() << "SampleApp can't be connected to.";
+ virtual void OnCreated() MOJO_OVERRIDE {
}
- private:
- class NativeViewportClientImpl : public NativeViewportClient {
- public:
- explicit NativeViewportClientImpl(
- ScopedNativeViewportHandle viewport_handle)
- : viewport_(viewport_handle.Pass(), this) {
- AllocationScope allocation;
- viewport_->Create(gfx::Rect(10, 10, 800, 600));
- viewport_->Show();
- ScopedMessagePipeHandle gles2_handle;
- ScopedMessagePipeHandle gles2_client_handle;
- CreateMessagePipe(&gles2_handle, &gles2_client_handle);
-
- viewport_->CreateGLES2Context(gles2_client_handle.Pass());
- host_.reset(new CompositorHost(gles2_handle.Pass()));
- }
-
- virtual ~NativeViewportClientImpl() {}
-
- virtual void OnCreated() MOJO_OVERRIDE {
- }
-
- virtual void OnDestroyed() MOJO_OVERRIDE {
- base::MessageLoop::current()->Quit();
- }
+ virtual void OnDestroyed() MOJO_OVERRIDE {
+ base::MessageLoop::current()->Quit();
+ }
- virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE {
- host_->SetSize(bounds.size());
- }
+ virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE {
+ host_->SetSize(bounds.size());
+ }
- virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
- if (!event.location().is_null()) {
- viewport_->AckEvent(event);
- }
+ virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
+ if (!event.location().is_null()) {
+ viewport_->AckEvent(event);
}
+ }
- private:
- RemotePtr<NativeViewport> viewport_;
- scoped_ptr<CompositorHost> host_;
- };
- RemotePtr<Shell> shell_;
- scoped_ptr<NativeViewportClientImpl> native_viewport_client_;
+ private:
+ RemotePtr<NativeViewport> viewport_;
+ scoped_ptr<CompositorHost> host_;
};
} // namespace examples
@@ -101,10 +81,7 @@ extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
base::MessageLoop loop;
mojo::GLES2Initializer gles2;
- mojo::examples::SampleApp app(
- mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
-
+ mojo::examples::SampleApp app(shell_handle);
loop.Run();
-
return MOJO_RESULT_OK;
}
diff --git a/mojo/examples/launcher/launcher.cc b/mojo/examples/launcher/launcher.cc
index 8c3ea63..1ba9043 100644
--- a/mojo/examples/launcher/launcher.cc
+++ b/mojo/examples/launcher/launcher.cc
@@ -16,6 +16,7 @@
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/gles2/gles2_cpp.h"
+#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojom/launcher.h"
@@ -187,13 +188,13 @@ class LauncherController : public views::TextfieldController {
DISALLOW_COPY_AND_ASSIGN(LauncherController);
};
-class LauncherImpl : public ShellClient,
+class LauncherImpl : public Application,
public Launcher,
public URLReceiver {
public:
- explicit LauncherImpl(ScopedShellHandle shell_handle)
- : launcher_controller_(this),
- shell_(shell_handle.Pass(), this),
+ explicit LauncherImpl(MojoHandle shell_handle)
+ : Application(shell_handle),
+ launcher_controller_(this),
pending_show_(false) {
screen_.reset(DemoScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
@@ -201,8 +202,8 @@ class LauncherImpl : public ShellClient,
InterfacePipe<NativeViewport, AnyInterface> pipe;
AllocationScope scope;
- shell_->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
+ shell()->Connect("mojo:mojo_native_viewport_service",
+ pipe.handle_to_peer.Pass());
root_window_host_.reset(new WindowTreeHostMojo(
pipe.handle_to_self.Pass(), gfx::Rect(50, 50, 450, 60),
@@ -210,7 +211,7 @@ class LauncherImpl : public ShellClient,
}
private:
- // Overridden from ShellClient:
+ // Overridden from Application:
virtual void AcceptConnection(const mojo::String& url,
ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
launcher_client_.reset(
@@ -272,7 +273,6 @@ class LauncherImpl : public ShellClient,
LauncherController launcher_controller_;
- RemotePtr<Shell> shell_;
RemotePtr<LauncherClient> launcher_client_;
scoped_ptr<WindowTreeHostMojo> root_window_host_;
scoped_ptr<aura::RootWindow> root_window_;
@@ -302,8 +302,7 @@ extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain(
// 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();
- mojo::examples::LauncherImpl launcher(
- mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
+ mojo::examples::LauncherImpl launcher(shell_handle);
loop.Run();
return MOJO_RESULT_OK;
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index a3f48f1..07e74c4 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -35,8 +35,8 @@ class SampleApp : public Application, public mojo::NativeViewportClient {
explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
mojo::AllocationScope scope;
- GetShell()->Connect("mojo:mojo_native_viewport_service",
- viewport_pipe.handle_to_peer.Pass());
+ shell()->Connect("mojo:mojo_native_viewport_service",
+ viewport_pipe.handle_to_peer.Pass());
viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
Rect::Builder rect;
Point::Builder point;
diff --git a/mojo/examples/view_manager/view_manager.cc b/mojo/examples/view_manager/view_manager.cc
index 571cc78..4c38dc3 100644
--- a/mojo/examples/view_manager/view_manager.cc
+++ b/mojo/examples/view_manager/view_manager.cc
@@ -9,6 +9,7 @@
#include "base/message_loop/message_loop.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
+#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojo/services/native_viewport/geometry_conversions.h"
@@ -55,13 +56,11 @@ class ViewImpl : public View {
DISALLOW_COPY_AND_ASSIGN(ViewImpl);
};
-class ViewManagerImpl : public ViewManager,
- public ShellClient,
+class ViewManagerImpl : public Service<ViewManager, ViewManagerImpl>,
public NativeViewportClient,
public LauncherClient {
public:
- explicit ViewManagerImpl(ScopedShellHandle shell_handle)
- : shell_(shell_handle.Pass(), this) {
+ explicit ViewManagerImpl() {
InitNativeViewport();
}
@@ -70,16 +69,7 @@ class ViewManagerImpl : public ViewManager,
virtual void CreateView() MOJO_OVERRIDE {
InterfacePipe<View> pipe;
views_.push_back(new ViewImpl(pipe.handle_to_peer.Pass()));
- client_->OnViewCreated(pipe.handle_to_self.Pass());
- }
-
- // Overridden from ShellClient:
- virtual void AcceptConnection(const mojo::String& url,
- ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
- client_.reset(
- MakeScopedHandle(
- ViewManagerClientHandle(handle.release().value())).Pass(),
- this);
+ client()->OnViewCreated(pipe.handle_to_self.Pass());
}
// Overridden from NativeViewportClient:
@@ -114,8 +104,8 @@ class ViewManagerImpl : public ViewManager,
InterfacePipe<NativeViewport, AnyInterface> pipe;
AllocationScope scope;
- shell_->Connect("mojo:mojo_native_viewport_service",
- pipe.handle_to_peer.Pass());
+ shell()->Connect("mojo:mojo_native_viewport_service",
+ pipe.handle_to_peer.Pass());
native_viewport_.reset(pipe.handle_to_self.Pass(), this);
native_viewport_->Create(gfx::Rect(50, 50, 800, 600));
@@ -129,7 +119,7 @@ class ViewManagerImpl : public ViewManager,
InterfacePipe<Launcher, AnyInterface> pipe;
AllocationScope scope;
- shell_->Connect("mojo:mojo_launcher", pipe.handle_to_peer.Pass());
+ shell()->Connect("mojo:mojo_launcher", pipe.handle_to_peer.Pass());
launcher_.reset(pipe.handle_to_self.Pass(), this);
}
@@ -137,8 +127,6 @@ class ViewManagerImpl : public ViewManager,
void DidCreateContext() {
}
- RemotePtr<Shell> shell_;
- RemotePtr<ViewManagerClient> client_;
ScopedVector<ViewImpl> views_;
RemotePtr<NativeViewport> native_viewport_;
RemotePtr<Launcher> launcher_;
@@ -152,8 +140,9 @@ class ViewManagerImpl : public ViewManager,
extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain(
MojoHandle shell_handle) {
base::MessageLoop loop;
- mojo::examples::ViewManagerImpl view_manager(
- mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
+ mojo::Application app(shell_handle);
+ app.AddServiceFactory(
+ new mojo::ServiceFactory<mojo::examples::ViewManagerImpl>);
loop.Run();
return MOJO_RESULT_OK;