| 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_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" |
| 11 #include "chrome/browser/undo/undo_operation.h" | 11 #include "chrome/browser/undo/undo_operation.h" |
| 12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 13 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
| 14 #include "components/bookmarks/browser/bookmark_node_data.h" | 14 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 15 #include "components/bookmarks/browser/bookmark_utils.h" | 15 #include "components/bookmarks/browser/bookmark_utils.h" |
| 16 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 16 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
| 17 | 17 |
| 18 using bookmarks::BookmarkNodeData; | 18 using bookmarks::BookmarkNodeData; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // BookmarkUndoOperation ------------------------------------------------------ | 22 // BookmarkUndoOperation ------------------------------------------------------ |
| 23 | 23 |
| 24 // Base class for all bookmark related UndoOperations that facilitates access to | 24 // Base class for all bookmark related UndoOperations that facilitates access to |
| 25 // the BookmarkUndoService. | 25 // the BookmarkUndoService. |
| 26 class BookmarkUndoOperation : public UndoOperation, | 26 class BookmarkUndoOperation : public UndoOperation, |
| 27 public BookmarkRenumberObserver { | 27 public BookmarkRenumberObserver { |
| 28 public: | 28 public: |
| 29 explicit BookmarkUndoOperation(Profile* profile); | 29 explicit BookmarkUndoOperation(Profile* profile); |
| 30 virtual ~BookmarkUndoOperation() {} | 30 ~BookmarkUndoOperation() override {} |
| 31 | 31 |
| 32 BookmarkModel* GetBookmarkModel() const; | 32 BookmarkModel* GetBookmarkModel() const; |
| 33 BookmarkRenumberObserver* GetUndoRenumberObserver() const; | 33 BookmarkRenumberObserver* GetUndoRenumberObserver() const; |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 Profile* profile_; | 36 Profile* profile_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 BookmarkUndoOperation::BookmarkUndoOperation(Profile* profile) | 39 BookmarkUndoOperation::BookmarkUndoOperation(Profile* profile) |
| 40 : profile_(profile) { | 40 : profile_(profile) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 BookmarkModel* BookmarkUndoOperation::GetBookmarkModel() const { | 43 BookmarkModel* BookmarkUndoOperation::GetBookmarkModel() const { |
| 44 return BookmarkModelFactory::GetForProfile(profile_); | 44 return BookmarkModelFactory::GetForProfile(profile_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 BookmarkRenumberObserver* BookmarkUndoOperation::GetUndoRenumberObserver() | 47 BookmarkRenumberObserver* BookmarkUndoOperation::GetUndoRenumberObserver() |
| 48 const { | 48 const { |
| 49 return BookmarkUndoServiceFactory::GetForProfile(profile_); | 49 return BookmarkUndoServiceFactory::GetForProfile(profile_); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // BookmarkAddOperation ------------------------------------------------------- | 52 // BookmarkAddOperation ------------------------------------------------------- |
| 53 | 53 |
| 54 // Handles the undo of the insertion of a bookmark or folder. | 54 // Handles the undo of the insertion of a bookmark or folder. |
| 55 class BookmarkAddOperation : public BookmarkUndoOperation { | 55 class BookmarkAddOperation : public BookmarkUndoOperation { |
| 56 public: | 56 public: |
| 57 BookmarkAddOperation(Profile* profile, const BookmarkNode* parent, int index); | 57 BookmarkAddOperation(Profile* profile, const BookmarkNode* parent, int index); |
| 58 virtual ~BookmarkAddOperation() {} | 58 ~BookmarkAddOperation() override {} |
| 59 | 59 |
| 60 // UndoOperation: | 60 // UndoOperation: |
| 61 virtual void Undo() override; | 61 void Undo() override; |
| 62 virtual int GetUndoLabelId() const override; | 62 int GetUndoLabelId() const override; |
| 63 virtual int GetRedoLabelId() const override; | 63 int GetRedoLabelId() const override; |
| 64 | 64 |
| 65 // BookmarkRenumberObserver: | 65 // BookmarkRenumberObserver: |
| 66 virtual void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; | 66 void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 int64 parent_id_; | 69 int64 parent_id_; |
| 70 const int index_; | 70 const int index_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(BookmarkAddOperation); | 72 DISALLOW_COPY_AND_ASSIGN(BookmarkAddOperation); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 BookmarkAddOperation::BookmarkAddOperation(Profile* profile, | 75 BookmarkAddOperation::BookmarkAddOperation(Profile* profile, |
| 76 const BookmarkNode* parent, | 76 const BookmarkNode* parent, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 107 // Handles the undo of the deletion of a bookmark node. For a bookmark folder, | 107 // Handles the undo of the deletion of a bookmark node. For a bookmark folder, |
| 108 // the information for all descendant bookmark nodes is maintained. | 108 // the information for all descendant bookmark nodes is maintained. |
| 109 // | 109 // |
| 110 // The BookmarkModel allows only single bookmark node to be removed. | 110 // The BookmarkModel allows only single bookmark node to be removed. |
| 111 class BookmarkRemoveOperation : public BookmarkUndoOperation { | 111 class BookmarkRemoveOperation : public BookmarkUndoOperation { |
| 112 public: | 112 public: |
| 113 BookmarkRemoveOperation(Profile* profile, | 113 BookmarkRemoveOperation(Profile* profile, |
| 114 const BookmarkNode* parent, | 114 const BookmarkNode* parent, |
| 115 int old_index, | 115 int old_index, |
| 116 const BookmarkNode* node); | 116 const BookmarkNode* node); |
| 117 virtual ~BookmarkRemoveOperation() {} | 117 ~BookmarkRemoveOperation() override {} |
| 118 | 118 |
| 119 // UndoOperation: | 119 // UndoOperation: |
| 120 virtual void Undo() override; | 120 void Undo() override; |
| 121 virtual int GetUndoLabelId() const override; | 121 int GetUndoLabelId() const override; |
| 122 virtual int GetRedoLabelId() const override; | 122 int GetRedoLabelId() const override; |
| 123 | 123 |
| 124 // BookmarkRenumberObserver: | 124 // BookmarkRenumberObserver: |
| 125 virtual void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; | 125 void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 void UpdateBookmarkIds(const BookmarkNodeData::Element& element, | 128 void UpdateBookmarkIds(const BookmarkNodeData::Element& element, |
| 129 const BookmarkNode* parent, | 129 const BookmarkNode* parent, |
| 130 int index_added_at) const; | 130 int index_added_at) const; |
| 131 | 131 |
| 132 int64 parent_id_; | 132 int64 parent_id_; |
| 133 const int old_index_; | 133 const int old_index_; |
| 134 BookmarkNodeData removed_node_; | 134 BookmarkNodeData removed_node_; |
| 135 | 135 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 parent_id_ = new_id; | 184 parent_id_ = new_id; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // BookmarkEditOperation ------------------------------------------------------ | 187 // BookmarkEditOperation ------------------------------------------------------ |
| 188 | 188 |
| 189 // Handles the undo of the modification of a bookmark node. | 189 // Handles the undo of the modification of a bookmark node. |
| 190 class BookmarkEditOperation : public BookmarkUndoOperation { | 190 class BookmarkEditOperation : public BookmarkUndoOperation { |
| 191 public: | 191 public: |
| 192 BookmarkEditOperation(Profile* profile, | 192 BookmarkEditOperation(Profile* profile, |
| 193 const BookmarkNode* node); | 193 const BookmarkNode* node); |
| 194 virtual ~BookmarkEditOperation() {} | 194 ~BookmarkEditOperation() override {} |
| 195 | 195 |
| 196 // UndoOperation: | 196 // UndoOperation: |
| 197 virtual void Undo() override; | 197 void Undo() override; |
| 198 virtual int GetUndoLabelId() const override; | 198 int GetUndoLabelId() const override; |
| 199 virtual int GetRedoLabelId() const override; | 199 int GetRedoLabelId() const override; |
| 200 | 200 |
| 201 // BookmarkRenumberObserver: | 201 // BookmarkRenumberObserver: |
| 202 virtual void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; | 202 void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; |
| 203 | 203 |
| 204 private: | 204 private: |
| 205 int64 node_id_; | 205 int64 node_id_; |
| 206 BookmarkNodeData original_bookmark_; | 206 BookmarkNodeData original_bookmark_; |
| 207 | 207 |
| 208 DISALLOW_COPY_AND_ASSIGN(BookmarkEditOperation); | 208 DISALLOW_COPY_AND_ASSIGN(BookmarkEditOperation); |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 BookmarkEditOperation::BookmarkEditOperation(Profile* profile, | 211 BookmarkEditOperation::BookmarkEditOperation(Profile* profile, |
| 212 const BookmarkNode* node) | 212 const BookmarkNode* node) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 242 // BookmarkMoveOperation ------------------------------------------------------ | 242 // BookmarkMoveOperation ------------------------------------------------------ |
| 243 | 243 |
| 244 // Handles the undo of a bookmark being moved to a new location. | 244 // Handles the undo of a bookmark being moved to a new location. |
| 245 class BookmarkMoveOperation : public BookmarkUndoOperation { | 245 class BookmarkMoveOperation : public BookmarkUndoOperation { |
| 246 public: | 246 public: |
| 247 BookmarkMoveOperation(Profile* profile, | 247 BookmarkMoveOperation(Profile* profile, |
| 248 const BookmarkNode* old_parent, | 248 const BookmarkNode* old_parent, |
| 249 int old_index, | 249 int old_index, |
| 250 const BookmarkNode* new_parent, | 250 const BookmarkNode* new_parent, |
| 251 int new_index); | 251 int new_index); |
| 252 virtual ~BookmarkMoveOperation() {} | 252 ~BookmarkMoveOperation() override {} |
| 253 virtual int GetUndoLabelId() const override; | 253 int GetUndoLabelId() const override; |
| 254 virtual int GetRedoLabelId() const override; | 254 int GetRedoLabelId() const override; |
| 255 | 255 |
| 256 // UndoOperation: | 256 // UndoOperation: |
| 257 virtual void Undo() override; | 257 void Undo() override; |
| 258 | 258 |
| 259 // BookmarkRenumberObserver: | 259 // BookmarkRenumberObserver: |
| 260 virtual void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; | 260 void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; |
| 261 | 261 |
| 262 private: | 262 private: |
| 263 int64 old_parent_id_; | 263 int64 old_parent_id_; |
| 264 int64 new_parent_id_; | 264 int64 new_parent_id_; |
| 265 int old_index_; | 265 int old_index_; |
| 266 int new_index_; | 266 int new_index_; |
| 267 | 267 |
| 268 DISALLOW_COPY_AND_ASSIGN(BookmarkMoveOperation); | 268 DISALLOW_COPY_AND_ASSIGN(BookmarkMoveOperation); |
| 269 }; | 269 }; |
| 270 | 270 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // BookmarkReorderOperation --------------------------------------------------- | 319 // BookmarkReorderOperation --------------------------------------------------- |
| 320 | 320 |
| 321 // Handle the undo of reordering of bookmarks that can happen as a result of | 321 // Handle the undo of reordering of bookmarks that can happen as a result of |
| 322 // sorting a bookmark folder by name or the undo of that operation. The change | 322 // sorting a bookmark folder by name or the undo of that operation. The change |
| 323 // of order is not recursive so only the order of the immediate children of the | 323 // of order is not recursive so only the order of the immediate children of the |
| 324 // folder need to be restored. | 324 // folder need to be restored. |
| 325 class BookmarkReorderOperation : public BookmarkUndoOperation { | 325 class BookmarkReorderOperation : public BookmarkUndoOperation { |
| 326 public: | 326 public: |
| 327 BookmarkReorderOperation(Profile* profile, | 327 BookmarkReorderOperation(Profile* profile, |
| 328 const BookmarkNode* parent); | 328 const BookmarkNode* parent); |
| 329 virtual ~BookmarkReorderOperation(); | 329 ~BookmarkReorderOperation() override; |
| 330 | 330 |
| 331 // UndoOperation: | 331 // UndoOperation: |
| 332 virtual void Undo() override; | 332 void Undo() override; |
| 333 virtual int GetUndoLabelId() const override; | 333 int GetUndoLabelId() const override; |
| 334 virtual int GetRedoLabelId() const override; | 334 int GetRedoLabelId() const override; |
| 335 | 335 |
| 336 // BookmarkRenumberObserver: | 336 // BookmarkRenumberObserver: |
| 337 virtual void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; | 337 void OnBookmarkRenumbered(int64 old_id, int64 new_id) override; |
| 338 | 338 |
| 339 private: | 339 private: |
| 340 int64 parent_id_; | 340 int64 parent_id_; |
| 341 std::vector<int64> ordered_bookmarks_; | 341 std::vector<int64> ordered_bookmarks_; |
| 342 | 342 |
| 343 DISALLOW_COPY_AND_ASSIGN(BookmarkReorderOperation); | 343 DISALLOW_COPY_AND_ASSIGN(BookmarkReorderOperation); |
| 344 }; | 344 }; |
| 345 | 345 |
| 346 BookmarkReorderOperation::BookmarkReorderOperation(Profile* profile, | 346 BookmarkReorderOperation::BookmarkReorderOperation(Profile* profile, |
| 347 const BookmarkNode* parent) | 347 const BookmarkNode* parent) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { | 477 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { |
| 478 std::vector<UndoOperation*> all_operations = | 478 std::vector<UndoOperation*> all_operations = |
| 479 undo_manager()->GetAllUndoOperations(); | 479 undo_manager()->GetAllUndoOperations(); |
| 480 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); | 480 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); |
| 481 it != all_operations.end(); ++it) { | 481 it != all_operations.end(); ++it) { |
| 482 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, | 482 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, |
| 483 new_id); | 483 new_id); |
| 484 } | 484 } |
| 485 } | 485 } |
| OLD | NEW |