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

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

Issue 1679023006: Reify view ownership as a message pipe. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « services/ui/view_manager/view_state.h ('k') | services/ui/view_manager/view_stub.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/view_manager/view_state.cc
diff --git a/services/ui/view_manager/view_state.cc b/services/ui/view_manager/view_state.cc
index 643f6f510f7cb35f5eaa68836fa1c558419ada5c..70125f4a53060b9442d25d8401c3ce541902abc2 100644
--- a/services/ui/view_manager/view_state.cc
+++ b/services/ui/view_manager/view_state.cc
@@ -4,52 +4,83 @@
#include "services/ui/view_manager/view_state.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
-#include "services/ui/view_manager/view_tree_state.h"
+#include "services/ui/view_manager/view_host_impl.h"
+#include "services/ui/view_manager/view_registry.h"
+#include "services/ui/view_manager/view_stub.h"
namespace view_manager {
-ViewState::ViewState(mojo::ui::ViewPtr view,
- mojo::ui::ViewTokenPtr view_token,
- const std::string& label)
+ViewState::ViewState(
+ ViewRegistry* registry,
+ mojo::ui::ViewPtr view,
+ mojo::ui::ViewTokenPtr view_token,
+ mojo::InterfaceRequest<mojo::ui::ViewHost> view_host_request,
+ const std::string& label)
: view_(view.Pass()),
view_token_(view_token.Pass()),
label_(label),
+ impl_(new ViewHostImpl(registry, this)),
+ host_binding_(impl_.get(), view_host_request.Pass()),
+ owner_binding_(impl_.get()),
weak_factory_(this) {
DCHECK(view_);
DCHECK(view_token_);
+
+ view_.set_connection_error_handler(
+ base::Bind(&ViewRegistry::OnViewDied, base::Unretained(registry),
+ base::Unretained(this), "View connection closed"));
+ host_binding_.set_connection_error_handler(
+ base::Bind(&ViewRegistry::OnViewDied, base::Unretained(registry),
+ base::Unretained(this), "ViewHost connection closed"));
+ owner_binding_.set_connection_error_handler(
+ base::Bind(&ViewRegistry::OnViewDied, base::Unretained(registry),
+ base::Unretained(this), "ViewOwner connection closed"));
}
ViewState::~ViewState() {}
-void ViewState::SetTree(ViewTreeState* tree, uint32_t key) {
- DCHECK(tree);
- DCHECK(!parent_); // must be the root
- if (tree_ != tree) {
- SetTreeUnchecked(tree);
- }
- key_ = key;
+void ViewState::LinkChild(uint32_t key, std::unique_ptr<ViewStub> child) {
+ DCHECK(children_.find(key) == children_.end());
+ DCHECK(child);
+ DCHECK(!child->is_linked());
+
+ child->SetParent(this, key);
+ children_.emplace(key, std::move(child));
+}
+
+std::unique_ptr<ViewStub> ViewState::UnlinkChild(uint32_t key) {
+ auto child_it = children_.find(key);
+ DCHECK(child_it != children_.end());
+ std::unique_ptr<ViewStub> child(std::move(child_it->second));
+ child->Unlink();
+ children_.erase(child_it);
+ children_needing_layout_.erase(child->key());
+ return child;
}
-void ViewState::SetTreeUnchecked(ViewTreeState* tree) {
- tree_ = tree;
- for (const auto& pair : children_) {
- pair.second->SetTreeUnchecked(tree);
+std::vector<std::unique_ptr<ViewStub>> ViewState::UnlinkAllChildren() {
+ std::vector<std::unique_ptr<ViewStub>> stubs;
+ for (auto& pair : children_) {
+ pair.second->Unlink();
+ stubs.push_back(std::move(pair.second));
}
+ children_.clear();
+ children_needing_layout_.clear();
+ return stubs;
}
-void ViewState::SetParent(ViewState* parent, uint32_t key) {
- DCHECK(parent);
- parent_ = parent;
- key_ = key;
- SetTreeUnchecked(parent->tree_);
+void ViewState::BindOwner(
+ mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request) {
+ DCHECK(!owner_binding_.is_bound());
+ owner_binding_.Bind(view_owner_request.Pass());
}
-void ViewState::ResetContainer() {
- parent_ = nullptr;
- key_ = 0;
- SetTreeUnchecked(nullptr);
+void ViewState::ReleaseOwner() {
+ DCHECK(owner_binding_.is_bound());
+ owner_binding_.Close();
}
mojo::ui::ViewLayoutInfoPtr ViewState::CreateLayoutInfo() {
@@ -62,7 +93,7 @@ mojo::ui::ViewLayoutInfoPtr ViewState::CreateLayoutInfo() {
return info;
}
-const std::string& ViewState::FormattedLabel() {
+const std::string& ViewState::FormattedLabel() const {
if (formatted_label_cache_.empty()) {
formatted_label_cache_ =
label_.empty()
« no previous file with comments | « services/ui/view_manager/view_state.h ('k') | services/ui/view_manager/view_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698