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

Side by Side Diff: services/ui/view_manager/view_tree_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 unified diff | Download patch
« no previous file with comments | « services/ui/view_manager/view_tree_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/view_manager/view_tree_state.h" 5 #include "services/ui/view_manager/view_tree_state.h"
6 6
7 #include "base/bind.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "services/ui/view_manager/view_registry.h"
11 #include "services/ui/view_manager/view_state.h"
12 #include "services/ui/view_manager/view_stub.h"
13 #include "services/ui/view_manager/view_tree_host_impl.h"
9 14
10 namespace view_manager { 15 namespace view_manager {
11 16
12 ViewTreeState::ViewTreeState(mojo::ui::ViewTreePtr view_tree, 17 ViewTreeState::ViewTreeState(
13 mojo::ui::ViewTreeTokenPtr view_tree_token, 18 ViewRegistry* registry,
14 const std::string& label) 19 mojo::ui::ViewTreePtr view_tree,
20 mojo::ui::ViewTreeTokenPtr view_tree_token,
21 mojo::InterfaceRequest<mojo::ui::ViewTreeHost> view_tree_host_request,
22 const std::string& label)
15 : view_tree_(view_tree.Pass()), 23 : view_tree_(view_tree.Pass()),
16 view_tree_token_(view_tree_token.Pass()), 24 view_tree_token_(view_tree_token.Pass()),
17 label_(label), 25 label_(label),
26 impl_(new ViewTreeHostImpl(registry, this)),
27 host_binding_(impl_.get(), view_tree_host_request.Pass()),
18 weak_factory_(this) { 28 weak_factory_(this) {
19 DCHECK(view_tree_); 29 DCHECK(view_tree_);
20 DCHECK(view_tree_token_); 30 DCHECK(view_tree_token_);
31
32 view_tree_.set_connection_error_handler(
33 base::Bind(&ViewRegistry::OnViewTreeDied, base::Unretained(registry),
34 base::Unretained(this), "ViewTree connection closed"));
35 host_binding_.set_connection_error_handler(
36 base::Bind(&ViewRegistry::OnViewTreeDied, base::Unretained(registry),
37 base::Unretained(this), "ViewTreeHost connection closed"));
21 } 38 }
22 39
23 ViewTreeState::~ViewTreeState() {} 40 ViewTreeState::~ViewTreeState() {}
24 41
25 void ViewTreeState::SetRoot(ViewState* root, uint32_t key) { 42 void ViewTreeState::LinkRoot(uint32_t key, std::unique_ptr<ViewStub> root) {
43 DCHECK(!root_);
26 DCHECK(root); 44 DCHECK(root);
27 if (root_ != root) { 45 DCHECK(!root->is_linked());
28 ResetRoot(); 46 root->SetTree(this, key);
29 root->SetTree(this, key); 47 root_ = std::move(root);
30 root_ = root;
31 }
32 } 48 }
33 49
34 void ViewTreeState::ResetRoot() { 50 std::unique_ptr<ViewStub> ViewTreeState::UnlinkRoot() {
35 if (root_) { 51 DCHECK(root_);
36 root_->ResetContainer(); 52 root_->Unlink();
37 } 53 return std::move(root_);
38 root_ = nullptr;
39 } 54 }
40 55
41 const std::string& ViewTreeState::FormattedLabel() { 56 const std::string& ViewTreeState::FormattedLabel() const {
42 if (formatted_label_cache_.empty()) { 57 if (formatted_label_cache_.empty()) {
43 formatted_label_cache_ = 58 formatted_label_cache_ =
44 label_.empty() ? base::StringPrintf("<%d>", view_tree_token_->value) 59 label_.empty() ? base::StringPrintf("<%d>", view_tree_token_->value)
45 : base::StringPrintf("<%d:%s>", view_tree_token_->value, 60 : base::StringPrintf("<%d:%s>", view_tree_token_->value,
46 label_.c_str()); 61 label_.c_str());
47 } 62 }
48 return formatted_label_cache_; 63 return formatted_label_cache_;
49 } 64 }
50 65
51 std::ostream& operator<<(std::ostream& os, ViewTreeState* view_tree_state) { 66 std::ostream& operator<<(std::ostream& os, ViewTreeState* view_tree_state) {
52 if (!view_tree_state) 67 if (!view_tree_state)
53 return os << "null"; 68 return os << "null";
54 return os << view_tree_state->FormattedLabel(); 69 return os << view_tree_state->FormattedLabel();
55 } 70 }
56 71
57 } // namespace view_manager 72 } // namespace view_manager
OLDNEW
« no previous file with comments | « services/ui/view_manager/view_tree_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698