OLD | NEW |
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/examples/launcher/launcher.mojom.h" | 10 #include "mojo/examples/launcher/launcher.mojom.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #else | 29 #else |
30 #define CDECL | 30 #define CDECL |
31 #define VIEW_MANAGER_EXPORT __attribute__((visibility("default"))) | 31 #define VIEW_MANAGER_EXPORT __attribute__((visibility("default"))) |
32 #endif | 32 #endif |
33 | 33 |
34 namespace mojo { | 34 namespace mojo { |
35 namespace examples { | 35 namespace examples { |
36 | 36 |
37 class ViewImpl : public View { | 37 class ViewImpl : public View { |
38 public: | 38 public: |
39 explicit ViewImpl(ScopedViewClientHandle client_handle) | 39 explicit ViewImpl(ScopedViewClientHandle handle) |
40 : id_(-1), | 40 : id_(-1), |
41 client_(client_handle.Pass()) {} | 41 client_(handle.Pass(), this) {} |
42 virtual ~ViewImpl() {} | 42 virtual ~ViewImpl() {} |
43 | 43 |
44 private: | 44 private: |
45 // Overridden from View: | 45 // Overridden from View: |
46 virtual void SetId(int view_id) MOJO_OVERRIDE { | 46 virtual void SetId(int view_id) MOJO_OVERRIDE { |
47 id_ = view_id; | 47 id_ = view_id; |
48 } | 48 } |
49 virtual void GetId() MOJO_OVERRIDE { | 49 virtual void GetId(const mojo::Callback<void(int32_t)>& callback) |
50 client_->OnGotId(id_); | 50 MOJO_OVERRIDE { |
| 51 callback.Run(id_); |
51 } | 52 } |
52 | 53 |
53 int id_; | 54 int id_; |
54 RemotePtr<ViewClient> client_; | 55 RemotePtr<ViewClient> client_; |
55 | 56 |
56 DISALLOW_COPY_AND_ASSIGN(ViewImpl); | 57 DISALLOW_COPY_AND_ASSIGN(ViewImpl); |
57 }; | 58 }; |
58 | 59 |
59 class ViewManagerImpl : public Service<ViewManager, ViewManagerImpl>, | 60 class ViewManagerImpl : public Service<ViewManager, ViewManagerImpl>, |
60 public NativeViewportClient, | 61 public NativeViewportClient, |
61 public LauncherClient { | 62 public LauncherClient { |
62 public: | 63 public: |
63 explicit ViewManagerImpl() { | 64 explicit ViewManagerImpl() { |
64 InitNativeViewport(); | 65 InitNativeViewport(); |
65 } | 66 } |
66 | 67 |
67 private: | 68 private: |
68 // Overridden from ViewManager: | 69 // Overridden from ViewManager: |
69 virtual void CreateView() MOJO_OVERRIDE { | 70 virtual void CreateView(const Callback<void(ScopedViewHandle)>& callback) |
| 71 MOJO_OVERRIDE { |
70 InterfacePipe<View> pipe; | 72 InterfacePipe<View> pipe; |
71 views_.push_back(new ViewImpl(pipe.handle_to_peer.Pass())); | 73 views_.push_back(new ViewImpl(pipe.handle_to_peer.Pass())); |
72 client()->OnViewCreated(pipe.handle_to_self.Pass()); | 74 callback.Run(pipe.handle_to_self.Pass()); |
73 } | 75 } |
74 | 76 |
75 // Overridden from NativeViewportClient: | 77 // Overridden from NativeViewportClient: |
76 virtual void OnCreated() OVERRIDE { | 78 virtual void OnCreated() OVERRIDE { |
77 } | 79 } |
78 virtual void OnDestroyed() OVERRIDE { | 80 virtual void OnDestroyed() OVERRIDE { |
79 base::MessageLoop::current()->Quit(); | 81 base::MessageLoop::current()->Quit(); |
80 } | 82 } |
81 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { | 83 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { |
82 // TODO(beng): | 84 // TODO(beng): |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain( | 142 extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain( |
141 MojoHandle shell_handle) { | 143 MojoHandle shell_handle) { |
142 base::MessageLoop loop; | 144 base::MessageLoop loop; |
143 mojo::Application app(shell_handle); | 145 mojo::Application app(shell_handle); |
144 app.AddServiceFactory( | 146 app.AddServiceFactory( |
145 new mojo::ServiceFactory<mojo::examples::ViewManagerImpl>); | 147 new mojo::ServiceFactory<mojo::examples::ViewManagerImpl>); |
146 loop.Run(); | 148 loop.Run(); |
147 | 149 |
148 return MOJO_RESULT_OK; | 150 return MOJO_RESULT_OK; |
149 } | 151 } |
OLD | NEW |