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..7aab94223c293affec00bab48ffa2d96c31834ce 100644 |
--- a/services/ui/view_manager/view_associate_table.cc |
+++ b/services/ui/view_manager/view_associate_table.cc |
@@ -23,32 +23,40 @@ ViewAssociateTable::ViewAssociateTable() {} |
ViewAssociateTable::~ViewAssociateTable() {} |
-void ViewAssociateTable::ConnectAssociates( |
- mojo::ApplicationImpl* app_impl, |
+void ViewAssociateTable::RegisterViewAssociate( |
mojo::ui::ViewInspector* inspector, |
- const std::vector<std::string>& urls, |
- const AssociateConnectionErrorCallback& connection_error_callback) { |
- DCHECK(app_impl); |
+ mojo::ui::ViewAssociatePtr associate, |
+ const AssociateConnectionErrorCallback& connection_error_callback, |
+ const mojo::String& label) { |
DCHECK(inspector); |
+ DCHECK(associate.is_bound()); |
- for (auto& url : urls) { |
- DVLOG(1) << "Connecting to view associate: url=" << url; |
- associates_.emplace_back(new AssociateData(url, inspector)); |
- AssociateData* data = associates_.back().get(); |
+ associates_.emplace_back( |
+ new AssociateData(label, associate.Pass(), inspector)); |
+ AssociateData* data = associates_.back().get(); |
- mojo::ConnectToService(app_impl->shell(), url, GetProxy(&data->associate)); |
+ if (connection_error_callback.is_null()) { |
+ // Set it to use our error handler. |
data->associate.set_connection_error_handler( |
- base::Bind(connection_error_callback, url)); |
+ base::Bind(&ViewAssociateTable::OnAssociateConnectionError, |
+ base::Unretained(this), data)); |
+ } |
- 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_)); |
+ // 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_)); |
- pending_connection_count_++; |
- } |
+ // Wait for the associate to connect to our view inspector. |
+ pending_connection_count_++; |
+} |
+ |
+void ViewAssociateTable::RegisterViewAssociateWatcher( |
+ mojo::ui::ViewAssociateWatcherPtr view_associate_watcher) { |
+ associate_watchers_.push_back(view_associate_watcher.Pass()); |
jeffbrown
2016/05/17 00:44:49
prefer emplace_back where possible
|
} |
void ViewAssociateTable::ConnectToViewService( |
@@ -68,7 +76,7 @@ void ViewAssociateTable::ConnectToViewService( |
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; |
+ << ", associate_label=" << data->label; |
DCHECK(data->associate); |
data->associate->ConnectToViewService(view_token.Pass(), service_name, |
client_handle.Pass()); |
@@ -81,6 +89,28 @@ void ViewAssociateTable::ConnectToViewService( |
// Allow pipe to be closed as an indication of failure. |
} |
+void ViewAssociateTable::OnAssociateConnectionError( |
+ AssociateData* associate_data) { |
+ // Remove associate from our list. |
+ std::string label; |
+ for (auto it = associates_.begin(); it != associates_.end(); it++) { |
+ AssociateData* data = it->get(); |
+ if (associate_data == data) { |
+ DVLOG(2) << "ViewAssociate disconnected, removing from table" |
+ << ", associate_label=" << data->label; |
+ label = data->label; |
+ associates_.erase(it); |
+ break; |
+ } |
+ } |
+ for (auto& view_associate_watcher : associate_watchers_) { |
+ // TODO(mikejurka) do we even need this callback? |
+ mojo::Callback<void()> null_callback; |
+ view_associate_watcher->OnViewAssociateConnectionError(label, |
+ null_callback); |
+ } |
+} |
+ |
void ViewAssociateTable::ConnectToViewTreeService( |
mojo::ui::ViewTreeTokenPtr view_tree_token, |
const mojo::String& service_name, |
@@ -98,7 +128,7 @@ void ViewAssociateTable::ConnectToViewTreeService( |
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; |
+ << ", associate_label=" << data->label; |
DCHECK(data->associate); |
data->associate->ConnectToViewTreeService( |
view_tree_token.Pass(), service_name, client_handle.Pass()); |
@@ -117,7 +147,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 |
+ DVLOG(1) << "Connected to view associate: label=" << associates_[index]->label |
<< ", info=" << info; |
associates_[index]->info = info.Pass(); |
@@ -134,10 +164,15 @@ void ViewAssociateTable::CompleteDeferredWork() { |
deferred_work_.clear(); |
} |
+size_t ViewAssociateTable::associate_count() { |
+ return associates_.size(); |
+} |
+ |
ViewAssociateTable::AssociateData::AssociateData( |
- const std::string& url, |
+ const std::string& label, |
+ mojo::ui::ViewAssociatePtr associate, |
mojo::ui::ViewInspector* inspector) |
- : url(url), inspector_binding(inspector) {} |
+ : label(label), associate(associate.Pass()), inspector_binding(inspector) {} |
ViewAssociateTable::AssociateData::~AssociateData() {} |