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

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

Issue 256783003: Small refactoring extension_toolbar_model.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ExtensionService* extension_service =
188 extensions::ExtensionSystem::Get(profile_)->extension_service(); 188 ExtensionSystem::Get(profile_)->extension_service();
189 if (!extension_service || !extension_service->is_ready()) 189 DCHECK(extension_service);
190 if (!extension_service->is_ready())
190 return; 191 return;
191 192
192 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { 193 switch (type) {
193 InitializeExtensionList(extension_service); 194 case chrome::NOTIFICATION_EXTENSIONS_READY:
194 return; 195 InitializeExtensionList(extension_service);
195 } 196 break;
196 197 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
197 const Extension* extension = NULL; 198 const Extension* extension =
198 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { 199 content::Details<const Extension>(details).ptr();
199 extension = content::Details<extensions::UnloadedExtensionInfo>( 200 // We don't want to add the same extension twice. It may have already been
200 details)->extension; 201 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
201 } else if (type == 202 // hides the browser action and then disables and enables the extension.
202 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { 203 for (size_t i = 0; i < toolbar_items_.size(); i++) {
203 extension = extension_service->GetExtensionById( 204 if (toolbar_items_[i].get() == extension)
204 *content::Details<const std::string>(details).ptr(), true); 205 return; // Already exists.
205 } else { 206 }
206 extension = content::Details<const Extension>(details).ptr(); 207 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
207 } 208 extension->id())) {
208 if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { 209 AddExtension(extension);
209 // We don't want to add the same extension twice. It may have already been 210 }
210 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user 211 break;
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 } 212 }
216 if (ExtensionActionAPI::GetBrowserActionVisibility( 213 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
217 extension_prefs_, extension->id())) { 214 const Extension* extension =
218 AddExtension(extension); 215 content::Details<extensions::UnloadedExtensionInfo>(details)
216 ->extension;
217 RemoveExtension(extension);
218 break;
219 } 219 }
220 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { 220 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
221 RemoveExtension(extension); 221 const Extension* extension =
222 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) { 222 content::Details<const Extension>(details).ptr();
223 UninstalledExtension(extension); 223 UninstalledExtension(extension);
224 } else if (type == 224 break;
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);
231 } 225 }
232 } else { 226 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: {
233 NOTREACHED() << "Received unexpected notification"; 227 const Extension* extension = extension_service->GetExtensionById(
228 *content::Details<const std::string>(details).ptr(), true);
229 if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
230 extension->id())) {
231 AddExtension(extension);
232 } else {
233 RemoveExtension(extension);
234 }
235 break;
236 }
237 default:
238 NOTREACHED() << "Received unexpected notification";
234 } 239 }
235 } 240 }
236 241
237 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( 242 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood(
238 const Extension* extension) { 243 const Extension* extension) {
239 // See if we have last known good position for this extension. 244 // See if we have last known good position for this extension.
240 size_t new_index = 0; 245 size_t new_index = 0;
241 // Loop through the ID list of known positions, to count the number of visible 246 // Loop through the ID list of known positions, to count the number of visible
242 // browser action icons preceding |extension|. 247 // browser action icons preceding |extension|.
243 for (ExtensionIdList::const_iterator iter_id = last_known_positions_.begin(); 248 for (ExtensionIdList::const_iterator iter_id = last_known_positions_.begin();
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 is_highlighting_ = false; 590 is_highlighting_ = false;
586 if (old_visible_icon_count_ != visible_icon_count_) { 591 if (old_visible_icon_count_ != visible_icon_count_) {
587 SetVisibleIconCount(old_visible_icon_count_); 592 SetVisibleIconCount(old_visible_icon_count_);
588 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); 593 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged());
589 } 594 }
590 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); 595 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false));
591 } 596 }
592 }; 597 };
593 598
594 } // namespace extensions 599 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698