OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/test_utils.h" | 5 #include "content/public/test/test_utils.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/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/thread_task_runner_handle.h" |
11 #include "base/values.h" | 13 #include "base/values.h" |
12 #include "content/public/browser/browser_child_process_host_iterator.h" | 14 #include "content/public/browser/browser_child_process_host_iterator.h" |
13 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/common/process_type.h" | 18 #include "content/public/common/process_type.h" |
17 #include "content/public/test/test_launcher.h" | 19 #include "content/public/test/test_launcher.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // Number of times to repost a Quit task so that the MessageLoop finishes up | 26 // Number of times to repost a Quit task so that the MessageLoop finishes up |
25 // pending tasks and tasks posted by those pending tasks without risking the | 27 // pending tasks and tasks posted by those pending tasks without risking the |
26 // potential hang behavior of MessageLoop::QuitWhenIdle. | 28 // potential hang behavior of MessageLoop::QuitWhenIdle. |
27 // The criteria for choosing this number: it should be high enough to make the | 29 // The criteria for choosing this number: it should be high enough to make the |
28 // quit act like QuitWhenIdle, while taking into account that any page which is | 30 // quit act like QuitWhenIdle, while taking into account that any page which is |
29 // animating may be rendering another frame for each quit deferral. For an | 31 // animating may be rendering another frame for each quit deferral. For an |
30 // animating page, the potential delay to quitting the RunLoop would be | 32 // animating page, the potential delay to quitting the RunLoop would be |
31 // kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as | 33 // kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as |
32 // 200ms/frame. | 34 // 200ms/frame. |
33 static const int kNumQuitDeferrals = 10; | 35 static const int kNumQuitDeferrals = 10; |
34 | 36 |
35 static void DeferredQuitRunLoop(const base::Closure& quit_task, | 37 static void DeferredQuitRunLoop(const base::Closure& quit_task, |
36 int num_quit_deferrals) { | 38 int num_quit_deferrals) { |
37 if (num_quit_deferrals <= 0) { | 39 if (num_quit_deferrals <= 0) { |
38 quit_task.Run(); | 40 quit_task.Run(); |
39 } else { | 41 } else { |
40 base::MessageLoop::current()->PostTask( | 42 base::ThreadTaskRunnerHandle::Get()->PostTask( |
41 FROM_HERE, | 43 FROM_HERE, |
42 base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1)); | 44 base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1)); |
43 } | 45 } |
44 } | 46 } |
45 | 47 |
46 void RunAllPendingMessageAndSendQuit(BrowserThread::ID thread_id, | 48 void RunAllPendingMessageAndSendQuit(BrowserThread::ID thread_id, |
47 const base::Closure& quit_task) { | 49 const base::Closure& quit_task) { |
48 RunAllPendingInMessageLoop(); | 50 RunAllPendingInMessageLoop(); |
49 BrowserThread::PostTask(thread_id, FROM_HERE, quit_task); | 51 BrowserThread::PostTask(thread_id, FROM_HERE, quit_task); |
50 } | 52 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 #endif | 122 #endif |
121 if (delegate) | 123 if (delegate) |
122 delegate->PreRunMessageLoop(run_loop); | 124 delegate->PreRunMessageLoop(run_loop); |
123 run_loop->Run(); | 125 run_loop->Run(); |
124 if (delegate) | 126 if (delegate) |
125 delegate->PostRunMessageLoop(); | 127 delegate->PostRunMessageLoop(); |
126 } | 128 } |
127 | 129 |
128 void RunAllPendingInMessageLoop() { | 130 void RunAllPendingInMessageLoop() { |
129 base::RunLoop run_loop; | 131 base::RunLoop run_loop; |
130 base::MessageLoop::current()->PostTask( | 132 base::ThreadTaskRunnerHandle::Get()->PostTask( |
131 FROM_HERE, GetQuitTaskForRunLoop(&run_loop)); | 133 FROM_HERE, GetQuitTaskForRunLoop(&run_loop)); |
132 RunThisRunLoop(&run_loop); | 134 RunThisRunLoop(&run_loop); |
133 } | 135 } |
134 | 136 |
135 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { | 137 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { |
136 if (BrowserThread::CurrentlyOn(thread_id)) { | 138 if (BrowserThread::CurrentlyOn(thread_id)) { |
137 RunAllPendingInMessageLoop(); | 139 RunAllPendingInMessageLoop(); |
138 return; | 140 return; |
139 } | 141 } |
140 BrowserThread::ID current_thread_id; | 142 BrowserThread::ID current_thread_id; |
141 if (!BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)) { | 143 if (!BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 void InProcessUtilityThreadHelper::BrowserChildProcessHostDisconnected( | 305 void InProcessUtilityThreadHelper::BrowserChildProcessHostDisconnected( |
304 const ChildProcessData& data) { | 306 const ChildProcessData& data) { |
305 if (--child_thread_count_) | 307 if (--child_thread_count_) |
306 return; | 308 return; |
307 | 309 |
308 if (runner_.get()) | 310 if (runner_.get()) |
309 runner_->Quit(); | 311 runner_->Quit(); |
310 } | 312 } |
311 | 313 |
312 } // namespace content | 314 } // namespace content |
OLD | NEW |