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

Side by Side Diff: mojo/services/view_manager/view_manager_service_impl.h

Issue 513923004: More viewmanager renaming: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sim30 Created 6 years, 3 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
OLDNEW
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_SERVICE_IMPL_H_ 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_ 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
17 #include "mojo/services/view_manager/access_policy_delegate.h" 17 #include "mojo/services/view_manager/access_policy_delegate.h"
18 #include "mojo/services/view_manager/ids.h" 18 #include "mojo/services/view_manager/ids.h"
19 #include "mojo/services/view_manager/view_manager_export.h" 19 #include "mojo/services/view_manager/view_manager_export.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 class Rect; 22 class Rect;
23 } 23 }
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace service { 26 namespace service {
27 27
28 class AccessPolicy; 28 class AccessPolicy;
29 class Node; 29 class ConnectionManager;
30 class RootNodeManager; 30 class ServerView;
31 31
32 #if defined(OS_WIN) 32 #if defined(OS_WIN)
33 // Equivalent of NON_EXPORTED_BASE which does not work with the template snafu 33 // Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
34 // below. 34 // below.
35 #pragma warning(push) 35 #pragma warning(push)
36 #pragma warning(disable : 4275) 36 #pragma warning(disable : 4275)
37 #endif 37 #endif
38 38
39 // Manages a connection from the client. 39 // Manages a connection from the client.
40 class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl 40 class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
41 : public InterfaceImpl<ViewManagerService>, 41 : public InterfaceImpl<ViewManagerService>,
42 public AccessPolicyDelegate { 42 public AccessPolicyDelegate {
43 public: 43 public:
44 ViewManagerServiceImpl(RootNodeManager* root_node_manager, 44 ViewManagerServiceImpl(ConnectionManager* connection_manager,
45 ConnectionSpecificId creator_id, 45 ConnectionSpecificId creator_id,
46 const std::string& creator_url, 46 const std::string& creator_url,
47 const std::string& url, 47 const std::string& url,
48 const NodeId& root_id, 48 const ViewId& root_id,
49 InterfaceRequest<ServiceProvider> service_provider); 49 InterfaceRequest<ServiceProvider> service_provider);
50 virtual ~ViewManagerServiceImpl(); 50 virtual ~ViewManagerServiceImpl();
51 51
52 // Used to mark this connection as originating from a call to 52 // Used to mark this connection as originating from a call to
53 // ViewManagerService::Connect(). When set OnConnectionError() deletes |this|. 53 // ViewManagerService::Connect(). When set OnConnectionError() deletes |this|.
54 void set_delete_on_connection_error() { delete_on_connection_error_ = true; } 54 void set_delete_on_connection_error() { delete_on_connection_error_ = true; }
55 55
56 ConnectionSpecificId id() const { return id_; } 56 ConnectionSpecificId id() const { return id_; }
57 ConnectionSpecificId creator_id() const { return creator_id_; } 57 ConnectionSpecificId creator_id() const { return creator_id_; }
58 const std::string& url() const { return url_; } 58 const std::string& url() const { return url_; }
59 59
60 // Returns the Node with the specified id. 60 // Returns the View with the specified id.
61 Node* GetNode(const NodeId& id) { 61 ServerView* GetView(const ViewId& id) {
62 return const_cast<Node*>( 62 return const_cast<ServerView*>(
63 const_cast<const ViewManagerServiceImpl*>(this)->GetNode(id)); 63 const_cast<const ViewManagerServiceImpl*>(this)->GetView(id));
64 } 64 }
65 const Node* GetNode(const NodeId& id) const; 65 const ServerView* GetView(const ViewId& id) const;
66 66
67 // Returns true if this has |id| as a root. 67 // Returns true if this has |id| as a root.
68 bool HasRoot(const NodeId& id) const; 68 bool HasRoot(const ViewId& id) const;
69 69
70 // Invoked when a connection is destroyed. 70 // Invoked when a connection is destroyed.
71 void OnViewManagerServiceImplDestroyed(ConnectionSpecificId id); 71 void OnViewManagerServiceImplDestroyed(ConnectionSpecificId id);
72 72
73 // The following methods are invoked after the corresponding change has been 73 // The following methods are invoked after the corresponding change has been
74 // processed. They do the appropriate bookkeeping and update the client as 74 // processed. They do the appropriate bookkeeping and update the client as
75 // necessary. 75 // necessary.
76 void ProcessNodeBoundsChanged(const Node* node, 76 void ProcessViewBoundsChanged(const ServerView* view,
77 const gfx::Rect& old_bounds, 77 const gfx::Rect& old_bounds,
78 const gfx::Rect& new_bounds, 78 const gfx::Rect& new_bounds,
79 bool originated_change); 79 bool originated_change);
80 void ProcessNodeHierarchyChanged(const Node* node, 80 void ProcessViewHierarchyChanged(const ServerView* view,
81 const Node* new_parent, 81 const ServerView* new_parent,
82 const Node* old_parent, 82 const ServerView* old_parent,
83 bool originated_change); 83 bool originated_change);
84 void ProcessNodeReorder(const Node* node, 84 void ProcessViewReorder(const ServerView* view,
85 const Node* relative_node, 85 const ServerView* relative_view,
86 OrderDirection direction, 86 OrderDirection direction,
87 bool originated_change); 87 bool originated_change);
88 void ProcessNodeDeleted(const NodeId& node, bool originated_change); 88 void ProcessViewDeleted(const ViewId& view, bool originated_change);
89 89
90 // TODO(sky): move this to private section (currently can't because of 90 // TODO(sky): move this to private section (currently can't because of
91 // bindings). 91 // bindings).
92 // InterfaceImp overrides: 92 // InterfaceImp overrides:
93 virtual void OnConnectionError() MOJO_OVERRIDE; 93 virtual void OnConnectionError() MOJO_OVERRIDE;
94 94
95 private: 95 private:
96 typedef std::map<ConnectionSpecificId, Node*> NodeMap; 96 typedef std::map<ConnectionSpecificId, ServerView*> ViewMap;
97 typedef base::hash_set<Id> NodeIdSet; 97 typedef base::hash_set<Id> ViewIdSet;
98 98
99 bool IsNodeKnown(const Node* node) const; 99 bool IsViewKnown(const ServerView* view) const;
100 100
101 // These functions return true if the corresponding mojom function is allowed 101 // These functions return true if the corresponding mojom function is allowed
102 // for this connection. 102 // for this connection.
103 bool CanReorderNode(const Node* node, 103 bool CanReorderView(const ServerView* view,
104 const Node* relative_node, 104 const ServerView* relative_view,
105 OrderDirection direction) const; 105 OrderDirection direction) const;
106 106
107 // Deletes a node owned by this connection. Returns true on success. |source| 107 // Deletes a view owned by this connection. Returns true on success. |source|
108 // is the connection that originated the change. 108 // is the connection that originated the change.
109 bool DeleteNodeImpl(ViewManagerServiceImpl* source, Node* node); 109 bool DeleteViewImpl(ViewManagerServiceImpl* source, ServerView* view);
110 110
111 // If |node| is known (in |known_nodes_|) does nothing. Otherwise adds |node| 111 // If |view| is known (in |known_views_|) does nothing. Otherwise adds |view|
112 // to |nodes|, marks |node| as known and recurses. 112 // to |views|, marks |view| as known and recurses.
113 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes); 113 void GetUnknownViewsFrom(const ServerView* view,
114 std::vector<const ServerView*>* views);
114 115
115 // Removes |node| and all its descendants from |known_nodes_|. This does not 116 // Removes |view| and all its descendants from |known_views_|. This does not
116 // recurse through nodes that were created by this connection. All nodes owned 117 // recurse through views that were created by this connection. All views owned
117 // by this connection are added to |local_nodes|. 118 // by this connection are added to |local_views|.
118 void RemoveFromKnown(const Node* node, std::vector<Node*>* local_nodes); 119 void RemoveFromKnown(const ServerView* view,
120 std::vector<ServerView*>* local_views);
119 121
120 // Adds |node_id| to the set of roots this connection knows about. The caller 122 // Adds |view_id| to the set of roots this connection knows about. The caller
121 // should have verified |node_id| is not among the roots of this connection. 123 // should have verified |view_id| is not among the roots of this connection.
122 void AddRoot(const NodeId& node_id, 124 void AddRoot(const ViewId& view_id,
123 InterfaceRequest<ServiceProvider> service_provider); 125 InterfaceRequest<ServiceProvider> service_provider);
124 126
125 // Removes |node_id| from the set of roots this connection knows about. 127 // Removes |view_id| from the set of roots this connection knows about.
126 void RemoveRoot(const NodeId& node_id); 128 void RemoveRoot(const ViewId& view_id);
127 129
128 void RemoveChildrenAsPartOfEmbed(const NodeId& node_id); 130 void RemoveChildrenAsPartOfEmbed(const ViewId& view_id);
129 131
130 // Converts Node(s) to ViewData(s) for transport. This assumes all the nodes 132 // Converts View(s) to ViewData(s) for transport. This assumes all the views
131 // are valid for the client. The parent of nodes the client is not allowed to 133 // are valid for the client. The parent of views the client is not allowed to
132 // see are set to NULL (in the returned ViewData(s)). 134 // see are set to NULL (in the returned ViewData(s)).
133 Array<ViewDataPtr> NodesToViewDatas(const std::vector<const Node*>& nodes); 135 Array<ViewDataPtr> ViewsToViewDatas(
134 ViewDataPtr NodeToViewData(const Node* node); 136 const std::vector<const ServerView*>& views);
137 ViewDataPtr ViewToViewData(const ServerView* view);
135 138
136 // Implementation of GetNodeTree(). Adds |node| to |nodes| and recurses if 139 // Implementation of GetViewTree(). Adds |view| to |views| and recurses if
137 // CanDescendIntoNodeForNodeTree() returns true. 140 // CanDescendIntoViewForViewTree() returns true.
138 void GetNodeTreeImpl(const Node* node, std::vector<const Node*>* nodes) const; 141 void GetViewTreeImpl(const ServerView* view,
142 std::vector<const ServerView*>* views) const;
139 143
140 // ViewManagerService: 144 // ViewManagerService:
141 virtual void CreateView(Id transport_view_id, 145 virtual void CreateView(Id transport_view_id,
142 const Callback<void(ErrorCode)>& callback) OVERRIDE; 146 const Callback<void(ErrorCode)>& callback) OVERRIDE;
143 virtual void DeleteView(Id transport_view_id, 147 virtual void DeleteView(Id transport_view_id,
144 const Callback<void(bool)>& callback) OVERRIDE; 148 const Callback<void(bool)>& callback) OVERRIDE;
145 virtual void AddView(Id parent_id, 149 virtual void AddView(Id parent_id,
146 Id child_id, 150 Id child_id,
147 const Callback<void(bool)>& callback) OVERRIDE; 151 const Callback<void(bool)>& callback) OVERRIDE;
148 virtual void RemoveViewFromParent( 152 virtual void RemoveViewFromParent(
149 Id node_id, 153 Id view_id,
150 const Callback<void(bool)>& callback) OVERRIDE; 154 const Callback<void(bool)>& callback) OVERRIDE;
151 virtual void ReorderView(Id view_id, 155 virtual void ReorderView(Id view_id,
152 Id relative_view_id, 156 Id relative_view_id,
153 OrderDirection direction, 157 OrderDirection direction,
154 const Callback<void(bool)>& callback) OVERRIDE; 158 const Callback<void(bool)>& callback) OVERRIDE;
155 virtual void GetViewTree( 159 virtual void GetViewTree(
156 Id view_id, 160 Id view_id,
157 const Callback<void(Array<ViewDataPtr>)>& callback) OVERRIDE; 161 const Callback<void(Array<ViewDataPtr>)>& callback) OVERRIDE;
158 virtual void SetViewContents(Id view_id, 162 virtual void SetViewContents(Id view_id,
159 ScopedSharedBufferHandle buffer, 163 ScopedSharedBufferHandle buffer,
160 uint32_t buffer_size, 164 uint32_t buffer_size,
161 const Callback<void(bool)>& callback) OVERRIDE; 165 const Callback<void(bool)>& callback) OVERRIDE;
162 virtual void SetViewBounds(Id view_id, 166 virtual void SetViewBounds(Id view_id,
163 RectPtr bounds, 167 RectPtr bounds,
164 const Callback<void(bool)>& callback) OVERRIDE; 168 const Callback<void(bool)>& callback) OVERRIDE;
165 virtual void SetViewVisibility(Id view_id, 169 virtual void SetViewVisibility(Id view_id,
166 bool visible, 170 bool visible,
167 const Callback<void(bool)>& callback) OVERRIDE; 171 const Callback<void(bool)>& callback) OVERRIDE;
168 virtual void Embed(const String& url, 172 virtual void Embed(const String& url,
169 Id view_id, 173 Id view_id,
170 ServiceProviderPtr service_provider, 174 ServiceProviderPtr service_provider,
171 const Callback<void(bool)>& callback) OVERRIDE; 175 const Callback<void(bool)>& callback) OVERRIDE;
172 virtual void DispatchOnViewInputEvent(Id view_id, EventPtr event) OVERRIDE; 176 virtual void DispatchOnViewInputEvent(Id view_id, EventPtr event) OVERRIDE;
173 177
174 // InterfaceImpl: 178 // InterfaceImpl:
175 virtual void OnConnectionEstablished() MOJO_OVERRIDE; 179 virtual void OnConnectionEstablished() MOJO_OVERRIDE;
176 180
177 // AccessPolicyDelegate: 181 // AccessPolicyDelegate:
178 virtual const base::hash_set<Id>& GetRootsForAccessPolicy() const OVERRIDE; 182 virtual const base::hash_set<Id>& GetRootsForAccessPolicy() const OVERRIDE;
179 virtual bool IsNodeKnownForAccessPolicy(const Node* node) const OVERRIDE; 183 virtual bool IsViewKnownForAccessPolicy(
180 virtual bool IsNodeRootOfAnotherConnectionForAccessPolicy( 184 const ServerView* view) const OVERRIDE;
181 const Node* node) const OVERRIDE; 185 virtual bool IsViewRootOfAnotherConnectionForAccessPolicy(
186 const ServerView* view) const OVERRIDE;
182 187
183 RootNodeManager* root_node_manager_; 188 ConnectionManager* connection_manager_;
184 189
185 // Id of this connection as assigned by RootNodeManager. 190 // Id of this connection as assigned by ConnectionManager.
186 const ConnectionSpecificId id_; 191 const ConnectionSpecificId id_;
187 192
188 // URL this connection was created for. 193 // URL this connection was created for.
189 const std::string url_; 194 const std::string url_;
190 195
191 // ID of the connection that created us. If 0 it indicates either we were 196 // ID of the connection that created us. If 0 it indicates either we were
192 // created by the root, or the connection that created us has been destroyed. 197 // created by the root, or the connection that created us has been destroyed.
193 ConnectionSpecificId creator_id_; 198 ConnectionSpecificId creator_id_;
194 199
195 // The URL of the app that embedded the app this connection was created for. 200 // The URL of the app that embedded the app this connection was created for.
196 const std::string creator_url_; 201 const std::string creator_url_;
197 202
198 scoped_ptr<AccessPolicy> access_policy_; 203 scoped_ptr<AccessPolicy> access_policy_;
199 204
200 // The nodes and views created by this connection. This connection owns these 205 // The views and views created by this connection. This connection owns these
201 // objects. 206 // objects.
202 NodeMap node_map_; 207 ViewMap view_map_;
203 208
204 // The set of nodes that has been communicated to the client. 209 // The set of views that has been communicated to the client.
205 NodeIdSet known_nodes_; 210 ViewIdSet known_views_;
206 211
207 // Set of root nodes from other connections. More specifically any time 212 // Set of root views from other connections. More specifically any time
208 // Embed() is invoked the id of the node is added to this set for the child 213 // Embed() is invoked the id of the view is added to this set for the child
209 // connection. The connection Embed() was invoked on (the parent) doesn't 214 // connection. The connection Embed() was invoked on (the parent) doesn't
210 // directly track which connections are attached to which of its nodes. That 215 // directly track which connections are attached to which of its views. That
211 // information can be found by looking through the |roots_| of all 216 // information can be found by looking through the |roots_| of all
212 // connections. 217 // connections.
213 NodeIdSet roots_; 218 ViewIdSet roots_;
214 219
215 // See description above setter. 220 // See description above setter.
216 bool delete_on_connection_error_; 221 bool delete_on_connection_error_;
217 222
218 InterfaceRequest<ServiceProvider> service_provider_; 223 InterfaceRequest<ServiceProvider> service_provider_;
219 224
220 DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceImpl); 225 DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceImpl);
221 }; 226 };
222 227
223 #if defined(OS_WIN) 228 #if defined(OS_WIN)
224 #pragma warning(pop) 229 #pragma warning(pop)
225 #endif 230 #endif
226 231
227 } // namespace service 232 } // namespace service
228 } // namespace mojo 233 } // namespace mojo
229 234
230 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_ 235 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_init_service_impl.h ('k') | mojo/services/view_manager/view_manager_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698