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 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "mojo/public/cpp/shell/service.h" | 9 #include "mojo/public/cpp/shell/service.h" |
10 #include "mojo/public/interfaces/shell/shell.mojom.h" | 10 #include "mojo/public/interfaces/shell/shell.mojom.h" |
11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" | 11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
| 12 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
12 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 13 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
13 #include "mojo/services/public/cpp/view_manager/util.h" | 14 #include "mojo/services/public/cpp/view_manager/util.h" |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
16 namespace services { | 17 namespace services { |
17 namespace view_manager { | 18 namespace view_manager { |
18 | 19 |
19 TransportNodeId MakeTransportNodeId(uint16_t connection_id, | 20 uint32_t MakeTransportId(uint16_t connection_id, uint16_t local_id) { |
20 uint16_t local_node_id) { | 21 return (connection_id << 16) | local_id; |
21 return (connection_id << 16) | local_node_id; | 22 } |
| 23 |
| 24 // Helper called to construct a local node/view object from transport data. |
| 25 ViewTreeNode* AddNodeToViewManager(ViewManager* manager, |
| 26 ViewTreeNode* parent, |
| 27 TransportNodeId node_id, |
| 28 TransportViewId view_id) { |
| 29 // We don't use the ctor that takes a ViewManager here, since it will call |
| 30 // back to the service and attempt to create a new node. |
| 31 ViewTreeNode* node = ViewTreeNodePrivate::LocalCreate(); |
| 32 ViewTreeNodePrivate private_node(node); |
| 33 private_node.set_view_manager(manager); |
| 34 private_node.set_id(node_id); |
| 35 if (parent) |
| 36 ViewTreeNodePrivate(parent).LocalAddChild(node); |
| 37 ViewManagerPrivate private_manager(manager); |
| 38 private_manager.AddNode(node->id(), node); |
| 39 |
| 40 // View. |
| 41 if (view_id != 0) { |
| 42 View* view = ViewPrivate::LocalCreate(); |
| 43 ViewPrivate private_view(view); |
| 44 private_view.set_view_manager(manager); |
| 45 private_view.set_id(view_id); |
| 46 private_view.set_node(node); |
| 47 // TODO(beng): this broadcasts notifications locally... do we want this? I |
| 48 // don't think so. same story for LocalAddChild above! |
| 49 private_node.LocalSetActiveView(view); |
| 50 private_manager.AddView(view->id(), view); |
| 51 } |
| 52 return node; |
22 } | 53 } |
23 | 54 |
24 class ViewManagerTransaction { | 55 class ViewManagerTransaction { |
25 public: | 56 public: |
26 virtual ~ViewManagerTransaction() {} | 57 virtual ~ViewManagerTransaction() {} |
27 | 58 |
28 void Commit() { | 59 void Commit() { |
29 DCHECK(!committed_); | 60 DCHECK(!committed_); |
30 DoCommit(); | 61 DoCommit(); |
31 committed_ = true; | 62 committed_ = true; |
32 } | 63 } |
33 | 64 |
34 bool committed() const { return committed_; } | 65 bool committed() const { return committed_; } |
35 TransportChangeId client_change_id() const { return client_change_id_; } | 66 TransportChangeId client_change_id() const { return client_change_id_; } |
36 | 67 |
37 // General callback to be used for commits to the service. | 68 // General callback to be used for commits to the service. |
38 void OnActionCompleted(bool success) { | 69 void OnActionCompleted(bool success) { |
39 DCHECK(success); | 70 DCHECK(success); |
40 DoActionCompleted(success); | 71 DoActionCompleted(success); |
41 synchronizer_->RemoveFromPendingQueue(this); | 72 synchronizer_->RemoveFromPendingQueue(this); |
42 } | 73 } |
43 | 74 |
44 protected: | 75 protected: |
45 enum TransactionType { | 76 enum TransactionType { |
| 77 // View creation and destruction. |
| 78 TYPE_CREATE_VIEW, |
| 79 TYPE_DESTROY_VIEW, |
46 // Node creation and destruction. | 80 // Node creation and destruction. |
47 TYPE_CREATE_VIEW_TREE_NODE, | 81 TYPE_CREATE_VIEW_TREE_NODE, |
48 TYPE_DESTROY_VIEW_TREE_NODE, | 82 TYPE_DESTROY_VIEW_TREE_NODE, |
49 // Modifications to the hierarchy (addition of or removal of nodes from a | 83 // Modifications to the hierarchy (addition of or removal of nodes from a |
50 // parent.) | 84 // parent.) |
51 TYPE_HIERARCHY | 85 TYPE_HIERARCHY, |
| 86 // View replacement. |
| 87 TYPE_SET_ACTIVE_VIEW |
52 }; | 88 }; |
53 | 89 |
54 ViewManagerTransaction(TransactionType transaction_type, | 90 ViewManagerTransaction(TransactionType transaction_type, |
55 ViewManagerSynchronizer* synchronizer) | 91 ViewManagerSynchronizer* synchronizer) |
56 : transaction_type_(transaction_type), | 92 : transaction_type_(transaction_type), |
57 client_change_id_(synchronizer->GetNextClientChangeId()), | 93 client_change_id_(synchronizer->GetNextClientChangeId()), |
58 committed_(false), | 94 committed_(false), |
59 synchronizer_(synchronizer) { | 95 synchronizer_(synchronizer) { |
60 } | 96 } |
61 | 97 |
(...skipping 12 matching lines...) Expand all Loading... |
74 | 110 |
75 private: | 111 private: |
76 const TransactionType transaction_type_; | 112 const TransactionType transaction_type_; |
77 const uint32_t client_change_id_; | 113 const uint32_t client_change_id_; |
78 bool committed_; | 114 bool committed_; |
79 ViewManagerSynchronizer* synchronizer_; | 115 ViewManagerSynchronizer* synchronizer_; |
80 | 116 |
81 DISALLOW_COPY_AND_ASSIGN(ViewManagerTransaction); | 117 DISALLOW_COPY_AND_ASSIGN(ViewManagerTransaction); |
82 }; | 118 }; |
83 | 119 |
| 120 class CreateViewTransaction : public ViewManagerTransaction { |
| 121 public: |
| 122 CreateViewTransaction(uint16_t view_id, |
| 123 ViewManagerSynchronizer* synchronizer) |
| 124 : ViewManagerTransaction(TYPE_CREATE_VIEW, synchronizer), |
| 125 view_id_(view_id) {} |
| 126 virtual ~CreateViewTransaction() {} |
| 127 |
| 128 private: |
| 129 // Overridden from ViewManagerTransaction: |
| 130 virtual void DoCommit() OVERRIDE { |
| 131 service()->CreateView( |
| 132 view_id_, |
| 133 base::Bind(&ViewManagerTransaction::OnActionCompleted, |
| 134 base::Unretained(this))); |
| 135 } |
| 136 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 137 // TODO(beng): failure. |
| 138 } |
| 139 |
| 140 const uint16_t view_id_; |
| 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(CreateViewTransaction); |
| 143 }; |
| 144 |
| 145 class DestroyViewTransaction : public ViewManagerTransaction { |
| 146 public: |
| 147 DestroyViewTransaction(TransportViewId view_id, |
| 148 ViewManagerSynchronizer* synchronizer) |
| 149 : ViewManagerTransaction(TYPE_DESTROY_VIEW, synchronizer), |
| 150 view_id_(view_id) {} |
| 151 virtual ~DestroyViewTransaction() {} |
| 152 |
| 153 private: |
| 154 // Overridden from ViewManagerTransaction: |
| 155 virtual void DoCommit() OVERRIDE { |
| 156 service()->DeleteView( |
| 157 view_id_, |
| 158 client_change_id(), |
| 159 base::Bind(&ViewManagerTransaction::OnActionCompleted, |
| 160 base::Unretained(this))); |
| 161 } |
| 162 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 163 // TODO(beng): recovery? |
| 164 } |
| 165 |
| 166 const TransportViewId view_id_; |
| 167 |
| 168 DISALLOW_COPY_AND_ASSIGN(DestroyViewTransaction); |
| 169 }; |
| 170 |
84 class CreateViewTreeNodeTransaction : public ViewManagerTransaction { | 171 class CreateViewTreeNodeTransaction : public ViewManagerTransaction { |
85 public: | 172 public: |
86 CreateViewTreeNodeTransaction(uint16_t node_id, | 173 CreateViewTreeNodeTransaction(uint16_t node_id, |
87 ViewManagerSynchronizer* synchronizer) | 174 ViewManagerSynchronizer* synchronizer) |
88 : ViewManagerTransaction(TYPE_CREATE_VIEW_TREE_NODE, synchronizer), | 175 : ViewManagerTransaction(TYPE_CREATE_VIEW_TREE_NODE, synchronizer), |
89 node_id_(node_id) {} | 176 node_id_(node_id) {} |
90 virtual ~CreateViewTreeNodeTransaction() {} | 177 virtual ~CreateViewTreeNodeTransaction() {} |
91 | 178 |
92 private: | 179 private: |
93 // Overridden from ViewManagerTransaction: | 180 // Overridden from ViewManagerTransaction: |
(...skipping 29 matching lines...) Expand all Loading... |
123 service()->DeleteNode( | 210 service()->DeleteNode( |
124 node_id_, | 211 node_id_, |
125 client_change_id(), | 212 client_change_id(), |
126 base::Bind(&ViewManagerTransaction::OnActionCompleted, | 213 base::Bind(&ViewManagerTransaction::OnActionCompleted, |
127 base::Unretained(this))); | 214 base::Unretained(this))); |
128 } | 215 } |
129 virtual void DoActionCompleted(bool success) OVERRIDE { | 216 virtual void DoActionCompleted(bool success) OVERRIDE { |
130 // TODO(beng): recovery? | 217 // TODO(beng): recovery? |
131 } | 218 } |
132 | 219 |
133 TransportNodeId node_id_; | 220 const TransportNodeId node_id_; |
134 DISALLOW_COPY_AND_ASSIGN(DestroyViewTreeNodeTransaction); | 221 DISALLOW_COPY_AND_ASSIGN(DestroyViewTreeNodeTransaction); |
135 }; | 222 }; |
136 | 223 |
137 class HierarchyTransaction : public ViewManagerTransaction { | 224 class HierarchyTransaction : public ViewManagerTransaction { |
138 public: | 225 public: |
139 enum HierarchyChangeType { | 226 enum HierarchyChangeType { |
140 TYPE_ADD, | 227 TYPE_ADD, |
141 TYPE_REMOVE | 228 TYPE_REMOVE |
142 }; | 229 }; |
143 HierarchyTransaction(HierarchyChangeType hierarchy_change_type, | 230 HierarchyTransaction(HierarchyChangeType hierarchy_change_type, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // or we passed the same node id for both params. Roll back? | 266 // or we passed the same node id for both params. Roll back? |
180 } | 267 } |
181 | 268 |
182 const HierarchyChangeType hierarchy_change_type_; | 269 const HierarchyChangeType hierarchy_change_type_; |
183 const TransportNodeId child_id_; | 270 const TransportNodeId child_id_; |
184 const TransportNodeId parent_id_; | 271 const TransportNodeId parent_id_; |
185 | 272 |
186 DISALLOW_COPY_AND_ASSIGN(HierarchyTransaction); | 273 DISALLOW_COPY_AND_ASSIGN(HierarchyTransaction); |
187 }; | 274 }; |
188 | 275 |
| 276 class SetActiveViewTransaction : public ViewManagerTransaction { |
| 277 public: |
| 278 SetActiveViewTransaction(TransportNodeId node_id, |
| 279 TransportViewId view_id, |
| 280 ViewManagerSynchronizer* synchronizer) |
| 281 : ViewManagerTransaction(TYPE_SET_ACTIVE_VIEW, synchronizer), |
| 282 node_id_(node_id), |
| 283 view_id_(view_id) {} |
| 284 virtual ~SetActiveViewTransaction() {} |
| 285 |
| 286 private: |
| 287 // Overridden from ViewManagerTransaction: |
| 288 virtual void DoCommit() OVERRIDE { |
| 289 service()->SetView( |
| 290 node_id_, |
| 291 view_id_, |
| 292 client_change_id(), |
| 293 base::Bind(&ViewManagerTransaction::OnActionCompleted, |
| 294 base::Unretained(this))); |
| 295 } |
| 296 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 297 // TODO(beng): recovery? |
| 298 } |
| 299 |
| 300 const TransportNodeId node_id_; |
| 301 const TransportViewId view_id_; |
| 302 |
| 303 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); |
| 304 }; |
| 305 |
189 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager) | 306 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManager* view_manager) |
190 : view_manager_(view_manager), | 307 : view_manager_(view_manager), |
191 connected_(false), | 308 connected_(false), |
192 connection_id_(0), | 309 connection_id_(0), |
193 next_id_(1), | 310 next_id_(1), |
194 next_client_change_id_(0), | 311 next_client_change_id_(0), |
195 next_server_change_id_(0), | 312 next_server_change_id_(0), |
196 sync_factory_(this), | 313 sync_factory_(this), |
197 init_loop_(NULL) { | 314 init_loop_(NULL) { |
198 ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager", | 315 ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager", |
(...skipping 14 matching lines...) Expand all Loading... |
213 | 330 |
214 ViewManagerSynchronizer::~ViewManagerSynchronizer() { | 331 ViewManagerSynchronizer::~ViewManagerSynchronizer() { |
215 Sync(); | 332 Sync(); |
216 } | 333 } |
217 | 334 |
218 TransportNodeId ViewManagerSynchronizer::CreateViewTreeNode() { | 335 TransportNodeId ViewManagerSynchronizer::CreateViewTreeNode() { |
219 DCHECK(connected_); | 336 DCHECK(connected_); |
220 uint16_t id = ++next_id_; | 337 uint16_t id = ++next_id_; |
221 pending_transactions_.push_back(new CreateViewTreeNodeTransaction(id, this)); | 338 pending_transactions_.push_back(new CreateViewTreeNodeTransaction(id, this)); |
222 Sync(); | 339 Sync(); |
223 return MakeTransportNodeId(connection_id_, id); | 340 return MakeTransportId(connection_id_, id); |
224 } | 341 } |
225 | 342 |
226 void ViewManagerSynchronizer::DestroyViewTreeNode(TransportNodeId node_id) { | 343 void ViewManagerSynchronizer::DestroyViewTreeNode(TransportNodeId node_id) { |
227 DCHECK(connected_); | 344 DCHECK(connected_); |
228 pending_transactions_.push_back( | 345 pending_transactions_.push_back( |
229 new DestroyViewTreeNodeTransaction(node_id, this)); | 346 new DestroyViewTreeNodeTransaction(node_id, this)); |
230 Sync(); | 347 Sync(); |
231 } | 348 } |
232 | 349 |
| 350 TransportViewId ViewManagerSynchronizer::CreateView() { |
| 351 DCHECK(connected_); |
| 352 uint16_t id = ++next_id_; |
| 353 pending_transactions_.push_back(new CreateViewTransaction(id, this)); |
| 354 Sync(); |
| 355 return MakeTransportId(connection_id_, id); |
| 356 } |
| 357 |
| 358 void ViewManagerSynchronizer::DestroyView(TransportViewId view_id) { |
| 359 DCHECK(connected_); |
| 360 pending_transactions_.push_back(new DestroyViewTransaction(view_id, this)); |
| 361 Sync(); |
| 362 } |
| 363 |
233 void ViewManagerSynchronizer::AddChild(TransportNodeId child_id, | 364 void ViewManagerSynchronizer::AddChild(TransportNodeId child_id, |
234 TransportNodeId parent_id) { | 365 TransportNodeId parent_id) { |
235 DCHECK(connected_); | 366 DCHECK(connected_); |
236 pending_transactions_.push_back( | 367 pending_transactions_.push_back( |
237 new HierarchyTransaction(HierarchyTransaction::TYPE_ADD, | 368 new HierarchyTransaction(HierarchyTransaction::TYPE_ADD, |
238 child_id, | 369 child_id, |
239 parent_id, | 370 parent_id, |
240 this)); | 371 this)); |
241 Sync(); | 372 Sync(); |
242 } | 373 } |
243 | 374 |
244 void ViewManagerSynchronizer::RemoveChild(TransportNodeId child_id, | 375 void ViewManagerSynchronizer::RemoveChild(TransportNodeId child_id, |
245 TransportNodeId parent_id) { | 376 TransportNodeId parent_id) { |
246 DCHECK(connected_); | 377 DCHECK(connected_); |
247 pending_transactions_.push_back( | 378 pending_transactions_.push_back( |
248 new HierarchyTransaction(HierarchyTransaction::TYPE_REMOVE, | 379 new HierarchyTransaction(HierarchyTransaction::TYPE_REMOVE, |
249 child_id, | 380 child_id, |
250 parent_id, | 381 parent_id, |
251 this)); | 382 this)); |
252 Sync(); | 383 Sync(); |
253 } | 384 } |
254 | 385 |
255 bool ViewManagerSynchronizer::OwnsNode(TransportNodeId id) const { | 386 bool ViewManagerSynchronizer::OwnsNode(TransportNodeId id) const { |
256 return HiWord(id) == connection_id_; | 387 return HiWord(id) == connection_id_; |
257 } | 388 } |
258 | 389 |
| 390 bool ViewManagerSynchronizer::OwnsView(TransportViewId id) const { |
| 391 return HiWord(id) == connection_id_; |
| 392 } |
| 393 |
| 394 void ViewManagerSynchronizer::SetActiveView(TransportNodeId node_id, |
| 395 TransportViewId view_id) { |
| 396 DCHECK(connected_); |
| 397 pending_transactions_.push_back( |
| 398 new SetActiveViewTransaction(node_id, view_id, this)); |
| 399 Sync(); |
| 400 } |
| 401 |
259 //////////////////////////////////////////////////////////////////////////////// | 402 //////////////////////////////////////////////////////////////////////////////// |
260 // ViewManagerSynchronizer, IViewManagerClient implementation: | 403 // ViewManagerSynchronizer, IViewManagerClient implementation: |
261 | 404 |
262 void ViewManagerSynchronizer::OnConnectionEstablished( | 405 void ViewManagerSynchronizer::OnConnectionEstablished( |
263 TransportConnectionId connection_id, | 406 TransportConnectionId connection_id, |
264 TransportChangeId next_server_change_id) { | 407 TransportChangeId next_server_change_id) { |
265 connected_ = true; | 408 connected_ = true; |
266 connection_id_ = connection_id; | 409 connection_id_ = connection_id; |
267 next_server_change_id_ = next_server_change_id; | 410 next_server_change_id_ = next_server_change_id; |
268 Sync(); | 411 Sync(); |
(...skipping 17 matching lines...) Expand all Loading... |
286 // TODO(beng): verify this is actually true. | 429 // TODO(beng): verify this is actually true. |
287 node = view_manager_->GetNodeById(node_id); | 430 node = view_manager_->GetNodeById(node_id); |
288 DCHECK_EQ(node->parent(), old_parent); | 431 DCHECK_EQ(node->parent(), old_parent); |
289 } else { | 432 } else { |
290 // New node, originating from another connection. | 433 // New node, originating from another connection. |
291 node = ViewTreeNodePrivate::LocalCreate(); | 434 node = ViewTreeNodePrivate::LocalCreate(); |
292 ViewTreeNodePrivate private_node(node); | 435 ViewTreeNodePrivate private_node(node); |
293 private_node.set_view_manager(view_manager_); | 436 private_node.set_view_manager(view_manager_); |
294 private_node.set_id(node_id); | 437 private_node.set_id(node_id); |
295 ViewManagerPrivate(view_manager_).AddNode(node->id(), node); | 438 ViewManagerPrivate(view_manager_).AddNode(node->id(), node); |
| 439 |
| 440 // TODO(beng): view changes. |
296 } | 441 } |
297 if (new_parent) | 442 if (new_parent) |
298 ViewTreeNodePrivate(new_parent).LocalAddChild(node); | 443 ViewTreeNodePrivate(new_parent).LocalAddChild(node); |
299 else | 444 else |
300 ViewTreeNodePrivate(old_parent).LocalRemoveChild(node); | 445 ViewTreeNodePrivate(old_parent).LocalRemoveChild(node); |
301 } | 446 } |
302 next_server_change_id_ = server_change_id + 1; | 447 next_server_change_id_ = server_change_id + 1; |
303 } | 448 } |
304 | 449 |
305 void ViewManagerSynchronizer::OnNodeDeleted( | 450 void ViewManagerSynchronizer::OnNodeViewReplaced(uint32_t node_id, |
306 TransportNodeId node_id, | 451 uint32_t new_view_id, |
307 TransportChangeId server_change_id, | 452 uint32_t old_view_id, |
308 TransportChangeId client_change_id) { | 453 uint32_t client_change_id) { |
| 454 if (client_change_id == 0) { |
| 455 ViewTreeNode* node = view_manager_->GetNodeById(node_id); |
| 456 View* new_view = view_manager_->GetViewById(new_view_id); |
| 457 if (!new_view && new_view_id != 0) { |
| 458 // This client wasn't aware of this View until now. |
| 459 new_view = ViewPrivate::LocalCreate(); |
| 460 ViewPrivate private_view(new_view); |
| 461 private_view.set_view_manager(view_manager_); |
| 462 private_view.set_id(new_view_id); |
| 463 private_view.set_node(node); |
| 464 ViewManagerPrivate(view_manager_).AddView(new_view->id(), new_view); |
| 465 } |
| 466 View* old_view = view_manager_->GetViewById(old_view_id); |
| 467 DCHECK_EQ(old_view, node->active_view()); |
| 468 ViewTreeNodePrivate(node).LocalSetActiveView(new_view); |
| 469 } |
| 470 } |
| 471 |
| 472 void ViewManagerSynchronizer::OnNodeDeleted(uint32_t node_id, |
| 473 uint32_t server_change_id, |
| 474 uint32_t client_change_id) { |
309 next_server_change_id_ = server_change_id + 1; | 475 next_server_change_id_ = server_change_id + 1; |
310 if (client_change_id == 0) { | 476 if (client_change_id == 0) { |
311 ViewTreeNode* node = view_manager_->GetNodeById(node_id); | 477 ViewTreeNode* node = view_manager_->GetNodeById(node_id); |
312 if (node) | 478 if (node) |
313 ViewTreeNodePrivate(node).LocalDestroy(); | 479 ViewTreeNodePrivate(node).LocalDestroy(); |
314 } | 480 } |
315 } | 481 } |
316 | 482 |
317 void ViewManagerSynchronizer::OnNodeViewReplaced(uint32_t node, | 483 void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id, |
318 uint32_t new_view_id, | 484 uint32_t server_change_id, |
319 uint32_t old_view_id, | 485 uint32_t client_change_id) { |
320 uint32_t client_change_id) { | 486 next_server_change_id_ = server_change_id + 1; |
321 // .. | 487 if (client_change_id == 0) { |
| 488 View* view = view_manager_->GetViewById(view_id); |
| 489 if (view) |
| 490 ViewPrivate(view).LocalDestroy(); |
| 491 } |
322 } | 492 } |
323 | 493 |
324 //////////////////////////////////////////////////////////////////////////////// | 494 //////////////////////////////////////////////////////////////////////////////// |
325 // ViewManagerSynchronizer, private: | 495 // ViewManagerSynchronizer, private: |
326 | 496 |
327 void ViewManagerSynchronizer::Sync() { | 497 void ViewManagerSynchronizer::Sync() { |
328 // The service connection may not be set up yet. OnConnectionEstablished() | 498 // The service connection may not be set up yet. OnConnectionEstablished() |
329 // will schedule another sync when it is. | 499 // will schedule another sync when it is. |
330 if (!connected_) | 500 if (!connected_) |
331 return; | 501 return; |
(...skipping 15 matching lines...) Expand all Loading... |
347 } | 517 } |
348 | 518 |
349 void ViewManagerSynchronizer::RemoveFromPendingQueue( | 519 void ViewManagerSynchronizer::RemoveFromPendingQueue( |
350 ViewManagerTransaction* transaction) { | 520 ViewManagerTransaction* transaction) { |
351 DCHECK_EQ(transaction, pending_transactions_.front()); | 521 DCHECK_EQ(transaction, pending_transactions_.front()); |
352 pending_transactions_.erase(pending_transactions_.begin()); | 522 pending_transactions_.erase(pending_transactions_.begin()); |
353 } | 523 } |
354 | 524 |
355 void ViewManagerSynchronizer::OnRootTreeReceived( | 525 void ViewManagerSynchronizer::OnRootTreeReceived( |
356 const Array<INode>& nodes) { | 526 const Array<INode>& nodes) { |
| 527 ViewManagerPrivate private_manager(view_manager_); |
357 std::vector<ViewTreeNode*> parents; | 528 std::vector<ViewTreeNode*> parents; |
358 ViewTreeNode* root = NULL; | 529 ViewTreeNode* root = NULL; |
359 ViewTreeNode* last_node = NULL; | 530 ViewTreeNode* last_node = NULL; |
360 for (size_t i = 0; i < nodes.size(); ++i) { | 531 for (size_t i = 0; i < nodes.size(); ++i) { |
361 if (last_node && nodes[i].parent_id() == last_node->id()) { | 532 if (last_node && nodes[i].parent_id() == last_node->id()) { |
362 parents.push_back(last_node); | 533 parents.push_back(last_node); |
363 } else if (!parents.empty()) { | 534 } else if (!parents.empty()) { |
364 while (parents.back()->id() != nodes[i].parent_id()) | 535 while (parents.back()->id() != nodes[i].parent_id()) |
365 parents.pop_back(); | 536 parents.pop_back(); |
366 } | 537 } |
367 // We don't use the ctor that takes a ViewManager here, since it will call | 538 ViewTreeNode* node = |
368 // back to the service and attempt to create a new node. | 539 AddNodeToViewManager(view_manager_, |
369 ViewTreeNode* node = ViewTreeNodePrivate::LocalCreate(); | 540 !parents.empty() ? parents.back() : NULL, |
370 ViewTreeNodePrivate private_node(node); | 541 nodes[i].node_id(), |
371 private_node.set_view_manager(view_manager_); | 542 nodes[i].view_id()); |
372 private_node.set_id(nodes[i].node_id()); | |
373 if (!parents.empty()) | |
374 ViewTreeNodePrivate(parents.back()).LocalAddChild(node); | |
375 if (!last_node) | 543 if (!last_node) |
376 root = node; | 544 root = node; |
377 last_node = node; | 545 last_node = node; |
378 ViewManagerPrivate(view_manager_).AddNode(node->id(), node); | |
379 } | 546 } |
380 ViewManagerPrivate(view_manager_).set_root(root); | 547 private_manager.set_root(root); |
381 if (init_loop_) | 548 if (init_loop_) |
382 init_loop_->Quit(); | 549 init_loop_->Quit(); |
383 } | 550 } |
384 | 551 |
385 } // namespace view_manager | 552 } // namespace view_manager |
386 } // namespace services | 553 } // namespace services |
387 } // namespace mojo | 554 } // namespace mojo |
OLD | NEW |