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

Unified Diff: net/proxy/proxy_config_service_linux_unittest.cc

Issue 10912132: Move ProxyConfigService construction onto the IO thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust comments Created 8 years, 2 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
Index: net/proxy/proxy_config_service_linux_unittest.cc
diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc
index a0534c8a126dc2526a16c6cef5fc15867cb3bbdd..8045df4c0d2eefb196ecd2ae782a20b410bec11e 100644
--- a/net/proxy/proxy_config_service_linux_unittest.cc
+++ b/net/proxy/proxy_config_service_linux_unittest.cc
@@ -262,6 +262,7 @@ class SynchConfigGetter {
explicit SynchConfigGetter(net::ProxyConfigServiceLinux* config_service)
: event_(false, false),
io_thread_("IO_Thread"),
+ glib_task_runner_(base::MessageLoopProxy::current()),
config_service_(config_service) {
// Start an IO thread.
base::Thread::Options options;
@@ -284,16 +285,18 @@ class SynchConfigGetter {
Wait();
}
- // Does gconf setup and initial fetch of the proxy config,
- // all on the calling thread (meant to be the thread with the
- // default glib main loop, which is the UI thread).
+ // Does gconf setup and initial fetch of the proxy config.
void SetupAndInitialFetch() {
- MessageLoop* file_loop = io_thread_.message_loop();
- DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type());
- // We pass the mock IO thread as both the IO and file threads.
- config_service_->SetupAndFetchInitialConfig(
- base::MessageLoopProxy::current(), io_thread_.message_loop_proxy(),
- static_cast<MessageLoopForIO*>(file_loop));
+ io_thread_.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&SynchConfigGetter::SetupAndInitialFetchOnIOThread,
+ base::Unretained(this)));
+ Wait();
+ // ProxyConfigServiceLinux will post back to the UI thread, so let it run
+ MessageLoop::current()->RunAllPending();
+ // ProxyConfigServiceLinux will post back to the IO thread, so let it run
+ io_thread_.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&SynchConfigGetter::CleanUp, base::Unretained(this)));
+ Wait();
}
// Synchronously gets the proxy config.
net::ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig(
@@ -320,6 +323,17 @@ class SynchConfigGetter {
event_.Signal();
}
+ void SetupAndInitialFetchOnIOThread() {
+ MessageLoop* file_loop = io_thread_.message_loop();
+ DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type());
+ DCHECK(io_thread_.message_loop_proxy()->RunsTasksOnCurrentThread());
+ // We pass the mock IO thread as both the IO and file threads.
+ config_service_->SetupAndFetchInitialConfig(
+ glib_task_runner_, io_thread_.message_loop_proxy(),
+ static_cast<MessageLoopForIO*>(file_loop));
+ event_.Signal();
+ }
+
// [Runs on |io_thread_|] Signals |event_| on cleanup completion.
void CleanUp() {
MessageLoop::current()->RunAllPending();
@@ -333,6 +347,7 @@ class SynchConfigGetter {
base::WaitableEvent event_;
base::Thread io_thread_;
+ base::SingleThreadTaskRunner *glib_task_runner_;
net::ProxyConfigServiceLinux* config_service_;

Powered by Google App Engine
This is Rietveld 408576698