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

Side by Side Diff: mojo/services/native_viewport/native_viewport_service.cc

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 5 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/services/launcher/launcher.cc ('k') | mojo/services/network/main.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport_service.h" 5 #include "mojo/services/native_viewport/native_viewport_service.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/interface_factory.h"
12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
13 #include "mojo/services/gles2/command_buffer_impl.h" 14 #include "mojo/services/gles2/command_buffer_impl.h"
14 #include "mojo/services/native_viewport/native_viewport.h" 15 #include "mojo/services/native_viewport/native_viewport.h"
15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
16 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" 17 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
17 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h" 18 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
18 #include "ui/events/event.h" 19 #include "ui/events/event.h"
19 20
20 namespace mojo { 21 namespace mojo {
21 namespace services { 22 namespace services {
22 namespace { 23 namespace {
23 24
24 bool IsRateLimitedEventType(ui::Event* event) { 25 bool IsRateLimitedEventType(ui::Event* event) {
25 return event->type() == ui::ET_MOUSE_MOVED || 26 return event->type() == ui::ET_MOUSE_MOVED ||
26 event->type() == ui::ET_MOUSE_DRAGGED || 27 event->type() == ui::ET_MOUSE_DRAGGED ||
27 event->type() == ui::ET_TOUCH_MOVED; 28 event->type() == ui::ET_TOUCH_MOVED;
28 } 29 }
29 30
30 } // namespace 31 } // namespace
31 32
32 class NativeViewportImpl 33 class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>,
33 : public InterfaceImpl<mojo::NativeViewport>, 34 public NativeViewportDelegate {
34 public NativeViewportDelegate {
35 public: 35 public:
36 explicit NativeViewportImpl(ApplicationConnection* connection) 36 NativeViewportImpl()
37 : widget_(gfx::kNullAcceleratedWidget), 37 : widget_(gfx::kNullAcceleratedWidget),
38 waiting_for_event_ack_(false), 38 waiting_for_event_ack_(false),
39 weak_factory_(this) {} 39 weak_factory_(this) {}
40 virtual ~NativeViewportImpl() { 40 virtual ~NativeViewportImpl() {
41 // Destroy the NativeViewport early on as it may call us back during 41 // Destroy the NativeViewport early on as it may call us back during
42 // destruction and we want to be in a known state. 42 // destruction and we want to be in a known state.
43 native_viewport_.reset(); 43 native_viewport_.reset();
44 } 44 }
45 45
46 virtual void Create(RectPtr bounds) OVERRIDE { 46 virtual void Create(RectPtr bounds) OVERRIDE {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (!command_buffer_request_.is_pending()) 86 if (!command_buffer_request_.is_pending())
87 return; 87 return;
88 DCHECK(!command_buffer_.get()); 88 DCHECK(!command_buffer_.get());
89 if (widget_ == gfx::kNullAcceleratedWidget) 89 if (widget_ == gfx::kNullAcceleratedWidget)
90 return; 90 return;
91 gfx::Size size = native_viewport_->GetSize(); 91 gfx::Size size = native_viewport_->GetSize();
92 if (size.IsEmpty()) 92 if (size.IsEmpty())
93 return; 93 return;
94 command_buffer_.reset( 94 command_buffer_.reset(
95 new CommandBufferImpl(widget_, native_viewport_->GetSize())); 95 new CommandBufferImpl(widget_, native_viewport_->GetSize()));
96 BindToRequest(command_buffer_.get(), &command_buffer_request_); 96 WeakBindToRequest(command_buffer_.get(), &command_buffer_request_);
97 } 97 }
98 98
99 virtual bool OnEvent(ui::Event* ui_event) OVERRIDE { 99 virtual bool OnEvent(ui::Event* ui_event) OVERRIDE {
100 // Must not return early before updating capture. 100 // Must not return early before updating capture.
101 switch (ui_event->type()) { 101 switch (ui_event->type()) {
102 case ui::ET_MOUSE_PRESSED: 102 case ui::ET_MOUSE_PRESSED:
103 case ui::ET_TOUCH_PRESSED: 103 case ui::ET_TOUCH_PRESSED:
104 native_viewport_->SetCapture(); 104 native_viewport_->SetCapture();
105 break; 105 break;
106 case ui::ET_MOUSE_RELEASED: 106 case ui::ET_MOUSE_RELEASED:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 gfx::AcceleratedWidget widget_; 146 gfx::AcceleratedWidget widget_;
147 scoped_ptr<services::NativeViewport> native_viewport_; 147 scoped_ptr<services::NativeViewport> native_viewport_;
148 InterfaceRequest<CommandBuffer> command_buffer_request_; 148 InterfaceRequest<CommandBuffer> command_buffer_request_;
149 scoped_ptr<CommandBufferImpl> command_buffer_; 149 scoped_ptr<CommandBufferImpl> command_buffer_;
150 bool waiting_for_event_ack_; 150 bool waiting_for_event_ack_;
151 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; 151 base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
152 }; 152 };
153 153
154 class NVSDelegate : public ApplicationDelegate { 154 class NVSDelegate : public ApplicationDelegate,
155 public InterfaceFactory<mojo::NativeViewport> {
155 public: 156 public:
156 NVSDelegate() {} 157 NVSDelegate() {}
157 virtual ~NVSDelegate() {} 158 virtual ~NVSDelegate() {}
158 159
160 // ApplicationDelegate implementation.
159 virtual bool ConfigureIncomingConnection( 161 virtual bool ConfigureIncomingConnection(
160 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { 162 mojo::ApplicationConnection* connection) OVERRIDE {
161 connection->AddService<NativeViewportImpl>(); 163 connection->AddService(this);
162 return true; 164 return true;
163 } 165 }
166
167 // ServiceFactory<mojo::NativeViewport> implementation.
168 virtual void Create(ApplicationConnection* connection,
169 InterfaceRequest<mojo::NativeViewport> request) OVERRIDE {
170 BindToRequest(new NativeViewportImpl, &request);
171 }
164 }; 172 };
165 173
166 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* 174 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl*
167 CreateNativeViewportService( 175 CreateNativeViewportService(
168 ScopedMessagePipeHandle service_provider_handle) { 176 ScopedMessagePipeHandle service_provider_handle) {
169 ApplicationImpl* app = new ApplicationImpl( 177 ApplicationImpl* app = new ApplicationImpl(
170 new NVSDelegate(), service_provider_handle.Pass()); 178 new NVSDelegate(), service_provider_handle.Pass());
171 return app; 179 return app;
172 } 180 }
173 181
174 } // namespace services 182 } // namespace services
175 } // namespace mojo 183 } // namespace mojo
176 184
OLDNEW
« no previous file with comments | « mojo/services/launcher/launcher.cc ('k') | mojo/services/network/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698