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

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

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

Powered by Google App Engine
This is Rietveld 408576698