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