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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 while (!views_.empty()) { | 36 while (!views_.empty()) { |
37 IdToViewMap::iterator it = views_.begin(); | 37 IdToViewMap::iterator it = views_.begin(); |
38 if (synchronizer_->OwnsView(it->second->id())) | 38 if (synchronizer_->OwnsView(it->second->id())) |
39 it->second->Destroy(); | 39 it->second->Destroy(); |
40 else | 40 else |
41 views_.erase(it); | 41 views_.erase(it); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 // static | 45 // static |
46 ViewManager* ViewManager::CreateBlocking(Application* application) { | 46 ViewManager* ViewManager::CreateBlocking( |
| 47 Application* application, |
| 48 const base::Callback<void(ViewManager*)>& root_added_callback) { |
47 base::RunLoop init_loop; | 49 base::RunLoop init_loop; |
48 ViewManager* manager = new ViewManager( | 50 ViewManager* manager = new ViewManager( |
49 application, | 51 application, |
50 base::Bind(&OnViewManagerReady, &init_loop)); | 52 base::Bind(&OnViewManagerReady, &init_loop)); |
51 init_loop.Run(); | 53 init_loop.Run(); |
52 return manager; | 54 return manager; |
53 } | 55 } |
54 | 56 |
55 // static | 57 // static |
56 void ViewManager::Create( | 58 void ViewManager::Create( |
57 Application* application, | 59 Application* application, |
58 const base::Callback<void(ViewManager*)> ready_callback) { | 60 const base::Callback<void(ViewManager*)>& root_added_callback) { |
59 new ViewManager(application, ready_callback); | 61 new ViewManager(application, root_added_callback); |
60 } | 62 } |
61 | 63 |
62 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { | 64 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { |
63 IdToNodeMap::const_iterator it = nodes_.find(id); | 65 IdToNodeMap::const_iterator it = nodes_.find(id); |
64 return it != nodes_.end() ? it->second : NULL; | 66 return it != nodes_.end() ? it->second : NULL; |
65 } | 67 } |
66 | 68 |
67 View* ViewManager::GetViewById(TransportViewId id) { | 69 View* ViewManager::GetViewById(TransportViewId id) { |
68 IdToViewMap::const_iterator it = views_.find(id); | 70 IdToViewMap::const_iterator it = views_.find(id); |
69 return it != views_.end() ? it->second : NULL; | 71 return it != views_.end() ? it->second : NULL; |
70 } | 72 } |
71 | 73 |
72 void ViewManager::Embed(const String& url, ViewTreeNode* node) { | |
73 synchronizer_->Embed(url, node->id()); | |
74 } | |
75 | |
76 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
77 // ViewManager, private: | 75 // ViewManager, private: |
78 | 76 |
79 ViewManager::ViewManager( | 77 ViewManager::ViewManager( |
80 Application* application, | 78 Application* application, |
81 const base::Callback<void(ViewManager*)> ready_callback) | 79 const base::Callback<void(ViewManager*)>& root_added_callback) |
82 : ready_callback_(ready_callback), | 80 : root_added_callback_(root_added_callback), |
83 synchronizer_(NULL), | 81 synchronizer_(NULL) { |
84 tree_(NULL) { | |
85 application->AddService<ViewManagerSynchronizer>(this); | 82 application->AddService<ViewManagerSynchronizer>(this); |
86 } | 83 } |
87 | 84 |
88 } // namespace view_manager | 85 } // namespace view_manager |
89 } // namespace mojo | 86 } // namespace mojo |
OLD | NEW |