Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: webkit/tools/test_shell/simple_resource_loader_bridge.cc

Issue 14520026: webkit: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 7 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
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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 buf_(new net::IOBuffer(kDataSize)), 336 buf_(new net::IOBuffer(kDataSize)),
337 last_upload_position_(0) { 337 last_upload_position_(0) {
338 } 338 }
339 339
340 void DropPeer() { 340 void DropPeer() {
341 peer_ = NULL; 341 peer_ = NULL;
342 } 342 }
343 343
344 void Start(ResourceLoaderBridge::Peer* peer, RequestParams* params) { 344 void Start(ResourceLoaderBridge::Peer* peer, RequestParams* params) {
345 peer_ = peer; 345 peer_ = peer;
346 owner_loop_ = MessageLoop::current(); 346 owner_loop_ = base::MessageLoop::current();
347 347
348 ConvertRequestParamsForFileOverHTTPIfNeeded(params); 348 ConvertRequestParamsForFileOverHTTPIfNeeded(params);
349 // proxy over to the io thread 349 // proxy over to the io thread
350 g_io_thread->message_loop()->PostTask( 350 g_io_thread->message_loop()->PostTask(
351 FROM_HERE, 351 FROM_HERE,
352 base::Bind(&RequestProxy::AsyncStart, this, params)); 352 base::Bind(&RequestProxy::AsyncStart, this, params));
353 } 353 }
354 354
355 void Cancel() { 355 void Cancel() {
356 // proxy over to the io thread 356 // proxy over to the io thread
357 g_io_thread->message_loop()->PostTask( 357 g_io_thread->message_loop()->PostTask(
358 FROM_HERE, 358 FROM_HERE,
359 base::Bind(&RequestProxy::AsyncCancel, this)); 359 base::Bind(&RequestProxy::AsyncCancel, this));
360 } 360 }
361 361
362 protected: 362 protected:
363 friend class base::DeleteHelper<RequestProxy>; 363 friend class base::DeleteHelper<RequestProxy>;
364 friend class base::RefCountedThreadSafe<RequestProxy>; 364 friend class base::RefCountedThreadSafe<RequestProxy>;
365 friend struct DeleteOnIOThread; 365 friend struct DeleteOnIOThread;
366 366
367 virtual ~RequestProxy() { 367 virtual ~RequestProxy() {
368 // Ensure we are deleted on the IO thread because base::Timer requires that. 368 // Ensure we are deleted on the IO thread because base::Timer requires that.
369 // (guaranteed by the Traits class template parameter). 369 // (guaranteed by the Traits class template parameter).
370 DCHECK(MessageLoop::current() == g_io_thread->message_loop()); 370 DCHECK(base::MessageLoop::current() == g_io_thread->message_loop());
371 } 371 }
372 372
373 // -------------------------------------------------------------------------- 373 // --------------------------------------------------------------------------
374 // The following methods are called on the owner's thread in response to 374 // The following methods are called on the owner's thread in response to
375 // various net::URLRequest callbacks. The event hooks, defined below, trigger 375 // various net::URLRequest callbacks. The event hooks, defined below, trigger
376 // these methods asynchronously. 376 // these methods asynchronously.
377 377
378 void NotifyReceivedRedirect(const GURL& new_url, 378 void NotifyReceivedRedirect(const GURL& new_url,
379 const ResourceResponseInfo& info) { 379 const ResourceResponseInfo& info) {
380 bool has_new_first_party_for_cookies = false; 380 bool has_new_first_party_for_cookies = false;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 bool download_to_file_; 792 bool download_to_file_;
793 scoped_ptr<net::FileStream> file_stream_; 793 scoped_ptr<net::FileStream> file_stream_;
794 scoped_refptr<ShareableFileReference> downloaded_file_; 794 scoped_refptr<ShareableFileReference> downloaded_file_;
795 795
796 // Size of our async IO data buffers 796 // Size of our async IO data buffers
797 static const int kDataSize = 16*1024; 797 static const int kDataSize = 16*1024;
798 798
799 // read buffer for async IO 799 // read buffer for async IO
800 scoped_refptr<net::IOBuffer> buf_; 800 scoped_refptr<net::IOBuffer> buf_;
801 801
802 MessageLoop* owner_loop_; 802 base::MessageLoop* owner_loop_;
803 803
804 // This is our peer in WebKit (implemented as ResourceHandleInternal). We do 804 // This is our peer in WebKit (implemented as ResourceHandleInternal). We do
805 // not manage its lifetime, and we may only access it from the owner's 805 // not manage its lifetime, and we may only access it from the owner's
806 // message loop (owner_loop_). 806 // message loop (owner_loop_).
807 ResourceLoaderBridge::Peer* peer_; 807 ResourceLoaderBridge::Peer* peer_;
808 808
809 // Timer used to pull upload progress info. 809 // Timer used to pull upload progress info.
810 base::RepeatingTimer<RequestProxy> upload_progress_timer_; 810 base::RepeatingTimer<RequestProxy> upload_progress_timer_;
811 811
812 // Info used to determine whether or not to send an upload progress update. 812 // Info used to determine whether or not to send an upload progress update.
813 uint64 last_upload_position_; 813 uint64 last_upload_position_;
814 base::TimeTicks last_upload_ticks_; 814 base::TimeTicks last_upload_ticks_;
815 815
816 // Save the real FILE URL prefix for the FILE URL which converts to HTTP URL. 816 // Save the real FILE URL prefix for the FILE URL which converts to HTTP URL.
817 std::string file_url_prefix_; 817 std::string file_url_prefix_;
818 // Save a failed file request status to pass it to webkit. 818 // Save a failed file request status to pass it to webkit.
819 scoped_ptr<net::URLRequestStatus> failed_file_request_status_; 819 scoped_ptr<net::URLRequestStatus> failed_file_request_status_;
820 }; 820 };
821 821
822 // Helper guaranteeing deletion on the IO thread (like 822 // Helper guaranteeing deletion on the IO thread (like
823 // content::BrowserThread::DeleteOnIOThread, but without the dependency). 823 // content::BrowserThread::DeleteOnIOThread, but without the dependency).
824 struct DeleteOnIOThread { 824 struct DeleteOnIOThread {
825 static void Destruct(const RequestProxy* obj) { 825 static void Destruct(const RequestProxy* obj) {
826 if (MessageLoop::current() == g_io_thread->message_loop()) 826 if (base::MessageLoop::current() == g_io_thread->message_loop())
827 delete obj; 827 delete obj;
828 else 828 else
829 g_io_thread->message_loop()->DeleteSoon(FROM_HERE, obj); 829 g_io_thread->message_loop()->DeleteSoon(FROM_HERE, obj);
830 } 830 }
831 }; 831 };
832 832
833 //----------------------------------------------------------------------------- 833 //-----------------------------------------------------------------------------
834 834
835 class SyncRequestProxy : public RequestProxy { 835 class SyncRequestProxy : public RequestProxy {
836 public: 836 public:
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 // The request proxy is allocated when we start the request, and then it 978 // The request proxy is allocated when we start the request, and then it
979 // sticks around until this ResourceLoaderBridge is destroyed. 979 // sticks around until this ResourceLoaderBridge is destroyed.
980 RequestProxy* proxy_; 980 RequestProxy* proxy_;
981 }; 981 };
982 982
983 //----------------------------------------------------------------------------- 983 //-----------------------------------------------------------------------------
984 984
985 class CookieSetter : public base::RefCountedThreadSafe<CookieSetter> { 985 class CookieSetter : public base::RefCountedThreadSafe<CookieSetter> {
986 public: 986 public:
987 void Set(const GURL& url, const std::string& cookie) { 987 void Set(const GURL& url, const std::string& cookie) {
988 DCHECK(MessageLoop::current() == g_io_thread->message_loop()); 988 DCHECK(base::MessageLoop::current() == g_io_thread->message_loop());
989 g_request_context->cookie_store()->SetCookieWithOptionsAsync( 989 g_request_context->cookie_store()
990 url, cookie, net::CookieOptions(), 990 ->SetCookieWithOptionsAsync(url,
brettw 2013/05/06 17:43:33 You didn't need to change this and I think the old
xhwang 2013/05/07 00:11:07 Done.
xhwang 2013/05/07 00:11:07 Done.
991 net::CookieStore::SetCookiesCallback()); 991 cookie,
992 net::CookieOptions(),
993 net::CookieStore::SetCookiesCallback());
992 } 994 }
993 995
994 private: 996 private:
995 friend class base::RefCountedThreadSafe<CookieSetter>; 997 friend class base::RefCountedThreadSafe<CookieSetter>;
996 ~CookieSetter() {} 998 ~CookieSetter() {}
997 }; 999 };
998 1000
999 class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> { 1001 class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> {
1000 public: 1002 public:
1001 CookieGetter() : event_(false, false) { 1003 CookieGetter() : event_(false, false) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 #if defined(OS_MACOSX) || defined(OS_WIN) 1114 #if defined(OS_MACOSX) || defined(OS_WIN)
1113 // We want to be sure to init NSPR on the main thread. 1115 // We want to be sure to init NSPR on the main thread.
1114 crypto::EnsureNSPRInit(); 1116 crypto::EnsureNSPRInit();
1115 #endif 1117 #endif
1116 1118
1117 // Create the cache thread. We want the cache thread to outlive the IO thread, 1119 // Create the cache thread. We want the cache thread to outlive the IO thread,
1118 // so its lifetime is bonded to the IO thread lifetime. 1120 // so its lifetime is bonded to the IO thread lifetime.
1119 DCHECK(!g_cache_thread); 1121 DCHECK(!g_cache_thread);
1120 g_cache_thread = new base::Thread("cache"); 1122 g_cache_thread = new base::Thread("cache");
1121 CHECK(g_cache_thread->StartWithOptions( 1123 CHECK(g_cache_thread->StartWithOptions(
1122 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1124 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
1123 1125
1124 g_io_thread = new IOThread(); 1126 g_io_thread = new IOThread();
1125 base::Thread::Options options; 1127 base::Thread::Options options;
1126 options.message_loop_type = MessageLoop::TYPE_IO; 1128 options.message_loop_type = base::MessageLoop::TYPE_IO;
1127 return g_io_thread->StartWithOptions(options); 1129 return g_io_thread->StartWithOptions(options);
1128 } 1130 }
1129 1131
1130 // static 1132 // static
1131 void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) { 1133 void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) {
1132 g_accept_all_cookies = accept_all_cookies; 1134 g_accept_all_cookies = accept_all_cookies;
1133 } 1135 }
1134 1136
1135 // static 1137 // static
1136 scoped_refptr<base::MessageLoopProxy> 1138 scoped_refptr<base::MessageLoopProxy>
(...skipping 20 matching lines...) Expand all
1157 if (!g_file_over_http_mappings) 1159 if (!g_file_over_http_mappings)
1158 g_file_over_http_mappings = new FileOverHTTPPathMappings(); 1160 g_file_over_http_mappings = new FileOverHTTPPathMappings();
1159 g_file_over_http_mappings->AddMapping(file_path_template, http_prefix); 1161 g_file_over_http_mappings->AddMapping(file_path_template, http_prefix);
1160 } 1162 }
1161 1163
1162 // static 1164 // static
1163 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( 1165 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create(
1164 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { 1166 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
1165 return new ResourceLoaderBridgeImpl(request_info); 1167 return new ResourceLoaderBridgeImpl(request_info);
1166 } 1168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698