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

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

Issue 941373002: [Extensions] Fix extension toolbar crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marijn's Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_toolbar_model.cc
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index aae8a148842fe95e4e95583ed48d853f6bf62b1f..21451194f6f7fe83c88cd2b38252fca953928e0d 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -328,6 +328,12 @@ void ExtensionToolbarModel::AddExtension(const Extension* extension) {
last_known_positions_.end(),
toolbar_items_[new_index - 1]->id()) -
last_known_positions_.begin() + 1;
+ // In theory, the extension before this one should always
+ // be in last known positions, but if something funny happened with prefs,
+ // make sure we handle it.
+ // TODO(devlin): Track down these cases so we can CHECK this.
+ new_last_known_index =
+ std::min<int>(new_last_known_index, last_known_positions_.size());
last_known_positions_.insert(
last_known_positions_.begin() + new_last_known_index, extension->id());
UpdatePrefs();
@@ -423,19 +429,19 @@ void ExtensionToolbarModel::InitializeExtensionList() {
if (profile_->IsOffTheRecord())
IncognitoPopulate();
else
- Populate(last_known_positions_);
+ Populate(&last_known_positions_);
extensions_initialized_ = true;
MaybeUpdateVisibilityPrefs();
FOR_EACH_OBSERVER(Observer, observers_, OnToolbarModelInitialized());
}
-void ExtensionToolbarModel::Populate(const ExtensionIdList& positions) {
+void ExtensionToolbarModel::Populate(ExtensionIdList* positions) {
DCHECK(!profile_->IsOffTheRecord());
const ExtensionSet& extensions =
ExtensionRegistry::Get(profile_)->enabled_extensions();
// Items that have explicit positions.
- ExtensionList sorted(positions.size(), NULL);
+ ExtensionList sorted(positions->size(), NULL);
// The items that don't have explicit positions.
ExtensionList unsorted;
@@ -450,11 +456,15 @@ void ExtensionToolbarModel::Populate(const ExtensionIdList& positions) {
}
ExtensionIdList::const_iterator pos =
- std::find(positions.begin(), positions.end(), extension->id());
- if (pos != positions.end())
- sorted[pos - positions.begin()] = extension;
- else
+ std::find(positions->begin(), positions->end(), extension->id());
+ if (pos != positions->end()) {
+ sorted[pos - positions->begin()] = extension;
+ } else {
+ // Unknown extension - push it to the back of unsorted, and add it to the
+ // list of ids at the end.
unsorted.push_back(extension);
+ positions->push_back(extension->id());
+ }
}
// Merge the lists.
@@ -590,7 +600,7 @@ void ExtensionToolbarModel::OnExtensionToolbarPrefChange() {
DCHECK(toolbar_items_.empty());
// ...Add the new...
- Populate(last_known_positions_);
+ Populate(&last_known_positions_);
// ...And notify.
for (size_t i = 0; i < toolbar_items().size(); ++i) {
« no previous file with comments | « chrome/browser/extensions/extension_toolbar_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698