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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 289073008: Add TriggerOnUninstalled to ExtensionRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comment Created 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_toolbar_model.h" 5 #include "chrome/browser/extensions/extension_toolbar_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_base.h" 10 #include "base/metrics/histogram_base.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 184 }
185 } 185 }
186 186
187 void ExtensionToolbarModel::OnExtensionUnloaded( 187 void ExtensionToolbarModel::OnExtensionUnloaded(
188 content::BrowserContext* browser_context, 188 content::BrowserContext* browser_context,
189 const Extension* extension, 189 const Extension* extension,
190 UnloadedExtensionInfo::Reason reason) { 190 UnloadedExtensionInfo::Reason reason) {
191 RemoveExtension(extension); 191 RemoveExtension(extension);
192 } 192 }
193 193
194 void ExtensionToolbarModel::OnExtensionUninstalled(
195 content::BrowserContext* browser_context,
196 const Extension* extension) {
197 // Remove the extension id from the ordered list, if it exists (the extension
198 // might not be represented in the list because it might not have an icon).
199 ExtensionIdList::iterator pos =
200 std::find(last_known_positions_.begin(),
201 last_known_positions_.end(), extension->id());
202
203 if (pos != last_known_positions_.end()) {
204 last_known_positions_.erase(pos);
205 UpdatePrefs();
206 }
207 }
208
194 void ExtensionToolbarModel::Observe( 209 void ExtensionToolbarModel::Observe(
195 int type, 210 int type,
196 const content::NotificationSource& source, 211 const content::NotificationSource& source,
197 const content::NotificationDetails& details) { 212 const content::NotificationDetails& details) {
198 switch (type) { 213 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
199 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { 214 type);
200 const Extension* extension = 215 const Extension* extension =
201 content::Details<const Extension>(details).ptr(); 216 ExtensionRegistry::Get(profile_)->GetExtensionById(
202 UninstalledExtension(extension); 217 *content::Details<const std::string>(details).ptr(),
203 break; 218 ExtensionRegistry::EVERYTHING);
204 } 219 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
205 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: { 220 extension->id())) {
206 const Extension* extension = 221 AddExtension(extension);
207 ExtensionRegistry::Get(profile_)->GetExtensionById( 222 } else {
208 *content::Details<const std::string>(details).ptr(), 223 RemoveExtension(extension);
209 ExtensionRegistry::EVERYTHING);
210 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
211 extension->id())) {
212 AddExtension(extension);
213 } else {
214 RemoveExtension(extension);
215 }
216 break;
217 }
218 default:
219 NOTREACHED() << "Received unexpected notification";
220 } 224 }
221 } 225 }
222 226
223 void ExtensionToolbarModel::OnReady() { 227 void ExtensionToolbarModel::OnReady() {
224 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 228 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
225 InitializeExtensionList(registry->enabled_extensions()); 229 InitializeExtensionList(registry->enabled_extensions());
226 // Wait until the extension system is ready before observing any further 230 // Wait until the extension system is ready before observing any further
227 // changes so that the toolbar buttons can be shown in their stable ordering 231 // changes so that the toolbar buttons can be shown in their stable ordering
228 // taken from prefs. 232 // taken from prefs.
229 extension_registry_observer_.Add(registry); 233 extension_registry_observer_.Add(registry);
230 registrar_.Add(this,
231 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
232 content::Source<Profile>(profile_));
233 registrar_.Add( 234 registrar_.Add(
234 this, 235 this,
235 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 236 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
236 content::Source<ExtensionPrefs>(extension_prefs_)); 237 content::Source<ExtensionPrefs>(extension_prefs_));
237 } 238 }
238 239
239 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( 240 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood(
240 const Extension* extension) { 241 const Extension* extension) {
241 // See if we have last known good position for this extension. 242 // See if we have last known good position for this extension.
242 size_t new_index = 0; 243 size_t new_index = 0;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (highlighted_items_.empty()) 319 if (highlighted_items_.empty())
319 StopHighlighting(); 320 StopHighlighting();
320 } 321 }
321 } else { 322 } else {
322 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionRemoved(extension)); 323 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionRemoved(extension));
323 } 324 }
324 325
325 UpdatePrefs(); 326 UpdatePrefs();
326 } 327 }
327 328
328 void ExtensionToolbarModel::UninstalledExtension(const Extension* extension) {
329 // Remove the extension id from the ordered list, if it exists (the extension
330 // might not be represented in the list because it might not have an icon).
331 ExtensionIdList::iterator pos =
332 std::find(last_known_positions_.begin(),
333 last_known_positions_.end(), extension->id());
334
335 if (pos != last_known_positions_.end()) {
336 last_known_positions_.erase(pos);
337 UpdatePrefs();
338 }
339 }
340
341 // Combine the currently enabled extensions that have browser actions (which 329 // Combine the currently enabled extensions that have browser actions (which
342 // we get from the ExtensionRegistry) with the ordering we get from the 330 // we get from the ExtensionRegistry) with the ordering we get from the
343 // pref service. For robustness we use a somewhat inefficient process: 331 // pref service. For robustness we use a somewhat inefficient process:
344 // 1. Create a vector of extensions sorted by their pref values. This vector may 332 // 1. Create a vector of extensions sorted by their pref values. This vector may
345 // have holes. 333 // have holes.
346 // 2. Create a vector of extensions that did not have a pref value. 334 // 2. Create a vector of extensions that did not have a pref value.
347 // 3. Remove holes from the sorted vector and append the unsorted vector. 335 // 3. Remove holes from the sorted vector and append the unsorted vector.
348 void ExtensionToolbarModel::InitializeExtensionList( 336 void ExtensionToolbarModel::InitializeExtensionList(
349 const ExtensionSet& extensions) { 337 const ExtensionSet& extensions) {
350 last_known_positions_ = extension_prefs_->GetToolbarOrder(); 338 last_known_positions_ = extension_prefs_->GetToolbarOrder();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 void ExtensionToolbarModel::StopHighlighting() { 570 void ExtensionToolbarModel::StopHighlighting() {
583 if (is_highlighting_) { 571 if (is_highlighting_) {
584 highlighted_items_.clear(); 572 highlighted_items_.clear();
585 is_highlighting_ = false; 573 is_highlighting_ = false;
586 if (old_visible_icon_count_ != visible_icon_count_) { 574 if (old_visible_icon_count_ != visible_icon_count_) {
587 SetVisibleIconCount(old_visible_icon_count_); 575 SetVisibleIconCount(old_visible_icon_count_);
588 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); 576 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged());
589 } 577 }
590 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); 578 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false));
591 } 579 }
592 }; 580 }
593 581
594 } // namespace extensions 582 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | extensions/browser/extension_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698