| OLD | NEW |
| 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" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/undo/bookmark_renumber_observer.h" | 12 #include "chrome/browser/undo/bookmark_renumber_observer.h" |
| 13 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 13 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 14 #include "chrome/browser/undo/bookmark_undo_utils.h" | |
| 15 #include "chrome/browser/undo/undo_operation.h" | 14 #include "chrome/browser/undo/undo_operation.h" |
| 16 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 // BookmarkUndoOperation ------------------------------------------------------ | 20 // BookmarkUndoOperation ------------------------------------------------------ |
| 22 | 21 |
| 23 // Base class for all bookmark related UndoOperations that facilitates access to | 22 // Base class for all bookmark related UndoOperations that facilitates access to |
| 24 // the BookmarkUndoService. | 23 // the BookmarkUndoService. |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 383 |
| 385 // BookmarkUndoService -------------------------------------------------------- | 384 // BookmarkUndoService -------------------------------------------------------- |
| 386 | 385 |
| 387 BookmarkUndoService::BookmarkUndoService(Profile* profile) : profile_(profile) { | 386 BookmarkUndoService::BookmarkUndoService(Profile* profile) : profile_(profile) { |
| 388 } | 387 } |
| 389 | 388 |
| 390 BookmarkUndoService::~BookmarkUndoService() { | 389 BookmarkUndoService::~BookmarkUndoService() { |
| 391 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this); | 390 BookmarkModelFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 392 } | 391 } |
| 393 | 392 |
| 394 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { | |
| 395 std::vector<UndoOperation*> all_operations = | |
| 396 undo_manager()->GetAllUndoOperations(); | |
| 397 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); | |
| 398 it != all_operations.end(); ++it) { | |
| 399 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, | |
| 400 new_id); | |
| 401 } | |
| 402 } | |
| 403 | |
| 404 void BookmarkUndoService::BookmarkModelLoaded(BookmarkModel* model, | 393 void BookmarkUndoService::BookmarkModelLoaded(BookmarkModel* model, |
| 405 bool ids_reassigned) { | 394 bool ids_reassigned) { |
| 406 undo_manager_.RemoveAllOperations(); | 395 undo_manager_.RemoveAllOperations(); |
| 407 } | 396 } |
| 408 | 397 |
| 409 void BookmarkUndoService::BookmarkModelBeingDeleted(BookmarkModel* model) { | 398 void BookmarkUndoService::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 410 undo_manager_.RemoveAllOperations(); | 399 undo_manager_.RemoveAllOperations(); |
| 411 } | 400 } |
| 412 | 401 |
| 413 void BookmarkUndoService::BookmarkNodeMoved(BookmarkModel* model, | 402 void BookmarkUndoService::BookmarkNodeMoved(BookmarkModel* model, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 437 int old_index, | 426 int old_index, |
| 438 const BookmarkNode* node) { | 427 const BookmarkNode* node) { |
| 439 scoped_ptr<UndoOperation> op(new BookmarkRemoveOperation(profile_, | 428 scoped_ptr<UndoOperation> op(new BookmarkRemoveOperation(profile_, |
| 440 parent, | 429 parent, |
| 441 old_index, | 430 old_index, |
| 442 node)); | 431 node)); |
| 443 undo_manager()->AddUndoOperation(op.Pass()); | 432 undo_manager()->AddUndoOperation(op.Pass()); |
| 444 } | 433 } |
| 445 | 434 |
| 446 void BookmarkUndoService::OnWillRemoveAllBookmarks(BookmarkModel* model) { | 435 void BookmarkUndoService::OnWillRemoveAllBookmarks(BookmarkModel* model) { |
| 447 ScopedGroupBookmarkActions merge_removes(profile_); | 436 bookmark_utils::ScopedGroupBookmarkActions merge_removes(profile_); |
| 448 for (int i = 0; i < model->root_node()->child_count(); ++i) { | 437 for (int i = 0; i < model->root_node()->child_count(); ++i) { |
| 449 const BookmarkNode* permanent_node = model->root_node()->GetChild(i); | 438 const BookmarkNode* permanent_node = model->root_node()->GetChild(i); |
| 450 for (int j = permanent_node->child_count() - 1; j >= 0; --j) { | 439 for (int j = permanent_node->child_count() - 1; j >= 0; --j) { |
| 451 scoped_ptr<UndoOperation> op(new BookmarkRemoveOperation(profile_, | 440 scoped_ptr<UndoOperation> op(new BookmarkRemoveOperation(profile_, |
| 452 permanent_node, j, permanent_node->GetChild(j))); | 441 permanent_node, j, permanent_node->GetChild(j))); |
| 453 undo_manager()->AddUndoOperation(op.Pass()); | 442 undo_manager()->AddUndoOperation(op.Pass()); |
| 454 } | 443 } |
| 455 } | 444 } |
| 456 } | 445 } |
| 457 | 446 |
| 458 void BookmarkUndoService::OnWillChangeBookmarkNode(BookmarkModel* model, | 447 void BookmarkUndoService::OnWillChangeBookmarkNode(BookmarkModel* model, |
| 459 const BookmarkNode* node) { | 448 const BookmarkNode* node) { |
| 460 scoped_ptr<UndoOperation> op(new BookmarkEditOperation(profile_, node)); | 449 scoped_ptr<UndoOperation> op(new BookmarkEditOperation(profile_, node)); |
| 461 undo_manager()->AddUndoOperation(op.Pass()); | 450 undo_manager()->AddUndoOperation(op.Pass()); |
| 462 } | 451 } |
| 463 | 452 |
| 464 void BookmarkUndoService::OnWillReorderBookmarkNode(BookmarkModel* model, | 453 void BookmarkUndoService::OnWillReorderBookmarkNode(BookmarkModel* model, |
| 465 const BookmarkNode* node) { | 454 const BookmarkNode* node) { |
| 466 scoped_ptr<UndoOperation> op(new BookmarkReorderOperation(profile_, node)); | 455 scoped_ptr<UndoOperation> op(new BookmarkReorderOperation(profile_, node)); |
| 467 undo_manager()->AddUndoOperation(op.Pass()); | 456 undo_manager()->AddUndoOperation(op.Pass()); |
| 468 } | 457 } |
| 458 |
| 459 void BookmarkUndoService::GroupedBookmarkChangesBeginning( |
| 460 BookmarkModel* model) { |
| 461 undo_manager()->StartGroupingActions(); |
| 462 } |
| 463 |
| 464 void BookmarkUndoService::GroupedBookmarkChangesEnded(BookmarkModel* model) { |
| 465 undo_manager()->EndGroupingActions(); |
| 466 } |
| 467 |
| 468 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { |
| 469 std::vector<UndoOperation*> all_operations = |
| 470 undo_manager()->GetAllUndoOperations(); |
| 471 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); |
| 472 it != all_operations.end(); ++it) { |
| 473 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, |
| 474 new_id); |
| 475 } |
| 476 } |
| 477 |
| OLD | NEW |