| 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/message_loop/message_loop.h" | |
| 8 #include "mojo/public/cpp/application/application.h" | |
| 9 #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" |
| 10 #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" |
| 11 #include "mojo/services/public/cpp/view_manager/view.h" | 9 #include "mojo/services/public/cpp/view_manager/view.h" |
| 12 | 10 |
| 13 namespace mojo { | 11 namespace mojo { |
| 14 namespace view_manager { | 12 namespace view_manager { |
| 15 | 13 |
| 16 ViewManager::ViewManager(Application* application) | 14 ViewManager::ViewManager(ServiceProvider* service_provider) |
| 17 : synchronizer_(NULL), | 15 : service_provider_(service_provider) {} |
| 18 tree_(NULL) { | |
| 19 application->AddService<ViewManagerSynchronizer>(this); | |
| 20 // Block in a nested message loop until the ViewManagerSynchronizer is set up. | |
| 21 base::MessageLoop::current()->Run(); | |
| 22 } | |
| 23 | 16 |
| 24 ViewManager::~ViewManager() { | 17 ViewManager::~ViewManager() { |
| 25 while (!nodes_.empty()) { | 18 while (!nodes_.empty()) { |
| 26 IdToNodeMap::iterator it = nodes_.begin(); | 19 IdToNodeMap::iterator it = nodes_.begin(); |
| 27 if (synchronizer_->OwnsNode(it->second->id())) | 20 if (synchronizer_->OwnsNode(it->second->id())) |
| 28 it->second->Destroy(); | 21 it->second->Destroy(); |
| 29 else | 22 else |
| 30 nodes_.erase(it); | 23 nodes_.erase(it); |
| 31 } | 24 } |
| 32 while (!views_.empty()) { | 25 while (!views_.empty()) { |
| 33 IdToViewMap::iterator it = views_.begin(); | 26 IdToViewMap::iterator it = views_.begin(); |
| 34 if (synchronizer_->OwnsView(it->second->id())) | 27 if (synchronizer_->OwnsView(it->second->id())) |
| 35 it->second->Destroy(); | 28 it->second->Destroy(); |
| 36 else | 29 else |
| 37 views_.erase(it); | 30 views_.erase(it); |
| 38 } | 31 } |
| 39 } | 32 } |
| 40 | 33 |
| 34 void ViewManager::Init() { |
| 35 synchronizer_.reset(new ViewManagerSynchronizer(this)); |
| 36 } |
| 37 |
| 41 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { | 38 ViewTreeNode* ViewManager::GetNodeById(TransportNodeId id) { |
| 42 IdToNodeMap::const_iterator it = nodes_.find(id); | 39 IdToNodeMap::const_iterator it = nodes_.find(id); |
| 43 return it != nodes_.end() ? it->second : NULL; | 40 return it != nodes_.end() ? it->second : NULL; |
| 44 } | 41 } |
| 45 | 42 |
| 46 View* ViewManager::GetViewById(TransportViewId id) { | 43 View* ViewManager::GetViewById(TransportViewId id) { |
| 47 IdToViewMap::const_iterator it = views_.find(id); | 44 IdToViewMap::const_iterator it = views_.find(id); |
| 48 return it != views_.end() ? it->second : NULL; | 45 return it != views_.end() ? it->second : NULL; |
| 49 } | 46 } |
| 50 | 47 |
| 51 void ViewManager::Embed(const String& url, ViewTreeNode* node) { | |
| 52 synchronizer_->Embed(url, node->id()); | |
| 53 } | |
| 54 | |
| 55 } // namespace view_manager | 48 } // namespace view_manager |
| 56 } // namespace mojo | 49 } // namespace mojo |
| OLD | NEW |