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

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

Issue 2249005: AppCache: Use a dedicated thread for the disk cache. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Bound to IO thread Created 10 years, 6 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 URLRequest, meaning it is a "simple" version 6 // The class is implemented using URLRequest, meaning it is a "simple" version
7 // that directly issues requests. The more complicated one used in the 7 // that directly issues requests. The more complicated one used in the
8 // browser uses IPC. 8 // browser uses IPC.
9 // 9 //
10 // Because URLRequest only provides an asynchronous resource loading API, this 10 // Because URLRequest only provides an asynchronous resource loading API, this
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 accept_all_cookies(false) {} 79 accept_all_cookies(false) {}
80 80
81 FilePath cache_path; 81 FilePath cache_path;
82 net::HttpCache::Mode cache_mode; 82 net::HttpCache::Mode cache_mode;
83 bool no_proxy; 83 bool no_proxy;
84 bool accept_all_cookies; 84 bool accept_all_cookies;
85 }; 85 };
86 86
87 TestShellRequestContextParams* g_request_context_params = NULL; 87 TestShellRequestContextParams* g_request_context_params = NULL;
88 URLRequestContext* g_request_context = NULL; 88 URLRequestContext* g_request_context = NULL;
89 base::Thread* g_cache_thread = NULL;
89 90
90 //----------------------------------------------------------------------------- 91 //-----------------------------------------------------------------------------
91 92
92 class IOThread : public base::Thread { 93 class IOThread : public base::Thread {
93 public: 94 public:
94 IOThread() : base::Thread("IOThread") { 95 IOThread() : base::Thread("IOThread") {
95 } 96 }
96 97
97 ~IOThread() { 98 ~IOThread() {
98 // We cannot rely on our base class to stop the thread since we want our 99 // We cannot rely on our base class to stop the thread since we want our
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 g_request_context_params = new TestShellRequestContextParams( 727 g_request_context_params = new TestShellRequestContextParams(
727 cache_path, cache_mode, no_proxy); 728 cache_path, cache_mode, no_proxy);
728 } 729 }
729 730
730 // static 731 // static
731 void SimpleResourceLoaderBridge::Shutdown() { 732 void SimpleResourceLoaderBridge::Shutdown() {
732 if (g_io_thread) { 733 if (g_io_thread) {
733 delete g_io_thread; 734 delete g_io_thread;
734 g_io_thread = NULL; 735 g_io_thread = NULL;
735 736
737 DCHECK(g_cache_thread);
738 delete g_cache_thread;
739 g_cache_thread = NULL;
740
736 DCHECK(!g_request_context) << "should have been nulled by thread dtor"; 741 DCHECK(!g_request_context) << "should have been nulled by thread dtor";
737 } else { 742 } else {
738 delete g_request_context_params; 743 delete g_request_context_params;
739 g_request_context_params = NULL; 744 g_request_context_params = NULL;
740 } 745 }
741 } 746 }
742 747
743 // static 748 // static
744 void SimpleResourceLoaderBridge::SetCookie(const GURL& url, 749 void SimpleResourceLoaderBridge::SetCookie(const GURL& url,
745 const GURL& first_party_for_cookies, 750 const GURL& first_party_for_cookies,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 786
782 #if defined(OS_WIN) 787 #if defined(OS_WIN)
783 // Use NSS for SSL on Windows. TODO(wtc): this should eventually be hidden 788 // Use NSS for SSL on Windows. TODO(wtc): this should eventually be hidden
784 // inside DefaultClientSocketFactory::CreateSSLClientSocket. 789 // inside DefaultClientSocketFactory::CreateSSLClientSocket.
785 net::ClientSocketFactory::SetSSLClientSocketFactory( 790 net::ClientSocketFactory::SetSSLClientSocketFactory(
786 net::SSLClientSocketNSSFactory); 791 net::SSLClientSocketNSSFactory);
787 // We want to be sure to init NSPR on the main thread. 792 // We want to be sure to init NSPR on the main thread.
788 base::EnsureNSPRInit(); 793 base::EnsureNSPRInit();
789 #endif 794 #endif
790 795
796 // Create the cache thread. We want the cache thread to outlive the IO thread,
797 // so its lifetime is bonded to the IO thread lifetime.
798 DCHECK(!g_cache_thread);
799 g_cache_thread = new base::Thread("cache");
800 CHECK(g_cache_thread->StartWithOptions(
801 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
802
791 g_io_thread = new IOThread(); 803 g_io_thread = new IOThread();
792 base::Thread::Options options; 804 base::Thread::Options options;
793 options.message_loop_type = MessageLoop::TYPE_IO; 805 options.message_loop_type = MessageLoop::TYPE_IO;
794 return g_io_thread->StartWithOptions(options); 806 return g_io_thread->StartWithOptions(options);
795 } 807 }
796 808
797 // static 809 // static
798 void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) { 810 void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) {
799 if (g_request_context_params) { 811 if (g_request_context_params) {
800 g_request_context_params->accept_all_cookies = accept_all_cookies; 812 g_request_context_params->accept_all_cookies = accept_all_cookies;
801 DCHECK(!g_request_context); 813 DCHECK(!g_request_context);
802 DCHECK(!g_io_thread); 814 DCHECK(!g_io_thread);
803 } else { 815 } else {
804 g_io_thread->SetAcceptAllCookies(accept_all_cookies); 816 g_io_thread->SetAcceptAllCookies(accept_all_cookies);
805 } 817 }
806 } 818 }
819
820 // static
821 scoped_refptr<base::MessageLoopProxy>
822 SimpleResourceLoaderBridge::GetCacheThread() {
823 return g_cache_thread->message_loop_proxy();
824 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/simple_resource_loader_bridge.h ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698