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

Unified Diff: ui/views/controls/menu/menu_controller.cc

Issue 2656823008: New MenuController Checks (Closed)
Patch Set: Todos to remove after bug Created 3 years, 11 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 | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_runner_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_controller.cc
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index aa002f26882d79ca43b067baf83c580db4b26f93..2accca917ad307be34bdb091ef31dc1aeef1fb59 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -433,6 +433,12 @@ MenuItemView* MenuController::Run(Widget* parent,
} else {
showing_ = true;
+ // TODO(jonross): remove after tracking down the cause of
+ // (crbug.com/683087).
+ // If we are not showing we should be shutting down, this could lead to
+ // incorrect delegate states.
+ CHECK(!running_);
+
if (owner_)
owner_->RemoveObserver(this);
owner_ = parent;
@@ -470,6 +476,10 @@ MenuItemView* MenuController::Run(Widget* parent,
if (ViewsDelegate::GetInstance())
ViewsDelegate::GetInstance()->AddRef();
+ // TODO(jonross): remove after tracking down the cause of (crbug.com/683087).
+ // About to either exit and run async, or nest message loop.
+ running_ = true;
+
if (async_run_)
return nullptr;
@@ -518,6 +528,11 @@ void MenuController::Cancel(ExitType type) {
SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT);
if (!blocking_run_) {
+ // TODO(jonross): remove after tracking down the cause of
+ // (crbug.com/683087).
+ bool nested = delegate_stack_.size() > 1;
+ CHECK(!nested);
+ base::WeakPtr<MenuController> this_ref = AsWeakPtr();
// If we didn't block the caller we need to notify the menu, which
// triggers deleting us.
DCHECK(selected);
@@ -525,6 +540,7 @@ void MenuController::Cancel(ExitType type) {
delegate_->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
selected->GetRootMenuItem(), accept_event_flags_);
// WARNING: the call to MenuClosed deletes us.
+ CHECK(!this_ref);
return;
}
@@ -544,6 +560,12 @@ void MenuController::Cancel(ExitType type) {
void MenuController::AddNestedDelegate(
internal::MenuControllerDelegate* delegate) {
+ // TODO(jonross): remove after tracking down the cause of (crbug.com/683087).
+ for (auto delegates : delegate_stack_) {
+ // Having the same delegate in the stack could cause deletion order issues.
+ CHECK_NE(delegates.first, delegate);
+ }
+
delegate_stack_.push_back(std::make_pair(delegate, async_run_));
delegate_ = delegate;
}
@@ -979,9 +1001,13 @@ int MenuController::OnPerformDrop(SubmenuView* source,
drop_target = drop_target->GetParentMenuItem();
if (!IsBlockingRun()) {
+ // TODO(jonross): remove after tracking down the cause of
+ // (crbug.com/683087).
+ base::WeakPtr<MenuController> this_ref = AsWeakPtr();
delegate_->OnMenuClosed(
internal::MenuControllerDelegate::DONT_NOTIFY_DELEGATE,
item->GetRootMenuItem(), accept_event_flags_);
+ CHECK(!this_ref);
}
// WARNING: the call to MenuClosed deletes us.
@@ -1380,6 +1406,7 @@ MenuController::MenuController(bool blocking,
internal::MenuControllerDelegate* delegate)
: blocking_run_(blocking),
showing_(false),
+ running_(false),
exit_type_(EXIT_NONE),
did_capture_(false),
result_(NULL),
@@ -2658,6 +2685,9 @@ MenuItemView* MenuController::ExitMenuRun() {
showing_ = false;
did_capture_ = false;
+ // TODO(jonross): remove after tracking down the cause of
+ // (crbug.com/683087).
+ running_ = false;
}
MenuItemView* result = result_;
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_runner_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698