Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 UninstalledExtension(extension); | |
|
not at google - send to devlin
2014/05/23 20:24:05
given the only caller of UninstalledExtension is h
limasdf
2014/05/23 20:47:22
Done.
| |
| 198 } | |
| 199 | |
| 194 void ExtensionToolbarModel::Observe( | 200 void ExtensionToolbarModel::Observe( |
| 195 int type, | 201 int type, |
| 196 const content::NotificationSource& source, | 202 const content::NotificationSource& source, |
| 197 const content::NotificationDetails& details) { | 203 const content::NotificationDetails& details) { |
| 198 switch (type) { | 204 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 199 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 205 type); |
| 200 const Extension* extension = | 206 const Extension* extension = |
| 201 content::Details<const Extension>(details).ptr(); | 207 ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 202 UninstalledExtension(extension); | 208 *content::Details<const std::string>(details).ptr(), |
| 203 break; | 209 ExtensionRegistry::EVERYTHING); |
| 204 } | 210 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, |
| 205 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: { | 211 extension->id())) { |
| 206 const Extension* extension = | 212 AddExtension(extension); |
| 207 ExtensionRegistry::Get(profile_)->GetExtensionById( | 213 } else { |
| 208 *content::Details<const std::string>(details).ptr(), | 214 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 } | 215 } |
| 221 } | 216 } |
| 222 | 217 |
| 223 void ExtensionToolbarModel::OnReady() { | 218 void ExtensionToolbarModel::OnReady() { |
| 224 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 219 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 225 InitializeExtensionList(registry->enabled_extensions()); | 220 InitializeExtensionList(registry->enabled_extensions()); |
| 226 // Wait until the extension system is ready before observing any further | 221 // 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 | 222 // changes so that the toolbar buttons can be shown in their stable ordering |
| 228 // taken from prefs. | 223 // taken from prefs. |
| 229 extension_registry_observer_.Add(registry); | 224 extension_registry_observer_.Add(registry); |
| 230 registrar_.Add(this, | |
| 231 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | |
| 232 content::Source<Profile>(profile_)); | |
| 233 registrar_.Add( | 225 registrar_.Add( |
| 234 this, | 226 this, |
| 235 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 227 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
| 236 content::Source<ExtensionPrefs>(extension_prefs_)); | 228 content::Source<ExtensionPrefs>(extension_prefs_)); |
| 237 } | 229 } |
| 238 | 230 |
| 239 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( | 231 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( |
| 240 const Extension* extension) { | 232 const Extension* extension) { |
| 241 // See if we have last known good position for this extension. | 233 // See if we have last known good position for this extension. |
| 242 size_t new_index = 0; | 234 size_t new_index = 0; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 void ExtensionToolbarModel::StopHighlighting() { | 574 void ExtensionToolbarModel::StopHighlighting() { |
| 583 if (is_highlighting_) { | 575 if (is_highlighting_) { |
| 584 highlighted_items_.clear(); | 576 highlighted_items_.clear(); |
| 585 is_highlighting_ = false; | 577 is_highlighting_ = false; |
| 586 if (old_visible_icon_count_ != visible_icon_count_) { | 578 if (old_visible_icon_count_ != visible_icon_count_) { |
| 587 SetVisibleIconCount(old_visible_icon_count_); | 579 SetVisibleIconCount(old_visible_icon_count_); |
| 588 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 580 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
| 589 } | 581 } |
| 590 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 582 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
| 591 } | 583 } |
| 592 }; | 584 } |
| 593 | 585 |
| 594 } // namespace extensions | 586 } // namespace extensions |
| OLD | NEW |