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 "mojo/services/view_manager/connection_manager.h" | 5 #include "mojo/services/view_manager/connection_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/converters/input_events/input_events_type_converters.h" | 9 #include "mojo/converters/input_events/input_events_type_converters.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 11 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
12 #include "mojo/services/view_manager/connection_manager_delegate.h" | 12 #include "mojo/services/view_manager/connection_manager_delegate.h" |
13 #include "mojo/services/view_manager/view_manager_service_impl.h" | 13 #include "mojo/services/view_manager/view_manager_service_impl.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace service { | 16 namespace service { |
17 | 17 |
| 18 class WindowManagerInternalClientImpl |
| 19 : public InterfaceImpl<WindowManagerInternalClient> { |
| 20 public: |
| 21 WindowManagerInternalClientImpl(WindowManagerInternalClient* real_client, |
| 22 ErrorHandler* error_handler) |
| 23 : real_client_(real_client), error_handler_(error_handler) {} |
| 24 ~WindowManagerInternalClientImpl() override {} |
| 25 |
| 26 // WindowManagerInternalClient: |
| 27 void DispatchInputEventToView(Id transport_view_id, EventPtr event) override { |
| 28 real_client_->DispatchInputEventToView(transport_view_id, event.Pass()); |
| 29 } |
| 30 |
| 31 // InterfaceImpl: |
| 32 void OnConnectionError() override { error_handler_->OnConnectionError(); } |
| 33 |
| 34 private: |
| 35 WindowManagerInternalClient* real_client_; |
| 36 ErrorHandler* error_handler_; |
| 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(WindowManagerInternalClientImpl); |
| 39 }; |
| 40 |
18 ConnectionManager::ScopedChange::ScopedChange( | 41 ConnectionManager::ScopedChange::ScopedChange( |
19 ViewManagerServiceImpl* connection, | 42 ViewManagerServiceImpl* connection, |
20 ConnectionManager* connection_manager, | 43 ConnectionManager* connection_manager, |
21 bool is_delete_view) | 44 bool is_delete_view) |
22 : connection_manager_(connection_manager), | 45 : connection_manager_(connection_manager), |
23 connection_id_(connection->id()), | 46 connection_id_(connection->id()), |
24 is_delete_view_(is_delete_view) { | 47 is_delete_view_(is_delete_view) { |
25 connection_manager_->PrepareForChange(this); | 48 connection_manager_->PrepareForChange(this); |
26 } | 49 } |
27 | 50 |
28 ConnectionManager::ScopedChange::~ScopedChange() { | 51 ConnectionManager::ScopedChange::~ScopedChange() { |
29 connection_manager_->FinishChange(); | 52 connection_manager_->FinishChange(); |
30 } | 53 } |
31 | 54 |
32 ConnectionManager::ConnectionManager(ApplicationConnection* app_connection, | 55 ConnectionManager::ConnectionManager(ApplicationConnection* app_connection, |
33 ConnectionManagerDelegate* delegate) | 56 ConnectionManagerDelegate* delegate) |
34 : app_connection_(app_connection), | 57 : app_connection_(app_connection), |
35 delegate_(delegate), | 58 delegate_(delegate), |
36 window_manager_vm_service_(nullptr), | 59 window_manager_vm_service_(nullptr), |
37 next_connection_id_(1), | 60 next_connection_id_(1), |
38 display_manager_( | 61 display_manager_( |
39 app_connection, | 62 app_connection, |
40 this, | 63 this, |
41 base::Bind(&ConnectionManagerDelegate::OnNativeViewportDestroyed, | 64 base::Bind(&ConnectionManagerDelegate::OnNativeViewportDestroyed, |
42 base::Unretained(delegate))), | 65 base::Unretained(delegate))), |
43 root_(new ServerView(this, RootViewId())), | 66 root_(new ServerView(this, RootViewId())), |
44 current_change_(NULL), | 67 current_change_(NULL), |
45 in_destructor_(false) { | 68 in_destructor_(false) { |
46 app_connection->ConnectToService(&window_manager_); | |
47 window_manager_.set_client(this); | |
48 window_manager_.set_error_handler(this); | |
49 // |app_connection| originates from the WindowManager. Let it connect | 69 // |app_connection| originates from the WindowManager. Let it connect |
50 // directly to the ViewManager. | 70 // directly to the ViewManager and WindowManagerInternalClient. |
51 app_connection->AddService(this); | 71 app_connection->AddService( |
| 72 static_cast<InterfaceFactory<ViewManagerService>*>(this)); |
| 73 app_connection->AddService( |
| 74 static_cast<InterfaceFactory<WindowManagerInternalClient>*>(this)); |
52 root_->SetBounds(gfx::Rect(800, 600)); | 75 root_->SetBounds(gfx::Rect(800, 600)); |
53 } | 76 } |
54 | 77 |
55 ConnectionManager::~ConnectionManager() { | 78 ConnectionManager::~ConnectionManager() { |
56 in_destructor_ = true; | 79 in_destructor_ = true; |
57 | 80 |
58 STLDeleteValues(&connection_map_); | 81 STLDeleteValues(&connection_map_); |
59 // All the connections should have been destroyed. | 82 // All the connections should have been destroyed. |
60 DCHECK(connection_map_.empty()); | 83 DCHECK(connection_map_.empty()); |
61 root_.reset(); | 84 root_.reset(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 const ViewId& id) const { | 165 const ViewId& id) const { |
143 for (ConnectionMap::const_iterator i = connection_map_.begin(); | 166 for (ConnectionMap::const_iterator i = connection_map_.begin(); |
144 i != connection_map_.end(); | 167 i != connection_map_.end(); |
145 ++i) { | 168 ++i) { |
146 if (i->second->HasRoot(id)) | 169 if (i->second->HasRoot(id)) |
147 return i->second; | 170 return i->second; |
148 } | 171 } |
149 return NULL; | 172 return NULL; |
150 } | 173 } |
151 | 174 |
152 void ConnectionManager::DispatchViewInputEventToDelegate(EventPtr event) { | |
153 window_manager_->OnViewInputEvent(event.Pass()); | |
154 } | |
155 | |
156 void ConnectionManager::ProcessViewBoundsChanged(const ServerView* view, | 175 void ConnectionManager::ProcessViewBoundsChanged(const ServerView* view, |
157 const gfx::Rect& old_bounds, | 176 const gfx::Rect& old_bounds, |
158 const gfx::Rect& new_bounds) { | 177 const gfx::Rect& new_bounds) { |
159 for (ConnectionMap::iterator i = connection_map_.begin(); | 178 for (ConnectionMap::iterator i = connection_map_.begin(); |
160 i != connection_map_.end(); | 179 i != connection_map_.end(); |
161 ++i) { | 180 ++i) { |
162 i->second->ProcessViewBoundsChanged( | 181 i->second->ProcessViewBoundsChanged( |
163 view, old_bounds, new_bounds, IsChangeSource(i->first)); | 182 view, old_bounds, new_bounds, IsChangeSource(i->first)); |
164 } | 183 } |
165 } | 184 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 new ViewManagerServiceImpl(this, | 348 new ViewManagerServiceImpl(this, |
330 kInvalidConnectionId, | 349 kInvalidConnectionId, |
331 std::string(), | 350 std::string(), |
332 std::string("mojo:window_manager"), | 351 std::string("mojo:window_manager"), |
333 RootViewId(), | 352 RootViewId(), |
334 InterfaceRequest<ServiceProvider>()); | 353 InterfaceRequest<ServiceProvider>()); |
335 AddConnection(window_manager_vm_service_); | 354 AddConnection(window_manager_vm_service_); |
336 WeakBindToRequest(window_manager_vm_service_, &request); | 355 WeakBindToRequest(window_manager_vm_service_, &request); |
337 } | 356 } |
338 | 357 |
| 358 void ConnectionManager::Create( |
| 359 ApplicationConnection* connection, |
| 360 InterfaceRequest<WindowManagerInternalClient> request) { |
| 361 if (wm_internal_client_impl_.get()) { |
| 362 VLOG(1) << "WindowManagerInternalClient requested more than once."; |
| 363 return; |
| 364 } |
| 365 |
| 366 wm_internal_client_impl_.reset( |
| 367 new WindowManagerInternalClientImpl(this, this)); |
| 368 WeakBindToRequest(wm_internal_client_impl_.get(), &request); |
| 369 } |
| 370 |
339 void ConnectionManager::OnConnectionError() { | 371 void ConnectionManager::OnConnectionError() { |
340 delegate_->OnLostConnectionToWindowManager(); | 372 delegate_->OnLostConnectionToWindowManager(); |
341 } | 373 } |
342 | 374 |
343 } // namespace service | 375 } // namespace service |
344 } // namespace mojo | 376 } // namespace mojo |
OLD | NEW |