Add histogram for content verification failures of policy based installs
[chromium-blink-merge.git] / components / webui_generator / view.cc
bloba335ef54432d3c7d788f162530205fb89322eac1
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
3 // found in the LICENSE file.
5 #include "components/webui_generator/view.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "components/webui_generator/view_model.h"
11 namespace webui_generator {
13 View::View(const std::string& id)
14 : parent_(NULL),
15 id_(id),
16 ready_children_(0),
17 view_model_ready_(false),
18 ready_(false),
19 weak_factory_(this) {
22 View::~View() {
25 void View::Init() {
26 CreateAndAddChildren();
28 if (!IsRootView())
29 path_ = parent_->path() + "$";
31 path_ += id_;
32 view_model_.reset(CreateViewModel());
33 view_model_->SetView(this);
35 for (auto& id_child : children_)
36 id_child.second->Init();
38 if (children_.empty())
39 OnChildrenReady();
42 bool View::IsRootView() const {
43 return !parent_;
46 ViewModel* View::GetViewModel() const {
47 return view_model_.get();
50 void View::OnViewModelReady() {
51 view_model_ready_ = true;
52 if (ready_children_ == static_cast<int>(children_.size()))
53 OnReady();
56 View* View::GetChild(const std::string& id) const {
57 auto it = children_.find(id);
58 if (it == children_.end())
59 return nullptr;
61 return it->second;
64 void View::OnReady() {
65 if (ready_)
66 return;
68 ready_ = true;
69 if (!IsRootView())
70 parent_->OnChildReady(this);
73 void View::UpdateContext(const base::DictionaryValue& diff) {
74 DCHECK(ready_);
75 view_model_->UpdateContext(diff);
78 void View::HandleEvent(const std::string& event) {
79 DCHECK(ready_);
80 view_model_->OnEvent(event);
83 void View::AddChild(View* child) {
84 DCHECK(children_.find(child->id()) == children_.end());
85 DCHECK(!child->id().empty());
86 children_.set(child->id(), make_scoped_ptr(child));
87 child->set_parent(this);
90 void View::OnChildReady(View* child) {
91 ++ready_children_;
92 if (ready_children_ == static_cast<int>(children_.size()))
93 OnChildrenReady();
96 void View::OnChildrenReady() {
97 view_model_->OnChildrenReady();
98 if (view_model_ready_)
99 OnReady();
102 } // namespace webui_generator