summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-14 19:33:52 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-14 19:33:52 +0000
commitb5717a4f9f66283a9fe04ae1f9a3a89920d5b6b0 (patch)
tree9d14cf64e2cbeed63b232ba09a8c1274280d81b0 /chrome
parentbbdfcab9e264df0f264f56d8cb5f7ef61e5f96b6 (diff)
downloadchromium_src-b5717a4f9f66283a9fe04ae1f9a3a89920d5b6b0.zip
chromium_src-b5717a4f9f66283a9fe04ae1f9a3a89920d5b6b0.tar.gz
chromium_src-b5717a4f9f66283a9fe04ae1f9a3a89920d5b6b0.tar.bz2
Prefer ScopedNestableTaskAllower over manual save/restore
Cleanup. Changes various calls sites to use the ScopedNestableTaskAllower class to save/restore nestable task state. BUG=None TEST=Existing unit tests R=jar@chromium.org, scottbyer@chromium.org, sky@chromium.org, akalin@chromium.org, rsleevi@chromium.org, brettw@chromium.org, tony@chromium.org Review URL: https://chromiumcodereview.appspot.com/9384024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider_win.cc6
-rw-r--r--chrome/browser/printing/print_job.cc7
-rw-r--r--chrome/browser/printing/print_view_manager.cc9
-rw-r--r--chrome/browser/sessions/session_restore.cc8
-rw-r--r--chrome/browser/sync/profile_sync_service_harness.cc21
-rw-r--r--chrome/browser/ui/views/simple_message_box_views.cc8
-rw-r--r--chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.cc11
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc12
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc4
-rw-r--r--chrome/browser/ui/webui/downloads_dom_handler.cc2
-rw-r--r--chrome/test/base/ui_test_utils.cc4
11 files changed, 43 insertions, 49 deletions
diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc
index bcc8f63..5165cd5 100644
--- a/chrome/browser/automation/automation_provider_win.cc
+++ b/chrome/browser/automation/automation_provider_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -149,11 +149,9 @@ void AutomationProvider::WindowSimulateDrag(
false,
MessageLoop::QuitClosure());
MessageLoopForUI* loop = MessageLoopForUI::current();
- bool did_allow_task_nesting = loop->NestableTasksAllowed();
- loop->SetNestableTasksAllowed(true);
views::AcceleratorHandler handler;
+ MessageLoop::ScopedNestableTaskAllower allow(loop);
loop->RunWithDispatcher(&handler);
- loop->SetNestableTasksAllowed(did_allow_task_nesting);
}
SendMessage(top_level_hwnd, up_message, wparam_flags,
MAKELPARAM(end.x, end.y));
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc
index b374b685..aa312de 100644
--- a/chrome/browser/printing/print_job.cc
+++ b/chrome/browser/printing/print_job.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -202,11 +202,8 @@ bool PrintJob::FlushJob(int timeout_ms) {
MessageLoop::current(), &MessageLoop::Quit);
}
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
MessageLoop::current()->Run();
- // Restore task state.
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
return true;
}
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 3a5bdd6..32403c2 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -556,11 +556,10 @@ bool PrintViewManager::RunInnerMessageLoop() {
inside_inner_message_loop_ = true;
// Need to enable recursive task.
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
- MessageLoop::current()->Run();
- // Restore task state.
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
+ {
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ MessageLoop::current()->Run();
+ }
bool success = true;
if (inside_inner_message_loop_) {
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc
index fb83dcb..7c576dc 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -475,10 +475,10 @@ class SessionRestoreImpl : public content::NotificationObserver {
base::Bind(&SessionRestoreImpl::OnGotSession, base::Unretained(this)));
if (synchronous_) {
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
- MessageLoop::current()->Run();
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
+ {
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ MessageLoop::current()->Run();
+ }
Browser* browser = ProcessSessionWindows(&windows_);
delete this;
return browser;
diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc
index 34b6124..13fcc71 100644
--- a/chrome/browser/sync/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/profile_sync_service_harness.cc
@@ -746,16 +746,17 @@ bool ProfileSyncServiceHarness::AwaitStatusChangeWithTimeout(
}
scoped_refptr<StateChangeTimeoutEvent> timeout_signal(
new StateChangeTimeoutEvent(this, reason));
- MessageLoop* loop = MessageLoop::current();
- bool did_allow_nestable_tasks = loop->NestableTasksAllowed();
- loop->SetNestableTasksAllowed(true);
- loop->PostDelayedTask(
- FROM_HERE,
- base::Bind(&StateChangeTimeoutEvent::Callback,
- timeout_signal.get()),
- base::TimeDelta::FromMilliseconds(timeout_milliseconds));
- loop->Run();
- loop->SetNestableTasksAllowed(did_allow_nestable_tasks);
+ {
+ MessageLoop* loop = MessageLoop::current();
+ MessageLoop::ScopedNestableTaskAllower allow(loop);
+ loop->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&StateChangeTimeoutEvent::Callback,
+ timeout_signal.get()),
+ base::TimeDelta::FromMilliseconds(timeout_milliseconds));
+ loop->Run();
+ }
+
if (timeout_signal->Abort()) {
DVLOG(1) << GetClientInfoString("AwaitStatusChangeWithTimeout succeeded");
return true;
diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc
index c644a4e..596b7d9 100644
--- a/chrome/browser/ui/views/simple_message_box_views.cc
+++ b/chrome/browser/ui/views/simple_message_box_views.cc
@@ -63,10 +63,10 @@ bool SimpleMessageBoxViews::ShowYesNoBox(gfx::NativeWindow parent_window,
aura::client::GetDispatcherClient()->RunWithDispatcher(dialog,
parent_window, true);
#else
- bool old_state = MessageLoopForUI::current()->NestableTasksAllowed();
- MessageLoopForUI::current()->SetNestableTasksAllowed(true);
- MessageLoopForUI::current()->RunWithDispatcher(dialog);
- MessageLoopForUI::current()->SetNestableTasksAllowed(old_state);
+ {
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoopForUI::current());
+ MessageLoopForUI::current()->RunWithDispatcher(dialog);
+ }
#endif
g_browser_process->ReleaseModule();
diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.cc
index 795b967..ab1a843 100644
--- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.cc
+++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_aura.cc
@@ -211,11 +211,12 @@ void NativeTabContentsViewAura::StartDragging(const WebDropData& drop_data,
// We need to enable recursive tasks on the message loop so we can get
// updates while in the system DoDragDrop loop.
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
- int result_op = aura::client::GetDragDropClient()->StartDragAndDrop(
- data, ConvertFromWeb(ops));
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
+ int result_op = 0;
+ {
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ result_op = aura::client::GetDragDropClient()->StartDragAndDrop(
+ data, ConvertFromWeb(ops));
+ }
EndDrag(ConvertToWeb(result_op));
GetWebContents()->GetRenderViewHost()->DragSourceSystemDragEnded();
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc
index 2c289cb..58955a2 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc
@@ -312,12 +312,14 @@ void TabContentsDragWin::DoDragging(const WebDropData& drop_data,
// We need to enable recursive tasks on the message loop so we can get
// updates while in the system DoDragDrop loop.
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
DWORD effect;
- DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source_,
- web_drag_utils_win::WebDragOpMaskToWinDragOpMask(ops), &effect);
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
+ {
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data),
+ drag_source_,
+ web_drag_utils_win::WebDragOpMaskToWinDragOpMask(ops),
+ &effect);
+ }
// This works because WebDragSource::OnDragSourceDrop uses PostTask to
// dispatch the actual event.
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
index 4325e40..45dde04 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
@@ -362,10 +362,8 @@ void TabContentsViewViews::ShowContextMenu(
// Enable recursive tasks on the message loop so we can get updates while
// the context menu is being displayed.
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
context_menu_->RunMenuAt(screen_point.x(), screen_point.y());
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
}
void TabContentsViewViews::ShowPopupMenu(const gfx::Rect& bounds,
diff --git a/chrome/browser/ui/webui/downloads_dom_handler.cc b/chrome/browser/ui/webui/downloads_dom_handler.cc
index 92ae005..7fbe6ac 100644
--- a/chrome/browser/ui/webui/downloads_dom_handler.cc
+++ b/chrome/browser/ui/webui/downloads_dom_handler.cc
@@ -268,7 +268,7 @@ void DownloadsDOMHandler::HandleDrag(const ListValue* args) {
gfx::NativeView view = web_ui()->GetWebContents()->GetNativeView();
{
// Enable nested tasks during DnD, while |DragDownload()| blocks.
- MessageLoop::ScopedNestableTaskAllower allower(MessageLoop::current());
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
download_util::DragDownload(file, icon, view);
}
}
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index dc68764..6a580d7 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -266,8 +266,7 @@ void RunMessageLoop() {
MessageLoopForUI* ui_loop =
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ?
MessageLoopForUI::current() : NULL;
- bool did_allow_task_nesting = loop->NestableTasksAllowed();
- loop->SetNestableTasksAllowed(true);
+ MessageLoop::ScopedNestableTaskAllower allow(loop);
if (ui_loop) {
#if defined(USE_AURA)
aura::RootWindow::GetInstance()->Run();
@@ -282,7 +281,6 @@ void RunMessageLoop() {
} else {
loop->Run();
}
- loop->SetNestableTasksAllowed(did_allow_task_nesting);
}
void RunAllPendingInMessageLoop() {