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

Unified Diff: chrome/browser/ui/views/bookmarks/bookmark_editor_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
Index: chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
index 5f0baf99e4a046fb09096733a23dc71a2d252dc0..ae570bb2f2e2d2281843c7cb3df626fd2ac57c79 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
@@ -414,8 +415,7 @@ void BookmarkEditorView::Reset() {
// tree_view will try to invoke something on the model we just deleted.
tree_view_->SetModel(NULL);
- EditorNode* root_node = CreateRootNode();
- tree_model_.reset(new EditorTreeModel(root_node));
+ tree_model_.reset(new EditorTreeModel(CreateRootNode()));
tree_view_->SetModel(tree_model_.get());
tree_view_->SetController(this);
@@ -458,11 +458,11 @@ void BookmarkEditorView::NewFolder() {
BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewFolder(
EditorNode* parent) {
- EditorNode* new_node = new EditorNode(
- l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME), 0);
- // |new_node| is now owned by |parent|.
- tree_model_->Add(parent, new_node, parent->child_count());
- return new_node;
+ return tree_model_->Add(
+ parent,
+ base::MakeUnique<EditorNode>(
+ l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME), 0),
+ parent->child_count());
}
void BookmarkEditorView::ExpandAndSelect() {
@@ -488,10 +488,12 @@ void BookmarkEditorView::ExpandAndSelect() {
tree_view_->SetSelectedNode(b_node);
}
-BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() {
- EditorNode* root_node = new EditorNode(base::string16(), 0);
+std::unique_ptr<BookmarkEditorView::EditorNode>
+BookmarkEditorView::CreateRootNode() {
+ std::unique_ptr<EditorNode> root_node =
+ base::MakeUnique<EditorNode>(base::string16(), 0);
const BookmarkNode* bb_root_node = bb_model_->root_node();
- CreateNodes(bb_root_node, root_node);
+ CreateNodes(bb_root_node, root_node.get());
DCHECK(root_node->child_count() >= 2 && root_node->child_count() <= 4);
DCHECK_EQ(BookmarkNode::BOOKMARK_BAR, bb_root_node->GetChild(0)->type());
DCHECK_EQ(BookmarkNode::OTHER_NODE, bb_root_node->GetChild(1)->type());
@@ -506,9 +508,10 @@ void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node,
const BookmarkNode* child_bb_node = bb_node->GetChild(i);
if (child_bb_node->IsVisible() && child_bb_node->is_folder() &&
bb_model_->client()->CanBeEditedByUser(child_bb_node)) {
- EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(),
- child_bb_node->id());
- b_node->Add(new_b_node, b_node->child_count());
+ EditorNode* new_b_node =
+ b_node->Add(base::MakeUnique<EditorNode>(child_bb_node->GetTitle(),
+ child_bb_node->id()),
+ b_node->child_count());
CreateNodes(child_bb_node, new_b_node);
}
}
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_editor_view.h ('k') | components/bookmarks/browser/bookmark_codec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698