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

Unified Diff: services/ui/view_manager/view_stub.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_stub.h ('k') | services/ui/view_manager/view_tree_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/view_manager/view_stub.cc
diff --git a/services/ui/view_manager/view_stub.cc b/services/ui/view_manager/view_stub.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8fd5eae8f402e58e006f63e97f693bcdffb063a2
--- /dev/null
+++ b/services/ui/view_manager/view_stub.cc
@@ -0,0 +1,98 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/ui/view_manager/view_stub.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "services/ui/view_manager/view_registry.h"
+#include "services/ui/view_manager/view_state.h"
+#include "services/ui/view_manager/view_tree_state.h"
+
+namespace view_manager {
+
+ViewStub::ViewStub(ViewRegistry* registry, mojo::ui::ViewOwnerPtr owner)
+ : registry_(registry), owner_(owner.Pass()) {
+ DCHECK(registry_);
+ DCHECK(owner_);
+
+ owner_.set_connection_error_handler(
+ base::Bind(&ViewStub::OnViewResolved, base::Unretained(this), nullptr));
+ owner_->GetToken(
+ base::Bind(&ViewStub::OnViewResolved, base::Unretained(this)));
+}
+
+ViewStub::~ViewStub() {
+ // Ensure that everything was properly released before this object was
+ // destroyed. The |ViewRegistry| is responsible for maintaining the
+ // invariant that all |ViewState| objects are owned so by the time we
+ // get here, the view should have found a new owner or been unregistered.
+ DCHECK(is_unavailable());
+}
+
+void ViewStub::AttachView(ViewState* state) {
+ DCHECK(state);
+ DCHECK(!state->view_stub());
+ DCHECK(is_pending());
+
+ state_ = state;
+ state_->set_view_stub(this);
+}
+
+ViewState* ViewStub::ReleaseView() {
+ if (is_unavailable())
+ return nullptr;
+
+ ViewState* state = state_;
+ if (state) {
+ DCHECK(state->view_stub() == this);
+ state->set_view_stub(nullptr);
+ state_ = nullptr;
+ }
+ unavailable_ = true;
+ return state;
+}
+
+void ViewStub::SetTree(ViewTreeState* tree, uint32_t key) {
+ DCHECK(tree);
+ DCHECK(!tree_ && !parent_);
+
+ key_ = key;
+ SetTreeRecursively(tree);
+}
+
+void ViewStub::SetParent(ViewState* parent, uint32_t key) {
+ DCHECK(parent);
+ DCHECK(!tree_ && !parent_);
+
+ parent_ = parent;
+ key_ = key;
+ if (parent->view_stub())
+ SetTreeRecursively(parent->view_stub()->tree());
+}
+
+void ViewStub::Unlink() {
+ parent_ = nullptr;
+ key_ = 0;
+ SetTreeRecursively(nullptr);
+}
+
+void ViewStub::SetTreeRecursively(ViewTreeState* tree) {
+ if (tree_ == tree)
+ return;
+ tree_ = tree;
+ if (state_) {
+ for (const auto& pair : state_->children()) {
+ pair.second->SetTreeRecursively(tree);
+ }
+ }
+}
+
+void ViewStub::OnViewResolved(mojo::ui::ViewTokenPtr view_token) {
+ DCHECK(owner_);
+ owner_.reset();
+ registry_->OnViewResolved(this, view_token.Pass());
+}
+
+} // namespace view_manager
« no previous file with comments | « services/ui/view_manager/view_stub.h ('k') | services/ui/view_manager/view_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698