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

Side by Side Diff: mojo/examples/view_manager/view_manager.cc

Issue 162213002: Change mojo demo apps to use Application. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add shell() to ServiceFactory::Owner Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/sample_app/sample_app.cc ('k') | mojo/public/shell/application.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mojo/public/bindings/allocation_scope.h" 10 #include "mojo/public/bindings/allocation_scope.h"
11 #include "mojo/public/bindings/remote_ptr.h" 11 #include "mojo/public/bindings/remote_ptr.h"
12 #include "mojo/public/shell/application.h"
12 #include "mojo/public/system/core.h" 13 #include "mojo/public/system/core.h"
13 #include "mojo/public/system/macros.h" 14 #include "mojo/public/system/macros.h"
14 #include "mojo/services/native_viewport/geometry_conversions.h" 15 #include "mojo/services/native_viewport/geometry_conversions.h"
15 #include "mojom/launcher.h" 16 #include "mojom/launcher.h"
16 #include "mojom/native_viewport.h" 17 #include "mojom/native_viewport.h"
17 #include "mojom/shell.h" 18 #include "mojom/shell.h"
18 #include "mojom/view_manager.h" 19 #include "mojom/view_manager.h"
19 #include "ui/events/event_constants.h" 20 #include "ui/events/event_constants.h"
20 #include "ui/events/keycodes/keyboard_codes.h" 21 #include "ui/events/keycodes/keyboard_codes.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
(...skipping 26 matching lines...) Expand all
48 virtual void GetId() MOJO_OVERRIDE { 49 virtual void GetId() MOJO_OVERRIDE {
49 client_->OnGotId(id_); 50 client_->OnGotId(id_);
50 } 51 }
51 52
52 int id_; 53 int id_;
53 RemotePtr<ViewClient> client_; 54 RemotePtr<ViewClient> client_;
54 55
55 DISALLOW_COPY_AND_ASSIGN(ViewImpl); 56 DISALLOW_COPY_AND_ASSIGN(ViewImpl);
56 }; 57 };
57 58
58 class ViewManagerImpl : public ViewManager, 59 class ViewManagerImpl : public Service<ViewManager, ViewManagerImpl>,
59 public ShellClient,
60 public NativeViewportClient, 60 public NativeViewportClient,
61 public LauncherClient { 61 public LauncherClient {
62 public: 62 public:
63 explicit ViewManagerImpl(ScopedShellHandle shell_handle) 63 explicit ViewManagerImpl() {
64 : shell_(shell_handle.Pass(), this) {
65 InitNativeViewport(); 64 InitNativeViewport();
66 } 65 }
67 66
68 private: 67 private:
69 // Overridden from ViewManager: 68 // Overridden from ViewManager:
70 virtual void CreateView() MOJO_OVERRIDE { 69 virtual void CreateView() MOJO_OVERRIDE {
71 InterfacePipe<View> pipe; 70 InterfacePipe<View> pipe;
72 views_.push_back(new ViewImpl(pipe.handle_to_peer.Pass())); 71 views_.push_back(new ViewImpl(pipe.handle_to_peer.Pass()));
73 client_->OnViewCreated(pipe.handle_to_self.Pass()); 72 client()->OnViewCreated(pipe.handle_to_self.Pass());
74 }
75
76 // Overridden from ShellClient:
77 virtual void AcceptConnection(const mojo::String& url,
78 ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
79 client_.reset(
80 MakeScopedHandle(
81 ViewManagerClientHandle(handle.release().value())).Pass(),
82 this);
83 } 73 }
84 74
85 // Overridden from NativeViewportClient: 75 // Overridden from NativeViewportClient:
86 virtual void OnCreated() OVERRIDE { 76 virtual void OnCreated() OVERRIDE {
87 } 77 }
88 virtual void OnDestroyed() OVERRIDE { 78 virtual void OnDestroyed() OVERRIDE {
89 base::MessageLoop::current()->Quit(); 79 base::MessageLoop::current()->Quit();
90 } 80 }
91 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { 81 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE {
92 // TODO(beng): 82 // TODO(beng):
(...skipping 14 matching lines...) Expand all
107 virtual void OnURLEntered(const mojo::String& url) OVERRIDE { 97 virtual void OnURLEntered(const mojo::String& url) OVERRIDE {
108 std::string url_spec = url.To<std::string>(); 98 std::string url_spec = url.To<std::string>();
109 printf("Received URL from launcher app: %s\n", url_spec.c_str()); 99 printf("Received URL from launcher app: %s\n", url_spec.c_str());
110 launcher_->Hide(); 100 launcher_->Hide();
111 } 101 }
112 102
113 void InitNativeViewport() { 103 void InitNativeViewport() {
114 InterfacePipe<NativeViewport, AnyInterface> pipe; 104 InterfacePipe<NativeViewport, AnyInterface> pipe;
115 105
116 AllocationScope scope; 106 AllocationScope scope;
117 shell_->Connect("mojo:mojo_native_viewport_service", 107 shell()->Connect("mojo:mojo_native_viewport_service",
118 pipe.handle_to_peer.Pass()); 108 pipe.handle_to_peer.Pass());
119 109
120 native_viewport_.reset(pipe.handle_to_self.Pass(), this); 110 native_viewport_.reset(pipe.handle_to_self.Pass(), this);
121 native_viewport_->Create(gfx::Rect(50, 50, 800, 600)); 111 native_viewport_->Create(gfx::Rect(50, 50, 800, 600));
122 native_viewport_->Show(); 112 native_viewport_->Show();
123 } 113 }
124 114
125 void InitLauncher() { 115 void InitLauncher() {
126 if (!launcher_.is_null()) 116 if (!launcher_.is_null())
127 return; 117 return;
128 118
129 InterfacePipe<Launcher, AnyInterface> pipe; 119 InterfacePipe<Launcher, AnyInterface> pipe;
130 120
131 AllocationScope scope; 121 AllocationScope scope;
132 shell_->Connect("mojo:mojo_launcher", pipe.handle_to_peer.Pass()); 122 shell()->Connect("mojo:mojo_launcher", pipe.handle_to_peer.Pass());
133 123
134 launcher_.reset(pipe.handle_to_self.Pass(), this); 124 launcher_.reset(pipe.handle_to_self.Pass(), this);
135 } 125 }
136 126
137 void DidCreateContext() { 127 void DidCreateContext() {
138 } 128 }
139 129
140 RemotePtr<Shell> shell_;
141 RemotePtr<ViewManagerClient> client_;
142 ScopedVector<ViewImpl> views_; 130 ScopedVector<ViewImpl> views_;
143 RemotePtr<NativeViewport> native_viewport_; 131 RemotePtr<NativeViewport> native_viewport_;
144 RemotePtr<Launcher> launcher_; 132 RemotePtr<Launcher> launcher_;
145 133
146 DISALLOW_COPY_AND_ASSIGN(ViewManagerImpl); 134 DISALLOW_COPY_AND_ASSIGN(ViewManagerImpl);
147 }; 135 };
148 136
149 } // namespace examples 137 } // namespace examples
150 } // namespace mojo 138 } // namespace mojo
151 139
152 extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain( 140 extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain(
153 MojoHandle shell_handle) { 141 MojoHandle shell_handle) {
154 base::MessageLoop loop; 142 base::MessageLoop loop;
155 mojo::examples::ViewManagerImpl view_manager( 143 mojo::Application app(shell_handle);
156 mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass()); 144 app.AddServiceFactory(
145 new mojo::ServiceFactory<mojo::examples::ViewManagerImpl>);
157 loop.Run(); 146 loop.Run();
158 147
159 return MOJO_RESULT_OK; 148 return MOJO_RESULT_OK;
160 } 149 }
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/sample_app.cc ('k') | mojo/public/shell/application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698