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