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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/test_utils.cc
===================================================================
--- content/public/test/test_utils.cc (revision 243741)
+++ content/public/test/test_utils.cc (working copy)
@@ -9,8 +9,11 @@
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
+#include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/common/process_type.h"
#include "content/public/test/test_launcher.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -242,4 +245,35 @@
running_ = false;
}
+InProcessUtilityThreadHelper::InProcessUtilityThreadHelper()
+ : child_thread_count_(0) {
+ RenderProcessHost::SetRunRendererInProcess(true);
+ BrowserChildProcessObserver::Add(this);
+}
+
+InProcessUtilityThreadHelper::~InProcessUtilityThreadHelper() {
+ if (child_thread_count_) {
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::UI));
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
+ runner_ = new MessageLoopRunner;
+ runner_->Run();
+ }
+ BrowserChildProcessObserver::Remove(this);
+ RenderProcessHost::SetRunRendererInProcess(false);
+}
+
+void InProcessUtilityThreadHelper::BrowserChildProcessHostConnected(
+ const ChildProcessData& data) {
+ child_thread_count_++;
+}
+
+void InProcessUtilityThreadHelper::BrowserChildProcessHostDisconnected(
+ const ChildProcessData& data) {
+ if (--child_thread_count_)
+ return;
+
+ if (runner_.get())
+ runner_->Quit();
+}
+
} // namespace content
« 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