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

Unified Diff: ui/views/controls/tree/tree_view.cc

Issue 2379863002: Fix object ownership in ui/base/models. (Closed)
Patch Set: fix Created 4 years, 3 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 | « ui/views/controls/tree/tree_view.h ('k') | ui/views/controls/tree/tree_view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/tree/tree_view.cc
diff --git a/ui/views/controls/tree/tree_view.cc b/ui/views/controls/tree/tree_view.cc
index 1f7b2ddf74c50b4674625f93251fadd1c27c772c..a87875e7870ddb7af5c099fcd3f9a917d7d549a1 100644
--- a/ui/views/controls/tree/tree_view.cc
+++ b/ui/views/controls/tree/tree_view.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/i18n/rtl.h"
+#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/base/ime/input_method.h"
@@ -136,7 +137,7 @@ void TreeView::SetModel(TreeModel* model) {
model_->AddObserver(this);
model_->GetIcons(&icons_);
- root_.RemoveAll();
+ root_.DeleteAll();
ConfigureInternalNode(model_->GetRoot(), &root_);
LoadChildren(&root_);
root_.set_is_expanded(true);
@@ -429,9 +430,9 @@ void TreeView::TreeNodesAdded(TreeModel* model,
if (!parent_node || !parent_node->loaded_children())
return;
for (int i = 0; i < count; ++i) {
- InternalNode* child = new InternalNode;
- ConfigureInternalNode(model_->GetChild(parent, start + i), child);
- parent_node->Add(child, start + i);
+ std::unique_ptr<InternalNode> child = base::MakeUnique<InternalNode>();
+ ConfigureInternalNode(model_->GetChild(parent, start + i), child.get());
+ parent_node->Add(std::move(child), start + i);
}
if (IsExpanded(parent))
DrawnNodesChanged();
@@ -450,7 +451,7 @@ void TreeView::TreeNodesRemoved(TreeModel* model,
InternalNode* child_removing = parent_node->GetChild(start);
if (selected_node_ && selected_node_->HasAncestor(child_removing))
reset_selection = true;
- delete parent_node->Remove(child_removing);
+ parent_node->Remove(child_removing);
}
if (reset_selection) {
// selected_node_ is no longer valid (at the time we enter this function
@@ -667,9 +668,9 @@ void TreeView::LoadChildren(InternalNode* node) {
node->set_loaded_children(true);
for (int i = 0, child_count = model_->GetChildCount(node->model_node());
i < child_count; ++i) {
- InternalNode* child = new InternalNode;
- ConfigureInternalNode(model_->GetChild(node->model_node(), i), child);
- node->Add(child, node->child_count());
+ std::unique_ptr<InternalNode> child = base::MakeUnique<InternalNode>();
+ ConfigureInternalNode(model_->GetChild(node->model_node(), i), child.get());
+ node->Add(std::move(child), node->child_count());
}
}
« no previous file with comments | « ui/views/controls/tree/tree_view.h ('k') | ui/views/controls/tree/tree_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698