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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This file contains an implementation of the ResourceLoaderBridge class. 5 // This file contains an implementation of the ResourceLoaderBridge class.
6 // The class is implemented using net::URLRequest, meaning it is a "simple" 6 // The class is implemented using net::URLRequest, meaning it is a "simple"
7 // version that directly issues requests. The more complicated one used in the 7 // version that directly issues requests. The more complicated one used in the
8 // browser uses IPC. 8 // browser uses IPC.
9 // 9 //
10 // Because net::URLRequest only provides an asynchronous resource loading API, 10 // Because net::URLRequest only provides an asynchronous resource loading API,
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 bool download_to_file; 265 bool download_to_file;
266 scoped_refptr<net::UploadData> upload; 266 scoped_refptr<net::UploadData> upload;
267 }; 267 };
268 268
269 // The interval for calls to RequestProxy::MaybeUpdateUploadProgress 269 // The interval for calls to RequestProxy::MaybeUpdateUploadProgress
270 static const int kUpdateUploadProgressIntervalMsec = 100; 270 static const int kUpdateUploadProgressIntervalMsec = 100;
271 271
272 // The RequestProxy does most of its work on the IO thread. The Start and 272 // The RequestProxy does most of its work on the IO thread. The Start and
273 // Cancel methods are proxied over to the IO thread, where an net::URLRequest 273 // Cancel methods are proxied over to the IO thread, where an net::URLRequest
274 // object is instantiated. 274 // object is instantiated.
275 class RequestProxy : public net::URLRequest::Delegate, 275 struct DeleteOnIOThread; // See below.
276 public base::RefCountedThreadSafe<RequestProxy> { 276 class RequestProxy
277 : public net::URLRequest::Delegate,
278 public base::RefCountedThreadSafe<RequestProxy, DeleteOnIOThread> {
277 public: 279 public:
278 // Takes ownership of the params. 280 // Takes ownership of the params.
279 RequestProxy() 281 RequestProxy()
280 : download_to_file_(false), 282 : download_to_file_(false),
281 file_stream_(NULL), 283 file_stream_(NULL),
282 buf_(new net::IOBuffer(kDataSize)), 284 buf_(new net::IOBuffer(kDataSize)),
283 last_upload_position_(0) { 285 last_upload_position_(0) {
284 } 286 }
285 287
286 void DropPeer() { 288 void DropPeer() {
(...skipping 12 matching lines...) Expand all
299 } 301 }
300 302
301 void Cancel() { 303 void Cancel() {
302 // proxy over to the io thread 304 // proxy over to the io thread
303 g_io_thread->message_loop()->PostTask( 305 g_io_thread->message_loop()->PostTask(
304 FROM_HERE, 306 FROM_HERE,
305 base::Bind(&RequestProxy::AsyncCancel, this)); 307 base::Bind(&RequestProxy::AsyncCancel, this));
306 } 308 }
307 309
308 protected: 310 protected:
311 friend class base::DeleteHelper<RequestProxy>;
309 friend class base::RefCountedThreadSafe<RequestProxy>; 312 friend class base::RefCountedThreadSafe<RequestProxy>;
313 friend struct DeleteOnIOThread;
310 314
311 virtual ~RequestProxy() { 315 virtual ~RequestProxy() {
312 // If we have a request, then we'd better be on the io thread! 316 // Ensure we are deleted on the IO thread because base::Timer requires that.
313 DCHECK(!request_.get() || 317 // (guaranteed by the Traits class template parameter).
314 MessageLoop::current() == g_io_thread->message_loop()); 318 DCHECK(MessageLoop::current() == g_io_thread->message_loop());
315 } 319 }
316 320
317 // -------------------------------------------------------------------------- 321 // --------------------------------------------------------------------------
318 // The following methods are called on the owner's thread in response to 322 // The following methods are called on the owner's thread in response to
319 // various net::URLRequest callbacks. The event hooks, defined below, trigger 323 // various net::URLRequest callbacks. The event hooks, defined below, trigger
320 // these methods asynchronously. 324 // these methods asynchronously.
321 325
322 void NotifyReceivedRedirect(const GURL& new_url, 326 void NotifyReceivedRedirect(const GURL& new_url,
323 const ResourceResponseInfo& info) { 327 const ResourceResponseInfo& info) {
324 bool has_new_first_party_for_cookies = false; 328 bool has_new_first_party_for_cookies = false;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // Info used to determine whether or not to send an upload progress update. 748 // Info used to determine whether or not to send an upload progress update.
745 uint64 last_upload_position_; 749 uint64 last_upload_position_;
746 base::TimeTicks last_upload_ticks_; 750 base::TimeTicks last_upload_ticks_;
747 751
748 // Save the real FILE URL prefix for the FILE URL which converts to HTTP URL. 752 // Save the real FILE URL prefix for the FILE URL which converts to HTTP URL.
749 std::string file_url_prefix_; 753 std::string file_url_prefix_;
750 // Save a failed file request status to pass it to webkit. 754 // Save a failed file request status to pass it to webkit.
751 scoped_ptr<net::URLRequestStatus> failed_file_request_status_; 755 scoped_ptr<net::URLRequestStatus> failed_file_request_status_;
752 }; 756 };
753 757
758 // Helper guaranteeing deletion on the IO thread (like
759 // content::BrowserThread::DeleteOnIOThread, but without the dependency).
760 struct DeleteOnIOThread {
761 static void Destruct(const RequestProxy* obj) {
762 if (MessageLoop::current() == g_io_thread->message_loop())
763 delete obj;
764 else
765 g_io_thread->message_loop()->DeleteSoon(FROM_HERE, obj);
766 }
767 };
768
754 //----------------------------------------------------------------------------- 769 //-----------------------------------------------------------------------------
755 770
756 class SyncRequestProxy : public RequestProxy { 771 class SyncRequestProxy : public RequestProxy {
757 public: 772 public:
758 explicit SyncRequestProxy(ResourceLoaderBridge::SyncLoadResponse* result) 773 explicit SyncRequestProxy(ResourceLoaderBridge::SyncLoadResponse* result)
759 : result_(result), event_(true, false) { 774 : result_(result), event_(true, false) {
760 } 775 }
761 776
762 void WaitForCompletion() { 777 void WaitForCompletion() {
763 event_.Wait(); 778 event_.Wait();
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); 1115 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https")));
1101 g_file_over_http_params = new FileOverHTTPParams(file_path_template, 1116 g_file_over_http_params = new FileOverHTTPParams(file_path_template,
1102 http_prefix); 1117 http_prefix);
1103 } 1118 }
1104 1119
1105 // static 1120 // static
1106 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( 1121 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create(
1107 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { 1122 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
1108 return new ResourceLoaderBridgeImpl(request_info); 1123 return new ResourceLoaderBridgeImpl(request_info);
1109 } 1124 }
OLDNEW
« 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