OLD | NEW |
---|---|
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 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 // Called on the IO thread. | 611 // Called on the IO thread. |
612 void MaybeUpdateUploadProgress() { | 612 void MaybeUpdateUploadProgress() { |
613 // If a redirect is received upload is cancelled in net::URLRequest, we | 613 // If a redirect is received upload is cancelled in net::URLRequest, we |
614 // should try to stop the |upload_progress_timer_| timer and return. | 614 // should try to stop the |upload_progress_timer_| timer and return. |
615 if (!request_->has_upload()) { | 615 if (!request_->has_upload()) { |
616 if (upload_progress_timer_.IsRunning()) | 616 if (upload_progress_timer_.IsRunning()) |
617 upload_progress_timer_.Stop(); | 617 upload_progress_timer_.Stop(); |
618 return; | 618 return; |
619 } | 619 } |
620 | 620 |
621 // GetContentLengthSync() may perform file IO, but it's ok here, as file | 621 const net::UploadProgress progress = request_->GetUploadProgress(); |
darin (slow to review)
2012/08/29 22:36:16
nit: no need for 'const' here
hashimoto
2012/08/29 22:48:55
Done.
| |
622 // IO is not prohibited in IOThread defined in the file. | 622 if (progress.position == last_upload_position_) |
623 uint64 size = request_->get_upload_mutable()->GetContentLengthSync(); | |
624 uint64 position = request_->GetUploadProgress(); | |
625 if (position == last_upload_position_) | |
626 return; // no progress made since last time | 623 return; // no progress made since last time |
627 | 624 |
628 const uint64 kHalfPercentIncrements = 200; | 625 const uint64 kHalfPercentIncrements = 200; |
629 const base::TimeDelta kOneSecond = base::TimeDelta::FromMilliseconds(1000); | 626 const base::TimeDelta kOneSecond = base::TimeDelta::FromMilliseconds(1000); |
630 | 627 |
631 uint64 amt_since_last = position - last_upload_position_; | 628 uint64 amt_since_last = progress.position - last_upload_position_; |
632 base::TimeDelta time_since_last = base::TimeTicks::Now() - | 629 base::TimeDelta time_since_last = base::TimeTicks::Now() - |
633 last_upload_ticks_; | 630 last_upload_ticks_; |
634 | 631 |
635 bool is_finished = (size == position); | 632 bool is_finished = (progress.size == progress.position); |
636 bool enough_new_progress = (amt_since_last > (size / | 633 bool enough_new_progress = (amt_since_last > (progress.size / |
637 kHalfPercentIncrements)); | 634 kHalfPercentIncrements)); |
638 bool too_much_time_passed = time_since_last > kOneSecond; | 635 bool too_much_time_passed = time_since_last > kOneSecond; |
639 | 636 |
640 if (is_finished || enough_new_progress || too_much_time_passed) { | 637 if (is_finished || enough_new_progress || too_much_time_passed) { |
641 owner_loop_->PostTask( | 638 owner_loop_->PostTask( |
642 FROM_HERE, | 639 FROM_HERE, |
643 base::Bind(&RequestProxy::NotifyUploadProgress, this, position, | 640 base::Bind(&RequestProxy::NotifyUploadProgress, this, |
644 size)); | 641 progress.position, progress.size)); |
645 last_upload_ticks_ = base::TimeTicks::Now(); | 642 last_upload_ticks_ = base::TimeTicks::Now(); |
646 last_upload_position_ = position; | 643 last_upload_position_ = progress.position; |
647 } | 644 } |
648 } | 645 } |
649 | 646 |
650 void PopulateResponseInfo(net::URLRequest* request, | 647 void PopulateResponseInfo(net::URLRequest* request, |
651 ResourceResponseInfo* info) const { | 648 ResourceResponseInfo* info) const { |
652 info->request_time = request->request_time(); | 649 info->request_time = request->request_time(); |
653 info->response_time = request->response_time(); | 650 info->response_time = request->response_time(); |
654 info->headers = request->response_headers(); | 651 info->headers = request->response_headers(); |
655 request->GetMimeType(&info->mime_type); | 652 request->GetMimeType(&info->mime_type); |
656 request->GetCharset(&info->charset); | 653 request->GetCharset(&info->charset); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); | 1104 (http_prefix.SchemeIs("http") || http_prefix.SchemeIs("https"))); |
1108 g_file_over_http_params = new FileOverHTTPParams(file_path_template, | 1105 g_file_over_http_params = new FileOverHTTPParams(file_path_template, |
1109 http_prefix); | 1106 http_prefix); |
1110 } | 1107 } |
1111 | 1108 |
1112 // static | 1109 // static |
1113 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( | 1110 webkit_glue::ResourceLoaderBridge* SimpleResourceLoaderBridge::Create( |
1114 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 1111 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
1115 return new ResourceLoaderBridgeImpl(request_info); | 1112 return new ResourceLoaderBridgeImpl(request_info); |
1116 } | 1113 } |
OLD | NEW |