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

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

Issue 10066044: RefCounted types should not have public destructors, webkit/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implementation ordering Created 8 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }; 102 };
103 103
104 //----------------------------------------------------------------------------- 104 //-----------------------------------------------------------------------------
105 105
106 bool g_accept_all_cookies = false; 106 bool g_accept_all_cookies = false;
107 107
108 class TestShellNetworkDelegate : public net::NetworkDelegate { 108 class TestShellNetworkDelegate : public net::NetworkDelegate {
109 public: 109 public:
110 virtual ~TestShellNetworkDelegate() {} 110 virtual ~TestShellNetworkDelegate() {}
111 111
112 private: 112 protected:
113 // net::NetworkDelegate implementation. 113 // net::NetworkDelegate implementation.
114 virtual int OnBeforeURLRequest(net::URLRequest* request, 114 virtual int OnBeforeURLRequest(net::URLRequest* request,
115 const net::CompletionCallback& callback, 115 const net::CompletionCallback& callback,
116 GURL* new_url) OVERRIDE { 116 GURL* new_url) OVERRIDE {
117 return net::OK; 117 return net::OK;
118 } 118 }
119 virtual int OnBeforeSendHeaders(net::URLRequest* request, 119 virtual int OnBeforeSendHeaders(net::URLRequest* request,
120 const net::CompletionCallback& callback, 120 const net::CompletionCallback& callback,
121 net::HttpRequestHeaders* headers) OVERRIDE { 121 net::HttpRequestHeaders* headers) OVERRIDE {
122 return net::OK; 122 return net::OK;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 std::string file_path_template; 188 std::string file_path_template;
189 GURL http_prefix; 189 GURL http_prefix;
190 }; 190 };
191 191
192 FileOverHTTPParams* g_file_over_http_params = NULL; 192 FileOverHTTPParams* g_file_over_http_params = NULL;
193 193
194 //----------------------------------------------------------------------------- 194 //-----------------------------------------------------------------------------
195 195
196 class IOThread : public base::Thread { 196 class IOThread : public base::Thread {
197 public: 197 public:
198 IOThread() : base::Thread("IOThread") { 198 IOThread() : base::Thread("IOThread") {}
199 }
200 199
201 ~IOThread() { 200 ~IOThread() {
202 Stop(); 201 Stop();
203 } 202 }
204 203
205 virtual void Init() { 204 virtual void Init() OVERRIDE {
206 if (g_request_context_params) { 205 if (g_request_context_params) {
207 g_request_context = new TestShellRequestContext( 206 g_request_context = new TestShellRequestContext(
208 g_request_context_params->cache_path, 207 g_request_context_params->cache_path,
209 g_request_context_params->cache_mode, 208 g_request_context_params->cache_mode,
210 g_request_context_params->no_proxy); 209 g_request_context_params->no_proxy);
211 delete g_request_context_params; 210 delete g_request_context_params;
212 g_request_context_params = NULL; 211 g_request_context_params = NULL;
213 } else { 212 } else {
214 g_request_context = new TestShellRequestContext(); 213 g_request_context = new TestShellRequestContext();
215 } 214 }
216 215
217 g_request_context->AddRef(); 216 g_request_context->AddRef();
218 217
219 g_network_delegate = new TestShellNetworkDelegate(); 218 g_network_delegate = new TestShellNetworkDelegate();
220 g_request_context->set_network_delegate(g_network_delegate); 219 g_request_context->set_network_delegate(g_network_delegate);
221 220
222 SimpleAppCacheSystem::InitializeOnIOThread(g_request_context); 221 SimpleAppCacheSystem::InitializeOnIOThread(g_request_context);
223 SimpleSocketStreamBridge::InitializeOnIOThread(g_request_context); 222 SimpleSocketStreamBridge::InitializeOnIOThread(g_request_context);
224 SimpleFileWriter::InitializeOnIOThread(g_request_context); 223 SimpleFileWriter::InitializeOnIOThread(g_request_context);
225 SimpleFileSystem::InitializeOnIOThread( 224 SimpleFileSystem::InitializeOnIOThread(
226 g_request_context->blob_storage_controller()); 225 g_request_context->blob_storage_controller());
227 TestShellWebBlobRegistryImpl::InitializeOnIOThread( 226 TestShellWebBlobRegistryImpl::InitializeOnIOThread(
228 g_request_context->blob_storage_controller()); 227 g_request_context->blob_storage_controller());
229 } 228 }
230 229
231 virtual void CleanUp() { 230 virtual void CleanUp() OVERRIDE {
232 // In reverse order of initialization. 231 // In reverse order of initialization.
233 TestShellWebBlobRegistryImpl::Cleanup(); 232 TestShellWebBlobRegistryImpl::Cleanup();
234 SimpleFileSystem::CleanupOnIOThread(); 233 SimpleFileSystem::CleanupOnIOThread();
235 SimpleFileWriter::CleanupOnIOThread(); 234 SimpleFileWriter::CleanupOnIOThread();
236 SimpleSocketStreamBridge::Cleanup(); 235 SimpleSocketStreamBridge::Cleanup();
237 SimpleAppCacheSystem::CleanupOnIOThread(); 236 SimpleAppCacheSystem::CleanupOnIOThread();
238 237
239 if (g_request_context) { 238 if (g_request_context) {
240 g_request_context->set_network_delegate(NULL); 239 g_request_context->set_network_delegate(NULL);
241 g_request_context->Release(); 240 g_request_context->Release();
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 public: 771 public:
773 explicit SyncRequestProxy(ResourceLoaderBridge::SyncLoadResponse* result) 772 explicit SyncRequestProxy(ResourceLoaderBridge::SyncLoadResponse* result)
774 : result_(result), event_(true, false) { 773 : result_(result), event_(true, false) {
775 } 774 }
776 775
777 void WaitForCompletion() { 776 void WaitForCompletion() {
778 event_.Wait(); 777 event_.Wait();
779 } 778 }
780 779
781 // -------------------------------------------------------------------------- 780 // --------------------------------------------------------------------------
782 // Event hooks that run on the IO thread: 781 // RequestProxy event hooks that run on the IO thread:
783 782
784 virtual void OnReceivedRedirect( 783 virtual void OnReceivedRedirect(
785 const GURL& new_url, 784 const GURL& new_url,
786 const ResourceResponseInfo& info, 785 const ResourceResponseInfo& info,
787 bool* defer_redirect) { 786 bool* defer_redirect) OVERRIDE {
788 // TODO(darin): It would be much better if this could live in WebCore, but 787 // TODO(darin): It would be much better if this could live in WebCore, but
789 // doing so requires API changes at all levels. Similar code exists in 788 // doing so requires API changes at all levels. Similar code exists in
790 // WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-( 789 // WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-(
791 if (new_url.GetOrigin() != result_->url.GetOrigin()) { 790 if (new_url.GetOrigin() != result_->url.GetOrigin()) {
792 DLOG(WARNING) << "Cross origin redirect denied"; 791 DLOG(WARNING) << "Cross origin redirect denied";
793 Cancel(); 792 Cancel();
794 return; 793 return;
795 } 794 }
796 result_->url = new_url; 795 result_->url = new_url;
797 } 796 }
798 797
799 virtual void OnReceivedResponse(const ResourceResponseInfo& info) { 798 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE {
800 *static_cast<ResourceResponseInfo*>(result_) = info; 799 *static_cast<ResourceResponseInfo*>(result_) = info;
801 } 800 }
802 801
803 virtual void OnReceivedData(int bytes_read) { 802 virtual void OnReceivedData(int bytes_read) OVERRIDE {
804 if (download_to_file_) 803 if (download_to_file_)
805 file_stream_.WriteSync(buf_->data(), bytes_read); 804 file_stream_.WriteSync(buf_->data(), bytes_read);
806 else 805 else
807 result_->data.append(buf_->data(), bytes_read); 806 result_->data.append(buf_->data(), bytes_read);
808 AsyncReadData(); // read more (may recurse) 807 AsyncReadData(); // read more (may recurse)
809 } 808 }
810 809
811 virtual void OnCompletedRequest(const net::URLRequestStatus& status, 810 virtual void OnCompletedRequest(
812 const std::string& security_info, 811 const net::URLRequestStatus& status,
813 const base::TimeTicks& complete_time) { 812 const std::string& security_info,
813 const base::TimeTicks& complete_time) OVERRIDE {
814 if (download_to_file_) 814 if (download_to_file_)
815 file_stream_.CloseSync(); 815 file_stream_.CloseSync();
816 result_->status = status; 816 result_->status = status;
817 event_.Signal(); 817 event_.Signal();
818 } 818 }
819 819
820 protected:
821 virtual ~SyncRequestProxy() {}
822
820 private: 823 private:
821 ResourceLoaderBridge::SyncLoadResponse* result_; 824 ResourceLoaderBridge::SyncLoadResponse* result_;
822 base::WaitableEvent event_; 825 base::WaitableEvent event_;
823 }; 826 };
824 827
825 //----------------------------------------------------------------------------- 828 //-----------------------------------------------------------------------------
826 829
827 class ResourceLoaderBridgeImpl : public ResourceLoaderBridge { 830 class ResourceLoaderBridgeImpl : public ResourceLoaderBridge {
828 public: 831 public:
829 ResourceLoaderBridgeImpl( 832 ResourceLoaderBridgeImpl(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 public: 945 public:
943 void Set(const GURL& url, const std::string& cookie) { 946 void Set(const GURL& url, const std::string& cookie) {
944 DCHECK(MessageLoop::current() == g_io_thread->message_loop()); 947 DCHECK(MessageLoop::current() == g_io_thread->message_loop());
945 g_request_context->cookie_store()->SetCookieWithOptionsAsync( 948 g_request_context->cookie_store()->SetCookieWithOptionsAsync(
946 url, cookie, net::CookieOptions(), 949 url, cookie, net::CookieOptions(),
947 net::CookieStore::SetCookiesCallback()); 950 net::CookieStore::SetCookiesCallback());
948 } 951 }
949 952
950 private: 953 private:
951 friend class base::RefCountedThreadSafe<CookieSetter>; 954 friend class base::RefCountedThreadSafe<CookieSetter>;
952
953 ~CookieSetter() {} 955 ~CookieSetter() {}
954 }; 956 };
955 957
956 class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> { 958 class CookieGetter : public base::RefCountedThreadSafe<CookieGetter> {
957 public: 959 public:
958 CookieGetter() : event_(false, false) { 960 CookieGetter() : event_(false, false) {
959 } 961 }
960 962
961 void Get(const GURL& url) { 963 void Get(const GURL& url) {
962 g_request_context->cookie_store()->GetCookiesWithOptionsAsync( 964 g_request_context->cookie_store()->GetCookiesWithOptionsAsync(
963 url, net::CookieOptions(), 965 url, net::CookieOptions(),
964 base::Bind(&CookieGetter::OnGetCookies, this)); 966 base::Bind(&CookieGetter::OnGetCookies, this));
965 } 967 }
966 968
967 std::string GetResult() { 969 std::string GetResult() {
968 event_.Wait(); 970 event_.Wait();
969 return result_; 971 return result_;
970 } 972 }
971 973
972 private: 974 private:
975 friend class base::RefCountedThreadSafe<CookieGetter>;
976 ~CookieGetter() {}
977
973 void OnGetCookies(const std::string& cookie_line) { 978 void OnGetCookies(const std::string& cookie_line) {
974 result_ = cookie_line; 979 result_ = cookie_line;
975 event_.Signal(); 980 event_.Signal();
976 } 981 }
977 friend class base::RefCountedThreadSafe<CookieGetter>;
978
979 ~CookieGetter() {}
980 982
981 base::WaitableEvent event_; 983 base::WaitableEvent event_;
982 std::string result_; 984 std::string result_;
983 }; 985 };
984 986
985 } // anonymous namespace 987 } // anonymous namespace
986 988
987 //----------------------------------------------------------------------------- 989 //-----------------------------------------------------------------------------
988 990
989 // static 991 // static
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); 1117 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https")));
1116 g_file_over_http_params = new FileOverHTTPParams(file_path_template, 1118 g_file_over_http_params = new FileOverHTTPParams(file_path_template,
1117 http_prefix); 1119 http_prefix);
1118 } 1120 }
1119 1121
1120 // static 1122 // static
1121 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( 1123 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create(
1122 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { 1124 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
1123 return new ResourceLoaderBridgeImpl(request_info); 1125 return new ResourceLoaderBridgeImpl(request_info);
1124 } 1126 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/simple_file_writer.cc ('k') | webkit/tools/test_shell/test_shell_webblobregistry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698