Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: services/ui/view_manager/view_associate_table.cc

Issue 1949233002: Create a RegisterViewAssociate method in ViewManager (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: one more compile fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..fe1b632b3f53fd105e8530cceefae1871a2fc127 100644
--- a/services/ui/view_manager/view_associate_table.cc
+++ b/services/ui/view_manager/view_associate_table.cc
@@ -23,39 +23,51 @@ 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,
+ mojo::InterfaceRequest<mojo::ui::ViewAssociateOwner>
+ view_associate_owner_request,
+ 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(), this, 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));
+ data->BindOwner(view_associate_owner_request.Pass());
- 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_));
+ // Set it to use our error handler.
+ data->associate.set_connection_error_handler(
+ base::Bind(&ViewAssociateTable::OnAssociateConnectionError,
+ base::Unretained(this), data));
- pending_connection_count_++;
- }
+ data->associate_owner.set_connection_error_handler(
+ base::Bind(&ViewAssociateTable::OnAssociateOwnerConnectionError,
+ 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::FinishedRegisteringViewAssociates() {
+ waiting_to_register_associates_ = false;
jeffbrown 2016/05/18 18:07:16 This needs to kick deferred work in the same way t
mikejurka 2016/05/18 19:09:10 Done.
}
void ViewAssociateTable::ConnectToViewService(
mojo::ui::ViewTokenPtr view_token,
const mojo::String& service_name,
mojo::ScopedMessagePipeHandle client_handle) {
- if (pending_connection_count_) {
+ if (waiting_to_register_associates_ || pending_connection_count_) {
deferred_work_.push_back(
base::Bind(&ViewAssociateTable::ConnectToViewService,
base::Unretained(this), base::Passed(view_token.Pass()),
@@ -68,7 +80,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,11 +93,39 @@ void ViewAssociateTable::ConnectToViewService(
// Allow pipe to be closed as an indication of failure.
}
+void ViewAssociateTable::OnAssociateConnectionError(
+ AssociateData* associate_data) {
+ // Remove associate from our list.
+ 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;
+ associates_.erase(it);
+ break;
+ }
+ }
jeffbrown 2016/05/18 18:07:16 nit: if we fail to find the associate then there's
mikejurka 2016/05/18 19:09:10 Done.
+}
+
+void ViewAssociateTable::OnAssociateOwnerConnectionError(
+ AssociateData* associate_data) {
+ // Remove associate from our list.
+ for (auto it = associates_.begin(); it != associates_.end(); it++) {
+ AssociateData* data = it->get();
+ if (associate_data == data) {
+ DVLOG(2) << "ViewAssociateOwner disconnected, removing from table"
+ << ", associate_label=" << data->label;
+ associates_.erase(it);
+ break;
+ }
+ }
+}
+
void ViewAssociateTable::ConnectToViewTreeService(
mojo::ui::ViewTreeTokenPtr view_tree_token,
const mojo::String& service_name,
mojo::ScopedMessagePipeHandle client_handle) {
- if (pending_connection_count_) {
+ if (waiting_to_register_associates_ || pending_connection_count_) {
deferred_work_.push_back(
base::Bind(&ViewAssociateTable::ConnectToViewTreeService,
base::Unretained(this), base::Passed(view_tree_token.Pass()),
@@ -98,7 +138,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,28 +157,44 @@ 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();
pending_connection_count_--;
- if (!pending_connection_count_)
+ if (!waiting_to_register_associates_ && !pending_connection_count_)
jeffbrown 2016/05/18 18:07:16 Consider renaming CompleteDeferredWork to Complete
mikejurka 2016/05/18 19:09:10 Done.
CompleteDeferredWork();
}
void ViewAssociateTable::CompleteDeferredWork() {
DCHECK(!pending_connection_count_);
+ DCHECK(!waiting_to_register_associates_);
for (auto& work : deferred_work_)
work.Run();
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::ViewAssociateOwner* associate_owner_impl,
mojo::ui::ViewInspector* inspector)
- : url(url), inspector_binding(inspector) {}
+ : label(label),
+ associate(associate.Pass()),
+ associate_owner(associate_owner_impl),
+ inspector_binding(inspector) {}
ViewAssociateTable::AssociateData::~AssociateData() {}
+void ViewAssociateTable::AssociateData::BindOwner(
+ mojo::InterfaceRequest<mojo::ui::ViewAssociateOwner>
+ view_associate_owner_request) {
+ associate_owner.Bind(view_associate_owner_request.Pass());
+}
+
} // namespace view_manager

Powered by Google App Engine
This is Rietveld 408576698