Chromium Code Reviews| Index: mojo/services/public/cpp/view_manager/lib/view_manager.cc |
| diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager.cc b/mojo/services/public/cpp/view_manager/lib/view_manager.cc |
| index 74fa6998ff2d02e77338cb4eb922ec937420931d..4032d8df577a4a22fdec6ddb8074beaf13870c78 100644 |
| --- a/mojo/services/public/cpp/view_manager/lib/view_manager.cc |
| +++ b/mojo/services/public/cpp/view_manager/lib/view_manager.cc |
| @@ -4,23 +4,27 @@ |
| #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| -#include "base/message_loop/message_loop.h" |
| +#include "base/bind.h" |
| +#include "base/run_loop.h" |
| #include "mojo/public/cpp/application/application.h" |
| +#include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
| #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
| #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
| #include "mojo/services/public/cpp/view_manager/view.h" |
| namespace mojo { |
| namespace view_manager { |
| +namespace { |
| -ViewManager::ViewManager(Application* application) |
| - : synchronizer_(NULL), |
| - tree_(NULL) { |
| - application->AddService<ViewManagerSynchronizer>(this); |
| - // Block in a nested message loop until the ViewManagerSynchronizer is set up. |
| - base::MessageLoop::current()->Run(); |
| +void OnViewManagerReady(base::RunLoop* loop, ViewManager* manager) { |
| + loop->Quit(); |
| } |
| +} // namespace |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ViewManager, public: |
| + |
| ViewManager::~ViewManager() { |
| while (!nodes_.empty()) { |
| IdToNodeMap::iterator it = nodes_.begin(); |
| @@ -38,6 +42,24 @@ ViewManager::~ViewManager() { |
| } |
| } |
| +// static |
| +ViewManager* ViewManager::CreateBlocking(Application* application) { |
| + base::RunLoop init_loop; |
| + ViewManager* manager = new ViewManager( |
| + application, |
| + base::Bind(&OnViewManagerReady, &init_loop)); |
| + init_loop.Run(); |
| + return manager; |
| +} |
| + |
| +// static |
| +void ViewManager::Create( |
| + Application* application, |
| + const base::Callback<void(ViewManager*)> ready_callback) { |
| + new ViewManager(application, ready_callback); |
| +} |
| + |
| + |
|
sky
2014/06/03 20:15:26
nit: only one newline.
|
| ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { |
| IdToNodeMap::const_iterator it = nodes_.find(id); |
| return it != nodes_.end() ? it->second : NULL; |
| @@ -52,5 +74,17 @@ void ViewManager::Embed(const String& url, ViewTreeNode* node) { |
| synchronizer_->Embed(url, node->id()); |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ViewManager, private: |
| + |
| +ViewManager::ViewManager( |
| + Application* application, |
| + const base::Callback<void(ViewManager*)> ready_callback) |
| + : ready_callback_(ready_callback), |
| + synchronizer_(NULL), |
| + tree_(NULL) { |
| + application->AddService<ViewManagerSynchronizer>(this); |
| +} |
| + |
| } // namespace view_manager |
| } // namespace mojo |