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 "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/application/application.h" | 9 #include "mojo/public/cpp/application/application.h" |
10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" | 10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
12 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 12 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
13 #include "mojo/services/public/cpp/view_manager/view.h" | 13 #include "mojo/services/public/cpp/view_manager/view.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace view_manager { | 16 namespace view_manager { |
17 namespace { | 17 namespace { |
18 | 18 |
19 void OnViewManagerReady(base::RunLoop* loop, ViewManager* manager) { | 19 void OnViewManagerReady(base::RunLoop* loop, |
| 20 ViewManager* manager, |
| 21 ViewTreeNode* root) { |
20 loop->Quit(); | 22 loop->Quit(); |
21 } | 23 } |
22 | 24 |
23 } // namespace | 25 } // namespace |
24 | 26 |
25 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
26 // ViewManager, public: | 28 // ViewManager, public: |
27 | 29 |
28 ViewManager::~ViewManager() { | 30 ViewManager::~ViewManager() { |
29 while (!nodes_.empty()) { | 31 while (!nodes_.empty()) { |
30 IdToNodeMap::iterator it = nodes_.begin(); | 32 IdToNodeMap::iterator it = nodes_.begin(); |
31 if (synchronizer_->OwnsNode(it->second->id())) | 33 if (synchronizer_->OwnsNode(it->second->id())) |
32 it->second->Destroy(); | 34 it->second->Destroy(); |
33 else | 35 else |
34 nodes_.erase(it); | 36 nodes_.erase(it); |
35 } | 37 } |
36 while (!views_.empty()) { | 38 while (!views_.empty()) { |
37 IdToViewMap::iterator it = views_.begin(); | 39 IdToViewMap::iterator it = views_.begin(); |
38 if (synchronizer_->OwnsView(it->second->id())) | 40 if (synchronizer_->OwnsView(it->second->id())) |
39 it->second->Destroy(); | 41 it->second->Destroy(); |
40 else | 42 else |
41 views_.erase(it); | 43 views_.erase(it); |
42 } | 44 } |
43 } | 45 } |
44 | 46 |
45 // static | 47 // static |
46 ViewManager* ViewManager::CreateBlocking( | 48 ViewManager* ViewManager::CreateBlocking(Application* application) { |
47 Application* application, | |
48 const base::Callback<void(ViewManager*)>& root_added_callback) { | |
49 base::RunLoop init_loop; | 49 base::RunLoop init_loop; |
50 ViewManager* manager = new ViewManager( | 50 ViewManager* manager = new ViewManager( |
51 application, | 51 application, |
52 base::Bind(&OnViewManagerReady, &init_loop)); | 52 base::Bind(&OnViewManagerReady, &init_loop), |
| 53 RootCallback()); |
53 init_loop.Run(); | 54 init_loop.Run(); |
54 return manager; | 55 return manager; |
55 } | 56 } |
56 | 57 |
57 // static | 58 // static |
58 void ViewManager::Create( | 59 void ViewManager::Create( |
59 Application* application, | 60 Application* application, |
60 const base::Callback<void(ViewManager*)>& root_added_callback) { | 61 const RootCallback& root_added_callback, |
61 new ViewManager(application, root_added_callback); | 62 const RootCallback& root_removed_callback) { |
| 63 new ViewManager(application, root_added_callback, root_removed_callback); |
62 } | 64 } |
63 | 65 |
64 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { | 66 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { |
65 IdToNodeMap::const_iterator it = nodes_.find(id); | 67 IdToNodeMap::const_iterator it = nodes_.find(id); |
66 return it != nodes_.end() ? it->second : NULL; | 68 return it != nodes_.end() ? it->second : NULL; |
67 } | 69 } |
68 | 70 |
69 View* ViewManager::GetViewById(TransportViewId id) { | 71 View* ViewManager::GetViewById(TransportViewId id) { |
70 IdToViewMap::const_iterator it = views_.find(id); | 72 IdToViewMap::const_iterator it = views_.find(id); |
71 return it != views_.end() ? it->second : NULL; | 73 return it != views_.end() ? it->second : NULL; |
72 } | 74 } |
73 | 75 |
74 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
75 // ViewManager, private: | 77 // ViewManager, private: |
76 | 78 |
77 ViewManager::ViewManager( | 79 ViewManager::ViewManager( |
78 Application* application, | 80 Application* application, |
79 const base::Callback<void(ViewManager*)>& root_added_callback) | 81 const RootCallback& root_added_callback, |
| 82 const RootCallback& root_removed_callback) |
80 : root_added_callback_(root_added_callback), | 83 : root_added_callback_(root_added_callback), |
| 84 root_removed_callback_(root_removed_callback), |
81 synchronizer_(NULL) { | 85 synchronizer_(NULL) { |
82 application->AddService<ViewManagerSynchronizer>(this); | 86 application->AddService<ViewManagerSynchronizer>(this); |
83 } | 87 } |
84 | 88 |
85 } // namespace view_manager | 89 } // namespace view_manager |
86 } // namespace mojo | 90 } // namespace mojo |
OLD | NEW |