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

Unified Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 1007083003: [Extensions Toolbar] Make pref update non-destructive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_toolbar_model.cc
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index ac84f365434e411852ea1e4b891ffce48e15ecbb..a0ee22a3d98f8f8ab7fa865954f192a5e0a09a23 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -617,22 +617,23 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() {
}
last_known_positions_.swap(pref_positions);
- // Clear out the old...
- while (!toolbar_items_.empty()) {
- scoped_refptr<const Extension> extension = toolbar_items_.back();
- toolbar_items_.pop_back();
- FOR_EACH_OBSERVER(Observer, observers_,
- OnToolbarExtensionRemoved(extension.get()));
- }
- DCHECK(toolbar_items_.empty());
-
- // ...Add the new...
- Populate(&last_known_positions_);
-
- // ...And notify.
- for (size_t i = 0; i < toolbar_items().size(); ++i) {
- FOR_EACH_OBSERVER(Observer, observers_,
- OnToolbarExtensionAdded(toolbar_items()[i].get(), i));
+ int desired_index = 0;
+ // Loop over the updated list of last known positions, moving any extensions
+ // that are in the wrong place.
+ for (const std::string& id : last_known_positions_) {
+ int current_index = GetIndexForId(id);
+ if (current_index == -1)
+ continue;
+ if (current_index != desired_index) {
+ scoped_refptr<const Extension> extension = toolbar_items_[current_index];
+ toolbar_items_.erase(toolbar_items_.begin() + current_index);
+ toolbar_items_.insert(toolbar_items_.begin() + desired_index, extension);
+ // Notify the observers to keep them up-to-date.
+ FOR_EACH_OBSERVER(
+ Observer, observers_,
+ OnToolbarExtensionMoved(extension.get(), desired_index));
+ }
+ ++desired_index;
}
if (last_known_positions_.size() > pref_position_size) {
« no previous file with comments | « no previous file | chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698