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

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

Issue 726813002: [Extensions Toolbar] Make the ExtensionToolbarModel icon count more stable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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.h
diff --git a/chrome/browser/extensions/extension_toolbar_model.h b/chrome/browser/extensions/extension_toolbar_model.h
index df3e69731a0cb99582907f82d20e3c6e1b80cacb..fe38a6ba3b3002d0ffe2653bb37ef44e10da54c8 100644
--- a/chrome/browser/extensions/extension_toolbar_model.h
+++ b/chrome/browser/extensions/extension_toolbar_model.h
@@ -43,6 +43,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
public:
// TODO(devlin): Rename these methods to be OnFoo.
// Signals that an |extension| has been added to the toolbar at |index|.
+ // This will *only* be called after the toolbar model has been initialized.
virtual void ToolbarExtensionAdded(const Extension* extension,
int index) = 0;
@@ -79,17 +80,17 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// with the new set (and just assume the new set is different).
virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0;
+ // Signals that the toolbar model has been initialized, so that if any
+ // observers were postponing animation during the initialization stage, they
+ // can catch up.
+ virtual void OnToolbarModelInitialized() = 0;
+
// Signals that the toolbar needs to be reordered for the given
// |web_contents|. This is caused by an overflowed action wanting to run,
// and needing to "pop itself out".
virtual void OnToolbarReorderNecessary(
content::WebContents* web_contents) = 0;
- // Signals that the toolbar model has been initialized, so that if any
- // observers were postponing animation during the initialization stage, they
- // can catch up.
- virtual void OnToolbarModelInitialized() = 0;
-
// Returns the browser associated with the Observer.
virtual Browser* GetBrowser() = 0;
@@ -113,8 +114,13 @@ class ExtensionToolbarModel : public content::NotificationObserver,
void SetVisibleIconCount(size_t count);
size_t visible_icon_count() const {
+ // We have guards around this because |visible_icon_count_| can be set by
+ // prefs/sync, and we want to ensure that the icon count returned is within
+ // bounds.
return visible_icon_count_ == -1 ?
- toolbar_items().size() : static_cast<size_t>(visible_icon_count_);
+ toolbar_items().size() :
+ std::min(static_cast<size_t>(visible_icon_count_),
+ toolbar_items().size());
}
bool all_icons_visible() const { return visible_icon_count_ == -1; }
@@ -202,7 +208,7 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// Updates |extension|'s browser action visibility pref if the browser action
// is in the overflow menu and should be considered hidden.
- void MaybeUpdateVisibilityPref(const Extension* extension, int index);
+ void MaybeUpdateVisibilityPref(const Extension* extension, size_t index);
// Calls MaybeUpdateVisibilityPref() for each extension in |toolbar_items|.
void MaybeUpdateVisibilityPrefs();
@@ -256,6 +262,8 @@ class ExtensionToolbarModel : public content::NotificationObserver,
// The number of icons visible (the rest should be hidden in the overflow
// chevron). A value of -1 indicates that all icons should be visible.
+ // Instead of using this variable directly, use visible_icon_count() if
+ // possible.
// TODO(devlin): Make a new variable to indicate that all icons should be
// visible, instead of overloading this one.
int visible_icon_count_;
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_toolbar_model.cc » ('j') | chrome/browser/ui/toolbar/toolbar_actions_bar.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698