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

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

Issue 731353002: [Extensions Toolbar] Notify observers of extensions re-added after a pref change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marijn's Created 6 years, 1 month 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
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 cc3f817e686d92bca05ed88a08d09dd4b0f3e363..7f4c931243d30ef665ce5ea208053e9782063a87 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -394,16 +394,6 @@ void ExtensionToolbarModel::RemoveExtension(const Extension* extension) {
UpdatePrefs();
}
-void ExtensionToolbarModel::ClearItems() {
- size_t items_count = toolbar_items_.size();
- for (size_t i = 0; i < items_count; ++i) {
- const Extension* extension = toolbar_items_.back().get();
- toolbar_items_.pop_back();
- FOR_EACH_OBSERVER(Observer, observers_, ToolbarExtensionRemoved(extension));
- }
- DCHECK(toolbar_items_.empty());
-}
-
// Combine the currently enabled extensions that have browser actions (which
// we get from the ExtensionRegistry) with the ordering we get from the
// pref service. For robustness we use a somewhat inefficient process:
@@ -575,11 +565,25 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() {
}
last_known_positions_.swap(pref_positions);
- ClearItems();
+ // 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_, ToolbarExtensionRemoved(extension.get()));
+ }
+ DCHECK(toolbar_items_.empty());
- // Re-populate.
+ // ...Add the new...
Populate(last_known_positions_);
+ // ...And notify.
+ for (size_t i = 0; i < toolbar_items().size(); ++i) {
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ ToolbarExtensionAdded(toolbar_items()[i].get(), i));
+ }
+
if (last_known_positions_.size() > pref_position_size) {
// Need to update pref because we have extra icons. But can't call
// UpdatePrefs() directly within observation closure.
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | chrome/browser/extensions/extension_toolbar_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698