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

Side by Side Diff: net/url_request/url_fetcher_core.cc

Issue 2653183006: Make URLFetcherCore::ReleaseRequest() release |buffer_|. (Closed)
Patch Set: address comment Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | 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 #include "net/url_request/url_fetcher_core.h" 5 #include "net/url_request/url_fetcher_core.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const GURL& original_url, 75 const GURL& original_url,
76 URLFetcher::RequestType request_type, 76 URLFetcher::RequestType request_type,
77 URLFetcherDelegate* d) 77 URLFetcherDelegate* d)
78 : fetcher_(fetcher), 78 : fetcher_(fetcher),
79 original_url_(original_url), 79 original_url_(original_url),
80 request_type_(request_type), 80 request_type_(request_type),
81 delegate_(d), 81 delegate_(d),
82 delegate_task_runner_(base::SequencedTaskRunnerHandle::Get()), 82 delegate_task_runner_(base::SequencedTaskRunnerHandle::Get()),
83 load_flags_(LOAD_NORMAL), 83 load_flags_(LOAD_NORMAL),
84 response_code_(URLFetcher::RESPONSE_CODE_INVALID), 84 response_code_(URLFetcher::RESPONSE_CODE_INVALID),
85 buffer_(new IOBuffer(kBufferSize)),
86 url_request_data_key_(NULL), 85 url_request_data_key_(NULL),
87 was_fetched_via_proxy_(false), 86 was_fetched_via_proxy_(false),
88 was_cached_(false), 87 was_cached_(false),
89 received_response_content_length_(0), 88 received_response_content_length_(0),
90 total_received_bytes_(0), 89 total_received_bytes_(0),
91 upload_content_set_(false), 90 upload_content_set_(false),
92 upload_range_offset_(0), 91 upload_range_offset_(0),
93 upload_range_length_(0), 92 upload_range_length_(0),
94 referrer_policy_( 93 referrer_policy_(
95 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), 94 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 DCHECK(network_task_runner_->BelongsToCurrentThread()); 449 DCHECK(network_task_runner_->BelongsToCurrentThread());
451 450
452 if (!stopped_on_redirect_) 451 if (!stopped_on_redirect_)
453 url_ = request->url(); 452 url_ = request->url();
454 URLRequestThrottlerManager* throttler_manager = 453 URLRequestThrottlerManager* throttler_manager =
455 request->context()->throttler_manager(); 454 request->context()->throttler_manager();
456 if (throttler_manager) 455 if (throttler_manager)
457 url_throttler_entry_ = throttler_manager->RegisterRequestUrl(url_); 456 url_throttler_entry_ = throttler_manager->RegisterRequestUrl(url_);
458 457
459 while (bytes_read > 0) { 458 while (bytes_read > 0) {
459 DCHECK(buffer_);
460 current_response_bytes_ += bytes_read; 460 current_response_bytes_ += bytes_read;
461 InformDelegateDownloadProgress(); 461 InformDelegateDownloadProgress();
462 462
463 const int result = 463 const int result =
464 WriteBuffer(new DrainableIOBuffer(buffer_.get(), bytes_read)); 464 WriteBuffer(new DrainableIOBuffer(buffer_.get(), bytes_read));
465 if (result < 0) { 465 if (result < 0) {
466 // Write failed or waiting for write completion. 466 // Write failed or waiting for write completion.
467 return; 467 return;
468 } 468 }
469 bytes_read = request_->Read(buffer_.get(), kBufferSize); 469 bytes_read = request_->Read(buffer_.get(), kBufferSize);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 CancelURLRequest(result); 809 CancelURLRequest(result);
810 delegate_task_runner_->PostTask( 810 delegate_task_runner_->PostTask(
811 FROM_HERE, 811 FROM_HERE,
812 base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, this)); 812 base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, this));
813 } 813 }
814 814
815 void URLFetcherCore::ReleaseRequest() { 815 void URLFetcherCore::ReleaseRequest() {
816 request_context_getter_->RemoveObserver(this); 816 request_context_getter_->RemoveObserver(this);
817 upload_progress_checker_timer_.reset(); 817 upload_progress_checker_timer_.reset();
818 request_.reset(); 818 request_.reset();
819 buffer_ = nullptr;
819 g_registry.Get().RemoveURLFetcherCore(this); 820 g_registry.Get().RemoveURLFetcherCore(this);
820 } 821 }
821 822
822 base::TimeTicks URLFetcherCore::GetBackoffReleaseTime() { 823 base::TimeTicks URLFetcherCore::GetBackoffReleaseTime() {
823 DCHECK(network_task_runner_->BelongsToCurrentThread()); 824 DCHECK(network_task_runner_->BelongsToCurrentThread());
824 825
825 if (!original_url_throttler_entry_.get()) 826 if (!original_url_throttler_entry_.get())
826 return base::TimeTicks(); 827 return base::TimeTicks();
827 828
828 base::TimeTicks original_url_backoff = 829 base::TimeTicks original_url_backoff =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 if (request_.get()) 882 if (request_.get())
882 ReadResponse(); 883 ReadResponse();
883 } 884 }
884 885
885 void URLFetcherCore::ReadResponse() { 886 void URLFetcherCore::ReadResponse() {
886 // Some servers may treat HEAD requests as GET requests. To free up the 887 // Some servers may treat HEAD requests as GET requests. To free up the
887 // network connection as soon as possible, signal that the request has 888 // network connection as soon as possible, signal that the request has
888 // completed immediately, without trying to read any data back (all we care 889 // completed immediately, without trying to read any data back (all we care
889 // about is the response code and headers, which we already have). 890 // about is the response code and headers, which we already have).
890 int bytes_read = 0; 891 int bytes_read = 0;
891 if (request_type_ != URLFetcher::HEAD) 892 if (request_type_ != URLFetcher::HEAD) {
893 if (!buffer_)
894 buffer_ = new IOBuffer(kBufferSize);
mmenke 2017/01/25 16:32:16 Just do this unconditionally in OnResponseStarted,
xunjieli 2017/01/25 16:41:53 Done.
892 bytes_read = request_->Read(buffer_.get(), kBufferSize); 895 bytes_read = request_->Read(buffer_.get(), kBufferSize);
896 }
893 897
894 OnReadCompleted(request_.get(), bytes_read); 898 OnReadCompleted(request_.get(), bytes_read);
895 } 899 }
896 900
897 void URLFetcherCore::InformDelegateUploadProgress() { 901 void URLFetcherCore::InformDelegateUploadProgress() {
898 DCHECK(network_task_runner_->BelongsToCurrentThread()); 902 DCHECK(network_task_runner_->BelongsToCurrentThread());
899 if (request_.get()) { 903 if (request_.get()) {
900 int64_t current = request_->GetUploadProgress().position(); 904 int64_t current = request_->GetUploadProgress().position();
901 if (current_upload_bytes_ != current) { 905 if (current_upload_bytes_ != current) {
902 current_upload_bytes_ = current; 906 current_upload_bytes_ = current;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 956 }
953 957
954 void URLFetcherCore::AssertHasNoUploadData() const { 958 void URLFetcherCore::AssertHasNoUploadData() const {
955 DCHECK(!upload_content_set_); 959 DCHECK(!upload_content_set_);
956 DCHECK(upload_content_.empty()); 960 DCHECK(upload_content_.empty());
957 DCHECK(upload_file_path_.empty()); 961 DCHECK(upload_file_path_.empty());
958 DCHECK(upload_stream_factory_.is_null()); 962 DCHECK(upload_stream_factory_.is_null());
959 } 963 }
960 964
961 } // namespace net 965 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698