Commit 564ecc17 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

Fix potential edge case crashes in ExtensionToolbarModel

Fix two potential crashes in ExtensionToolbarModel.

Review URL: https://codereview.chromium.org/684373004

Cr-Commit-Position: refs/heads/master@{#302461}
parent 258af794
...@@ -211,6 +211,12 @@ void ExtensionToolbarModel::Observe( ...@@ -211,6 +211,12 @@ void ExtensionToolbarModel::Observe(
extension_prefs_, extension->id()); extension_prefs_, extension->id());
// Hiding works differently with the new and old toolbars. // Hiding works differently with the new and old toolbars.
if (include_all_extensions_) { if (include_all_extensions_) {
// It's possible that we haven't added this extension yet, if its
// visibility was adjusted in the course of its initialization.
if (std::find(toolbar_items_.begin(), toolbar_items_.end(), extension) ==
toolbar_items_.end())
return;
int new_size = 0; int new_size = 0;
int new_index = 0; int new_index = 0;
if (visible) { if (visible) {
...@@ -355,6 +361,10 @@ void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { ...@@ -355,6 +361,10 @@ void ExtensionToolbarModel::RemoveExtension(const Extension* extension) {
if (pos == toolbar_items_.end()) if (pos == toolbar_items_.end())
return; return;
// If our visible count is set to the current size, we need to decrement it.
if (visible_icon_count_ == static_cast<int>(toolbar_items_.size()))
SetVisibleIconCount(toolbar_items_.size() - 1);
toolbar_items_.erase(pos); toolbar_items_.erase(pos);
// If we're in highlight mode, we also have to remove the extension from // If we're in highlight mode, we also have to remove the extension from
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment