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..1aaf8e9024bca914b7a35f07c43ba62e3c0b3f73 100644 |
--- a/chrome/browser/extensions/extension_toolbar_model.cc |
+++ b/chrome/browser/extensions/extension_toolbar_model.cc |
@@ -328,6 +328,13 @@ 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(new_last_known_index, |
+ static_cast<int>(last_known_positions_.size())); |
Marijn Kruisselbrink
2015/02/20 18:26:41
I personally prefer std::min<int>(a, b) over std::
Devlin
2015/02/20 21:50:00
Done.
|
last_known_positions_.insert( |
last_known_positions_.begin() + new_last_known_index, extension->id()); |
UpdatePrefs(); |
@@ -423,19 +430,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 +457,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 |
+ // of ids at the end. |
Marijn Kruisselbrink
2015/02/20 18:26:41
"and add it to the of ids at the end"?
I think yo
Devlin
2015/02/20 21:50:00
Done.
|
unsorted.push_back(extension); |
+ positions->push_back(extension->id()); |
+ } |
} |
// Merge the lists. |
@@ -590,7 +601,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) { |