Commit 317db31b authored by jamescook's avatar jamescook Committed by Commit bot

Ash: Fix browser icon menu model lifetime

The menu model needs to be cleaned up if the menu is suppressed for being
too short.

BUG=406609
TEST=manual, see bug

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

Cr-Commit-Position: refs/heads/master@{#291600}
parent a4da60be
......@@ -1715,14 +1715,15 @@ bool ShelfView::ShowListMenuForView(const ShelfItem& item,
const ui::Event& event) {
ShelfItemDelegate* item_delegate =
item_manager_->GetShelfItemDelegate(item.id);
list_menu_model_.reset(item_delegate->CreateApplicationMenu(event.flags()));
scoped_ptr<ui::MenuModel> list_menu_model(
item_delegate->CreateApplicationMenu(event.flags()));
// Make sure we have a menu and it has at least two items in addition to the
// application title and the 3 spacing separators.
if (!list_menu_model_.get() || list_menu_model_->GetItemCount() <= 5)
if (!list_menu_model.get() || list_menu_model->GetItemCount() <= 5)
return false;
ShowMenu(list_menu_model_.get(),
ShowMenu(list_menu_model.get(),
source,
gfx::Point(),
false,
......
......@@ -369,8 +369,6 @@ class ASH_EXPORT ShelfView : public views::View,
scoped_ptr<views::FocusSearch> focus_search_;
scoped_ptr<ui::MenuModel> list_menu_model_;
scoped_ptr<ui::MenuModel> context_menu_model_;
scoped_ptr<views::MenuRunner> launcher_menu_runner_;
......
......@@ -20,10 +20,13 @@ ChromeLauncherAppMenuItemBrowser::ChromeLauncherAppMenuItemBrowser(
bool has_leading_separator)
: ChromeLauncherAppMenuItem(title, icon, has_leading_separator),
browser_(browser) {
DCHECK(browser);
registrar_.Add(this,
chrome::NOTIFICATION_BROWSER_CLOSING,
content::Source<Browser>(browser));
}
ChromeLauncherAppMenuItemBrowser::~ChromeLauncherAppMenuItemBrowser() {
}
bool ChromeLauncherAppMenuItemBrowser::IsActive() const {
return browser_ == chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
......
......@@ -22,6 +22,8 @@ class ChromeLauncherAppMenuItemBrowser : public content::NotificationObserver,
const gfx::Image* icon,
Browser* browser,
bool has_leading_separator);
virtual ~ChromeLauncherAppMenuItemBrowser();
virtual bool IsActive() const OVERRIDE;
virtual bool IsEnabled() const OVERRIDE;
virtual void Execute(int event_flags) OVERRIDE;
......
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