Index: services/ui/view_manager/view_associate_table.cc |
diff --git a/services/ui/view_manager/view_associate_table.cc b/services/ui/view_manager/view_associate_table.cc |
index 2088696f1a0193f8360a95b8d90c75dacd150a61..c4458d35cb1566320faff41fd92661d678fd2d00 100644 |
--- a/services/ui/view_manager/view_associate_table.cc |
+++ b/services/ui/view_manager/view_associate_table.cc |
@@ -32,25 +32,51 @@ void ViewAssociateTable::ConnectAssociates( |
DCHECK(inspector); |
for (auto& url : urls) { |
- DVLOG(1) << "Connecting to view associate: url=" << url; |
- associates_.emplace_back(new AssociateData(url, inspector)); |
- AssociateData* data = associates_.back().get(); |
- |
- mojo::ConnectToService(app_impl->shell(), url, GetProxy(&data->associate)); |
- data->associate.set_connection_error_handler( |
- base::Bind(connection_error_callback, url)); |
- |
- mojo::ui::ViewInspectorPtr inspector; |
- data->inspector_binding.Bind(GetProxy(&inspector)); |
- data->associate->Connect( |
- inspector.Pass(), |
- base::Bind(&ViewAssociateTable::OnConnected, base::Unretained(this), |
- pending_connection_count_)); |
- |
- pending_connection_count_++; |
+ ConnectAssociate(app_impl, inspector, url); |
} |
} |
+void ViewAssociateTable::ConnectAssociate(mojo::ApplicationImpl* app_impl, |
+ mojo::ui::ViewInspector* inspector, |
+ const std::string& url) { |
+ DCHECK(app_impl); |
+ DCHECK(inspector); |
+ |
+ DVLOG(1) << "Connecting to view associate: url=" << url; |
+ |
+ mojo::ui::ViewAssociatePtr associate; |
+ mojo::ConnectToService(app_impl->shell(), url, GetProxy(&associate)); |
+ |
+ // Wire up the associate to us |
+ RegisterViewAssociate(inspector, associate.Pass()); |
+} |
+ |
+void ViewAssociateTable::RegisterViewAssociate( |
+ mojo::ui::ViewInspector* inspector, |
+ mojo::ui::ViewAssociatePtr associate) { |
+ DCHECK(inspector); |
+ DCHECK(associate.is_bound()); |
+ |
+ associates_.emplace_back(new AssociateData(associate.Pass(), inspector)); |
+ AssociateData* data = associates_.back().get(); |
+ |
+ // set it to use our error handler |
+ data->associate.set_connection_error_handler( |
+ base::Bind(&ViewAssociateTable::OnAssociateConnectionError, |
+ base::Unretained(this), data)); |
+ |
+ // connect the associate to our view inspector |
+ mojo::ui::ViewInspectorPtr inspector_ptr; |
+ data->inspector_binding.Bind(GetProxy(&inspector_ptr)); |
+ data->associate->Connect( |
+ inspector_ptr.Pass(), |
+ base::Bind(&ViewAssociateTable::OnConnected, base::Unretained(this), |
+ pending_connection_count_)); |
+ |
+ // wait for the associate to connect to our view inspector |
+ pending_connection_count_++; |
+} |
+ |
void ViewAssociateTable::ConnectToViewService( |
mojo::ui::ViewTokenPtr view_token, |
const mojo::String& service_name, |
@@ -67,11 +93,11 @@ void ViewAssociateTable::ConnectToViewService( |
DCHECK(data->info); |
if (Contains(data->info->view_service_names, service_name)) { |
DVLOG(2) << "Connecting to view service: view_token=" << view_token |
- << ", service_name=" << service_name |
- << ", associate_url=" << data->url; |
+ << ", service_name=" << service_name; |
DCHECK(data->associate); |
data->associate->ConnectToViewService(view_token.Pass(), service_name, |
client_handle.Pass()); |
+ |
return; |
} |
} |
@@ -81,6 +107,22 @@ void ViewAssociateTable::ConnectToViewService( |
// Allow pipe to be closed as an indication of failure. |
} |
+void ViewAssociateTable::OnAssociateConnectionError( |
+ AssociateData* associate_data) { |
+ DVLOG(1) << "Exiting due to associate connection error."; |
+ |
+ // la, la de daaa..... |
+ for (auto it = associates_.begin(); it != associates_.end(); it++) { |
+ AssociateData* data = it->get(); |
+ // DCHECK(data->info); |
+ if (associate_data == data) { |
+ DVLOG(2) << "found it."; |
+ associates_.erase(it); |
+ break; |
+ } |
+ } |
+} |
+ |
void ViewAssociateTable::ConnectToViewTreeService( |
mojo::ui::ViewTreeTokenPtr view_tree_token, |
const mojo::String& service_name, |
@@ -97,8 +139,7 @@ void ViewAssociateTable::ConnectToViewTreeService( |
DCHECK(data->info); |
if (Contains(data->info->view_tree_service_names, service_name)) { |
DVLOG(2) << "Connecting to view tree service: view_tree_token=" |
- << view_tree_token << ", service_name=" << service_name |
- << ", associate_url=" << data->url; |
+ << view_tree_token << ", service_name=" << service_name; |
DCHECK(data->associate); |
data->associate->ConnectToViewTreeService( |
view_tree_token.Pass(), service_name, client_handle.Pass()); |
@@ -117,8 +158,7 @@ void ViewAssociateTable::OnConnected(uint32_t index, |
DCHECK(pending_connection_count_); |
DCHECK(!associates_[index]->info); |
- DVLOG(1) << "Connected to view associate: url=" << associates_[index]->url |
- << ", info=" << info; |
+ DVLOG(1) << "Connected to view associate, info=" << info; |
associates_[index]->info = info.Pass(); |
pending_connection_count_--; |
@@ -135,9 +175,9 @@ void ViewAssociateTable::CompleteDeferredWork() { |
} |
ViewAssociateTable::AssociateData::AssociateData( |
- const std::string& url, |
+ mojo::ui::ViewAssociatePtr associate, |
mojo::ui::ViewInspector* inspector) |
- : url(url), inspector_binding(inspector) {} |
+ : associate(associate.Pass()), inspector_binding(inspector) {} |
ViewAssociateTable::AssociateData::~AssociateData() {} |