0

Remove remaining uses of ScopedNestableTaskAllower.

ScopedNestableTaskAllower allows application tasks in native loops and
RunLoops that run within its scope. It is deprecated.

  If the intent is to allow application tasks in a native loop, it
  should be replaced with ScopedAllowApplicationTasksInNativeNestedLoop.

  If the intent is to allow application tasks in a RunLoop, the RunLoop
  should be constructed with Type::kNestableTasksAllowed.

  If no loop (native or RunLoop) runs within the scope of the
  ScopedNestableTaskAllower, it should just be removed.

We manually inspected the code to determine the appropriate replacement
for each remaining use.

Bug: 781352
Change-Id: I007bd0a0f9d6aa938f879f48864a9400808d486b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4035451
Reviewed-by: Gabriel Charette <gab@chromium.org>
Owners-Override: Gabriel Charette <gab@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1075631}
This commit is contained in:
Francois Doray
2022-11-24 21:09:18 +00:00
committed by Chromium LUCI CQ
parent b41a926368
commit a06ee176c7
18 changed files with 24 additions and 29 deletions

@ -473,7 +473,7 @@ void TestGLibLoopInternal(EventInjector* injector, OnceClosure done) {
// Run a nested, straight GLib message loop.
{
CurrentThread::ScopedNestableTaskAllower allow_nestable_tasks;
CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
runner->RunGLib();
}
@ -505,7 +505,7 @@ void TestGtkLoopInternal(EventInjector* injector, OnceClosure done) {
// Run a nested, straight Gtk message loop.
{
CurrentThread::ScopedNestableTaskAllower allow_nestable_tasks;
CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
runner->RunLoop();
}

@ -37,7 +37,7 @@ namespace {
// This function posts |task| and runs the given |mode|.
void RunTaskInMode(CFRunLoopMode mode, OnceClosure task) {
// Since this task is "ours" rather than a system task, allow nesting.
CurrentThread::ScopedNestableTaskAllower allow;
CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
CancelableOnceClosure cancelable(std::move(task));
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, cancelable.callback());
while (CFRunLoopRunInMode(mode, 0, true) == kCFRunLoopRunHandledSource)
@ -132,7 +132,7 @@ TEST(MessagePumpMacTest, QuitWithModalWindow) {
RunLoop run_loop;
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindLambdaForTesting([&] {
CurrentThread::ScopedNestableTaskAllower allow;
CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
ScopedPumpMessagesInPrivateModes pump_private;
[NSApp runModalForWindow:window];
}));

@ -56,9 +56,10 @@ class BASE_EXPORT MessagePumpWin : public MessagePump {
// Message queue. i.e. when:
// a. The pump is about to wakeup from idle.
// b. The pump is about to enter a nested native loop and a
// ScopedNestableTaskAllower was instantiated to allow application
// tasks to execute in that nested loop (ScopedNestableTaskAllower
// invokes ScheduleWork()).
// ScopedAllowApplicationTasksInNativeNestedLoop was instantiated to
// allow application tasks to execute in that nested loop
// (ScopedAllowApplicationTasksInNativeNestedLoop invokes
// ScheduleWork()).
// c. While in a native (nested) loop : HandleWorkMessage() =>
// ProcessPumpReplacementMessage() invokes ScheduleWork() before
// processing a native message to guarantee this pump will get another
@ -66,7 +67,7 @@ class BASE_EXPORT MessagePumpWin : public MessagePump {
// nested loop. This is different from (b.) because we're not yet
// processing an application task at the current run level and
// therefore are expected to keep pumping application tasks without
// necessitating a ScopedNestableTaskAllower.
// necessitating a ScopedAllowApplicationTasksInNativeNestedLoop.
//
// * MessagePumpforIO: there's a dummy IO completion item with |this| as an
// lpCompletionKey in the queue which is about to wakeup

@ -54,7 +54,7 @@ FirstRunShowBridge::FirstRunShowBridge(FirstRunDialogController* controller)
void FirstRunShowBridge::ShowDialog(base::OnceClosure quit_closure) {
// Proceeding past the modal dialog requires user interaction. Allow nested
// tasks to run so that signal handlers operate correctly.
base::CurrentThread::ScopedNestableTaskAllower allow_nested;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
[controller_ show];
std::move(quit_closure).Run();
}

@ -237,7 +237,7 @@ void RenderViewContextMenuMacCocoa::Show() {
{
// Make sure events can be pumped while the menu is up.
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
// Ensure the UI can update while the menu is fading out.
base::ScopedPumpMessagesInPrivateModes pump_private;

@ -309,7 +309,7 @@ void DoDragImpl(std::unique_ptr<ui::OSExchangeData> drag_data,
gfx::Point point,
int operation) {
// Allow nested run loop so we get DnD events as we drag this around.
base::CurrentThread::ScopedNestableTaskAllower nestable_task_allower;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
views::Widget* widget = views::Widget::GetWidgetForNativeView(native_view);
if (widget) {

@ -233,7 +233,7 @@ void EnterpriseStartupDialogView::RemoveWidgetObserver(
void EnterpriseStartupDialogView::StartModalDialog() {
#if BUILDFLAG(IS_MAC)
base::CurrentThread::ScopedNestableTaskAllower allow_nested;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
StartModal(GetWidget()->GetNativeWindow());
#endif
}

@ -393,7 +393,7 @@ void RenderViewContextMenuViews::Show() {
}
// Enable recursive tasks on the message loop so we can get updates while
// the context menu is being displayed.
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
RunMenuAt(top_level_widget, screen_point, params().source_type);
auto* submenu_view = static_cast<ToolkitDelegateViews*>(toolkit_delegate())

@ -163,7 +163,7 @@ void DownloadsDOMHandler::Drag(const std::string& id) {
screen->GetDisplayNearestView(view).device_scale_factor());
{
// Enable nested tasks during DnD, while |DragDownload()| blocks.
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
DragDownloadItem(file, icon, view);
}
}

@ -276,8 +276,6 @@ void NetInternalsTest::MessageHandler::RegisterMessage(
void NetInternalsTest::MessageHandler::HandleMessage(
const content::WebUI::MessageCallback& handler,
const base::Value::List& data) {
// The handler might run a nested loop to wait for something.
base::CurrentThread::ScopedNestableTaskAllower nestable_task_allower;
handler.Run(data);
}

@ -132,7 +132,7 @@ bool SendKeyPressToWindowSync(const gfx::NativeWindow window,
"interactive tests.";
#endif
base::RunLoop run_loop;
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
bool result = ui_controls::SendKeyPressNotifyWhenDone(
window, key, control, shift, alt, command, run_loop.QuitClosure());
#if BUILDFLAG(IS_WIN)
@ -149,7 +149,6 @@ bool SendKeyPressToWindowSync(const gfx::NativeWindow window,
// Run the message loop. It'll stop running when either the key was received
// or the test timed out (in which case testing::Test::HasFatalFailure should
// be set).
base::CurrentThread::ScopedNestableTaskAllower allow;
run_loop.Run();
return !testing::Test::HasFatalFailure();

@ -80,7 +80,7 @@ void PopupMenuHelper::ShowPopupMenu(
{
// Make sure events can be pumped while the menu is up.
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
// One of the events that could be pumped is |window.close()|.
// User-initiated event-tracking loops protect against this by

@ -1209,7 +1209,7 @@ void WebContentsViewAura::StartDragging(
DragOperation result_op;
{
gfx::NativeView content_native_view = GetContentNativeView();
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
result_op =
aura::client::GetDragDropClient(root_window)
->StartDragAndDrop(std::move(data), root_window,

@ -162,7 +162,7 @@ void WebContentsViewMac::StartDragging(
// The drag invokes a nested event loop, arrange to continue
// processing events.
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations);
[drag_dest_ setDragStartTrackersForProcess:source_rwh->GetProcess()->GetID()];
drag_source_start_rwh_ = source_rwh->GetWeakPtr();

@ -20,9 +20,6 @@ class FrameLoadWaiter : public RenderFrameObserver {
FrameLoadWaiter(const FrameLoadWaiter&) = delete;
FrameLoadWaiter& operator=(const FrameLoadWaiter&) = delete;
// Note: single-process browser tests need to enable nestable tasks by
// instantiating a base::CurrentThread::ScopedNestableTaskAllower or this
// method will never return.
void Wait();
private:

@ -276,7 +276,7 @@ current virtual thread. On threads with multiple task queues (e.g.
BrowserThread::UI) this can be a different queue than the one the current task
belongs to. The "current" task runner is intentionally not exposed via a static
getter. Either you know it already and can post to it directly or you don't and
the only sensible destination is the default queue. See https://bit.ly/3JvCLsX
the only sensible destination is the default queue. See https://bit.ly/3JvCLsX
for detailed discussion.
## Using Sequences Instead of Locks
@ -903,7 +903,7 @@ with dialogs (DialogBox), common dialogs (GetOpenFileName), OLE functions
Sample workaround when inner task processing is needed:
HRESULT hr;
{
CurrentThread::ScopedNestableTaskAllower allow;
CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
hr = DoDragDrop(...); // Implicitly runs a modal message loop.
}
// Process |hr| (the result returned by DoDragDrop()).
@ -911,7 +911,7 @@ Sample workaround when inner task processing is needed:
Please be SURE your task is reentrant (nestable) and all global variables
are stable and accessible before before using
CurrentThread::ScopedNestableTaskAllower.
CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop.
## APIs for general use

@ -113,7 +113,7 @@ HRESULT PrintingContextSystemDialogWin::ShowPrintDialog(PRINTDLGEX* options) {
// browser frame (but still being modal) so neither the browser frame nor
// the print dialog will get any input. See http://crbug.com/342697
// http://crbug.com/180997 for details.
base::CurrentThread::ScopedNestableTaskAllower allow;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
return PrintDlgEx(options);
}

@ -861,7 +861,7 @@ bool HWNDMessageHandler::RunMoveLoop(const gfx::Vector2d& drag_offset,
MoveLoopMouseWatcher watcher(this, hide_on_escape);
// In Aura, we handle touch events asynchronously. So we need to allow nested
// tasks while in windows move loop.
base::CurrentThread::ScopedNestableTaskAllower allow_nested;
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002,
static_cast<LPARAM>(GetMessagePos()));