| 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 #ifndef MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| 6 #define MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "mojo/public/cpp/application/interface_factory.h" | 12 #include "mojo/public/cpp/application/interface_factory.h" |
| 13 #include "mojo/public/cpp/bindings/array.h" | 13 #include "mojo/public/cpp/bindings/array.h" |
| 14 #include "mojo/public/cpp/bindings/error_handler.h" | 14 #include "mojo/public/cpp/bindings/error_handler.h" |
| 15 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 15 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
| 16 #include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h" | 16 #include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h" |
| 17 #include "mojo/services/view_manager/display_manager.h" | 17 #include "mojo/services/view_manager/display_manager.h" |
| 18 #include "mojo/services/view_manager/ids.h" | 18 #include "mojo/services/view_manager/ids.h" |
| 19 #include "mojo/services/view_manager/server_view.h" | 19 #include "mojo/services/view_manager/server_view.h" |
| 20 #include "mojo/services/view_manager/server_view_delegate.h" | 20 #include "mojo/services/view_manager/server_view_delegate.h" |
| 21 #include "mojo/services/view_manager/view_manager_export.h" | 21 #include "mojo/services/view_manager/view_manager_export.h" |
| 22 | 22 |
| 23 namespace mojo { | 23 namespace mojo { |
| 24 | 24 |
| 25 class ApplicationConnection; | 25 class ApplicationConnection; |
| 26 | 26 |
| 27 namespace service { | 27 namespace service { |
| 28 | 28 |
| 29 class ConnectionManagerDelegate; |
| 29 class ViewManagerServiceImpl; | 30 class ViewManagerServiceImpl; |
| 30 | 31 |
| 31 // ConnectionManager manages the set of connections to the ViewManager (all the | 32 // ConnectionManager manages the set of connections to the ViewManager (all the |
| 32 // ViewManagerServiceImpls) as well as providing the root of the hierarchy. | 33 // ViewManagerServiceImpls) as well as providing the root of the hierarchy. |
| 33 class MOJO_VIEW_MANAGER_EXPORT ConnectionManager | 34 class MOJO_VIEW_MANAGER_EXPORT ConnectionManager |
| 34 : public ServerViewDelegate, | 35 : public ServerViewDelegate, |
| 35 public WindowManagerInternalClient, | 36 public WindowManagerInternalClient, |
| 36 public InterfaceFactory<ViewManagerService>, | 37 public InterfaceFactory<ViewManagerService>, |
| 37 public ErrorHandler { | 38 public ErrorHandler { |
| 38 public: | 39 public: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 const ConnectionSpecificId connection_id_; | 64 const ConnectionSpecificId connection_id_; |
| 64 const bool is_delete_view_; | 65 const bool is_delete_view_; |
| 65 | 66 |
| 66 // See description of MarkConnectionAsMessaged/DidMessageConnection. | 67 // See description of MarkConnectionAsMessaged/DidMessageConnection. |
| 67 std::set<ConnectionSpecificId> message_ids_; | 68 std::set<ConnectionSpecificId> message_ids_; |
| 68 | 69 |
| 69 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 70 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 ConnectionManager(ApplicationConnection* app_connection, | 73 ConnectionManager(ApplicationConnection* app_connection, |
| 73 const Callback<void()>& native_viewport_closed_callback); | 74 ConnectionManagerDelegate* delegate); |
| 74 ~ConnectionManager() override; | 75 ~ConnectionManager() override; |
| 75 | 76 |
| 76 // Returns the id for the next ViewManagerServiceImpl. | 77 // Returns the id for the next ViewManagerServiceImpl. |
| 77 ConnectionSpecificId GetAndAdvanceNextConnectionId(); | 78 ConnectionSpecificId GetAndAdvanceNextConnectionId(); |
| 78 | 79 |
| 79 void AddConnection(ViewManagerServiceImpl* connection); | 80 // Invoked when a ViewManagerServiceImpl's connection encounters an error. |
| 80 void RemoveConnection(ViewManagerServiceImpl* connection); | 81 void OnConnectionError(ViewManagerServiceImpl* connection); |
| 81 | 82 |
| 82 // See description of ViewManagerService::Embed() for details. This assumes | 83 // See description of ViewManagerService::Embed() for details. This assumes |
| 83 // |transport_view_id| is valid. | 84 // |transport_view_id| is valid. |
| 84 void EmbedAtView(ConnectionSpecificId creator_id, | 85 void EmbedAtView(ConnectionSpecificId creator_id, |
| 85 const String& url, | 86 const String& url, |
| 86 Id transport_view_id, | 87 Id transport_view_id, |
| 87 InterfaceRequest<ServiceProvider> service_provider); | 88 InterfaceRequest<ServiceProvider> service_provider); |
| 88 | 89 |
| 89 // Returns the connection by id. | 90 // Returns the connection by id. |
| 90 ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id); | 91 ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void PrepareForChange(ScopedChange* change); | 146 void PrepareForChange(ScopedChange* change); |
| 146 | 147 |
| 147 // Balances a call to PrepareForChange(). | 148 // Balances a call to PrepareForChange(). |
| 148 void FinishChange(); | 149 void FinishChange(); |
| 149 | 150 |
| 150 // Returns true if the specified connection originated the current change. | 151 // Returns true if the specified connection originated the current change. |
| 151 bool IsChangeSource(ConnectionSpecificId connection_id) const { | 152 bool IsChangeSource(ConnectionSpecificId connection_id) const { |
| 152 return current_change_ && current_change_->connection_id() == connection_id; | 153 return current_change_ && current_change_->connection_id() == connection_id; |
| 153 } | 154 } |
| 154 | 155 |
| 155 // Implementation of the two embed variants. | 156 // Adds |connection| to internal maps. |
| 156 ViewManagerServiceImpl* EmbedImpl( | 157 void AddConnection(ViewManagerServiceImpl* connection); |
| 157 ConnectionSpecificId creator_id, | |
| 158 const String& url, | |
| 159 const ViewId& root_id, | |
| 160 InterfaceRequest<ServiceProvider> service_provider); | |
| 161 | 158 |
| 162 // Overridden from ServerViewDelegate: | 159 // Overridden from ServerViewDelegate: |
| 163 void OnViewDestroyed(const ServerView* view) override; | 160 void OnViewDestroyed(const ServerView* view) override; |
| 164 void OnWillChangeViewHierarchy(const ServerView* view, | 161 void OnWillChangeViewHierarchy(const ServerView* view, |
| 165 const ServerView* new_parent, | 162 const ServerView* new_parent, |
| 166 const ServerView* old_parent) override; | 163 const ServerView* old_parent) override; |
| 167 void OnViewHierarchyChanged(const ServerView* view, | 164 void OnViewHierarchyChanged(const ServerView* view, |
| 168 const ServerView* new_parent, | 165 const ServerView* new_parent, |
| 169 const ServerView* old_parent) override; | 166 const ServerView* old_parent) override; |
| 170 void OnViewBoundsChanged(const ServerView* view, | 167 void OnViewBoundsChanged(const ServerView* view, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 185 | 182 |
| 186 // InterfaceFactory<ViewManagerService>: | 183 // InterfaceFactory<ViewManagerService>: |
| 187 virtual void Create(ApplicationConnection* connection, | 184 virtual void Create(ApplicationConnection* connection, |
| 188 InterfaceRequest<ViewManagerService> request) override; | 185 InterfaceRequest<ViewManagerService> request) override; |
| 189 | 186 |
| 190 // ErrorHandler: | 187 // ErrorHandler: |
| 191 void OnConnectionError() override; | 188 void OnConnectionError() override; |
| 192 | 189 |
| 193 ApplicationConnection* app_connection_; | 190 ApplicationConnection* app_connection_; |
| 194 | 191 |
| 192 ConnectionManagerDelegate* delegate_; |
| 193 |
| 194 // The ViewManager implementation provided to the initial connection (the |
| 195 // WindowManager). |
| 196 // NOTE: |window_manager_vm_service_| is also in |connection_map_|. |
| 197 ViewManagerServiceImpl* window_manager_vm_service_; |
| 198 |
| 195 WindowManagerInternalServicePtr window_manager_; | 199 WindowManagerInternalServicePtr window_manager_; |
| 196 | 200 |
| 197 // ID to use for next ViewManagerServiceImpl. | 201 // ID to use for next ViewManagerServiceImpl. |
| 198 ConnectionSpecificId next_connection_id_; | 202 ConnectionSpecificId next_connection_id_; |
| 199 | 203 |
| 200 // Set of ViewManagerServiceImpls. | 204 // Set of ViewManagerServiceImpls. |
| 201 ConnectionMap connection_map_; | 205 ConnectionMap connection_map_; |
| 202 | 206 |
| 203 DisplayManager display_manager_; | 207 DisplayManager display_manager_; |
| 204 | 208 |
| 205 scoped_ptr<ServerView> root_; | 209 scoped_ptr<ServerView> root_; |
| 206 | 210 |
| 207 // Set of ViewManagerServiceImpls created by way of Connect(). These have to | |
| 208 // be explicitly destroyed. | |
| 209 std::set<ViewManagerServiceImpl*> connections_created_by_connect_; | |
| 210 | |
| 211 // If non-null we're processing a change. The ScopedChange is not owned by us | 211 // If non-null we're processing a change. The ScopedChange is not owned by us |
| 212 // (it's created on the stack by ViewManagerServiceImpl). | 212 // (it's created on the stack by ViewManagerServiceImpl). |
| 213 ScopedChange* current_change_; | 213 ScopedChange* current_change_; |
| 214 | 214 |
| 215 bool in_destructor_; |
| 216 |
| 215 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); | 217 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); |
| 216 }; | 218 }; |
| 217 | 219 |
| 218 } // namespace service | 220 } // namespace service |
| 219 } // namespace mojo | 221 } // namespace mojo |
| 220 | 222 |
| 221 #endif // MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 223 #endif // MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| OLD | NEW |