Commit 62a03a94 authored by tfarina's avatar tfarina Committed by Commit bot

ui/base/models: rewrite TreeNode without using ScopedVector

Now that we are using C++11, moveable types inside containers are supported
and ScopedVector will be removed. So we should migrate to a solution
that does not use ScopedVector.

Unfortunately children() accessor complicates the things and does not
allow us to easily use std::vector<scoped_ptr<NodeType>>, so another
solution with STLDeleteElements was choosen.

BUG=554289
TEST=ui_base_unittests --gtest_filter=*Tree*
R=sky@chromium.org

Review URL: https://codereview.chromium.org/1619733003

Cr-Commit-Position: refs/heads/master@{#370769}
parent 8b414be1
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
#include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
......
......@@ -10,12 +10,11 @@
#include <algorithm>
#include <vector>
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/observer_list.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "ui/base/models/tree_model.h"
......@@ -70,7 +69,9 @@ class TreeNode : public TreeModelNode {
explicit TreeNode(const base::string16& title)
: title_(title), parent_(NULL) {}
~TreeNode() override {}
~TreeNode() override {
STLDeleteElements(&children_);
}
// Adds |node| as a child of this node, at |index|.
virtual void Add(NodeType* node, int index) {
......@@ -92,7 +93,7 @@ class TreeNode : public TreeModelNode {
std::find(children_.begin(), children_.end(), node);
DCHECK(i != children_.end());
node->parent_ = NULL;
children_.weak_erase(i);
children_.erase(i);
return node;
}
......@@ -100,7 +101,7 @@ class TreeNode : public TreeModelNode {
void RemoveAll() {
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->parent_ = NULL;
children_.weak_clear();
children_.clear();
}
// Removes all existing children without deleting the nodes and adds all nodes
......@@ -169,7 +170,7 @@ class TreeNode : public TreeModelNode {
}
protected:
std::vector<NodeType*>& children() { return children_.get(); }
std::vector<NodeType*>& children() { return children_; }
private:
// Title displayed in the tree.
......@@ -179,7 +180,7 @@ class TreeNode : public TreeModelNode {
NodeType* parent_;
// This node's children.
ScopedVector<NodeType> children_;
std::vector<NodeType*> children_;
DISALLOW_COPY_AND_ASSIGN(TreeNode);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment