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

Side by Side Diff: services/ui/view_manager/view_registry.h

Issue 1679023006: Reify view ownership as a message pipe. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ 5 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_
6 #define SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_
7 7
8 #include <string>
8 #include <unordered_map> 9 #include <unordered_map>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "mojo/services/gfx/composition/interfaces/compositor.mojom.h" 12 #include "mojo/services/gfx/composition/interfaces/compositor.mojom.h"
12 #include "mojo/services/ui/views/interfaces/view_associates.mojom.h" 13 #include "mojo/services/ui/views/interfaces/view_associates.mojom.h"
13 #include "mojo/services/ui/views/interfaces/view_trees.mojom.h" 14 #include "mojo/services/ui/views/interfaces/view_trees.mojom.h"
14 #include "mojo/services/ui/views/interfaces/views.mojom.h" 15 #include "mojo/services/ui/views/interfaces/views.mojom.h"
15 #include "services/ui/view_manager/view_associate_table.h" 16 #include "services/ui/view_manager/view_associate_table.h"
16 #include "services/ui/view_manager/view_layout_request.h" 17 #include "services/ui/view_manager/view_layout_request.h"
17 #include "services/ui/view_manager/view_state.h" 18 #include "services/ui/view_manager/view_state.h"
19 #include "services/ui/view_manager/view_stub.h"
18 #include "services/ui/view_manager/view_tree_state.h" 20 #include "services/ui/view_manager/view_tree_state.h"
19 21
20 namespace view_manager { 22 namespace view_manager {
21 23
22 // Maintains a registry of the state of all views. 24 // Maintains a registry of the state of all views.
23 // All ViewState objects are owned by the registry. 25 // All ViewState objects are owned by the registry.
24 class ViewRegistry : public mojo::ui::ViewInspector { 26 class ViewRegistry : public mojo::ui::ViewInspector {
25 public: 27 public:
26 using AssociateConnectionErrorCallback = 28 using AssociateConnectionErrorCallback =
27 ViewAssociateTable::AssociateConnectionErrorCallback; 29 ViewAssociateTable::AssociateConnectionErrorCallback;
28 30
29 explicit ViewRegistry(mojo::gfx::composition::CompositorPtr compositor); 31 explicit ViewRegistry(mojo::gfx::composition::CompositorPtr compositor);
30 ~ViewRegistry() override; 32 ~ViewRegistry() override;
31 33
32 // Begins connecting to the view associates. 34 // Begins connecting to the view associates.
33 // Invokes |connection_error_callback| if an associate connection fails 35 // Invokes |connection_error_callback| if an associate connection fails
34 // and provides the associate's url. 36 // and provides the associate's url.
35 void ConnectAssociates( 37 void ConnectAssociates(
36 mojo::ApplicationImpl* app_impl, 38 mojo::ApplicationImpl* app_impl,
37 const std::vector<std::string>& urls, 39 const std::vector<std::string>& urls,
38 const AssociateConnectionErrorCallback& connection_error_callback); 40 const AssociateConnectionErrorCallback& connection_error_callback);
39 41
40 // VIEW MANAGER REQUESTS 42 // VIEW MANAGER REQUESTS
41 43
42 // Registers a view and returns its ViewToken. 44 // Registers a view and returns its ViewToken.
43 mojo::ui::ViewTokenPtr RegisterView( 45 void RegisterView(
44 mojo::ui::ViewPtr view, 46 mojo::ui::ViewPtr view,
45 mojo::InterfaceRequest<mojo::ui::ViewHost> view_host_request, 47 mojo::InterfaceRequest<mojo::ui::ViewHost> view_host_request,
48 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
46 const mojo::String& label); 49 const mojo::String& label);
47 50
48 // Registers a view tree. 51 // Registers a view tree.
49 mojo::ui::ViewTreeTokenPtr RegisterViewTree( 52 void RegisterViewTree(
50 mojo::ui::ViewTreePtr view_tree, 53 mojo::ui::ViewTreePtr view_tree,
51 mojo::InterfaceRequest<mojo::ui::ViewTreeHost> view_tree_host_request, 54 mojo::InterfaceRequest<mojo::ui::ViewTreeHost> view_tree_host_request,
52 const mojo::String& label); 55 const mojo::String& label);
53 56
57 // VIEW STUB REQUESTS
58
59 void OnViewResolved(ViewStub* view_stub, mojo::ui::ViewTokenPtr view_token);
60
54 // VIEW HOST REQUESTS 61 // VIEW HOST REQUESTS
55 62
56 // Creates a scene for the view, replacing its current scene. 63 // Creates a scene for the view, replacing its current scene.
57 // Destroys |view_state| if an error occurs. 64 // Destroys |view_state| if an error occurs.
58 void CreateScene(ViewState* view_state, 65 void CreateScene(ViewState* view_state,
59 mojo::InterfaceRequest<mojo::gfx::composition::Scene> scene); 66 mojo::InterfaceRequest<mojo::gfx::composition::Scene> scene);
60 67
61 // Requests layout. 68 // Requests layout.
62 // Destroys |view_state| if an error occurs. 69 // Destroys |view_state| if an error occurs.
63 void RequestLayout(ViewState* view_state); 70 void RequestLayout(ViewState* view_state);
64 71
65 // Adds a child, reparenting it if necessary. 72 // Adds a child, reparenting it if necessary.
66 // Destroys |parent_state| if an error occurs. 73 // Destroys |parent_state| if an error occurs.
67 void AddChild(ViewState* parent_state, 74 void AddChild(ViewState* parent_state,
68 uint32_t child_key, 75 uint32_t child_key,
69 mojo::ui::ViewTokenPtr child_view_token); 76 mojo::ui::ViewOwnerPtr child_view_owner);
70 77
71 // Removes a child. 78 // Removes a child.
72 // Destroys |parent_state| if an error occurs. 79 // Destroys |parent_state| if an error occurs.
73 void RemoveChild(ViewState* parent_state, uint32_t child_key); 80 void RemoveChild(ViewState* parent_state,
81 uint32_t child_key,
82 mojo::InterfaceRequest<mojo::ui::ViewOwner>
83 transferred_view_owner_request);
74 84
75 // Lays out a child and optionally provides its size. 85 // Lays out a child and optionally provides its size.
76 // Destroys |parent_state| if an error occurs. 86 // Destroys |parent_state| if an error occurs.
77 void LayoutChild(ViewState* parent_state, 87 void LayoutChild(ViewState* parent_state,
78 uint32_t child_key, 88 uint32_t child_key,
79 mojo::ui::ViewLayoutParamsPtr child_layout_params, 89 mojo::ui::ViewLayoutParamsPtr child_layout_params,
80 const ViewLayoutCallback& callback); 90 const ViewLayoutCallback& callback);
81 91
82 // Connects to a view service. 92 // Connects to a view service.
83 // Destroys |view_state| if an error occurs. 93 // Destroys |view_state| if an error occurs.
84 void ConnectToViewService(ViewState* view_state, 94 void ConnectToViewService(ViewState* view_state,
85 const mojo::String& service_name, 95 const mojo::String& service_name,
86 mojo::ScopedMessagePipeHandle client_handle); 96 mojo::ScopedMessagePipeHandle client_handle);
87 97
98 // Called when one of the view pipes is closed remotely.
99 void OnViewDied(ViewState* view_state, const std::string& reason);
100
88 // VIEW TREE HOST REQUESTS 101 // VIEW TREE HOST REQUESTS
89 102
90 // Requests layout. 103 // Requests layout.
91 // Destroys |tree_state| if an error occurs. 104 // Destroys |tree_state| if an error occurs.
92 void RequestLayout(ViewTreeState* tree_state); 105 void RequestLayout(ViewTreeState* tree_state);
93 106
94 // Sets the root of the view tree. 107 // Sets the root of the view tree.
95 // Destroys |tree_state| if an error occurs. 108 // Destroys |tree_state| if an error occurs.
96 void SetRoot(ViewTreeState* tree_state, 109 void SetRoot(ViewTreeState* tree_state,
97 uint32_t root_key, 110 uint32_t root_key,
98 mojo::ui::ViewTokenPtr root_view_token); 111 mojo::ui::ViewOwnerPtr root_view_owner);
99 112
100 // Resets the root of the view tree. 113 // Resets the root of the view tree.
101 // Destroys |tree_state| if an error occurs. 114 // Destroys |tree_state| if an error occurs.
102 void ResetRoot(ViewTreeState* tree_state); 115 void ResetRoot(ViewTreeState* tree_state,
116 mojo::InterfaceRequest<mojo::ui::ViewOwner>
117 transferred_view_owner_request);
103 118
104 // Lays out a view tree's root and optionally provides its size. 119 // Lays out a view tree's root and optionally provides its size.
105 // Destroys |tree_state| if an error occurs. 120 // Destroys |tree_state| if an error occurs.
106 void LayoutRoot(ViewTreeState* tree_state, 121 void LayoutRoot(ViewTreeState* tree_state,
107 mojo::ui::ViewLayoutParamsPtr root_layout_params, 122 mojo::ui::ViewLayoutParamsPtr root_layout_params,
108 const ViewLayoutCallback& callback); 123 const ViewLayoutCallback& callback);
109 124
110 // Connects to a view service. 125 // Connects to a view service.
111 // Destroys |view_state| if an error occurs. 126 // Destroys |view_state| if an error occurs.
112 void ConnectToViewTreeService(ViewTreeState* tree_state, 127 void ConnectToViewTreeService(ViewTreeState* tree_state,
113 const mojo::String& service_name, 128 const mojo::String& service_name,
114 mojo::ScopedMessagePipeHandle client_handle); 129 mojo::ScopedMessagePipeHandle client_handle);
115 130
131 // Called when one of the view tree pipes is closed remotely.
132 void OnViewTreeDied(ViewTreeState* tree_state, const std::string& reason);
133
116 private: 134 private:
117 // LIFETIME 135 // LIFETIME
118 136
119 void OnViewConnectionError(ViewState* view_state);
120 void UnregisterView(ViewState* view_state); 137 void UnregisterView(ViewState* view_state);
121 void OnViewTreeConnectionError(ViewTreeState* tree_state);
122 void UnregisterViewTree(ViewTreeState* tree_state); 138 void UnregisterViewTree(ViewTreeState* tree_state);
123 139
124 // TREE MANIPULATION 140 // TREE MANIPULATION
125 141
126 ViewState* FindView(uint32_t view_token_value); 142 ViewState* FindView(uint32_t view_token_value);
127 void LinkChild(ViewState* parent_state, 143 ViewTreeState* FindViewTree(uint32_t view_tree_token_value);
128 uint32_t child_key,
129 ViewState* child_state);
130 void LinkChildAsUnavailable(ViewState* parent_state, uint32_t child_key);
131 void MarkChildAsUnavailable(ViewState* parent_state, uint32_t child_key);
132 void UnlinkChild(ViewState* parent_state,
133 ViewState::ChildrenMap::iterator child_it);
134 144
135 ViewTreeState* FindViewTree(uint32_t view_tree_token_value);
136 void LinkRoot(ViewTreeState* tree_state,
137 ViewState* root_state,
138 uint32_t root_key);
139 void UnlinkRoot(ViewTreeState* tree_state);
140 void HijackView(ViewState* view_state); 145 void HijackView(ViewState* view_state);
141 146
142 // Must be called before the view is actually unlinked from the tree. 147 void AttachViewStubAndNotify(ViewStub* view_stub, ViewState* view_state);
143 // Caller is still responsible for actually unlinking the view. 148 void ReleaseViewStubAndNotify(ViewStub* view_stub);
144 void ResetStateWhenUnlinking(ViewState* view_state); 149 void TransferOrUnregisterViewStub(std::unique_ptr<ViewStub> view_stub,
150 mojo::InterfaceRequest<mojo::ui::ViewOwner>
151 transferred_view_owner_request);
152 void UnregisterViewStub(std::unique_ptr<ViewStub> view_stub);
145 153
146 // LAYOUT 154 // LAYOUT
147 155
148 void InvalidateLayout(ViewState* view_state); 156 void SetLayout(ViewStub* view_stub,
149 void InvalidateLayoutForChild(ViewState* parent_state, uint32_t child_key);
150 void InvalidateLayoutForRoot(ViewTreeState* tree_state);
151 void SetLayout(ViewState* view_state,
152 mojo::ui::ViewLayoutParamsPtr layout_params, 157 mojo::ui::ViewLayoutParamsPtr layout_params,
153 const ViewLayoutCallback& callback); 158 const ViewLayoutCallback& callback);
154 void EnqueueLayoutRequest(ViewState* view_state, 159 void EnqueueLayoutRequest(ViewState* view_state,
155 mojo::ui::ViewLayoutParamsPtr layout_params); 160 mojo::ui::ViewLayoutParamsPtr layout_params);
161 void InvalidateLayout(ViewState* view_state);
162 void InvalidateLayoutForChild(ViewState* parent_state, uint32_t child_key);
163 void InvalidateLayoutForRoot(ViewTreeState* tree_state);
164
156 void IssueNextViewLayoutRequest(ViewState* view_state); 165 void IssueNextViewLayoutRequest(ViewState* view_state);
157 void IssueNextViewTreeLayoutRequest(ViewTreeState* tree_state); 166 void IssueNextViewTreeLayoutRequest(ViewTreeState* tree_state);
167 void OnViewLayoutResult(base::WeakPtr<ViewState> view_state_weak,
168 mojo::ui::ViewLayoutResultPtr result);
169 void OnViewTreeLayoutResult(base::WeakPtr<ViewTreeState> tree_state_weak);
158 170
159 // SCENE MANAGEMENT 171 // SCENE MANAGEMENT
160 172
161 void OnSceneCreated(base::WeakPtr<ViewState> view_state_weak, 173 void OnSceneCreated(base::WeakPtr<ViewState> view_state_weak,
162 mojo::gfx::composition::SceneTokenPtr scene_token); 174 mojo::gfx::composition::SceneTokenPtr scene_token);
163 175
164 // SIGNALING 176 // SIGNALING
165 177
166 void SendChildUnavailable(ViewState* parent_state, uint32_t child_key); 178 void SendChildUnavailable(ViewState* parent_state, uint32_t child_key);
167 void SendRootUnavailable(ViewTreeState* tree_state, uint32_t root_key); 179 void SendRootUnavailable(ViewTreeState* tree_state, uint32_t root_key);
168 void SendViewLayoutRequest(ViewState* view_state);
169 void SendViewTreeLayoutRequest(ViewTreeState* tree_state);
170 void OnViewLayoutResult(base::WeakPtr<ViewState> view_state_weak,
171 mojo::ui::ViewLayoutResultPtr result);
172 void OnViewTreeLayoutResult(base::WeakPtr<ViewTreeState> tree_state_weak);
173 180
174 bool IsViewStateRegisteredDebug(ViewState* view_state) { 181 bool IsViewStateRegisteredDebug(ViewState* view_state) {
175 return view_state && FindView(view_state->view_token()->value); 182 return view_state && FindView(view_state->view_token()->value);
176 } 183 }
177 184
178 bool IsViewTreeStateRegisteredDebug(ViewTreeState* tree_state) { 185 bool IsViewTreeStateRegisteredDebug(ViewTreeState* tree_state) {
179 return tree_state && FindViewTree(tree_state->view_tree_token()->value); 186 return tree_state && FindViewTree(tree_state->view_tree_token()->value);
180 } 187 }
181 188
182 mojo::gfx::composition::CompositorPtr compositor_; 189 mojo::gfx::composition::CompositorPtr compositor_;
183 ViewAssociateTable associate_table_; 190 ViewAssociateTable associate_table_;
184 191
185 uint32_t next_view_token_value_ = 1u; 192 uint32_t next_view_token_value_ = 1u;
186 uint32_t next_view_tree_token_value_ = 1u; 193 uint32_t next_view_tree_token_value_ = 1u;
187 std::unordered_map<uint32_t, ViewState*> views_by_token_; 194 std::unordered_map<uint32_t, ViewState*> views_by_token_;
188 std::unordered_map<uint32_t, ViewTreeState*> view_trees_by_token_; 195 std::unordered_map<uint32_t, ViewTreeState*> view_trees_by_token_;
189 196
190 DISALLOW_COPY_AND_ASSIGN(ViewRegistry); 197 DISALLOW_COPY_AND_ASSIGN(ViewRegistry);
191 }; 198 };
192 199
193 } // namespace view_manager 200 } // namespace view_manager
194 201
195 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_ 202 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_REGISTRY_H_
OLDNEW
« no previous file with comments | « services/ui/view_manager/view_manager_impl.cc ('k') | services/ui/view_manager/view_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698