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/view_manager.h" | 5 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
6 | 6 |
7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
8 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 8 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
9 #include "mojo/services/public/cpp/view_manager/view.h" | |
10 | 9 |
11 namespace mojo { | 10 namespace mojo { |
12 namespace services { | 11 namespace services { |
13 namespace view_manager { | 12 namespace view_manager { |
14 | 13 |
15 ViewManager::ViewManager(Shell* shell) | 14 ViewManager::ViewManager(Shell* shell) |
16 : shell_(shell) {} | 15 : shell_(shell) {} |
17 | 16 |
18 ViewManager::~ViewManager() { | 17 ViewManager::~ViewManager() { |
19 while (!nodes_.empty()) { | 18 while (!nodes_.empty()) { |
20 IdToNodeMap::iterator it = nodes_.begin(); | 19 IdToNodeMap::iterator it = nodes_.begin(); |
21 if (synchronizer_->OwnsNode(it->second->id())) | 20 if (synchronizer_->OwnsNode(it->second->id())) |
22 it->second->Destroy(); | 21 it->second->Destroy(); |
23 else | 22 else |
24 nodes_.erase(it); | 23 nodes_.erase(it); |
25 } | 24 } |
26 while (!views_.empty()) { | |
27 IdToViewMap::iterator it = views_.begin(); | |
28 if (synchronizer_->OwnsView(it->second->id())) | |
29 it->second->Destroy(); | |
30 else | |
31 views_.erase(it); | |
32 } | |
33 } | 25 } |
34 | 26 |
35 void ViewManager::Init() { | 27 void ViewManager::Init() { |
36 synchronizer_.reset(new ViewManagerSynchronizer(this)); | 28 synchronizer_.reset(new ViewManagerSynchronizer(this)); |
37 } | 29 } |
38 | 30 |
39 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { | 31 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { |
40 IdToNodeMap::const_iterator it = nodes_.find(id); | 32 IdToNodeMap::const_iterator it = nodes_.find(id); |
41 return it != nodes_.end() ? it->second : NULL; | 33 return it != nodes_.end() ? it->second : NULL; |
42 } | 34 } |
43 | 35 |
44 View* ViewManager::GetViewById(TransportViewId id) { | |
45 IdToViewMap::const_iterator it = views_.find(id); | |
46 return it != views_.end() ? it->second : NULL; | |
47 } | |
48 | |
49 } // namespace view_manager | 36 } // namespace view_manager |
50 } // namespace services | 37 } // namespace services |
51 } // namespace mojo | 38 } // namespace mojo |
OLD | NEW |