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

Side by Side Diff: components/undo/undo_manager.cc

Issue 1917673002: Convert //components/[u-z]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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
« no previous file with comments | « components/undo/undo_manager.h ('k') | components/undo/undo_manager_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/undo/undo_manager.h" 5 #include "components/undo/undo_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 12 matching lines...) Expand all
23 // UndoGroup ------------------------------------------------------------------ 23 // UndoGroup ------------------------------------------------------------------
24 24
25 UndoGroup::UndoGroup() 25 UndoGroup::UndoGroup()
26 : undo_label_id_(IDS_BOOKMARK_BAR_UNDO), 26 : undo_label_id_(IDS_BOOKMARK_BAR_UNDO),
27 redo_label_id_(IDS_BOOKMARK_BAR_REDO) { 27 redo_label_id_(IDS_BOOKMARK_BAR_REDO) {
28 } 28 }
29 29
30 UndoGroup::~UndoGroup() { 30 UndoGroup::~UndoGroup() {
31 } 31 }
32 32
33 void UndoGroup::AddOperation(scoped_ptr<UndoOperation> operation) { 33 void UndoGroup::AddOperation(std::unique_ptr<UndoOperation> operation) {
34 if (operations_.empty()) { 34 if (operations_.empty()) {
35 set_undo_label_id(operation->GetUndoLabelId()); 35 set_undo_label_id(operation->GetUndoLabelId());
36 set_redo_label_id(operation->GetRedoLabelId()); 36 set_redo_label_id(operation->GetRedoLabelId());
37 } 37 }
38 operations_.push_back(operation.release()); 38 operations_.push_back(operation.release());
39 } 39 }
40 40
41 void UndoGroup::Undo() { 41 void UndoGroup::Undo() {
42 for (ScopedVector<UndoOperation>::reverse_iterator ri = operations_.rbegin(); 42 for (ScopedVector<UndoOperation>::reverse_iterator ri = operations_.rbegin();
43 ri != operations_.rend(); ++ri) { 43 ri != operations_.rend(); ++ri) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 undo_actions_.empty() ? IDS_BOOKMARK_BAR_UNDO 75 undo_actions_.empty() ? IDS_BOOKMARK_BAR_UNDO
76 : undo_actions_.back()->get_undo_label_id()); 76 : undo_actions_.back()->get_undo_label_id());
77 } 77 }
78 78
79 base::string16 UndoManager::GetRedoLabel() const { 79 base::string16 UndoManager::GetRedoLabel() const {
80 return l10n_util::GetStringUTF16( 80 return l10n_util::GetStringUTF16(
81 redo_actions_.empty() ? IDS_BOOKMARK_BAR_REDO 81 redo_actions_.empty() ? IDS_BOOKMARK_BAR_REDO
82 : redo_actions_.back()->get_redo_label_id()); 82 : redo_actions_.back()->get_redo_label_id());
83 } 83 }
84 84
85 void UndoManager::AddUndoOperation(scoped_ptr<UndoOperation> operation) { 85 void UndoManager::AddUndoOperation(std::unique_ptr<UndoOperation> operation) {
86 if (IsUndoTrakingSuspended()) { 86 if (IsUndoTrakingSuspended()) {
87 RemoveAllOperations(); 87 RemoveAllOperations();
88 operation.reset(); 88 operation.reset();
89 return; 89 return;
90 } 90 }
91 91
92 if (group_actions_count_) { 92 if (group_actions_count_) {
93 pending_grouped_action_->AddOperation(std::move(operation)); 93 pending_grouped_action_->AddOperation(std::move(operation));
94 } else { 94 } else {
95 UndoGroup* new_action = new UndoGroup(); 95 UndoGroup* new_action = new UndoGroup();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 void UndoManager::Undo(bool* performing_indicator, 183 void UndoManager::Undo(bool* performing_indicator,
184 ScopedVector<UndoGroup>* active_undo_group) { 184 ScopedVector<UndoGroup>* active_undo_group) {
185 // Check that action grouping has been correctly ended. 185 // Check that action grouping has been correctly ended.
186 DCHECK(!group_actions_count_); 186 DCHECK(!group_actions_count_);
187 187
188 if (active_undo_group->empty()) 188 if (active_undo_group->empty())
189 return; 189 return;
190 190
191 base::AutoReset<bool> incoming_changes(performing_indicator, true); 191 base::AutoReset<bool> incoming_changes(performing_indicator, true);
192 scoped_ptr<UndoGroup> action(active_undo_group->back()); 192 std::unique_ptr<UndoGroup> action(active_undo_group->back());
193 base::AutoReset<UndoGroup*> action_context(&undo_in_progress_action_, 193 base::AutoReset<UndoGroup*> action_context(&undo_in_progress_action_,
194 action.get()); 194 action.get());
195 active_undo_group->weak_erase( 195 active_undo_group->weak_erase(
196 active_undo_group->begin() + active_undo_group->size() - 1); 196 active_undo_group->begin() + active_undo_group->size() - 1);
197 197
198 StartGroupingActions(); 198 StartGroupingActions();
199 action->Undo(); 199 action->Undo();
200 EndGroupingActions(); 200 EndGroupingActions();
201 201
202 NotifyOnUndoManagerStateChange(); 202 NotifyOnUndoManagerStateChange();
(...skipping 14 matching lines...) Expand all
217 // Limit the number of undo levels so the undo stack does not grow unbounded. 217 // Limit the number of undo levels so the undo stack does not grow unbounded.
218 if (GetActiveUndoGroup()->size() > kMaxUndoGroups) 218 if (GetActiveUndoGroup()->size() > kMaxUndoGroups)
219 GetActiveUndoGroup()->erase(GetActiveUndoGroup()->begin()); 219 GetActiveUndoGroup()->erase(GetActiveUndoGroup()->begin());
220 220
221 NotifyOnUndoManagerStateChange(); 221 NotifyOnUndoManagerStateChange();
222 } 222 }
223 223
224 ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() { 224 ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() {
225 return performing_undo_ ? &redo_actions_ : &undo_actions_; 225 return performing_undo_ ? &redo_actions_ : &undo_actions_;
226 } 226 }
OLDNEW
« no previous file with comments | « components/undo/undo_manager.h ('k') | components/undo/undo_manager_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698