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 #include <vector> | |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
13 #include "base/containers/hash_tables.h" | |
14 #include "mojo/public/cpp/shell/service.h" | 12 #include "mojo/public/cpp/shell/service.h" |
15 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 13 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
16 #include "mojo/services/view_manager/ids.h" | 14 #include "mojo/services/view_manager/ids.h" |
17 #include "mojo/services/view_manager/node_delegate.h" | 15 #include "mojo/services/view_manager/node_delegate.h" |
18 #include "mojo/services/view_manager/view_manager_export.h" | 16 #include "mojo/services/view_manager/view_manager_export.h" |
19 | 17 |
20 namespace mojo { | 18 namespace mojo { |
21 namespace view_manager { | 19 namespace view_manager { |
22 namespace service { | 20 namespace service { |
23 | 21 |
(...skipping 21 matching lines...) Expand all Loading... |
45 | 43 |
46 // Invoked when connection is established. | 44 // Invoked when connection is established. |
47 void Initialize(); | 45 void Initialize(); |
48 | 46 |
49 // Returns the Node with the specified id. | 47 // Returns the Node with the specified id. |
50 Node* GetNode(const NodeId& id); | 48 Node* GetNode(const NodeId& id); |
51 | 49 |
52 // Returns the View with the specified id. | 50 // Returns the View with the specified id. |
53 View* GetView(const ViewId& id); | 51 View* GetView(const ViewId& id); |
54 | 52 |
55 // The following methods are invoked after the corresponding change has been | 53 // Notifies the client of a hierarchy change. |
56 // processed. They do the appropriate bookkeeping and update the client as | 54 void NotifyNodeHierarchyChanged(const NodeId& node, |
57 // necessary. | 55 const NodeId& new_parent, |
58 // TODO(sky): convert these to take Node*s. | 56 const NodeId& old_parent, |
59 void ProcessNodeHierarchyChanged(const NodeId& node_id, | 57 TransportChangeId server_change_id); |
60 const NodeId& new_parent_id, | 58 void NotifyNodeViewReplaced(const NodeId& node, |
61 const NodeId& old_parent_id, | 59 const ViewId& new_view_id, |
62 TransportChangeId server_change_id, | 60 const ViewId& old_view_id); |
63 bool originated_change); | 61 void NotifyNodeDeleted(const NodeId& node, |
64 void ProcessNodeViewReplaced(const NodeId& node, | 62 TransportChangeId server_change_id); |
65 const ViewId& new_view_id, | 63 void NotifyViewDeleted(const ViewId& view); |
66 const ViewId& old_view_id, | |
67 bool originated_change); | |
68 void ProcessNodeDeleted(const NodeId& node, | |
69 TransportChangeId server_change_id, | |
70 bool originated_change); | |
71 void ProcessViewDeleted(const ViewId& view, bool originated_change); | |
72 | 64 |
73 private: | 65 private: |
74 typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap; | 66 typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap; |
75 typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap; | 67 typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap; |
76 typedef base::hash_set<TransportNodeId> NodeIdSet; | |
77 | 68 |
78 // Deletes a node owned by this connection. Returns true on success. |source| | 69 // Deletes a node owned by this connection. Returns true on success. |source| |
79 // is the connection that originated the change. | 70 // is the connection that originated the change. |
80 bool DeleteNodeImpl(ViewManagerConnection* source, const NodeId& node_id); | 71 bool DeleteNodeImpl(ViewManagerConnection* source, const NodeId& node_id); |
81 | 72 |
82 // Deletes a view owned by this connection. Returns true on success. |source| | 73 // Deletes a view owned by this connection. Returns true on success. |source| |
83 // is the connection that originated the change. | 74 // is the connection that originated the change. |
84 bool DeleteViewImpl(ViewManagerConnection* source, const ViewId& view_id); | 75 bool DeleteViewImpl(ViewManagerConnection* source, const ViewId& view_id); |
85 | 76 |
86 // Sets the view associated with a node. | 77 // Sets the view associated with a node. |
87 bool SetViewImpl(const NodeId& node_id, const ViewId& view_id); | 78 bool SetViewImpl(const NodeId& node_id, const ViewId& view_id); |
88 | 79 |
89 // If |node| is known (in |known_nodes_|) does nothing. Otherwise adds |node| | |
90 // to |nodes|, marks |node| as known and recurses. | |
91 void GetUnknownNodesFrom(Node* node, std::vector<Node*>* nodes); | |
92 | |
93 // Returns true if notification should be sent of a hierarchy change. If true | |
94 // is returned, any nodes that need to be sent to the client are added to | |
95 // |to_send|. | |
96 bool ShouldNotifyOnHierarchyChange(const NodeId& node_id, | |
97 const NodeId& new_parent_id, | |
98 const NodeId& old_parent_id, | |
99 std::vector<Node*>* to_send); | |
100 | |
101 // Overridden from IViewManager: | 80 // Overridden from IViewManager: |
102 virtual void CreateNode(TransportNodeId transport_node_id, | 81 virtual void CreateNode(TransportNodeId transport_node_id, |
103 const Callback<void(bool)>& callback) OVERRIDE; | 82 const Callback<void(bool)>& callback) OVERRIDE; |
104 virtual void DeleteNode(TransportNodeId transport_node_id, | 83 virtual void DeleteNode(TransportNodeId transport_node_id, |
105 const Callback<void(bool)>& callback) OVERRIDE; | 84 const Callback<void(bool)>& callback) OVERRIDE; |
106 virtual void AddNode(TransportNodeId parent_id, | 85 virtual void AddNode(TransportNodeId parent_id, |
107 TransportNodeId child_id, | 86 TransportNodeId child_id, |
108 TransportChangeId server_change_id, | 87 TransportChangeId server_change_id, |
109 const Callback<void(bool)>& callback) OVERRIDE; | 88 const Callback<void(bool)>& callback) OVERRIDE; |
110 virtual void RemoveNodeFromParent( | 89 virtual void RemoveNodeFromParent( |
(...skipping 23 matching lines...) Expand all Loading... |
134 const ViewId& old_view_id) OVERRIDE; | 113 const ViewId& old_view_id) OVERRIDE; |
135 | 114 |
136 // Id of this connection as assigned by RootNodeManager. Assigned in | 115 // Id of this connection as assigned by RootNodeManager. Assigned in |
137 // Initialize(). | 116 // Initialize(). |
138 TransportConnectionId id_; | 117 TransportConnectionId id_; |
139 | 118 |
140 NodeMap node_map_; | 119 NodeMap node_map_; |
141 | 120 |
142 ViewMap view_map_; | 121 ViewMap view_map_; |
143 | 122 |
144 // The set of nodes that has been communicated to the client. | |
145 NodeIdSet known_nodes_; | |
146 | |
147 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); | 123 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); |
148 }; | 124 }; |
149 | 125 |
150 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
151 #pragma warning(pop) | 127 #pragma warning(pop) |
152 #endif | 128 #endif |
153 | 129 |
154 } // namespace service | 130 } // namespace service |
155 } // namespace view_manager | 131 } // namespace view_manager |
156 } // namespace mojo | 132 } // namespace mojo |
157 | 133 |
158 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 134 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
OLD | NEW |