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

Side by Side Diff: chrome/browser/undo/bookmark_undo_service.cc

Issue 242823002: Extract GetNodeByID() method from BookmarkModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/undo/bookmark_undo_service.h" 5 #include "chrome/browser/undo/bookmark_undo_service.h"
6 6
7 #include "chrome/browser/bookmarks/bookmark_model.h" 7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/bookmarks/bookmark_node_data.h" 9 #include "chrome/browser/bookmarks/bookmark_node_data.h"
10 #include "chrome/browser/bookmarks/bookmark_utils.h" 10 #include "chrome/browser/bookmarks/bookmark_utils.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 BookmarkAddOperation::BookmarkAddOperation(Profile* profile, 74 BookmarkAddOperation::BookmarkAddOperation(Profile* profile,
75 const BookmarkNode* parent, 75 const BookmarkNode* parent,
76 int index) 76 int index)
77 : BookmarkUndoOperation(profile), 77 : BookmarkUndoOperation(profile),
78 parent_id_(parent->id()), 78 parent_id_(parent->id()),
79 index_(index) { 79 index_(index) {
80 } 80 }
81 81
82 void BookmarkAddOperation::Undo() { 82 void BookmarkAddOperation::Undo() {
83 BookmarkModel* model = GetBookmarkModel(); 83 BookmarkModel* model = GetBookmarkModel();
84 const BookmarkNode* parent = model->GetNodeByID(parent_id_); 84 const BookmarkNode* parent = bookmark_utils::GetNodeByID(model, parent_id_);
85 DCHECK(parent); 85 DCHECK(parent);
86 86
87 model->Remove(parent, index_); 87 model->Remove(parent, index_);
88 } 88 }
89 89
90 int BookmarkAddOperation::GetUndoLabelId() const { 90 int BookmarkAddOperation::GetUndoLabelId() const {
91 return IDS_BOOKMARK_BAR_UNDO_ADD; 91 return IDS_BOOKMARK_BAR_UNDO_ADD;
92 } 92 }
93 93
94 int BookmarkAddOperation::GetRedoLabelId() const { 94 int BookmarkAddOperation::GetRedoLabelId() const {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 const BookmarkNode* node) 140 const BookmarkNode* node)
141 : BookmarkUndoOperation(profile), 141 : BookmarkUndoOperation(profile),
142 parent_id_(parent->id()), 142 parent_id_(parent->id()),
143 old_index_(old_index), 143 old_index_(old_index),
144 removed_node_(node) { 144 removed_node_(node) {
145 } 145 }
146 146
147 void BookmarkRemoveOperation::Undo() { 147 void BookmarkRemoveOperation::Undo() {
148 DCHECK(removed_node_.is_valid()); 148 DCHECK(removed_node_.is_valid());
149 BookmarkModel* model = GetBookmarkModel(); 149 BookmarkModel* model = GetBookmarkModel();
150 const BookmarkNode* parent = model->GetNodeByID(parent_id_); 150 const BookmarkNode* parent = bookmark_utils::GetNodeByID(model, parent_id_);
151 DCHECK(parent); 151 DCHECK(parent);
152 152
153 bookmark_utils::CloneBookmarkNode(model, removed_node_.elements, parent, 153 bookmark_utils::CloneBookmarkNode(model, removed_node_.elements, parent,
154 old_index_, false); 154 old_index_, false);
155 UpdateBookmarkIds(removed_node_.elements[0], parent, old_index_); 155 UpdateBookmarkIds(removed_node_.elements[0], parent, old_index_);
156 } 156 }
157 157
158 int BookmarkRemoveOperation::GetUndoLabelId() const { 158 int BookmarkRemoveOperation::GetUndoLabelId() const {
159 return IDS_BOOKMARK_BAR_UNDO_DELETE; 159 return IDS_BOOKMARK_BAR_UNDO_DELETE;
160 } 160 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 BookmarkEditOperation::BookmarkEditOperation(Profile* profile, 208 BookmarkEditOperation::BookmarkEditOperation(Profile* profile,
209 const BookmarkNode* node) 209 const BookmarkNode* node)
210 : BookmarkUndoOperation(profile), 210 : BookmarkUndoOperation(profile),
211 node_id_(node->id()), 211 node_id_(node->id()),
212 original_bookmark_(node) { 212 original_bookmark_(node) {
213 } 213 }
214 214
215 void BookmarkEditOperation::Undo() { 215 void BookmarkEditOperation::Undo() {
216 DCHECK(original_bookmark_.is_valid()); 216 DCHECK(original_bookmark_.is_valid());
217 BookmarkModel* model = GetBookmarkModel(); 217 BookmarkModel* model = GetBookmarkModel();
218 const BookmarkNode* node = model->GetNodeByID(node_id_); 218 const BookmarkNode* node = bookmark_utils::GetNodeByID(model, node_id_);
219 DCHECK(node); 219 DCHECK(node);
220 220
221 model->SetTitle(node, original_bookmark_.elements[0].title); 221 model->SetTitle(node, original_bookmark_.elements[0].title);
222 if (original_bookmark_.elements[0].is_url) 222 if (original_bookmark_.elements[0].is_url)
223 model->SetURL(node, original_bookmark_.elements[0].url); 223 model->SetURL(node, original_bookmark_.elements[0].url);
224 } 224 }
225 225
226 int BookmarkEditOperation::GetUndoLabelId() const { 226 int BookmarkEditOperation::GetUndoLabelId() const {
227 return IDS_BOOKMARK_BAR_UNDO_EDIT; 227 return IDS_BOOKMARK_BAR_UNDO_EDIT;
228 } 228 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 int new_index) 272 int new_index)
273 : BookmarkUndoOperation(profile), 273 : BookmarkUndoOperation(profile),
274 old_parent_id_(old_parent->id()), 274 old_parent_id_(old_parent->id()),
275 new_parent_id_(new_parent->id()), 275 new_parent_id_(new_parent->id()),
276 old_index_(old_index), 276 old_index_(old_index),
277 new_index_(new_index) { 277 new_index_(new_index) {
278 } 278 }
279 279
280 void BookmarkMoveOperation::Undo() { 280 void BookmarkMoveOperation::Undo() {
281 BookmarkModel* model = GetBookmarkModel(); 281 BookmarkModel* model = GetBookmarkModel();
282 const BookmarkNode* old_parent = model->GetNodeByID(old_parent_id_); 282 const BookmarkNode* old_parent =
283 const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id_); 283 bookmark_utils::GetNodeByID(model, old_parent_id_);
284 const BookmarkNode* new_parent =
285 bookmark_utils::GetNodeByID(model, new_parent_id_);
284 DCHECK(old_parent); 286 DCHECK(old_parent);
285 DCHECK(new_parent); 287 DCHECK(new_parent);
286 288
287 const BookmarkNode* node = new_parent->GetChild(new_index_); 289 const BookmarkNode* node = new_parent->GetChild(new_index_);
288 int destination_index = old_index_; 290 int destination_index = old_index_;
289 291
290 // If the bookmark was moved up within the same parent then the destination 292 // If the bookmark was moved up within the same parent then the destination
291 // index needs to be incremented since the old index did not account for the 293 // index needs to be incremented since the old index did not account for the
292 // moved bookmark. 294 // moved bookmark.
293 if (old_parent == new_parent && new_index_ < old_index_) 295 if (old_parent == new_parent && new_index_ < old_index_)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 ordered_bookmarks_.resize(parent->child_count()); 347 ordered_bookmarks_.resize(parent->child_count());
346 for (int i = 0; i < parent->child_count(); ++i) 348 for (int i = 0; i < parent->child_count(); ++i)
347 ordered_bookmarks_[i] = parent->GetChild(i)->id(); 349 ordered_bookmarks_[i] = parent->GetChild(i)->id();
348 } 350 }
349 351
350 BookmarkReorderOperation::~BookmarkReorderOperation() { 352 BookmarkReorderOperation::~BookmarkReorderOperation() {
351 } 353 }
352 354
353 void BookmarkReorderOperation::Undo() { 355 void BookmarkReorderOperation::Undo() {
354 BookmarkModel* model = GetBookmarkModel(); 356 BookmarkModel* model = GetBookmarkModel();
355 const BookmarkNode* parent = model->GetNodeByID(parent_id_); 357 const BookmarkNode* parent = bookmark_utils::GetNodeByID(model, parent_id_);
356 DCHECK(parent); 358 DCHECK(parent);
357 359
358 std::vector<const BookmarkNode*> ordered_nodes; 360 std::vector<const BookmarkNode*> ordered_nodes;
359 for (size_t i = 0; i < ordered_bookmarks_.size(); ++i) 361 for (size_t i = 0; i < ordered_bookmarks_.size(); ++i) {
360 ordered_nodes.push_back(model->GetNodeByID(ordered_bookmarks_[i])); 362 ordered_nodes.push_back(
363 bookmark_utils::GetNodeByID(model, ordered_bookmarks_[i]));
364 }
361 365
362 model->ReorderChildren(parent, ordered_nodes); 366 model->ReorderChildren(parent, ordered_nodes);
363 } 367 }
364 368
365 int BookmarkReorderOperation::GetUndoLabelId() const { 369 int BookmarkReorderOperation::GetUndoLabelId() const {
366 return IDS_BOOKMARK_BAR_UNDO_REORDER; 370 return IDS_BOOKMARK_BAR_UNDO_REORDER;
367 } 371 }
368 372
369 int BookmarkReorderOperation::GetRedoLabelId() const { 373 int BookmarkReorderOperation::GetRedoLabelId() const {
370 return IDS_BOOKMARK_BAR_REDO_REORDER; 374 return IDS_BOOKMARK_BAR_REDO_REORDER;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 472
469 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { 473 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) {
470 std::vector<UndoOperation*> all_operations = 474 std::vector<UndoOperation*> all_operations =
471 undo_manager()->GetAllUndoOperations(); 475 undo_manager()->GetAllUndoOperations();
472 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); 476 for (std::vector<UndoOperation*>::iterator it = all_operations.begin();
473 it != all_operations.end(); ++it) { 477 it != all_operations.end(); ++it) {
474 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, 478 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id,
475 new_id); 479 new_id);
476 } 480 }
477 } 481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698