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

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

Issue 10834289: Split net::UploadData into two: for IPC and for upload handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + moved ResolveBlobRef from webkit_blob to webkit_glue Created 8 years, 4 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 | « webkit/glue/weburlloader_impl.cc ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "net/url_request/url_request.h" 61 #include "net/url_request/url_request.h"
62 #include "net/url_request/url_request_job.h" 62 #include "net/url_request/url_request_job.h"
63 #include "webkit/appcache/appcache_interfaces.h" 63 #include "webkit/appcache/appcache_interfaces.h"
64 #include "webkit/blob/blob_storage_controller.h" 64 #include "webkit/blob/blob_storage_controller.h"
65 #include "webkit/blob/blob_url_request_job.h" 65 #include "webkit/blob/blob_url_request_job.h"
66 #include "webkit/blob/shareable_file_reference.h" 66 #include "webkit/blob/shareable_file_reference.h"
67 #include "webkit/fileapi/file_system_context.h" 67 #include "webkit/fileapi/file_system_context.h"
68 #include "webkit/fileapi/file_system_dir_url_request_job.h" 68 #include "webkit/fileapi/file_system_dir_url_request_job.h"
69 #include "webkit/fileapi/file_system_url_request_job.h" 69 #include "webkit/fileapi/file_system_url_request_job.h"
70 #include "webkit/glue/resource_loader_bridge.h" 70 #include "webkit/glue/resource_loader_bridge.h"
71 #include "webkit/glue/resource_request_body.h"
71 #include "webkit/glue/webkit_glue.h" 72 #include "webkit/glue/webkit_glue.h"
72 #include "webkit/tools/test_shell/simple_appcache_system.h" 73 #include "webkit/tools/test_shell/simple_appcache_system.h"
73 #include "webkit/tools/test_shell/simple_file_system.h" 74 #include "webkit/tools/test_shell/simple_file_system.h"
74 #include "webkit/tools/test_shell/simple_file_writer.h" 75 #include "webkit/tools/test_shell/simple_file_writer.h"
75 #include "webkit/tools/test_shell/simple_socket_stream_bridge.h" 76 #include "webkit/tools/test_shell/simple_socket_stream_bridge.h"
76 #include "webkit/tools/test_shell/test_shell_request_context.h" 77 #include "webkit/tools/test_shell/test_shell_request_context.h"
77 #include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h" 78 #include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h"
78 79
79 #if defined(OS_MACOSX) || defined(OS_WIN) 80 #if defined(OS_MACOSX) || defined(OS_WIN)
80 #include "crypto/nss_util.h" 81 #include "crypto/nss_util.h"
81 #endif 82 #endif
82 83
83 using webkit_glue::ResourceLoaderBridge; 84 using webkit_glue::ResourceLoaderBridge;
85 using webkit_glue::ResourceRequestBody;
84 using webkit_glue::ResourceResponseInfo; 86 using webkit_glue::ResourceResponseInfo;
85 using net::StaticCookiePolicy; 87 using net::StaticCookiePolicy;
86 using net::HttpResponseHeaders; 88 using net::HttpResponseHeaders;
87 using webkit_blob::ShareableFileReference; 89 using webkit_blob::ShareableFileReference;
88 90
89 namespace { 91 namespace {
90 92
91 struct TestShellRequestContextParams { 93 struct TestShellRequestContextParams {
92 TestShellRequestContextParams( 94 TestShellRequestContextParams(
93 const FilePath& in_cache_path, 95 const FilePath& in_cache_path,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 std::string method; 274 std::string method;
273 GURL url; 275 GURL url;
274 GURL first_party_for_cookies; 276 GURL first_party_for_cookies;
275 GURL referrer; 277 GURL referrer;
276 WebKit::WebReferrerPolicy referrer_policy; 278 WebKit::WebReferrerPolicy referrer_policy;
277 std::string headers; 279 std::string headers;
278 int load_flags; 280 int load_flags;
279 ResourceType::Type request_type; 281 ResourceType::Type request_type;
280 int appcache_host_id; 282 int appcache_host_id;
281 bool download_to_file; 283 bool download_to_file;
282 scoped_refptr<net::UploadData> upload; 284 scoped_refptr<ResourceRequestBody> request_body;
283 }; 285 };
284 286
285 // The interval for calls to RequestProxy::MaybeUpdateUploadProgress 287 // The interval for calls to RequestProxy::MaybeUpdateUploadProgress
286 static const int kUpdateUploadProgressIntervalMsec = 100; 288 static const int kUpdateUploadProgressIntervalMsec = 100;
287 289
288 // The RequestProxy does most of its work on the IO thread. The Start and 290 // The RequestProxy does most of its work on the IO thread. The Start and
289 // Cancel methods are proxied over to the IO thread, where an net::URLRequest 291 // Cancel methods are proxied over to the IO thread, where an net::URLRequest
290 // object is instantiated. 292 // object is instantiated.
291 struct DeleteOnIOThread; // See below. 293 struct DeleteOnIOThread; // See below.
292 class RequestProxy 294 class RequestProxy
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 void NotifyUploadProgress(uint64 position, uint64 size) { 409 void NotifyUploadProgress(uint64 position, uint64 size) {
408 if (peer_) 410 if (peer_)
409 peer_->OnUploadProgress(position, size); 411 peer_->OnUploadProgress(position, size);
410 } 412 }
411 413
412 // -------------------------------------------------------------------------- 414 // --------------------------------------------------------------------------
413 // The following methods are called on the io thread. They correspond to 415 // The following methods are called on the io thread. They correspond to
414 // actions performed on the owner's thread. 416 // actions performed on the owner's thread.
415 417
416 void AsyncStart(RequestParams* params) { 418 void AsyncStart(RequestParams* params) {
417 // Might need to resolve the blob references in the upload data.
418 if (params->upload) {
419 static_cast<TestShellRequestContext*>(g_request_context)->
420 blob_storage_controller()->ResolveBlobReferencesInUploadData(
421 params->upload.get());
422 }
423
424 request_.reset(new net::URLRequest(params->url, this, g_request_context)); 419 request_.reset(new net::URLRequest(params->url, this, g_request_context));
425 request_->set_method(params->method); 420 request_->set_method(params->method);
426 request_->set_first_party_for_cookies(params->first_party_for_cookies); 421 request_->set_first_party_for_cookies(params->first_party_for_cookies);
427 request_->set_referrer(params->referrer.spec()); 422 request_->set_referrer(params->referrer.spec());
428 webkit_glue::ConfigureURLRequestForReferrerPolicy( 423 webkit_glue::ConfigureURLRequestForReferrerPolicy(
429 request_.get(), params->referrer_policy); 424 request_.get(), params->referrer_policy);
430 net::HttpRequestHeaders headers; 425 net::HttpRequestHeaders headers;
431 headers.AddHeadersFromString(params->headers); 426 headers.AddHeadersFromString(params->headers);
432 request_->SetExtraRequestHeaders(headers); 427 request_->SetExtraRequestHeaders(headers);
433 request_->set_load_flags(params->load_flags); 428 request_->set_load_flags(params->load_flags);
434 request_->set_upload(params->upload.get()); 429 if (params->request_body) {
430 request_->set_upload(
431 params->request_body->ResolveElementsAndCreateUploadData(
432 static_cast<TestShellRequestContext*>(g_request_context)->
433 blob_storage_controller()));
434 }
435 SimpleAppCacheSystem::SetExtraRequestInfo( 435 SimpleAppCacheSystem::SetExtraRequestInfo(
436 request_.get(), params->appcache_host_id, params->request_type); 436 request_.get(), params->appcache_host_id, params->request_type);
437 437
438 download_to_file_ = params->download_to_file; 438 download_to_file_ = params->download_to_file;
439 if (download_to_file_) { 439 if (download_to_file_) {
440 FilePath path; 440 FilePath path;
441 if (file_util::CreateTemporaryFile(&path)) { 441 if (file_util::CreateTemporaryFile(&path)) {
442 downloaded_file_ = ShareableFileReference::GetOrCreate( 442 downloaded_file_ = ShareableFileReference::GetOrCreate(
443 path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, 443 path, ShareableFileReference::DELETE_ON_FINAL_RELEASE,
444 base::MessageLoopProxy::current()); 444 base::MessageLoopProxy::current());
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 if (proxy_) { 867 if (proxy_) {
868 proxy_->DropPeer(); 868 proxy_->DropPeer();
869 // Let the proxy die on the IO thread 869 // Let the proxy die on the IO thread
870 g_io_thread->message_loop()->ReleaseSoon(FROM_HERE, proxy_); 870 g_io_thread->message_loop()->ReleaseSoon(FROM_HERE, proxy_);
871 } 871 }
872 } 872 }
873 873
874 // -------------------------------------------------------------------------- 874 // --------------------------------------------------------------------------
875 // ResourceLoaderBridge implementation: 875 // ResourceLoaderBridge implementation:
876 876
877 virtual void AppendDataToUpload(const char* data, int data_len) { 877 virtual void SetRequestBody(ResourceRequestBody* request_body) {
878 DCHECK(params_.get()); 878 DCHECK(params_.get());
879 if (!params_->upload) 879 DCHECK(!params_->request_body);
880 params_->upload = new net::UploadData(); 880 params_->request_body = request_body;
881 params_->upload->AppendBytes(data, data_len);
882 }
883
884 virtual void AppendFileRangeToUpload(
885 const FilePath& file_path,
886 uint64 offset,
887 uint64 length,
888 const base::Time& expected_modification_time) {
889 DCHECK(params_.get());
890 if (!params_->upload)
891 params_->upload = new net::UploadData();
892 params_->upload->AppendFileRange(file_path, offset, length,
893 expected_modification_time);
894 }
895
896 virtual void AppendBlobToUpload(const GURL& blob_url) {
897 DCHECK(params_.get());
898 if (!params_->upload)
899 params_->upload = new net::UploadData();
900 params_->upload->AppendBlob(blob_url);
901 }
902
903 virtual void SetUploadIdentifier(int64 identifier) {
904 DCHECK(params_.get());
905 if (!params_->upload)
906 params_->upload = new net::UploadData();
907 params_->upload->set_identifier(identifier);
908 } 881 }
909 882
910 virtual bool Start(Peer* peer) { 883 virtual bool Start(Peer* peer) {
911 DCHECK(!proxy_); 884 DCHECK(!proxy_);
912 885
913 if (!SimpleResourceLoaderBridge::EnsureIOThread()) 886 if (!SimpleResourceLoaderBridge::EnsureIOThread())
914 return false; 887 return false;
915 888
916 proxy_ = new RequestProxy(); 889 proxy_ = new RequestProxy();
917 proxy_->AddRef(); 890 proxy_->AddRef();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); 1107 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https")));
1135 g_file_over_http_params = new FileOverHTTPParams(file_path_template, 1108 g_file_over_http_params = new FileOverHTTPParams(file_path_template,
1136 http_prefix); 1109 http_prefix);
1137 } 1110 }
1138 1111
1139 // static 1112 // static
1140 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( 1113 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create(
1141 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { 1114 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
1142 return new ResourceLoaderBridgeImpl(request_info); 1115 return new ResourceLoaderBridgeImpl(request_info);
1143 } 1116 }
OLDNEW
« no previous file with comments | « webkit/glue/weburlloader_impl.cc ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698