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

Unified Diff: chrome/browser/browser_process_impl.cc

Issue 160447: Add checks to DEBUG mode that no instance of URLRequest or URLFetcher survive... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Sync client Created 11 years, 4 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 | « chrome/browser/browser_process_impl.h ('k') | chrome/browser/net/url_fetcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_process_impl.cc
===================================================================
--- chrome/browser/browser_process_impl.cc (revision 23063)
+++ chrome/browser/browser_process_impl.cc (working copy)
@@ -58,7 +58,7 @@
: ChromeThread(identifier) {
}
- ~BrowserProcessSubThread() {
+ virtual ~BrowserProcessSubThread() {
// We cannot rely on our base class to stop the thread since we want our
// CleanUp function to run.
Stop();
@@ -92,6 +92,26 @@
NotificationService* notification_service_;
};
+class IOThread : public BrowserProcessSubThread {
+ public:
+ IOThread() : BrowserProcessSubThread(ChromeThread::IO) {}
+
+ virtual ~IOThread() {
+ // We cannot rely on our base class to stop the thread since we want our
+ // CleanUp function to run.
+ Stop();
+ }
+
+ protected:
+ virtual void CleanUp() {
+ // URLFetcher and URLRequest instances must NOT outlive the IO thread.
+ base::LeakTracker<URLRequest>::CheckForLeaks();
+ base::LeakTracker<URLFetcher>::CheckForLeaks();
+
+ BrowserProcessSubThread::CleanUp();
+ }
+};
+
} // namespace
BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
@@ -172,13 +192,6 @@
resource_dispatcher_host()->Shutdown();
}
- // Shutdown DNS prefetching now to ensure that network stack objects
- // living on the IO thread get destroyed before the IO thread goes away.
- if (io_thread_.get()) {
- io_thread_->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(chrome_browser_net::EnsureDnsPrefetchShutdown));
- }
-
#if defined(OS_LINUX)
// The IO thread must outlive the BACKGROUND_X11 thread.
background_x11_thread_.reset();
@@ -187,7 +200,7 @@
// Need to stop io_thread_ before resource_dispatcher_host_, since
// io_thread_ may still deref ResourceDispatcherHost and handle resource
// request before going away.
- io_thread_.reset();
+ ResetIOThread();
// Clean up state that lives on the file_thread_ before it goes away.
if (resource_dispatcher_host_.get()) {
@@ -307,8 +320,7 @@
background_x11_thread_.swap(background_x11_thread);
#endif
- scoped_ptr<base::Thread> thread(
- new BrowserProcessSubThread(ChromeThread::IO));
+ scoped_ptr<base::Thread> thread(new IOThread);
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
if (!thread->StartWithOptions(options))
@@ -316,6 +328,22 @@
io_thread_.swap(thread);
}
+void BrowserProcessImpl::ResetIOThread() {
+ if (io_thread_.get()) {
+ io_thread_->message_loop()->PostTask(FROM_HERE,
+ NewRunnableFunction(CleanupOnIOThread));
+ }
+ io_thread_.reset();
+}
+
+// static
+void BrowserProcessImpl::CleanupOnIOThread() {
+ // Shutdown DNS prefetching now to ensure that network stack objects
+ // living on the IO thread get destroyed before the IO thread goes away.
+ chrome_browser_net::EnsureDnsPrefetchShutdown();
+ // TODO(eroman): can this be merged into IOThread::CleanUp() ?
+}
+
void BrowserProcessImpl::CreateFileThread() {
DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
created_file_thread_ = true;
« no previous file with comments | « chrome/browser/browser_process_impl.h ('k') | chrome/browser/net/url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698