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

Unified Diff: webkit/tools/test_shell/simple_resource_loader_bridge.cc

Issue 10012010: Force deletion of test_shell's RequestProxy on the IO thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use traits instead of PTAR. Created 8 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/tools/test_shell/simple_resource_loader_bridge.cc
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
index b604babf3a08feb6c289f154ff2d9b246a52561c..374fb7061fc28b23ad28c223dff821963d437d4d 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
@@ -272,8 +272,10 @@ static const int kUpdateUploadProgressIntervalMsec = 100;
// The RequestProxy does most of its work on the IO thread. The Start and
// Cancel methods are proxied over to the IO thread, where an net::URLRequest
// object is instantiated.
-class RequestProxy : public net::URLRequest::Delegate,
- public base::RefCountedThreadSafe<RequestProxy> {
+struct DeleteOnIOThread; // See below.
+class RequestProxy
+ : public net::URLRequest::Delegate,
+ public base::RefCountedThreadSafe<RequestProxy, DeleteOnIOThread> {
public:
// Takes ownership of the params.
RequestProxy()
@@ -306,12 +308,14 @@ class RequestProxy : public net::URLRequest::Delegate,
}
protected:
+ friend class base::DeleteHelper<RequestProxy>;
friend class base::RefCountedThreadSafe<RequestProxy>;
+ friend struct DeleteOnIOThread;
virtual ~RequestProxy() {
- // If we have a request, then we'd better be on the io thread!
- DCHECK(!request_.get() ||
- MessageLoop::current() == g_io_thread->message_loop());
+ // Ensure we are deleted on the IO thread because base::Timer requires that.
+ // (guaranteed by the Traits class template parameter).
+ DCHECK(MessageLoop::current() == g_io_thread->message_loop());
}
// --------------------------------------------------------------------------
@@ -751,6 +755,17 @@ class RequestProxy : public net::URLRequest::Delegate,
scoped_ptr<net::URLRequestStatus> failed_file_request_status_;
};
+// Helper guaranteeing deletion on the IO thread (like
+// content::BrowserThread::DeleteOnIOThread, but without the dependency).
+struct DeleteOnIOThread {
+ static void Destruct(const RequestProxy* obj) {
+ if (MessageLoop::current() == g_io_thread->message_loop())
+ delete obj;
+ else
+ g_io_thread->message_loop()->DeleteSoon(FROM_HERE, obj);
+ }
+};
+
//-----------------------------------------------------------------------------
class SyncRequestProxy : public RequestProxy {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698