Chromium Code Reviews| 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/view_manager/view_manager_init_service_context.h" | 5 #include "mojo/services/view_manager/view_manager_init_service_context.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "mojo/services/view_manager/root_node_manager.h" | 9 #include "mojo/services/view_manager/root_node_manager.h" |
| 9 #include "mojo/services/view_manager/view_manager_init_service_impl.h" | 10 #include "mojo/services/view_manager/view_manager_init_service_impl.h" |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 namespace service { | 13 namespace service { |
| 13 | 14 |
| 15 ViewManagerInitServiceContext::ConnectParams::ConnectParams() {} | |
| 16 | |
| 17 ViewManagerInitServiceContext::ConnectParams::~ConnectParams() {} | |
| 18 | |
| 14 ViewManagerInitServiceContext::ViewManagerInitServiceContext() | 19 ViewManagerInitServiceContext::ViewManagerInitServiceContext() |
| 15 : is_tree_host_ready_(false) {} | 20 : is_tree_host_ready_(false), |
| 21 deleting_connection_(false) {} | |
| 16 ViewManagerInitServiceContext::~ViewManagerInitServiceContext() {} | 22 ViewManagerInitServiceContext::~ViewManagerInitServiceContext() {} |
| 17 | 23 |
| 18 void ViewManagerInitServiceContext::AddConnection( | 24 void ViewManagerInitServiceContext::AddConnection( |
| 19 ViewManagerInitServiceImpl* connection) { | 25 ViewManagerInitServiceImpl* connection) { |
| 20 DCHECK(std::find(connections_.begin(), connections_.end(), connection) == | 26 DCHECK(std::find(connections_.begin(), connections_.end(), connection) == |
| 21 connections_.end()); | 27 connections_.end()); |
| 22 connections_.push_back(connection); | 28 connections_.push_back(connection); |
| 23 } | 29 } |
| 24 | 30 |
| 25 void ViewManagerInitServiceContext::RemoveConnection( | 31 void ViewManagerInitServiceContext::RemoveConnection( |
| 26 ViewManagerInitServiceImpl* connection) { | 32 ViewManagerInitServiceImpl* connection) { |
| 27 Connections::iterator it = | 33 if (!deleting_connection_) { |
| 28 std::find(connections_.begin(), connections_.end(), connection); | 34 Connections::iterator it = |
| 29 DCHECK(it != connections_.end()); | 35 std::find(connections_.begin(), connections_.end(), connection); |
| 30 connections_.erase(it); | 36 DCHECK(it != connections_.end()); |
| 37 connections_.erase(it); | |
| 38 } | |
| 31 | 39 |
| 32 // This object is owned by an object that outlives the current thread's | 40 // This object is owned by an object that outlives the current thread's |
| 33 // message loop, so we need to destroy the RootNodeManager earlier, as it may | 41 // message loop, so we need to destroy the RootNodeManager earlier, as it may |
| 34 // attempt to post tasks during its destruction. | 42 // attempt to post tasks during its destruction. |
| 35 if (connections_.empty()) | 43 if (connections_.empty()) |
| 36 root_node_manager_.reset(); | 44 root_node_manager_.reset(); |
| 37 } | 45 } |
| 38 | 46 |
| 39 void ViewManagerInitServiceContext::ConfigureIncomingConnection( | 47 void ViewManagerInitServiceContext::ConfigureIncomingConnection( |
| 40 ApplicationConnection* connection) { | 48 ApplicationConnection* connection) { |
| 41 if (!root_node_manager_.get()) { | 49 if (!root_node_manager_.get()) { |
| 42 root_node_manager_.reset(new RootNodeManager( | 50 root_node_manager_.reset(new RootNodeManager( |
| 43 connection, | 51 connection, |
| 44 this, | 52 this, |
| 45 base::Bind(&ViewManagerInitServiceContext::OnNativeViewportDeleted, | 53 base::Bind(&ViewManagerInitServiceContext::OnNativeViewportDeleted, |
| 46 base::Unretained(this)))); | 54 base::Unretained(this)))); |
| 47 } | 55 } |
| 48 } | 56 } |
| 49 | 57 |
| 50 void ViewManagerInitServiceContext::OnNativeViewportDeleted() { | 58 void ViewManagerInitServiceContext::Embed( |
| 51 for (Connections::const_iterator it = connections_.begin(); | 59 const String& url, |
| 52 it != connections_.end(); ++it) { | 60 ServiceProviderPtr service_provider, |
| 53 (*it)->OnNativeViewportDeleted(); | 61 const Callback<void(bool)>& callback) { |
| 54 } | 62 ConnectParams* params = new ConnectParams; |
| 63 params->url = url.To<std::string>(); | |
| 64 params->callback = callback; | |
| 65 params->service_provider.Bind(service_provider.PassMessagePipe()); | |
| 66 connect_params_.push_back(params); | |
| 67 MaybeEmbed(); | |
| 55 } | 68 } |
| 56 | 69 |
| 57 void ViewManagerInitServiceContext::OnRootViewManagerWindowTreeHostCreated() { | 70 void ViewManagerInitServiceContext::OnRootViewManagerWindowTreeHostCreated() { |
| 58 DCHECK(!is_tree_host_ready_); | 71 DCHECK(!is_tree_host_ready_); |
| 59 is_tree_host_ready_ = true; | 72 is_tree_host_ready_ = true; |
| 73 MaybeEmbed(); | |
| 74 } | |
| 75 | |
| 76 void ViewManagerInitServiceContext::OnNativeViewportDeleted() { | |
| 77 // Prevent the connection from modifying the connection list during manual | |
| 78 // teardown. | |
| 79 base::AutoReset<bool> deleting_connection(&deleting_connection_, true); | |
| 60 for (Connections::const_iterator it = connections_.begin(); | 80 for (Connections::const_iterator it = connections_.begin(); |
| 61 it != connections_.end(); ++it) { | 81 it != connections_.end(); ++it) { |
| 62 (*it)->OnRootViewManagerWindowTreeHostCreated(); | 82 delete *it; |
| 63 } | 83 } |
| 84 connections_.clear(); | |
| 85 root_node_manager_.reset(); | |
| 86 } | |
| 87 | |
| 88 void ViewManagerInitServiceContext::MaybeEmbed() { | |
| 89 if (!is_tree_host_ready_) | |
| 90 return; | |
| 91 | |
| 92 ScopedVector<ConnectParams>::const_iterator it = connect_params_.begin(); | |
|
sky
2014/08/11 23:47:56
nit: move into for loop.
| |
| 93 for (; it != connect_params_.end(); ++it) { | |
| 94 root_node_manager_->EmbedRoot((*it)->url, (*it)->service_provider.Pass()); | |
| 95 (*it)->callback.Run(true); | |
| 96 } | |
| 97 connect_params_.clear(); | |
| 64 } | 98 } |
| 65 | 99 |
| 66 } // namespace service | 100 } // namespace service |
| 67 } // namespace mojo | 101 } // namespace mojo |
| OLD | NEW |