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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.cc

Issue 1143343005: chrome/browser: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
9 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 13 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
12 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h" 15 #include "content/public/test/test_utils.h"
14 16
15 ContextMenuNotificationObserver::ContextMenuNotificationObserver( 17 ContextMenuNotificationObserver::ContextMenuNotificationObserver(
16 int command_to_execute) 18 int command_to_execute)
17 : command_to_execute_(command_to_execute) { 19 : command_to_execute_(command_to_execute) {
18 registrar_.Add(this, 20 registrar_.Add(this,
19 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 21 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
20 content::NotificationService::AllSources()); 22 content::NotificationService::AllSources());
21 } 23 }
22 24
23 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() { 25 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
24 } 26 }
25 27
26 void ContextMenuNotificationObserver::Observe( 28 void ContextMenuNotificationObserver::Observe(
27 int type, 29 int type,
28 const content::NotificationSource& source, 30 const content::NotificationSource& source,
29 const content::NotificationDetails& details) { 31 const content::NotificationDetails& details) {
30 switch (type) { 32 switch (type) {
31 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 33 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
32 RenderViewContextMenu* context_menu = 34 RenderViewContextMenu* context_menu =
33 content::Source<RenderViewContextMenu>(source).ptr(); 35 content::Source<RenderViewContextMenu>(source).ptr();
34 base::MessageLoop::current()->PostTask( 36 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 FROM_HERE, 37 FROM_HERE,
36 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand, 38 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand,
37 base::Unretained(this), 39 base::Unretained(this), context_menu));
38 context_menu));
39 break; 40 break;
40 } 41 }
41 42
42 default: 43 default:
43 NOTREACHED(); 44 NOTREACHED();
44 } 45 }
45 } 46 }
46 47
47 void ContextMenuNotificationObserver::ExecuteCommand( 48 void ContextMenuNotificationObserver::ExecuteCommand(
48 RenderViewContextMenu* context_menu) { 49 RenderViewContextMenu* context_menu) {
(...skipping 11 matching lines...) Expand all
60 } 61 }
61 62
62 void ContextMenuWaiter::Observe(int type, 63 void ContextMenuWaiter::Observe(int type,
63 const content::NotificationSource& source, 64 const content::NotificationSource& source,
64 const content::NotificationDetails& details) { 65 const content::NotificationDetails& details) {
65 switch (type) { 66 switch (type) {
66 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 67 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
67 menu_visible_ = true; 68 menu_visible_ = true;
68 RenderViewContextMenu* context_menu = 69 RenderViewContextMenu* context_menu =
69 content::Source<RenderViewContextMenu>(source).ptr(); 70 content::Source<RenderViewContextMenu>(source).ptr();
70 base::MessageLoop::current()->PostTask( 71 base::ThreadTaskRunnerHandle::Get()->PostTask(
71 FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel, 72 FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel,
72 base::Unretained(this), context_menu)); 73 base::Unretained(this), context_menu));
73 break; 74 break;
74 } 75 }
75 76
76 default: 77 default:
77 NOTREACHED(); 78 NOTREACHED();
78 } 79 }
79 } 80 }
80 81
81 void ContextMenuWaiter::WaitForMenuOpenAndClose() { 82 void ContextMenuWaiter::WaitForMenuOpenAndClose() {
82 content::WindowedNotificationObserver menu_observer( 83 content::WindowedNotificationObserver menu_observer(
83 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 84 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
84 content::NotificationService::AllSources()); 85 content::NotificationService::AllSources());
85 if (!menu_visible_) 86 if (!menu_visible_)
86 menu_observer.Wait(); 87 menu_observer.Wait();
87 88
88 content::RunAllPendingInMessageLoop(); 89 content::RunAllPendingInMessageLoop();
89 menu_visible_ = false; 90 menu_visible_ = false;
90 } 91 }
91 92
92 content::ContextMenuParams& ContextMenuWaiter::params() { 93 content::ContextMenuParams& ContextMenuWaiter::params() {
93 return params_; 94 return params_;
94 } 95 }
95 96
96 void ContextMenuWaiter::Cancel(RenderViewContextMenu* context_menu) { 97 void ContextMenuWaiter::Cancel(RenderViewContextMenu* context_menu) {
97 params_ = context_menu->params(); 98 params_ = context_menu->params();
98 context_menu->Cancel(); 99 context_menu->Cancel();
99 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698