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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 if (!is_highlighting_) { | 177 if (!is_highlighting_) { |
| 178 prefs_->SetInteger(extensions::pref_names::kToolbarSize, | 178 prefs_->SetInteger(extensions::pref_names::kToolbarSize, |
| 179 visible_icon_count_); | 179 visible_icon_count_); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 void ExtensionToolbarModel::Observe( | 183 void ExtensionToolbarModel::Observe( |
| 184 int type, | 184 int type, |
| 185 const content::NotificationSource& source, | 185 const content::NotificationSource& source, |
| 186 const content::NotificationDetails& details) { | 186 const content::NotificationDetails& details) { |
| 187 ExtensionService* extension_service = | 187 switch (type) { |
| 188 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 188 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
| 189 if (!extension_service || !extension_service->is_ready()) | 189 ExtensionService* extension_service = |
|
not at google - send to devlin
2014/04/25 16:53:34
it looks like this whole function early-exits if t
not at google - send to devlin
2014/04/25 16:54:34
another option: just pull the ES back to the start
limasdf
2014/04/25 17:42:54
I chose second method to keep exisitng code as muc
| |
| 190 return; | 190 ExtensionSystem::Get(profile_)->extension_service(); |
| 191 | 191 if (extension_service && extension_service->is_ready()) |
| 192 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { | 192 InitializeExtensionList(extension_service); |
| 193 InitializeExtensionList(extension_service); | 193 break; |
| 194 return; | |
| 195 } | |
| 196 | |
| 197 const Extension* extension = NULL; | |
| 198 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | |
| 199 extension = content::Details<extensions::UnloadedExtensionInfo>( | |
| 200 details)->extension; | |
| 201 } else if (type == | |
| 202 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { | |
| 203 extension = extension_service->GetExtensionById( | |
| 204 *content::Details<const std::string>(details).ptr(), true); | |
| 205 } else { | |
| 206 extension = content::Details<const Extension>(details).ptr(); | |
| 207 } | |
| 208 if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { | |
| 209 // We don't want to add the same extension twice. It may have already been | |
| 210 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | |
| 211 // hides the browser action and then disables and enables the extension. | |
| 212 for (size_t i = 0; i < toolbar_items_.size(); i++) { | |
| 213 if (toolbar_items_[i].get() == extension) | |
| 214 return; // Already exists. | |
| 215 } | 194 } |
| 216 if (ExtensionActionAPI::GetBrowserActionVisibility( | 195 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
| 217 extension_prefs_, extension->id())) { | 196 const Extension* extension = |
| 218 AddExtension(extension); | 197 content::Details<const Extension>(details).ptr(); |
| 198 // We don't want to add the same extension twice. It may have already been | |
| 199 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | |
| 200 // hides the browser action and then disables and enables the extension. | |
| 201 for (size_t i = 0; i < toolbar_items_.size(); i++) { | |
| 202 if (toolbar_items_[i].get() == extension) | |
| 203 return; // Already exists. | |
| 204 } | |
| 205 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, | |
| 206 extension->id())) { | |
| 207 AddExtension(extension); | |
| 208 } | |
| 209 break; | |
| 219 } | 210 } |
| 220 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | 211 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
| 221 RemoveExtension(extension); | 212 const Extension* extension = |
| 222 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) { | 213 content::Details<extensions::UnloadedExtensionInfo>(details) |
| 223 UninstalledExtension(extension); | 214 ->extension; |
| 224 } else if (type == | |
| 225 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { | |
| 226 if (ExtensionActionAPI::GetBrowserActionVisibility( | |
| 227 extension_prefs_, extension->id())) { | |
| 228 AddExtension(extension); | |
| 229 } else { | |
| 230 RemoveExtension(extension); | 215 RemoveExtension(extension); |
| 216 break; | |
| 231 } | 217 } |
| 232 } else { | 218 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 233 NOTREACHED() << "Received unexpected notification"; | 219 const Extension* extension = |
| 220 content::Details<const Extension>(details).ptr(); | |
| 221 UninstalledExtension(extension); | |
| 222 break; | |
| 223 } | |
| 224 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: { | |
| 225 ExtensionService* extension_service = | |
| 226 ExtensionSystem::Get(profile_)->extension_service(); | |
| 227 if (extension_service && extension_service->is_ready()) { | |
| 228 const Extension* extension = extension_service->GetExtensionById( | |
| 229 *content::Details<const std::string>(details).ptr(), true); | |
| 230 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_, | |
| 231 extension->id())) { | |
| 232 AddExtension(extension); | |
| 233 } else { | |
| 234 RemoveExtension(extension); | |
| 235 } | |
| 236 } | |
| 237 break; | |
| 238 } | |
| 239 default: | |
| 240 NOTREACHED() << "Received unexpected notification"; | |
| 234 } | 241 } |
| 235 } | 242 } |
| 236 | 243 |
| 237 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( | 244 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( |
| 238 const Extension* extension) { | 245 const Extension* extension) { |
| 239 // See if we have last known good position for this extension. | 246 // See if we have last known good position for this extension. |
| 240 size_t new_index = 0; | 247 size_t new_index = 0; |
| 241 // Loop through the ID list of known positions, to count the number of visible | 248 // Loop through the ID list of known positions, to count the number of visible |
| 242 // browser action icons preceding |extension|. | 249 // browser action icons preceding |extension|. |
| 243 for (ExtensionIdList::const_iterator iter_id = last_known_positions_.begin(); | 250 for (ExtensionIdList::const_iterator iter_id = last_known_positions_.begin(); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 is_highlighting_ = false; | 592 is_highlighting_ = false; |
| 586 if (old_visible_icon_count_ != visible_icon_count_) { | 593 if (old_visible_icon_count_ != visible_icon_count_) { |
| 587 SetVisibleIconCount(old_visible_icon_count_); | 594 SetVisibleIconCount(old_visible_icon_count_); |
| 588 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 595 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
| 589 } | 596 } |
| 590 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 597 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
| 591 } | 598 } |
| 592 }; | 599 }; |
| 593 | 600 |
| 594 } // namespace extensions | 601 } // namespace extensions |
| OLD | NEW |