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..2374a3131db3c8747551f66827ef798a470972fe 100644 |
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc |
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc |
@@ -289,7 +289,7 @@ class RequestProxy : public net::URLRequest::Delegate, |
void Start(ResourceLoaderBridge::Peer* peer, RequestParams* params) { |
peer_ = peer; |
- owner_loop_ = MessageLoop::current(); |
+ owner_loop_ = base::MessageLoopProxy::current(); |
ConvertRequestParamsForFileOverHTTPIfNeeded(params); |
// proxy over to the io thread |
@@ -309,9 +309,8 @@ class RequestProxy : public net::URLRequest::Delegate, |
friend class base::RefCountedThreadSafe<RequestProxy>; |
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. |
+ DCHECK(MessageLoop::current() == g_io_thread->message_loop()); |
} |
// -------------------------------------------------------------------------- |
@@ -479,36 +478,44 @@ class RequestProxy : public net::URLRequest::Delegate, |
// The following methods are event hooks (corresponding to net::URLRequest |
// callbacks) that run on the IO thread. They are designed to be overridden |
// by the SyncRequestProxy subclass. |
+ // |
+ // Note that since |this| must be ultimately destroyed on the IO thread, each |
+ // of these uses a do-nothing reply closure to extend |this|'s lifetime long |
+ // enough to avoid being deleted on the owner thread. |
virtual void OnReceivedRedirect( |
const GURL& new_url, |
const ResourceResponseInfo& info, |
bool* defer_redirect) { |
*defer_redirect = true; // See AsyncFollowDeferredRedirect |
- owner_loop_->PostTask( |
+ owner_loop_->PostTaskAndReply( |
FROM_HERE, |
- base::Bind(&RequestProxy::NotifyReceivedRedirect, this, new_url, info)); |
+ base::Bind(&RequestProxy::NotifyReceivedRedirect, this, new_url, info), |
+ base::Bind(&RequestProxy::DoNothing, this)); |
} |
virtual void OnReceivedResponse( |
const ResourceResponseInfo& info) { |
- owner_loop_->PostTask( |
+ owner_loop_->PostTaskAndReply( |
FROM_HERE, |
- base::Bind(&RequestProxy::NotifyReceivedResponse, this, info)); |
+ base::Bind(&RequestProxy::NotifyReceivedResponse, this, info), |
+ base::Bind(&RequestProxy::DoNothing, this)); |
} |
virtual void OnReceivedData(int bytes_read) { |
if (download_to_file_) { |
file_stream_.WriteSync(buf_->data(), bytes_read); |
- owner_loop_->PostTask( |
+ owner_loop_->PostTaskAndReply( |
FROM_HERE, |
- base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read)); |
+ base::Bind(&RequestProxy::NotifyDownloadedData, this, bytes_read), |
+ base::Bind(&RequestProxy::DoNothing, this)); |
return; |
} |
- owner_loop_->PostTask( |
+ owner_loop_->PostTaskAndReply( |
FROM_HERE, |
- base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); |
+ base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read), |
+ base::Bind(&RequestProxy::DoNothing, this)); |
} |
virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
@@ -516,10 +523,11 @@ class RequestProxy : public net::URLRequest::Delegate, |
const base::TimeTicks& complete_time) { |
if (download_to_file_) |
file_stream_.CloseSync(); |
- owner_loop_->PostTask( |
+ owner_loop_->PostTaskAndReply( |
FROM_HERE, |
base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, |
- security_info, complete_time)); |
+ security_info, complete_time), |
+ base::Bind(&RequestProxy::DoNothing, this)); |
} |
// -------------------------------------------------------------------------- |
@@ -617,10 +625,10 @@ class RequestProxy : public net::URLRequest::Delegate, |
bool too_much_time_passed = time_since_last > kOneSecond; |
if (is_finished || enough_new_progress || too_much_time_passed) { |
- owner_loop_->PostTask( |
+ owner_loop_->PostTaskAndReply( |
FROM_HERE, |
- base::Bind(&RequestProxy::NotifyUploadProgress, this, position, |
- size)); |
+ base::Bind(&RequestProxy::NotifyUploadProgress, this, position, size), |
+ base::Bind(&RequestProxy::DoNothing, this)); |
last_upload_ticks_ = base::TimeTicks::Now(); |
last_upload_position_ = position; |
} |
@@ -731,7 +739,7 @@ class RequestProxy : public net::URLRequest::Delegate, |
// read buffer for async IO |
scoped_refptr<net::IOBuffer> buf_; |
- MessageLoop* owner_loop_; |
+ scoped_refptr<base::MessageLoopProxy> owner_loop_; |
// This is our peer in WebKit (implemented as ResourceHandleInternal). We do |
// not manage its lifetime, and we may only access it from the owner's |
@@ -749,6 +757,11 @@ class RequestProxy : public net::URLRequest::Delegate, |
std::string file_url_prefix_; |
// Save a failed file request status to pass it to webkit. |
scoped_ptr<net::URLRequestStatus> failed_file_request_status_; |
+ |
+ private: |
+ // Helper used to extend the lifetime of |this| to ensure deletion on the IO |
+ // thread. |
+ void DoNothing() {} |
}; |
//----------------------------------------------------------------------------- |