| 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_VIEW_MANAGER_CONNECTION_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
| 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "mojo/public/cpp/shell/service.h" | 11 #include "mojo/public/cpp/shell/service.h" |
| 12 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 12 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
| 13 #include "mojo/services/view_manager/node_delegate.h" | 13 #include "mojo/services/view_manager/node_delegate.h" |
| 14 #include "mojo/services/view_manager/view_manager_export.h" | 14 #include "mojo/services/view_manager/view_manager_export.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace services { | 17 namespace services { |
| 18 namespace view_manager { | 18 namespace view_manager { |
| 19 | 19 |
| 20 class Node; | 20 class Node; |
| 21 class RootNodeManager; | 21 class RootNodeManager; |
| 22 class View; | |
| 23 | 22 |
| 24 // Manages a connection from the client. | 23 // Manages a connection from the client. |
| 25 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection | 24 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection |
| 26 : public ServiceConnection<ViewManager, ViewManagerConnection, | 25 : public ServiceConnection<ViewManager, ViewManagerConnection, |
| 27 RootNodeManager>, | 26 RootNodeManager>, |
| 28 public NodeDelegate { | 27 public NodeDelegate { |
| 29 public: | 28 public: |
| 30 ViewManagerConnection(); | 29 ViewManagerConnection(); |
| 31 virtual ~ViewManagerConnection(); | 30 virtual ~ViewManagerConnection(); |
| 32 | 31 |
| 33 uint16_t id() const { return id_; } | 32 uint16_t id() const { return id_; } |
| 34 | 33 |
| 35 // Invoked from Service when connection is established. | 34 // Invoked from Service when connection is established. |
| 36 void Initialize( | 35 void Initialize( |
| 37 ServiceConnector<ViewManagerConnection, RootNodeManager>* service_factory, | 36 ServiceConnector<ViewManagerConnection, RootNodeManager>* service_factory, |
| 38 ScopedMessagePipeHandle client_handle); | 37 ScopedMessagePipeHandle client_handle); |
| 39 | 38 |
| 40 // Returns the Node with the specified id. | 39 // Returns the Node by id. |
| 41 Node* GetNode(const NodeId& id); | 40 Node* GetNode(const NodeId& id); |
| 42 | 41 |
| 43 // Returns the View with the specified id. | |
| 44 View* GetView(const ViewId& id); | |
| 45 | |
| 46 // Notifies the client of a hierarchy change. | 42 // Notifies the client of a hierarchy change. |
| 47 void NotifyNodeHierarchyChanged(const NodeId& node, | 43 void NotifyNodeHierarchyChanged(const NodeId& node, |
| 48 const NodeId& new_parent, | 44 const NodeId& new_parent, |
| 49 const NodeId& old_parent, | 45 const NodeId& old_parent, |
| 50 int32_t change_id); | 46 int32_t change_id); |
| 51 void NotifyNodeViewReplaced(const NodeId& node, | |
| 52 const ViewId& new_view_id, | |
| 53 const ViewId& old_view_id, | |
| 54 int32_t change_id); | |
| 55 | 47 |
| 56 private: | 48 private: |
| 57 typedef std::map<uint16_t, Node*> NodeMap; | 49 typedef std::map<uint16_t, Node*> NodeMap; |
| 58 typedef std::map<uint16_t, View*> ViewMap; | |
| 59 | |
| 60 // Deletes a node owned by this connection. Returns true on success. |source| | |
| 61 // is the connection that originated the change. | |
| 62 bool DeleteNodeImpl(ViewManagerConnection* source, | |
| 63 const NodeId& node_id, | |
| 64 int32_t change_id); | |
| 65 | |
| 66 // Deletes a view owned by this connection. Returns true on success. |source| | |
| 67 // is the connection that originated the change. | |
| 68 bool DeleteViewImpl(ViewManagerConnection* source, | |
| 69 const ViewId& view_id, | |
| 70 int32_t change_id); | |
| 71 | |
| 72 // Sets the view associated with a node. | |
| 73 bool SetViewImpl(const NodeId& node_id, | |
| 74 const ViewId& view_id, | |
| 75 int32_t change_id); | |
| 76 | 50 |
| 77 // Overridden from ViewManager: | 51 // Overridden from ViewManager: |
| 78 virtual void CreateNode(uint16_t node_id, | 52 virtual void CreateNode(uint16_t node_id, |
| 79 const Callback<void(bool)>& callback) OVERRIDE; | 53 const Callback<void(bool)>& callback) OVERRIDE; |
| 80 virtual void DeleteNode(uint32_t transport_node_id, | |
| 81 int32_t change_id, | |
| 82 const mojo::Callback<void(bool)>& callback) OVERRIDE; | |
| 83 virtual void AddNode(uint32_t parent_id, | 54 virtual void AddNode(uint32_t parent_id, |
| 84 uint32_t child_id, | 55 uint32_t child_id, |
| 85 int32_t change_id, | 56 int32_t change_id, |
| 86 const Callback<void(bool)>& callback) OVERRIDE; | 57 const Callback<void(bool)>& callback) OVERRIDE; |
| 87 virtual void RemoveNodeFromParent( | 58 virtual void RemoveNodeFromParent( |
| 88 uint32_t node_id, | 59 uint32_t node_id, |
| 89 int32_t change_id, | 60 int32_t change_id, |
| 90 const Callback<void(bool)>& callback) OVERRIDE; | 61 const Callback<void(bool)>& callback) OVERRIDE; |
| 91 virtual void CreateView(uint16_t view_id, | |
| 92 const mojo::Callback<void(bool)>& callback) OVERRIDE; | |
| 93 virtual void DeleteView(uint32_t transport_view_id, | |
| 94 int32_t change_id, | |
| 95 const mojo::Callback<void(bool)>& callback) OVERRIDE; | |
| 96 virtual void SetView(uint32_t transport_node_id, | |
| 97 uint32_t transport_view_id, | |
| 98 int32_t change_id, | |
| 99 const mojo::Callback<void(bool)>& callback) OVERRIDE; | |
| 100 | 62 |
| 101 // Overriden from NodeDelegate: | 63 // Overriden from NodeDelegate: |
| 102 virtual void OnNodeHierarchyChanged(const NodeId& node, | 64 virtual void OnNodeHierarchyChanged(const NodeId& node, |
| 103 const NodeId& new_parent, | 65 const NodeId& new_parent, |
| 104 const NodeId& old_parent) OVERRIDE; | 66 const NodeId& old_parent) OVERRIDE; |
| 105 virtual void OnNodeViewReplaced(const NodeId& node, | |
| 106 const ViewId& new_view_id, | |
| 107 const ViewId& old_view_id); | |
| 108 | 67 |
| 109 // Id of this connection as assigned by RootNodeManager. Assigned in | 68 // Id of this connection as assigned by RootNodeManager. Assigned in |
| 110 // Initialize(). | 69 // Initialize(). |
| 111 uint16_t id_; | 70 uint16_t id_; |
| 112 | 71 |
| 113 NodeMap node_map_; | 72 NodeMap node_map_; |
| 114 | 73 |
| 115 ViewMap view_map_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); | 74 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); |
| 118 }; | 75 }; |
| 119 | 76 |
| 120 } // namespace view_manager | 77 } // namespace view_manager |
| 121 } // namespace services | 78 } // namespace services |
| 122 } // namespace mojo | 79 } // namespace mojo |
| 123 | 80 |
| 124 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 81 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
| OLD | NEW |