Chromium Code Reviews| Index: components/undo/undo_manager.cc |
| diff --git a/components/undo/undo_manager.cc b/components/undo/undo_manager.cc |
| index 6829e5215908c3ef29f6ae35b40a4a1cce9aee55..47174504696153fd52288b213d9e736be97650ea 100644 |
| --- a/components/undo/undo_manager.cc |
| +++ b/components/undo/undo_manager.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/auto_reset.h" |
| #include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| #include "components/undo/undo_manager_observer.h" |
| #include "components/undo/undo_operation.h" |
| #include "grit/components_strings.h" |
| @@ -18,6 +19,14 @@ namespace { |
| // Maximum number of changes that can be undone. |
| const size_t kMaxUndoGroups = 100; |
| +std::vector<UndoOperation*> ConvertToRawPtrVector( |
| + const std::vector<std::unique_ptr<UndoOperation>>& args) { |
| + std::vector<UndoOperation*> args_rawptrs; |
| + for (auto i = args.begin(); i != args.end(); ++i) |
| + args_rawptrs.push_back(i->get()); |
| + return args_rawptrs; |
| +} |
| + |
| } // namespace |
| // UndoGroup ------------------------------------------------------------------ |
| @@ -35,14 +44,12 @@ void UndoGroup::AddOperation(std::unique_ptr<UndoOperation> operation) { |
| set_undo_label_id(operation->GetUndoLabelId()); |
| set_redo_label_id(operation->GetRedoLabelId()); |
| } |
| - operations_.push_back(operation.release()); |
| + operations_.push_back(std::move(operation)); |
| } |
| void UndoGroup::Undo() { |
| - for (ScopedVector<UndoOperation>::reverse_iterator ri = operations_.rbegin(); |
| - ri != operations_.rend(); ++ri) { |
| + for (auto ri = operations_.rbegin(); ri != operations_.rend(); ++ri) |
| (*ri)->Undo(); |
| - } |
| } |
| // UndoManager ---------------------------------------------------------------- |
| @@ -142,13 +149,13 @@ bool UndoManager::IsUndoTrakingSuspended() const { |
| std::vector<UndoOperation*> UndoManager::GetAllUndoOperations() const { |
|
sky
2017/01/23 16:22:16
This function is only used in tests. Please move t
ke.he
2017/01/24 09:01:13
Done.
ConvertToRawPtrVector() is moved into test f
|
| std::vector<UndoOperation*> result; |
| for (size_t i = 0; i < undo_actions_.size(); ++i) { |
| - const std::vector<UndoOperation*>& operations = |
| - undo_actions_[i]->undo_operations(); |
| + const std::vector<UndoOperation*> operations = |
| + ConvertToRawPtrVector(undo_actions_[i]->undo_operations()); |
| result.insert(result.end(), operations.begin(), operations.end()); |
| } |
| for (size_t i = 0; i < redo_actions_.size(); ++i) { |
| - const std::vector<UndoOperation*>& operations = |
| - redo_actions_[i]->undo_operations(); |
| + const std::vector<UndoOperation*> operations = |
| + ConvertToRawPtrVector(redo_actions_[i]->undo_operations()); |
| result.insert(result.end(), operations.begin(), operations.end()); |
| } |
| // Ensure that if an Undo is in progress the UndoOperations part of that |
| @@ -156,8 +163,8 @@ std::vector<UndoOperation*> UndoManager::GetAllUndoOperations() const { |
| // changes (such as renumbering) will be applied to any potentially |
| // unprocessed UndoOperations. |
| if (undo_in_progress_action_) { |
| - const std::vector<UndoOperation*>& operations = |
| - undo_in_progress_action_->undo_operations(); |
| + const std::vector<UndoOperation*> operations = |
| + ConvertToRawPtrVector(undo_in_progress_action_->undo_operations()); |
| result.insert(result.end(), operations.begin(), operations.end()); |
| } |
| @@ -180,8 +187,9 @@ void UndoManager::RemoveObserver(UndoManagerObserver* observer) { |
| observers_.RemoveObserver(observer); |
| } |
| -void UndoManager::Undo(bool* performing_indicator, |
| - ScopedVector<UndoGroup>* active_undo_group) { |
| +void UndoManager::Undo( |
| + bool* performing_indicator, |
| + std::vector<std::unique_ptr<UndoGroup>>* active_undo_group) { |
| // Check that action grouping has been correctly ended. |
| DCHECK(!group_actions_count_); |
| @@ -189,11 +197,11 @@ void UndoManager::Undo(bool* performing_indicator, |
| return; |
| base::AutoReset<bool> incoming_changes(performing_indicator, true); |
| - std::unique_ptr<UndoGroup> action(active_undo_group->back()); |
| + std::unique_ptr<UndoGroup> action = std::move(active_undo_group->back()); |
| base::AutoReset<UndoGroup*> action_context(&undo_in_progress_action_, |
| action.get()); |
| - active_undo_group->weak_erase( |
| - active_undo_group->begin() + active_undo_group->size() - 1); |
| + active_undo_group->erase(active_undo_group->begin() + |
| + active_undo_group->size() - 1); |
| StartGroupingActions(); |
| action->Undo(); |
| @@ -208,7 +216,7 @@ void UndoManager::NotifyOnUndoManagerStateChange() { |
| } |
| void UndoManager::AddUndoGroup(UndoGroup* new_undo_group) { |
| - GetActiveUndoGroup()->push_back(new_undo_group); |
| + GetActiveUndoGroup()->push_back(base::WrapUnique<UndoGroup>(new_undo_group)); |
| // User actions invalidate any available redo actions. |
| if (is_user_action()) |
| @@ -221,6 +229,6 @@ void UndoManager::AddUndoGroup(UndoGroup* new_undo_group) { |
| NotifyOnUndoManagerStateChange(); |
| } |
| -ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() { |
| +std::vector<std::unique_ptr<UndoGroup>>* UndoManager::GetActiveUndoGroup() { |
| return performing_undo_ ? &redo_actions_ : &undo_actions_; |
| } |