OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // -------------------------------------------------------------------------- | 228 // -------------------------------------------------------------------------- |
229 // The following methods are called on the owner's thread in response to | 229 // The following methods are called on the owner's thread in response to |
230 // various net::URLRequest callbacks. The event hooks, defined below, trigger | 230 // various net::URLRequest callbacks. The event hooks, defined below, trigger |
231 // these methods asynchronously. | 231 // these methods asynchronously. |
232 | 232 |
233 void NotifyReceivedRedirect(const GURL& new_url, | 233 void NotifyReceivedRedirect(const GURL& new_url, |
234 const ResourceResponseInfo& info) { | 234 const ResourceResponseInfo& info) { |
235 bool has_new_first_party_for_cookies = false; | 235 bool has_new_first_party_for_cookies = false; |
236 GURL new_first_party_for_cookies; | 236 GURL new_first_party_for_cookies; |
237 if (peer_ && peer_->OnReceivedRedirect(new_url, info, | 237 if (peer_ && peer_->OnReceivedRedirect(new_url, info, |
| 238 base::TimeTicks(), base::TimeTicks(), |
238 &has_new_first_party_for_cookies, | 239 &has_new_first_party_for_cookies, |
239 &new_first_party_for_cookies)) { | 240 &new_first_party_for_cookies)) { |
240 g_io_thread->message_loop()->PostTask( | 241 g_io_thread->message_loop()->PostTask( |
241 FROM_HERE, | 242 FROM_HERE, |
242 base::Bind(&RequestProxy::AsyncFollowDeferredRedirect, this, | 243 base::Bind(&RequestProxy::AsyncFollowDeferredRedirect, this, |
243 has_new_first_party_for_cookies, | 244 has_new_first_party_for_cookies, |
244 new_first_party_for_cookies)); | 245 new_first_party_for_cookies)); |
245 } else { | 246 } else { |
246 Cancel(); | 247 Cancel(); |
247 } | 248 } |
248 } | 249 } |
249 | 250 |
250 void NotifyReceivedResponse(const ResourceResponseInfo& info) { | 251 void NotifyReceivedResponse(const ResourceResponseInfo& info) { |
251 if (peer_) | 252 if (peer_) |
252 peer_->OnReceivedResponse(info); | 253 peer_->OnReceivedResponse(info, base::TimeTicks(), base::TimeTicks()); |
253 } | 254 } |
254 | 255 |
255 void NotifyReceivedData(int bytes_read) { | 256 void NotifyReceivedData(int bytes_read) { |
256 if (!peer_) | 257 if (!peer_) |
257 return; | 258 return; |
258 | 259 |
259 // Make a local copy of buf_, since AsyncReadData reuses it. | 260 // Make a local copy of buf_, since AsyncReadData reuses it. |
260 scoped_array<char> buf_copy(new char[bytes_read]); | 261 scoped_array<char> buf_copy(new char[bytes_read]); |
261 memcpy(buf_copy.get(), buf_->data(), bytes_read); | 262 memcpy(buf_copy.get(), buf_->data(), bytes_read); |
262 | 263 |
(...skipping 18 matching lines...) Expand all Loading... |
281 // Continue reading more data, see the comment in NotifyReceivedData. | 282 // Continue reading more data, see the comment in NotifyReceivedData. |
282 g_io_thread->message_loop()->PostTask( | 283 g_io_thread->message_loop()->PostTask( |
283 FROM_HERE, | 284 FROM_HERE, |
284 base::Bind(&RequestProxy::AsyncReadData, this)); | 285 base::Bind(&RequestProxy::AsyncReadData, this)); |
285 | 286 |
286 peer_->OnDownloadedData(bytes_read); | 287 peer_->OnDownloadedData(bytes_read); |
287 } | 288 } |
288 | 289 |
289 void NotifyCompletedRequest(const net::URLRequestStatus& status, | 290 void NotifyCompletedRequest(const net::URLRequestStatus& status, |
290 const std::string& security_info, | 291 const std::string& security_info, |
291 const base::Time& complete_time) { | 292 const base::TimeTicks& complete_time) { |
292 if (peer_) { | 293 if (peer_) { |
293 peer_->OnCompletedRequest(status, security_info, complete_time); | 294 peer_->OnCompletedRequest(status, security_info, complete_time); |
294 DropPeer(); // ensure no further notifications | 295 DropPeer(); // ensure no further notifications |
295 } | 296 } |
296 } | 297 } |
297 | 298 |
298 void NotifyUploadProgress(uint64 position, uint64 size) { | 299 void NotifyUploadProgress(uint64 position, uint64 size) { |
299 if (peer_) | 300 if (peer_) |
300 peer_->OnUploadProgress(position, size); | 301 peer_->OnUploadProgress(position, size); |
301 } | 302 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 return; | 417 return; |
417 } | 418 } |
418 | 419 |
419 owner_loop_->PostTask( | 420 owner_loop_->PostTask( |
420 FROM_HERE, | 421 FROM_HERE, |
421 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); | 422 base::Bind(&RequestProxy::NotifyReceivedData, this, bytes_read)); |
422 } | 423 } |
423 | 424 |
424 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 425 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
425 const std::string& security_info, | 426 const std::string& security_info, |
426 const base::Time& complete_time) { | 427 const base::TimeTicks& complete_time) { |
427 if (download_to_file_) | 428 if (download_to_file_) |
428 file_stream_.Close(); | 429 file_stream_.Close(); |
429 owner_loop_->PostTask( | 430 owner_loop_->PostTask( |
430 FROM_HERE, | 431 FROM_HERE, |
431 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, | 432 base::Bind(&RequestProxy::NotifyCompletedRequest, this, status, |
432 security_info, complete_time)); | 433 security_info, complete_time)); |
433 } | 434 } |
434 | 435 |
435 // -------------------------------------------------------------------------- | 436 // -------------------------------------------------------------------------- |
436 // net::URLRequest::Delegate implementation: | 437 // net::URLRequest::Delegate implementation: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 if (upload_progress_timer_.IsRunning()) { | 513 if (upload_progress_timer_.IsRunning()) { |
513 MaybeUpdateUploadProgress(); | 514 MaybeUpdateUploadProgress(); |
514 upload_progress_timer_.Stop(); | 515 upload_progress_timer_.Stop(); |
515 } | 516 } |
516 DCHECK(request_.get()); | 517 DCHECK(request_.get()); |
517 // If |failed_file_request_status_| is not empty, which means the request | 518 // If |failed_file_request_status_| is not empty, which means the request |
518 // was a file request and encountered an error, then we need to use the | 519 // was a file request and encountered an error, then we need to use the |
519 // |failed_file_request_status_|. Otherwise use request_'s status. | 520 // |failed_file_request_status_|. Otherwise use request_'s status. |
520 OnCompletedRequest(failed_file_request_status_.get() ? | 521 OnCompletedRequest(failed_file_request_status_.get() ? |
521 *failed_file_request_status_ : request_->status(), | 522 *failed_file_request_status_ : request_->status(), |
522 std::string(), base::Time()); | 523 std::string(), base::TimeTicks()); |
523 request_.reset(); // destroy on the io thread | 524 request_.reset(); // destroy on the io thread |
524 } | 525 } |
525 | 526 |
526 // Called on the IO thread. | 527 // Called on the IO thread. |
527 void MaybeUpdateUploadProgress() { | 528 void MaybeUpdateUploadProgress() { |
528 // If a redirect is received upload is cancelled in net::URLRequest, we | 529 // If a redirect is received upload is cancelled in net::URLRequest, we |
529 // should try to stop the |upload_progress_timer_| timer and return. | 530 // should try to stop the |upload_progress_timer_| timer and return. |
530 if (!request_->has_upload()) { | 531 if (!request_->has_upload()) { |
531 if (upload_progress_timer_.IsRunning()) | 532 if (upload_progress_timer_.IsRunning()) |
532 upload_progress_timer_.Stop(); | 533 upload_progress_timer_.Stop(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 virtual void OnReceivedData(int bytes_read) { | 723 virtual void OnReceivedData(int bytes_read) { |
723 if (download_to_file_) | 724 if (download_to_file_) |
724 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); | 725 file_stream_.Write(buf_->data(), bytes_read, net::CompletionCallback()); |
725 else | 726 else |
726 result_->data.append(buf_->data(), bytes_read); | 727 result_->data.append(buf_->data(), bytes_read); |
727 AsyncReadData(); // read more (may recurse) | 728 AsyncReadData(); // read more (may recurse) |
728 } | 729 } |
729 | 730 |
730 virtual void OnCompletedRequest(const net::URLRequestStatus& status, | 731 virtual void OnCompletedRequest(const net::URLRequestStatus& status, |
731 const std::string& security_info, | 732 const std::string& security_info, |
732 const base::Time& complete_time) { | 733 const base::TimeTicks& complete_time) { |
733 if (download_to_file_) | 734 if (download_to_file_) |
734 file_stream_.Close(); | 735 file_stream_.Close(); |
735 result_->status = status; | 736 result_->status = status; |
736 event_.Signal(); | 737 event_.Signal(); |
737 } | 738 } |
738 | 739 |
739 private: | 740 private: |
740 ResourceLoaderBridge::SyncLoadResponse* result_; | 741 ResourceLoaderBridge::SyncLoadResponse* result_; |
741 base::WaitableEvent event_; | 742 base::WaitableEvent event_; |
742 }; | 743 }; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); | 1033 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); |
1033 g_file_over_http_params = new FileOverHTTPParams(file_path_template, | 1034 g_file_over_http_params = new FileOverHTTPParams(file_path_template, |
1034 http_prefix); | 1035 http_prefix); |
1035 } | 1036 } |
1036 | 1037 |
1037 // static | 1038 // static |
1038 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( | 1039 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( |
1039 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 1040 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
1040 return new ResourceLoaderBridgeImpl(request_info); | 1041 return new ResourceLoaderBridgeImpl(request_info); |
1041 } | 1042 } |
OLD | NEW |