Commit 000d99b6 authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

cros: Fix hanging ShelfButton when showing two menus

This fix does not fix the root cause, but it will prevent the bug from
reproing on M-71.

Root cause fix can be tracked in the same bug.

Bug: 881886
Change-Id: I83882f9d0a5725aad660ea8a6926dd3b689ad306
Reviewed-on: https://chromium-review.googlesource.com/c/1321729Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606080}
parent 2c3b223b
......@@ -446,6 +446,7 @@ void AppListItemView::OnContextMenuModelReceived(
const gfx::Point& point,
ui::MenuSourceType source_type,
std::vector<ash::mojom::MenuItemPtr> menu) {
waiting_for_context_menu_options_ = false;
if (menu.empty() || (context_menu_ && context_menu_->IsShowingMenu()))
return;
......@@ -490,6 +491,13 @@ void AppListItemView::OnContextMenuModelReceived(
void AppListItemView::ShowContextMenuForView(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// Prevent multiple requests for context menus before the current request
// completes. If a second request is sent before the first one can respond,
// the Chrome side delegate will become unresponsive
// (https://crbug.com/881886).
if (waiting_for_context_menu_options_)
return;
waiting_for_context_menu_options_ = true;
delegate_->GetContextMenuModel(
item_weak_->id(),
base::BindOnce(&AppListItemView::OnContextMenuModelReceived,
......
......@@ -224,6 +224,10 @@ class APP_LIST_EXPORT AppListItemView
const bool is_folder_;
const bool is_in_folder_;
// Whether context menu options have been requested. Prevents multiple
// requests.
bool waiting_for_context_menu_options_ = false;
AppListItem* item_weak_; // Owned by AppListModel. Can be NULL.
AppListViewDelegate* delegate_; // Unowned.
......
......@@ -2051,6 +2051,12 @@ void ShelfView::AfterGetContextMenuItems(
void ShelfView::ShowContextMenuForView(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// Prevent multiple requests for context menus before the current request
// completes. If a second request is sent before the first one can respond,
// the Chrome side ShelfItemDelegate will become unresponsive
// (https://crbug.com/881886).
if (waiting_for_context_menu_options_)
return;
last_pressed_index_ = -1;
const ShelfItem* item = ShelfItemForView(source);
const int64_t display_id = GetDisplayIdForView(this);
......@@ -2063,6 +2069,7 @@ void ShelfView::ShowContextMenuForView(views::View* source,
return;
}
waiting_for_context_menu_options_ = true;
// Get any custom entries; show the context menu in AfterGetContextMenuItems.
model_->GetShelfItemDelegate(item->id)->GetContextMenuItems(
display_id, base::Bind(&ShelfView::AfterGetContextMenuItems,
......@@ -2076,6 +2083,7 @@ void ShelfView::ShowMenu(std::unique_ptr<ui::SimpleMenuModel> menu_model,
bool context_menu,
ui::MenuSourceType source_type) {
DCHECK(!IsShowingMenu());
waiting_for_context_menu_options_ = false;
if (menu_model->GetItemCount() == 0)
return;
menu_owner_ = source;
......
......@@ -534,6 +534,10 @@ class ASH_EXPORT ShelfView : public views::View,
// True when an item being inserted or removed in the model cancels a drag.
bool cancelling_drag_model_changed_ = false;
// Whether context menu options have been requested. Prevents multiple
// requests.
bool waiting_for_context_menu_options_ = false;
// The timestamp of the event which closed the last menu - or 0.
base::TimeTicks closing_event_time_;
......
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