diff options
Diffstat (limited to 'chrome/browser')
11 files changed, 61 insertions, 70 deletions
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index abe66f2..06e1fde 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/autocomplete/search_provider.h" +#include "base/run_loop.h" #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" @@ -178,13 +179,12 @@ void SearchProviderTest::RunTillProviderDone() { return; quit_when_done_ = true; -#if defined(OS_MACOSX) - message_loop_.Run(); -#elif defined(OS_ANDROID) +#if defined(OS_ANDROID) // Android doesn't have Run(), only Start(). message_loop_.Start(); #else - message_loop_.RunWithDispatcher(NULL); + base::RunLoop run_loop; + run_loop.Run(); #endif } diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 13885c6..d156b5e 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -8,6 +8,7 @@ #include "base/callback.h" #include "base/debug/trace_event.h" #include "base/json/json_reader.h" +#include "base/run_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/automation/automation_browser_tracker.h" #include "chrome/browser/automation/automation_tab_tracker.h" @@ -36,6 +37,17 @@ using content::WebContents; namespace { +// Allow some pending tasks up to |num_deferrals| generations to complete. +void DeferredQuitRunLoop(const base::Closure& quit_task, + int num_quit_deferrals) { + if (num_quit_deferrals <= 0) { + quit_task.Run(); + } else { + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1)); + } +} + // This callback just adds another callback to the event queue. This is useful // if you want to ensure that any callbacks added to the event queue after this // one have already been processed by the time |callback| is run. @@ -139,6 +151,11 @@ void AutomationProvider::WindowSimulateDrag( if (press_escape_en_route) { // Press Escape, making sure we wait until chrome processes the escape. // TODO(phajdan.jr): make this use ui_test_utils::SendKeyPressSync. + views::AcceleratorHandler handler; + base::RunLoop run_loop(&handler); + // Number of times to repost Quit task to allow pending tasks to complete. + // See kNumQuitDeferrals in ui_test_utils.cc for explanation. + int num_quit_deferrals = 10; ui_controls::SendKeyPressNotifyWhenDone( window, ui::VKEY_ESCAPE, ((flags & ui::EF_CONTROL_DOWN) == @@ -147,11 +164,11 @@ void AutomationProvider::WindowSimulateDrag( ui::EF_SHIFT_DOWN), ((flags & ui::EF_ALT_DOWN) == ui::EF_ALT_DOWN), false, - MessageLoop::QuitClosure()); + base::Bind(&DeferredQuitRunLoop, run_loop.QuitClosure(), + num_quit_deferrals)); MessageLoopForUI* loop = MessageLoopForUI::current(); - views::AcceleratorHandler handler; MessageLoop::ScopedNestableTaskAllower allow(loop); - loop->RunWithDispatcher(&handler); + run_loop.Run(); } SendMessage(top_level_hwnd, up_message, wparam_flags, MAKELPARAM(end.x, end.y)); diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index bf106a4..54f308b 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -19,6 +19,7 @@ #include "base/path_service.h" #include "base/process_info.h" #include "base/process_util.h" +#include "base/run_loop.h" #include "base/string_number_conversions.h" #include "base/string_piece.h" #include "base/string_split.h" @@ -1900,16 +1901,14 @@ bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { // UI thread message loop as possible to get a stable measurement // across versions. RecordBrowserStartupTime(); -#if defined(USE_AURA) - MessageLoopForUI::current()->Run(); -#elif defined(TOOLKIT_VIEWS) + DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); +#if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) views::AcceleratorHandler accelerator_handler; - MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); -#elif defined(USE_X11) - MessageLoopForUI::current()->RunWithDispatcher(NULL); -#elif defined(OS_POSIX) - MessageLoopForUI::current()->Run(); + base::RunLoop run_loop(&accelerator_handler); +#else + base::RunLoop run_loop; #endif + run_loop.Run(); return true; } diff --git a/chrome/browser/referrer_policy_browsertest.cc b/chrome/browser/referrer_policy_browsertest.cc index 3e6fc20..7d59dbd 100644 --- a/chrome/browser/referrer_policy_browsertest.cc +++ b/chrome/browser/referrer_policy_browsertest.cc @@ -255,8 +255,7 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, HttpsMiddleClickTargetBlankOrigin) { // Context menu, from HTTP to HTTP. IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuOrigin) { ContextMenuNotificationObserver context_menu_observer( - IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, - chrome::NOTIFICATION_TAB_ADDED); + IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); RunReferrerTest("origin", false, false, false, true, WebKit::WebMouseEvent::ButtonRight, EXPECT_ORIGIN_AS_REFERRER); @@ -265,8 +264,7 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuOrigin) { // Context menu, from HTTPS to HTTP. IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_HttpsContextMenuOrigin) { ContextMenuNotificationObserver context_menu_observer( - IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, - chrome::NOTIFICATION_TAB_ADDED); + IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); RunReferrerTest("origin", true, false, false, true, WebKit::WebMouseEvent::ButtonRight, EXPECT_ORIGIN_AS_REFERRER); @@ -352,8 +350,7 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, // Context menu, from HTTP to HTTP via server redirect. IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuRedirect) { ContextMenuNotificationObserver context_menu_observer( - IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, - chrome::NOTIFICATION_TAB_ADDED); + IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); RunReferrerTest("origin", false, false, true, true, WebKit::WebMouseEvent::ButtonRight, EXPECT_ORIGIN_AS_REFERRER); @@ -362,8 +359,7 @@ IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_ContextMenuRedirect) { // Context menu, from HTTPS to HTTP via server redirect. IN_PROC_BROWSER_TEST_F(ReferrerPolicyTest, MAYBE_HttpsContextMenuRedirect) { ContextMenuNotificationObserver context_menu_observer( - IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, - chrome::NOTIFICATION_TAB_ADDED); + IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); RunReferrerTest("origin", true, false, true, true, WebKit::WebMouseEvent::ButtonRight, EXPECT_ORIGIN_AS_REFERRER); diff --git a/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc b/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc index e95b26c..362d57f 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc @@ -101,8 +101,7 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, MAYBE_RealMenu) { ContextMenuNotificationObserver menu_observer( - IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, - chrome::NOTIFICATION_TAB_ADDED); + IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( content::NotificationService::AllSources()); diff --git a/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.cc b/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.cc index 900581b..b86fbe4 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.cc @@ -11,20 +11,11 @@ #include "content/public/browser/notification_service.h" ContextMenuNotificationObserver::ContextMenuNotificationObserver( - int command_to_execute, - int expected_notification) - : command_to_execute_(command_to_execute), - expected_notification_(expected_notification), - seen_expected_notification_(false) { + int command_to_execute) + : command_to_execute_(command_to_execute) { registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, content::NotificationService::AllSources()); - registrar_.Add(this, - chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED, - content::NotificationService::AllSources()); - registrar_.Add(this, - expected_notification_, - content::NotificationService::AllSources()); } ContextMenuNotificationObserver::~ContextMenuNotificationObserver() { @@ -34,11 +25,6 @@ void ContextMenuNotificationObserver::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - if (type == expected_notification_) { - seen_expected_notification_ = true; - return; - } - switch (type) { case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { RenderViewContextMenu* context_menu = @@ -49,17 +35,6 @@ void ContextMenuNotificationObserver::Observe( base::Unretained(this), context_menu)); break; } - case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED: { - // Aura is running a nested message loop for menus. That means that - // whatever the test running us is waiting for (e.g. a new tab to be - // added) happened while the menu message loop was running, so the - // message loop run by this test never quits. - if (seen_expected_notification_ && - MessageLoop::current()->is_running()) { - MessageLoop::current()->QuitNow(); - } - break; - } default: NOTREACHED(); diff --git a/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.h b/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.h index 815454f..dac0c03 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.h +++ b/chrome/browser/tab_contents/render_view_context_menu_browsertest_util.h @@ -15,14 +15,7 @@ class RenderViewContextMenu; class ContextMenuNotificationObserver : public content::NotificationObserver { public: // Wait for a context menu to be shown, and then execute |command_to_execute|. - // As the context menu might spin a nested message loop, the usual way to wait - // for the result of the |command_to_execute|, i.e. running - // ui_test_utils::WindowedNotificationObserver::Wait, won't work. The - // ContextMenuNotificationObserver can work around this problem. In order to - // do so, you need to also specify what notification the - // WindowedNotificationObserver is waiting for. - ContextMenuNotificationObserver(int command_to_execute, - int expected_notification); + explicit ContextMenuNotificationObserver(int command_to_execute); virtual ~ContextMenuNotificationObserver(); private: @@ -34,8 +27,6 @@ class ContextMenuNotificationObserver : public content::NotificationObserver { content::NotificationRegistrar registrar_; int command_to_execute_; - int expected_notification_; - bool seen_expected_notification_; DISALLOW_COPY_AND_ASSIGN(ContextMenuNotificationObserver); }; diff --git a/chrome/browser/ui/views/simple_message_box_views.cc b/chrome/browser/ui/views/simple_message_box_views.cc index 805c6b5..a399885 100644 --- a/chrome/browser/ui/views/simple_message_box_views.cc +++ b/chrome/browser/ui/views/simple_message_box_views.cc @@ -8,6 +8,7 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/message_loop.h" +#include "base/run_loop.h" #include "chrome/browser/browser_process.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -179,7 +180,8 @@ MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, #else { MessageLoop::ScopedNestableTaskAllower allow(MessageLoopForUI::current()); - MessageLoopForUI::current()->RunWithDispatcher(dialog); + base::RunLoop run_loop(dialog); + run_loop.Run(); } #endif return dialog->result(); diff --git a/chrome/browser/ui/views/uninstall_view.cc b/chrome/browser/ui/views/uninstall_view.cc index 808d245..41fee09 100644 --- a/chrome/browser/ui/views/uninstall_view.cc +++ b/chrome/browser/ui/views/uninstall_view.cc @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "base/process_util.h" +#include "base/run_loop.h" #include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/shell_integration.h" @@ -23,19 +24,21 @@ #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -UninstallView::UninstallView(int* user_selection) +UninstallView::UninstallView(int* user_selection, + const base::Closure& quit_closure) : confirm_label_(NULL), delete_profile_(NULL), change_default_browser_(NULL), browsers_combo_(NULL), browsers_(NULL), - user_selection_(*user_selection) { + user_selection_(*user_selection), + quit_closure_(quit_closure) { SetupControls(); } UninstallView::~UninstallView() { // Exit the message loop we were started with so that uninstall can continue. - MessageLoop::current()->Quit(); + quit_closure_.Run(); } void UninstallView::SetupControls() { @@ -164,10 +167,13 @@ string16 UninstallView::GetItemAt(int index) { namespace browser { int ShowUninstallBrowserPrompt() { + DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); int result = content::RESULT_CODE_NORMAL_EXIT; - views::Widget::CreateWindow(new UninstallView(&result))->Show(); views::AcceleratorHandler accelerator_handler; - MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); + base::RunLoop run_loop(&accelerator_handler); + UninstallView* view = new UninstallView(&result, run_loop.QuitClosure()); + views::Widget::CreateWindow(view)->Show(); + run_loop.Run(); return result; } diff --git a/chrome/browser/ui/views/uninstall_view.h b/chrome/browser/ui/views/uninstall_view.h index 181c07a..47c02f2 100644 --- a/chrome/browser/ui/views/uninstall_view.h +++ b/chrome/browser/ui/views/uninstall_view.h @@ -8,6 +8,7 @@ #include <map> +#include "base/callback.h" #include "base/string16.h" #include "ui/base/models/combobox_model.h" #include "ui/views/window/dialog_delegate.h" @@ -25,7 +26,8 @@ class UninstallView : public views::ButtonListener, public views::DialogDelegateView, public ui::ComboboxModel { public: - explicit UninstallView(int* user_selection); + explicit UninstallView(int* user_selection, + const base::Closure& quit_closure); virtual ~UninstallView(); // Overridden form views::ButtonListener. @@ -56,6 +58,7 @@ class UninstallView : public views::ButtonListener, typedef std::map<std::wstring, std::wstring> BrowsersMap; scoped_ptr<BrowsersMap> browsers_; int& user_selection_; + base::Closure quit_closure_; DISALLOW_COPY_AND_ASSIGN(UninstallView); }; diff --git a/chrome/browser/ui/views/user_data_dir_dialog_view.cc b/chrome/browser/ui/views/user_data_dir_dialog_view.cc index a0e7128..2a1f29c 100644 --- a/chrome/browser/ui/views/user_data_dir_dialog_view.cc +++ b/chrome/browser/ui/views/user_data_dir_dialog_view.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/views/user_data_dir_dialog_view.h" #include "base/logging.h" +#include "base/run_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/ui/user_data_dir_dialog.h" #include "grit/chromium_strings.h" @@ -100,10 +101,12 @@ void UserDataDirDialogView::FileSelectionCanceled(void* params) { namespace browser { FilePath ShowUserDataDirDialog(const FilePath& user_data_dir) { + DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); // When the window closes, it will delete itself. UserDataDirDialogView* dialog = new UserDataDirDialogView(user_data_dir); views::Widget::CreateWindow(dialog)->Show(); - MessageLoopForUI::current()->RunWithDispatcher(dialog); + base::RunLoop run_loop(dialog); + run_loop.Run(); return dialog->user_data_dir(); } |