Index: mojo/services/view_manager/view_manager_init_service_context.cc |
diff --git a/mojo/services/view_manager/view_manager_init_service_context.cc b/mojo/services/view_manager/view_manager_init_service_context.cc |
index 66c8aa9a1e40653fe429097b7b48cd4bab869924..a833c1caf7f37a471a06cdabc812f9a1f7f5a4f3 100644 |
--- a/mojo/services/view_manager/view_manager_init_service_context.cc |
+++ b/mojo/services/view_manager/view_manager_init_service_context.cc |
@@ -4,6 +4,7 @@ |
#include "mojo/services/view_manager/view_manager_init_service_context.h" |
+#include "base/auto_reset.h" |
#include "base/bind.h" |
#include "mojo/services/view_manager/root_node_manager.h" |
#include "mojo/services/view_manager/view_manager_init_service_impl.h" |
@@ -11,8 +12,13 @@ |
namespace mojo { |
namespace service { |
+ViewManagerInitServiceContext::ConnectParams::ConnectParams() {} |
+ |
+ViewManagerInitServiceContext::ConnectParams::~ConnectParams() {} |
+ |
ViewManagerInitServiceContext::ViewManagerInitServiceContext() |
- : is_tree_host_ready_(false) {} |
+ : is_tree_host_ready_(false), |
+ deleting_connection_(false) {} |
ViewManagerInitServiceContext::~ViewManagerInitServiceContext() {} |
void ViewManagerInitServiceContext::AddConnection( |
@@ -24,10 +30,12 @@ void ViewManagerInitServiceContext::AddConnection( |
void ViewManagerInitServiceContext::RemoveConnection( |
ViewManagerInitServiceImpl* connection) { |
- Connections::iterator it = |
- std::find(connections_.begin(), connections_.end(), connection); |
- DCHECK(it != connections_.end()); |
- connections_.erase(it); |
+ if (!deleting_connection_) { |
+ Connections::iterator it = |
+ std::find(connections_.begin(), connections_.end(), connection); |
+ DCHECK(it != connections_.end()); |
+ connections_.erase(it); |
+ } |
// This object is owned by an object that outlives the current thread's |
// message loop, so we need to destroy the RootNodeManager earlier, as it may |
@@ -47,20 +55,46 @@ void ViewManagerInitServiceContext::ConfigureIncomingConnection( |
} |
} |
-void ViewManagerInitServiceContext::OnNativeViewportDeleted() { |
- for (Connections::const_iterator it = connections_.begin(); |
- it != connections_.end(); ++it) { |
- (*it)->OnNativeViewportDeleted(); |
- } |
+void ViewManagerInitServiceContext::Embed( |
+ const String& url, |
+ ServiceProviderPtr service_provider, |
+ const Callback<void(bool)>& callback) { |
+ ConnectParams* params = new ConnectParams; |
+ params->url = url.To<std::string>(); |
+ params->callback = callback; |
+ params->service_provider.Bind(service_provider.PassMessagePipe()); |
+ connect_params_.push_back(params); |
+ MaybeEmbed(); |
} |
void ViewManagerInitServiceContext::OnRootViewManagerWindowTreeHostCreated() { |
DCHECK(!is_tree_host_ready_); |
is_tree_host_ready_ = true; |
+ MaybeEmbed(); |
+} |
+ |
+void ViewManagerInitServiceContext::OnNativeViewportDeleted() { |
+ // Prevent the connection from modifying the connection list during manual |
+ // teardown. |
+ base::AutoReset<bool> deleting_connection(&deleting_connection_, true); |
for (Connections::const_iterator it = connections_.begin(); |
it != connections_.end(); ++it) { |
- (*it)->OnRootViewManagerWindowTreeHostCreated(); |
+ delete *it; |
+ } |
+ connections_.clear(); |
+ root_node_manager_.reset(); |
+} |
+ |
+void ViewManagerInitServiceContext::MaybeEmbed() { |
+ if (!is_tree_host_ready_) |
+ return; |
+ |
+ for (ScopedVector<ConnectParams>::const_iterator it = connect_params_.begin(); |
+ it != connect_params_.end(); ++it) { |
+ root_node_manager_->EmbedRoot((*it)->url, (*it)->service_provider.Pass()); |
+ (*it)->callback.Run(true); |
} |
+ connect_params_.clear(); |
} |
} // namespace service |