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

Side by Side Diff: content/public/test/test_utils.cc

Issue 128993004: Fix subtle bug with the in-process utility thread usage in unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "content/public/browser/browser_child_process_host_iterator.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/common/process_type.h"
14 #include "content/public/test/test_launcher.h" 17 #include "content/public/test/test_launcher.h"
15 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
16 19
17 namespace content { 20 namespace content {
18 21
19 namespace { 22 namespace {
20 23
21 // 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
22 // 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
23 // potential hang behavior of MessageLoop::QuitWhenIdle. 26 // potential hang behavior of MessageLoop::QuitWhenIdle.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return; 238 return;
236 239
237 seen_ = true; 240 seen_ = true;
238 if (!running_) 241 if (!running_)
239 return; 242 return;
240 243
241 message_loop_runner_->Quit(); 244 message_loop_runner_->Quit();
242 running_ = false; 245 running_ = false;
243 } 246 }
244 247
248 InProcessUtilityThreadHelper::InProcessUtilityThreadHelper()
249 : child_thread_count_(0) {
250 RenderProcessHost::SetRunRendererInProcess(true);
251 BrowserChildProcessObserver::Add(this);
252 }
253
254 InProcessUtilityThreadHelper::~InProcessUtilityThreadHelper() {
255 if (child_thread_count_) {
256 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::UI));
257 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
258 runner_ = new MessageLoopRunner;
259 runner_->Run();
260 }
261 BrowserChildProcessObserver::Remove(this);
262 RenderProcessHost::SetRunRendererInProcess(false);
263 }
264
265 void InProcessUtilityThreadHelper::BrowserChildProcessHostConnected(
266 const ChildProcessData& data) {
267 child_thread_count_++;
268 }
269
270 void InProcessUtilityThreadHelper::BrowserChildProcessHostDisconnected(
271 const ChildProcessData& data) {
272 if (--child_thread_count_)
273 return;
274
275 if (runner_.get())
276 runner_->Quit();
277 }
278
245 } // namespace content 279 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698