| Index: services/ui/view_manager/view_tree_state.cc
|
| diff --git a/services/ui/view_manager/view_tree_state.cc b/services/ui/view_manager/view_tree_state.cc
|
| index 4a69f2c318d7815e7c64c36b37269ce9c66826d3..1d8f502cf45081349aac27e268985347d05f178d 100644
|
| --- a/services/ui/view_manager/view_tree_state.cc
|
| +++ b/services/ui/view_manager/view_tree_state.cc
|
| @@ -4,41 +4,56 @@
|
|
|
| #include "services/ui/view_manager/view_tree_state.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/logging.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "services/ui/view_manager/view_registry.h"
|
| +#include "services/ui/view_manager/view_state.h"
|
| +#include "services/ui/view_manager/view_stub.h"
|
| +#include "services/ui/view_manager/view_tree_host_impl.h"
|
|
|
| namespace view_manager {
|
|
|
| -ViewTreeState::ViewTreeState(mojo::ui::ViewTreePtr view_tree,
|
| - mojo::ui::ViewTreeTokenPtr view_tree_token,
|
| - const std::string& label)
|
| +ViewTreeState::ViewTreeState(
|
| + ViewRegistry* registry,
|
| + mojo::ui::ViewTreePtr view_tree,
|
| + mojo::ui::ViewTreeTokenPtr view_tree_token,
|
| + mojo::InterfaceRequest<mojo::ui::ViewTreeHost> view_tree_host_request,
|
| + const std::string& label)
|
| : view_tree_(view_tree.Pass()),
|
| view_tree_token_(view_tree_token.Pass()),
|
| label_(label),
|
| + impl_(new ViewTreeHostImpl(registry, this)),
|
| + host_binding_(impl_.get(), view_tree_host_request.Pass()),
|
| weak_factory_(this) {
|
| DCHECK(view_tree_);
|
| DCHECK(view_tree_token_);
|
| +
|
| + view_tree_.set_connection_error_handler(
|
| + base::Bind(&ViewRegistry::OnViewTreeDied, base::Unretained(registry),
|
| + base::Unretained(this), "ViewTree connection closed"));
|
| + host_binding_.set_connection_error_handler(
|
| + base::Bind(&ViewRegistry::OnViewTreeDied, base::Unretained(registry),
|
| + base::Unretained(this), "ViewTreeHost connection closed"));
|
| }
|
|
|
| ViewTreeState::~ViewTreeState() {}
|
|
|
| -void ViewTreeState::SetRoot(ViewState* root, uint32_t key) {
|
| +void ViewTreeState::LinkRoot(uint32_t key, std::unique_ptr<ViewStub> root) {
|
| + DCHECK(!root_);
|
| DCHECK(root);
|
| - if (root_ != root) {
|
| - ResetRoot();
|
| - root->SetTree(this, key);
|
| - root_ = root;
|
| - }
|
| + DCHECK(!root->is_linked());
|
| + root->SetTree(this, key);
|
| + root_ = std::move(root);
|
| }
|
|
|
| -void ViewTreeState::ResetRoot() {
|
| - if (root_) {
|
| - root_->ResetContainer();
|
| - }
|
| - root_ = nullptr;
|
| +std::unique_ptr<ViewStub> ViewTreeState::UnlinkRoot() {
|
| + DCHECK(root_);
|
| + root_->Unlink();
|
| + return std::move(root_);
|
| }
|
|
|
| -const std::string& ViewTreeState::FormattedLabel() {
|
| +const std::string& ViewTreeState::FormattedLabel() const {
|
| if (formatted_label_cache_.empty()) {
|
| formatted_label_cache_ =
|
| label_.empty() ? base::StringPrintf("<%d>", view_tree_token_->value)
|
|
|