summaryrefslogtreecommitdiffstats
path: root/chrome/browser/io_thread.cc
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 15:56:41 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 15:56:41 +0000
commit2e5b60a280076017d700e56a5cb81ec62149a9bc (patch)
treee1f212d0f3cbdb7c04f4fd8fc67e1fcd26c350da /chrome/browser/io_thread.cc
parente04be707101e60bb5512c69a64ce5b64a1c4eeba (diff)
downloadchromium_src-2e5b60a280076017d700e56a5cb81ec62149a9bc.zip
chromium_src-2e5b60a280076017d700e56a5cb81ec62149a9bc.tar.gz
chromium_src-2e5b60a280076017d700e56a5cb81ec62149a9bc.tar.bz2
Have content/ create and destroy its own threads. (Re-land)
Change embedding API and embedders to allow for this. Push inheritance of base::Thread down to content::BrowserThreadImpl so that content::BrowserThread is just a namespace for API functions. This change temporarily disables chrome_frame_net_tests as agreed by the CF lead, see bug 105435. TBR=ben@chromium.org (IWYU change only) BUG=98716,104578,105435 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=111695 Reverted (problems on official bot): r111698 Review URL: http://codereview.chromium.org/8477004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111705 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/io_thread.cc')
-rw-r--r--chrome/browser/io_thread.cc53
1 files changed, 37 insertions, 16 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 18d1d2b..17b17a4 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -316,7 +316,8 @@ class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
SystemURLRequestContextGetter::SystemURLRequestContextGetter(
IOThread* io_thread)
: io_thread_(io_thread),
- io_message_loop_proxy_(io_thread->message_loop_proxy()) {
+ io_message_loop_proxy_(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
}
SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
@@ -347,8 +348,7 @@ IOThread::IOThread(
PrefService* local_state,
ChromeNetLog* net_log,
ExtensionEventRouterForwarder* extension_event_router_forwarder)
- : content::BrowserProcessSubThread(BrowserThread::IO),
- net_log_(net_log),
+ : net_log_(net_log),
extension_event_router_forwarder_(extension_event_router_forwarder),
globals_(NULL),
sdch_manager_(NULL),
@@ -371,17 +371,17 @@ IOThread::IOThread(
local_state);
ssl_config_service_manager_.reset(
SSLConfigServiceManager::CreateDefaultManager(local_state));
- MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(&IOThread::InitSystemRequestContext,
- weak_factory_.GetWeakPtr()));
+
+ BrowserThread::SetDelegate(BrowserThread::IO, this);
}
IOThread::~IOThread() {
+ // This isn't needed for production code, but in tests, IOThread may
+ // be multiply constructed.
+ BrowserThread::SetDelegate(BrowserThread::IO, NULL);
+
if (pref_proxy_config_tracker_.get())
pref_proxy_config_tracker_->DetachFromPrefService();
- // We cannot rely on our base class to stop the thread since we want our
- // CleanUp function to run.
- Stop();
DCHECK(!globals_);
}
@@ -407,9 +407,7 @@ void IOThread::Init() {
// messages around; it shouldn't be allowed to perform any blocking disk I/O.
base::ThreadRestrictions::SetIOAllowed(false);
- content::BrowserProcessSubThread::Init();
-
- DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
#if defined(USE_NSS)
net::SetMessageLoopForOCSP();
@@ -480,6 +478,26 @@ void IOThread::Init() {
sdch_manager_ = new net::SdchManager();
sdch_manager_->set_sdch_fetcher(new SdchDictionaryFetcher);
+
+ // InitSystemRequestContext turns right around and posts a task back
+ // to the IO thread, so we can't let it run until we know the IO
+ // thread has started.
+ //
+ // Note that since we are at BrowserThread::Init time, the UI thread
+ // is blocked waiting for the thread to start. Therefore, posting
+ // this task to the main thread's message loop here is guaranteed to
+ // get it onto the message loop while the IOThread object still
+ // exists. However, the message might not be processed on the UI
+ // thread until after IOThread is gone, so use a weak pointer.
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&IOThread::InitSystemRequestContext,
+ weak_factory_.GetWeakPtr()));
+
+ // We constructed the weak pointer on the IO thread but it will be
+ // used on the UI thread. Call this to avoid a thread checker
+ // error.
+ weak_factory_.DetachFromThread();
}
void IOThread::CleanUp() {
@@ -520,10 +538,6 @@ void IOThread::CleanUp() {
base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
-
- // This will delete the |notification_service_|. Make sure it's done after
- // anything else can reference it.
- content::BrowserProcessSubThread::CleanUp();
}
// static
@@ -574,6 +588,11 @@ void IOThread::ClearHostCache() {
host_cache->clear();
}
+MessageLoop* IOThread::message_loop() const {
+ return BrowserThread::UnsafeGetBrowserThread(
+ BrowserThread::IO)->message_loop();
+}
+
net::SSLConfigService* IOThread::GetSSLConfigService() {
return ssl_config_service_manager_->Get();
}
@@ -593,6 +612,8 @@ void IOThread::InitSystemRequestContext() {
}
system_url_request_context_getter_ =
new SystemURLRequestContextGetter(this);
+ // Safe to post an unretained this pointer, since IOThread is
+ // guaranteed to outlive the IO BrowserThread.
message_loop()->PostTask(
FROM_HERE, base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
base::Unretained(this)));