Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Unified Diff: mojo/examples/view_manager/view_manager.cc

Issue 149363006: Cleanup ViewManager code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: , Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/examples/aura_demo/root_window_host_mojo.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/view_manager/view_manager.cc
diff --git a/mojo/examples/view_manager/view_manager.cc b/mojo/examples/view_manager/view_manager.cc
index 8f7d4e8c4ee758f1367765d8fcf19ecf48f3e27b..ce5aa97157876751cfbc3dc78c492b1c70988ae7 100644
--- a/mojo/examples/view_manager/view_manager.cc
+++ b/mojo/examples/view_manager/view_manager.cc
@@ -33,35 +33,52 @@
namespace mojo {
namespace examples {
-// Convenience interface to connect to a service. Necessary because all code for
-// this app lives in one .cc file.
-class Connector {
+class ViewImpl : public View {
public:
- virtual void Connect(const String& url,
- ScopedMessagePipeHandle client_handle) = 0;
+ explicit ViewImpl(ScopedMessagePipeHandle handle)
+ : id_(-1),
+ client_(handle.Pass()) {}
+ virtual ~ViewImpl() {}
+
+ private:
+ // Overridden from View:
+ virtual void SetId(int view_id) MOJO_OVERRIDE {
+ id_ = view_id;
+ }
+ virtual void GetId() MOJO_OVERRIDE {
+ client_->OnGotId(id_);
+ }
+
+ int id_;
+ RemotePtr<ViewClient> client_;
- protected:
- virtual ~Connector() {}
+ DISALLOW_COPY_AND_ASSIGN(ViewImpl);
};
-class NativeViewportClientImpl : public NativeViewportClient,
- public LauncherClient {
+class ViewManagerImpl : public ViewManager,
+ public ShellClient,
+ public NativeViewportClient,
+ public LauncherClient {
public:
- explicit NativeViewportClientImpl(Connector* connector)
- : connector_(connector) {
- AllocationScope scope;
- ScopedMessagePipeHandle client_handle, native_viewport_handle;
- CreateMessagePipe(&client_handle, &native_viewport_handle);
- connector_->Connect("mojo:mojo_native_viewport_service",
- client_handle.Pass());
- native_viewport_.reset(native_viewport_handle.Pass(), this);
-
- native_viewport_->Create(gfx::Rect(50, 50, 800, 600));
- native_viewport_->Show();
+ explicit ViewManagerImpl(ScopedMessagePipeHandle shell_handle)
+ : shell_(shell_handle.Pass(), this) {
+ InitNativeViewport();
}
- virtual ~NativeViewportClientImpl() {}
private:
+ // Overridden from ViewManager:
+ virtual void CreateView() MOJO_OVERRIDE {
+ ScopedMessagePipeHandle server_handle, client_handle;
+ CreateMessagePipe(&server_handle, &client_handle);
+ views_.push_back(new ViewImpl(server_handle.Pass()));
+ client_->OnViewCreated(client_handle.Pass());
+ }
+
+ // Overridden from ShellClient:
+ virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
+ client_.reset(handle.Pass(), this);
+ }
+
// Overridden from NativeViewportClient:
virtual void OnCreated() OVERRIDE {
}
@@ -90,101 +107,47 @@ class NativeViewportClientImpl : public NativeViewportClient,
launcher_->Hide();
}
+ void InitNativeViewport() {
+ AllocationScope scope;
+ ScopedMessagePipeHandle client_handle, native_viewport_handle;
+ CreateMessagePipe(&client_handle, &native_viewport_handle);
+ shell_->Connect("mojo:mojo_native_viewport_service",
+ client_handle.Pass());
+ native_viewport_.reset(native_viewport_handle.Pass(), this);
+
+ native_viewport_->Create(gfx::Rect(50, 50, 800, 600));
+ native_viewport_->Show();
+ }
+
void InitLauncher() {
if (!launcher_.is_null())
return;
AllocationScope scope;
ScopedMessagePipeHandle client_handle, native_viewport_handle;
CreateMessagePipe(&client_handle, &native_viewport_handle);
- connector_->Connect("mojo:mojo_launcher", client_handle.Pass());
+ shell_->Connect("mojo:mojo_launcher", client_handle.Pass());
launcher_.reset(native_viewport_handle.Pass(), this);
}
- Connector* connector_;
- RemotePtr<NativeViewport> native_viewport_;
- RemotePtr<Launcher> launcher_;
-
- DISALLOW_COPY_AND_ASSIGN(NativeViewportClientImpl);
-};
-
-class ViewImpl : public View {
- public:
- explicit ViewImpl(ScopedMessagePipeHandle handle)
- : id_(-1),
- client_(handle.Pass()) {}
- virtual ~ViewImpl() {}
-
- private:
- // Overridden from View:
- virtual void SetId(int view_id) MOJO_OVERRIDE {
- id_ = view_id;
- }
- virtual void GetId() MOJO_OVERRIDE {
- client_->OnGotId(id_);
- }
-
- int id_;
- RemotePtr<ViewClient> client_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewImpl);
-};
-
-class ViewManagerImpl : public ViewManager {
- public:
- explicit ViewManagerImpl(ScopedMessagePipeHandle handle)
- : client_(handle.Pass()) {
- }
- virtual ~ViewManagerImpl() {}
-
- private:
- // Overridden from ViewManager:
- virtual void CreateView() MOJO_OVERRIDE {
- ScopedMessagePipeHandle server_handle, client_handle;
- CreateMessagePipe(&server_handle, &client_handle);
- views_.push_back(new ViewImpl(server_handle.Pass()));
- client_->OnViewCreated(client_handle.Pass());
+ void DidCreateContext() {
}
+ RemotePtr<Shell> shell_;
RemotePtr<ViewManagerClient> client_;
ScopedVector<ViewImpl> views_;
+ RemotePtr<NativeViewport> native_viewport_;
+ RemotePtr<Launcher> launcher_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerImpl);
};
-class ViewManager : public ShellClient,
- public Connector {
- public:
- explicit ViewManager(ScopedMessagePipeHandle shell_handle)
- : shell_(shell_handle.Pass(), this) {
- nvc_.reset(new NativeViewportClientImpl(this));
- }
-
- private:
- // Overridden from ShellClient:
- virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
- view_managers_.push_back(new ViewManagerImpl(handle.Pass()));
- }
-
- // Overridden from Connector:
- virtual void Connect(const String& url,
- ScopedMessagePipeHandle client_handle) OVERRIDE {
- shell_->Connect(url, client_handle.Pass());
- }
-
- RemotePtr<Shell> shell_;
- scoped_ptr<NativeViewportClientImpl> nvc_;
- ScopedVector<ViewManagerImpl> view_managers_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManager);
-};
-
} // namespace examples
} // namespace mojo
extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain(
MojoHandle shell_handle) {
base::MessageLoop loop;
- mojo::examples::ViewManager view_manager(
+ mojo::examples::ViewManagerImpl view_manager(
mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass());
loop.Run();
« no previous file with comments | « mojo/examples/aura_demo/root_window_host_mojo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698