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 #include "net/url_request/url_fetcher_core.h" | 5 #include "net/url_request/url_fetcher_core.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util_proxy.h" | 8 #include "base/file_util_proxy.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 URLFetcherCore::FileWriter::~FileWriter() { | 67 URLFetcherCore::FileWriter::~FileWriter() { |
68 CloseAndDeleteFile(); | 68 CloseAndDeleteFile(); |
69 } | 69 } |
70 | 70 |
71 void URLFetcherCore::FileWriter::CreateFileAtPath( | 71 void URLFetcherCore::FileWriter::CreateFileAtPath( |
72 const FilePath& file_path) { | 72 const FilePath& file_path) { |
73 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 73 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
74 DCHECK(file_task_runner_.get()); | 74 DCHECK(file_task_runner_.get()); |
75 base::FileUtilProxy::CreateOrOpen( | 75 base::FileUtilProxy::CreateOrOpen( |
76 file_task_runner_, | 76 file_task_runner_.get(), |
77 file_path, | 77 file_path, |
78 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, | 78 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, |
79 base::Bind(&URLFetcherCore::FileWriter::DidCreateFile, | 79 base::Bind(&URLFetcherCore::FileWriter::DidCreateFile, |
80 weak_factory_.GetWeakPtr(), | 80 weak_factory_.GetWeakPtr(), |
81 file_path)); | 81 file_path)); |
82 } | 82 } |
83 | 83 |
84 void URLFetcherCore::FileWriter::CreateTempFile() { | 84 void URLFetcherCore::FileWriter::CreateTempFile() { |
85 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 85 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
86 DCHECK(file_task_runner_.get()); | 86 DCHECK(file_task_runner_.get()); |
87 base::FileUtilProxy::CreateTemporary( | 87 base::FileUtilProxy::CreateTemporary( |
88 file_task_runner_, | 88 file_task_runner_.get(), |
89 0, // No additional file flags. | 89 0, // No additional file flags. |
90 base::Bind(&URLFetcherCore::FileWriter::DidCreateTempFile, | 90 base::Bind(&URLFetcherCore::FileWriter::DidCreateTempFile, |
91 weak_factory_.GetWeakPtr())); | 91 weak_factory_.GetWeakPtr())); |
92 } | 92 } |
93 | 93 |
94 void URLFetcherCore::FileWriter::WriteBuffer(int num_bytes) { | 94 void URLFetcherCore::FileWriter::WriteBuffer(int num_bytes) { |
95 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 95 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
96 | 96 |
97 // Start writing to the file by setting the initial state | 97 // Start writing to the file by setting the initial state |
98 // of |pending_bytes_| and |buffer_offset_| to indicate that the | 98 // of |pending_bytes_| and |buffer_offset_| to indicate that the |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_)); | 130 base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_)); |
131 return; | 131 return; |
132 } | 132 } |
133 | 133 |
134 total_bytes_written_ += bytes_written; | 134 total_bytes_written_ += bytes_written; |
135 buffer_offset_ += bytes_written; | 135 buffer_offset_ += bytes_written; |
136 pending_bytes_ -= bytes_written; | 136 pending_bytes_ -= bytes_written; |
137 | 137 |
138 if (pending_bytes_ > 0) { | 138 if (pending_bytes_ > 0) { |
139 base::FileUtilProxy::Write( | 139 base::FileUtilProxy::Write( |
140 file_task_runner_, file_handle_, | 140 file_task_runner_.get(), file_handle_, |
141 total_bytes_written_, // Append to the end | 141 total_bytes_written_, // Append to the end |
142 (core_->buffer_->data() + buffer_offset_), pending_bytes_, | 142 (core_->buffer_->data() + buffer_offset_), pending_bytes_, |
143 base::Bind(&URLFetcherCore::FileWriter::ContinueWrite, | 143 base::Bind(&URLFetcherCore::FileWriter::ContinueWrite, |
144 weak_factory_.GetWeakPtr())); | 144 weak_factory_.GetWeakPtr())); |
145 } else { | 145 } else { |
146 // Finished writing core_->buffer_ to the file. Read some more. | 146 // Finished writing core_->buffer_ to the file. Read some more. |
147 core_->ReadResponse(); | 147 core_->ReadResponse(); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void URLFetcherCore::FileWriter::DisownFile() { | 151 void URLFetcherCore::FileWriter::DisownFile() { |
152 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 152 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
153 | 153 |
154 // Disowning is done by the delegate's OnURLFetchComplete method. | 154 // Disowning is done by the delegate's OnURLFetchComplete method. |
155 // The file should be closed by the time that method is called. | 155 // The file should be closed by the time that method is called. |
156 DCHECK(file_handle_ == base::kInvalidPlatformFileValue); | 156 DCHECK(file_handle_ == base::kInvalidPlatformFileValue); |
157 | 157 |
158 // Forget about any file by reseting the path. | 158 // Forget about any file by reseting the path. |
159 file_path_.clear(); | 159 file_path_.clear(); |
160 } | 160 } |
161 | 161 |
162 void URLFetcherCore::FileWriter::CloseFileAndCompleteRequest() { | 162 void URLFetcherCore::FileWriter::CloseFileAndCompleteRequest() { |
163 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 163 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
164 | 164 |
165 if (file_handle_ != base::kInvalidPlatformFileValue) { | 165 if (file_handle_ != base::kInvalidPlatformFileValue) { |
166 base::FileUtilProxy::Close( | 166 base::FileUtilProxy::Close( |
167 file_task_runner_, file_handle_, | 167 file_task_runner_.get(), file_handle_, |
168 base::Bind(&URLFetcherCore::FileWriter::DidCloseFile, | 168 base::Bind(&URLFetcherCore::FileWriter::DidCloseFile, |
169 weak_factory_.GetWeakPtr())); | 169 weak_factory_.GetWeakPtr())); |
170 file_handle_ = base::kInvalidPlatformFileValue; | 170 file_handle_ = base::kInvalidPlatformFileValue; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 void URLFetcherCore::FileWriter::CloseAndDeleteFile() { | 174 void URLFetcherCore::FileWriter::CloseAndDeleteFile() { |
175 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 175 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
176 | 176 |
177 if (file_handle_ == base::kInvalidPlatformFileValue) { | 177 if (file_handle_ == base::kInvalidPlatformFileValue) { |
178 DeleteFile(base::PLATFORM_FILE_OK); | 178 DeleteFile(base::PLATFORM_FILE_OK); |
179 return; | 179 return; |
180 } | 180 } |
181 // Close the file if it is open. | 181 // Close the file if it is open. |
182 base::FileUtilProxy::Close( | 182 base::FileUtilProxy::Close( |
183 file_task_runner_, file_handle_, | 183 file_task_runner_.get(), file_handle_, |
184 base::Bind(&URLFetcherCore::FileWriter::DeleteFile, | 184 base::Bind(&URLFetcherCore::FileWriter::DeleteFile, |
185 weak_factory_.GetWeakPtr())); | 185 weak_factory_.GetWeakPtr())); |
186 file_handle_ = base::kInvalidPlatformFileValue; | 186 file_handle_ = base::kInvalidPlatformFileValue; |
187 } | 187 } |
188 | 188 |
189 void URLFetcherCore::FileWriter::DeleteFile( | 189 void URLFetcherCore::FileWriter::DeleteFile( |
190 base::PlatformFileError error_code) { | 190 base::PlatformFileError error_code) { |
191 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); | 191 DCHECK(core_->network_task_runner_->BelongsToCurrentThread()); |
192 if (file_path_.empty()) | 192 if (file_path_.empty()) |
193 return; | 193 return; |
194 | 194 |
195 base::FileUtilProxy::Delete( | 195 base::FileUtilProxy::Delete( |
196 file_task_runner_, file_path_, | 196 file_task_runner_.get(), file_path_, |
197 false, // No need to recurse, as the path is to a file. | 197 false, // No need to recurse, as the path is to a file. |
198 base::FileUtilProxy::StatusCallback()); | 198 base::FileUtilProxy::StatusCallback()); |
199 DisownFile(); | 199 DisownFile(); |
200 } | 200 } |
201 | 201 |
202 void URLFetcherCore::FileWriter::DidCreateFile( | 202 void URLFetcherCore::FileWriter::DidCreateFile( |
203 const FilePath& file_path, | 203 const FilePath& file_path, |
204 base::PlatformFileError error_code, | 204 base::PlatformFileError error_code, |
205 base::PassPlatformFile file_handle, | 205 base::PassPlatformFile file_handle, |
206 bool created) { | 206 bool created) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 max_retries_(0), | 288 max_retries_(0), |
289 current_upload_bytes_(-1), | 289 current_upload_bytes_(-1), |
290 current_response_bytes_(0), | 290 current_response_bytes_(0), |
291 total_response_bytes_(-1) { | 291 total_response_bytes_(-1) { |
292 CHECK(original_url_.is_valid()); | 292 CHECK(original_url_.is_valid()); |
293 } | 293 } |
294 | 294 |
295 void URLFetcherCore::Start() { | 295 void URLFetcherCore::Start() { |
296 DCHECK(delegate_task_runner_); | 296 DCHECK(delegate_task_runner_); |
297 DCHECK(request_context_getter_) << "We need an URLRequestContext!"; | 297 DCHECK(request_context_getter_) << "We need an URLRequestContext!"; |
298 if (network_task_runner_) { | 298 if (network_task_runner_.get()) { |
299 DCHECK_EQ(network_task_runner_, | 299 DCHECK_EQ(network_task_runner_, |
300 request_context_getter_->GetNetworkTaskRunner()); | 300 request_context_getter_->GetNetworkTaskRunner()); |
301 } else { | 301 } else { |
302 network_task_runner_ = request_context_getter_->GetNetworkTaskRunner(); | 302 network_task_runner_ = request_context_getter_->GetNetworkTaskRunner(); |
303 } | 303 } |
304 DCHECK(network_task_runner_.get()) << "We need an IO task runner"; | 304 DCHECK(network_task_runner_.get()) << "We need an IO task runner"; |
305 | 305 |
306 network_task_runner_->PostTask( | 306 network_task_runner_->PostTask( |
307 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); | 307 FROM_HERE, base::Bind(&URLFetcherCore::StartOnIOThread, this)); |
308 } | 308 } |
309 | 309 |
310 void URLFetcherCore::Stop() { | 310 void URLFetcherCore::Stop() { |
311 if (delegate_task_runner_) // May be NULL in tests. | 311 if (delegate_task_runner_.get()) // May be NULL in tests. |
312 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 312 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
313 | 313 |
314 delegate_ = NULL; | 314 delegate_ = NULL; |
315 fetcher_ = NULL; | 315 fetcher_ = NULL; |
316 if (!network_task_runner_.get()) | 316 if (!network_task_runner_.get()) |
317 return; | 317 return; |
318 if (network_task_runner_->RunsTasksOnCurrentThread()) { | 318 if (network_task_runner_->RunsTasksOnCurrentThread()) { |
319 CancelURLRequest(); | 319 CancelURLRequest(); |
320 } else { | 320 } else { |
321 network_task_runner_->PostTask( | 321 network_task_runner_->PostTask( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 extra_request_headers_.AddHeaderFromString(header_line); | 371 extra_request_headers_.AddHeaderFromString(header_line); |
372 } | 372 } |
373 | 373 |
374 void URLFetcherCore::GetExtraRequestHeaders( | 374 void URLFetcherCore::GetExtraRequestHeaders( |
375 HttpRequestHeaders* headers) const { | 375 HttpRequestHeaders* headers) const { |
376 headers->CopyFrom(extra_request_headers_); | 376 headers->CopyFrom(extra_request_headers_); |
377 } | 377 } |
378 | 378 |
379 void URLFetcherCore::SetRequestContext( | 379 void URLFetcherCore::SetRequestContext( |
380 URLRequestContextGetter* request_context_getter) { | 380 URLRequestContextGetter* request_context_getter) { |
381 DCHECK(!request_context_getter_); | 381 DCHECK(!request_context_getter_.get()); |
382 DCHECK(request_context_getter); | 382 DCHECK(request_context_getter); |
383 request_context_getter_ = request_context_getter; | 383 request_context_getter_ = request_context_getter; |
384 } | 384 } |
385 | 385 |
386 void URLFetcherCore::SetFirstPartyForCookies( | 386 void URLFetcherCore::SetFirstPartyForCookies( |
387 const GURL& first_party_for_cookies) { | 387 const GURL& first_party_for_cookies) { |
388 DCHECK(first_party_for_cookies_.is_empty()); | 388 DCHECK(first_party_for_cookies_.is_empty()); |
389 first_party_for_cookies_ = first_party_for_cookies; | 389 first_party_for_cookies_ = first_party_for_cookies; |
390 } | 390 } |
391 | 391 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 428 } |
429 | 429 |
430 void URLFetcherCore::SaveResponseToTemporaryFile( | 430 void URLFetcherCore::SaveResponseToTemporaryFile( |
431 scoped_refptr<base::TaskRunner> file_task_runner) { | 431 scoped_refptr<base::TaskRunner> file_task_runner) { |
432 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 432 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
433 file_task_runner_ = file_task_runner; | 433 file_task_runner_ = file_task_runner; |
434 response_destination_ = URLFetcherCore::TEMP_FILE; | 434 response_destination_ = URLFetcherCore::TEMP_FILE; |
435 } | 435 } |
436 | 436 |
437 HttpResponseHeaders* URLFetcherCore::GetResponseHeaders() const { | 437 HttpResponseHeaders* URLFetcherCore::GetResponseHeaders() const { |
438 return response_headers_; | 438 return response_headers_.get(); |
439 } | 439 } |
440 | 440 |
441 // TODO(panayiotis): socket_address_ is written in the IO thread, | 441 // TODO(panayiotis): socket_address_ is written in the IO thread, |
442 // if this is accessed in the UI thread, this could result in a race. | 442 // if this is accessed in the UI thread, this could result in a race. |
443 // Same for response_headers_ above and was_fetched_via_proxy_ below. | 443 // Same for response_headers_ above and was_fetched_via_proxy_ below. |
444 HostPortPair URLFetcherCore::GetSocketAddress() const { | 444 HostPortPair URLFetcherCore::GetSocketAddress() const { |
445 return socket_address_; | 445 return socket_address_; |
446 } | 446 } |
447 | 447 |
448 bool URLFetcherCore::WasFetchedViaProxy() const { | 448 bool URLFetcherCore::WasFetchedViaProxy() const { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 current_response_bytes_ += bytes_read; | 573 current_response_bytes_ += bytes_read; |
574 InformDelegateDownloadProgress(); | 574 InformDelegateDownloadProgress(); |
575 InformDelegateDownloadDataIfNecessary(bytes_read); | 575 InformDelegateDownloadDataIfNecessary(bytes_read); |
576 | 576 |
577 if (!WriteBuffer(bytes_read)) { | 577 if (!WriteBuffer(bytes_read)) { |
578 // If WriteBuffer() returns false, we have a pending write to | 578 // If WriteBuffer() returns false, we have a pending write to |
579 // wait on before reading further. | 579 // wait on before reading further. |
580 waiting_on_write = true; | 580 waiting_on_write = true; |
581 break; | 581 break; |
582 } | 582 } |
583 } while (request_->Read(buffer_, kBufferSize, &bytes_read)); | 583 } while (request_->Read(buffer_.get(), kBufferSize, &bytes_read)); |
584 | 584 |
585 const URLRequestStatus status = request_->status(); | 585 const URLRequestStatus status = request_->status(); |
586 | 586 |
587 if (status.is_success()) | 587 if (status.is_success()) |
588 request_->GetResponseCookies(&cookies_); | 588 request_->GetResponseCookies(&cookies_); |
589 | 589 |
590 // See comments re: HEAD requests in ReadResponse(). | 590 // See comments re: HEAD requests in ReadResponse(). |
591 if ((!status.is_io_pending() && !waiting_on_write) || | 591 if ((!status.is_io_pending() && !waiting_on_write) || |
592 (request_type_ == URLFetcher::HEAD)) { | 592 (request_type_ == URLFetcher::HEAD)) { |
593 status_ = status; | 593 status_ = status; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 745 |
746 void URLFetcherCore::StartURLRequestWhenAppropriate() { | 746 void URLFetcherCore::StartURLRequestWhenAppropriate() { |
747 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 747 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
748 | 748 |
749 if (was_cancelled_) | 749 if (was_cancelled_) |
750 return; | 750 return; |
751 | 751 |
752 DCHECK(request_context_getter_); | 752 DCHECK(request_context_getter_); |
753 | 753 |
754 int64 delay = 0LL; | 754 int64 delay = 0LL; |
755 if (original_url_throttler_entry_ == NULL) { | 755 if (original_url_throttler_entry_.get() == NULL) { |
756 URLRequestThrottlerManager* manager = | 756 URLRequestThrottlerManager* manager = |
757 request_context_getter_->GetURLRequestContext()->throttler_manager(); | 757 request_context_getter_->GetURLRequestContext()->throttler_manager(); |
758 if (manager) { | 758 if (manager) { |
759 original_url_throttler_entry_ = | 759 original_url_throttler_entry_ = |
760 manager->RegisterRequestUrl(original_url_); | 760 manager->RegisterRequestUrl(original_url_); |
761 } | 761 } |
762 } | 762 } |
763 if (original_url_throttler_entry_ != NULL) { | 763 if (original_url_throttler_entry_.get() != NULL) { |
764 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( | 764 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( |
765 GetBackoffReleaseTime()); | 765 GetBackoffReleaseTime()); |
766 } | 766 } |
767 | 767 |
768 if (delay == 0) { | 768 if (delay == 0) { |
769 StartURLRequest(); | 769 StartURLRequest(); |
770 } else { | 770 } else { |
771 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 771 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
772 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), | 772 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), |
773 base::TimeDelta::FromMilliseconds(delay)); | 773 base::TimeDelta::FromMilliseconds(delay)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 } | 805 } |
806 | 806 |
807 void URLFetcherCore::InformDelegateFetchIsComplete() { | 807 void URLFetcherCore::InformDelegateFetchIsComplete() { |
808 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 808 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
809 if (delegate_) | 809 if (delegate_) |
810 delegate_->OnURLFetchComplete(fetcher_); | 810 delegate_->OnURLFetchComplete(fetcher_); |
811 } | 811 } |
812 | 812 |
813 void URLFetcherCore::NotifyMalformedContent() { | 813 void URLFetcherCore::NotifyMalformedContent() { |
814 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 814 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
815 if (url_throttler_entry_ != NULL) { | 815 if (url_throttler_entry_.get() != NULL) { |
816 int status_code = response_code_; | 816 int status_code = response_code_; |
817 if (status_code == URLFetcher::RESPONSE_CODE_INVALID) { | 817 if (status_code == URLFetcher::RESPONSE_CODE_INVALID) { |
818 // The status code will generally be known by the time clients | 818 // The status code will generally be known by the time clients |
819 // call the |ReceivedContentWasMalformed()| function (which ends up | 819 // call the |ReceivedContentWasMalformed()| function (which ends up |
820 // calling the current function) but if it's not, we need to assume | 820 // calling the current function) but if it's not, we need to assume |
821 // the response was successful so that the total failure count | 821 // the response was successful so that the total failure count |
822 // used to calculate exponential back-off goes up. | 822 // used to calculate exponential back-off goes up. |
823 status_code = 200; | 823 status_code = 200; |
824 } | 824 } |
825 url_throttler_entry_->ReceivedContentWasMalformed(status_code); | 825 url_throttler_entry_->ReceivedContentWasMalformed(status_code); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 869 |
870 void URLFetcherCore::ReleaseRequest() { | 870 void URLFetcherCore::ReleaseRequest() { |
871 upload_progress_checker_timer_.reset(); | 871 upload_progress_checker_timer_.reset(); |
872 request_.reset(); | 872 request_.reset(); |
873 g_registry.Get().RemoveURLFetcherCore(this); | 873 g_registry.Get().RemoveURLFetcherCore(this); |
874 } | 874 } |
875 | 875 |
876 base::TimeTicks URLFetcherCore::GetBackoffReleaseTime() { | 876 base::TimeTicks URLFetcherCore::GetBackoffReleaseTime() { |
877 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 877 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
878 | 878 |
879 if (original_url_throttler_entry_) { | 879 if (original_url_throttler_entry_.get()) { |
880 base::TimeTicks original_url_backoff = | 880 base::TimeTicks original_url_backoff = |
881 original_url_throttler_entry_->GetExponentialBackoffReleaseTime(); | 881 original_url_throttler_entry_->GetExponentialBackoffReleaseTime(); |
882 base::TimeTicks destination_url_backoff; | 882 base::TimeTicks destination_url_backoff; |
883 if (url_throttler_entry_ != NULL && | 883 if (url_throttler_entry_.get() != NULL && |
884 original_url_throttler_entry_ != url_throttler_entry_) { | 884 original_url_throttler_entry_.get() != url_throttler_entry_.get()) { |
885 destination_url_backoff = | 885 destination_url_backoff = |
886 url_throttler_entry_->GetExponentialBackoffReleaseTime(); | 886 url_throttler_entry_->GetExponentialBackoffReleaseTime(); |
887 } | 887 } |
888 | 888 |
889 return original_url_backoff > destination_url_backoff ? | 889 return original_url_backoff > destination_url_backoff ? |
890 original_url_backoff : destination_url_backoff; | 890 original_url_backoff : destination_url_backoff; |
891 } else { | 891 } else { |
892 return base::TimeTicks(); | 892 return base::TimeTicks(); |
893 } | 893 } |
894 } | 894 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 } | 934 } |
935 | 935 |
936 void URLFetcherCore::ReadResponse() { | 936 void URLFetcherCore::ReadResponse() { |
937 // Some servers may treat HEAD requests as GET requests. To free up the | 937 // Some servers may treat HEAD requests as GET requests. To free up the |
938 // network connection as soon as possible, signal that the request has | 938 // network connection as soon as possible, signal that the request has |
939 // completed immediately, without trying to read any data back (all we care | 939 // completed immediately, without trying to read any data back (all we care |
940 // about is the response code and headers, which we already have). | 940 // about is the response code and headers, which we already have). |
941 int bytes_read = 0; | 941 int bytes_read = 0; |
942 if (request_->status().is_success() && | 942 if (request_->status().is_success() && |
943 (request_type_ != URLFetcher::HEAD)) | 943 (request_type_ != URLFetcher::HEAD)) |
944 request_->Read(buffer_, kBufferSize, &bytes_read); | 944 request_->Read(buffer_.get(), kBufferSize, &bytes_read); |
945 OnReadCompleted(request_.get(), bytes_read); | 945 OnReadCompleted(request_.get(), bytes_read); |
946 } | 946 } |
947 | 947 |
948 void URLFetcherCore::DisownFile() { | 948 void URLFetcherCore::DisownFile() { |
949 file_writer_->DisownFile(); | 949 file_writer_->DisownFile(); |
950 } | 950 } |
951 | 951 |
952 void URLFetcherCore::InformDelegateUploadProgress() { | 952 void URLFetcherCore::InformDelegateUploadProgress() { |
953 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 953 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
954 if (request_.get()) { | 954 if (request_.get()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 } | 1004 } |
1005 | 1005 |
1006 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( | 1006 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( |
1007 scoped_ptr<std::string> download_data) { | 1007 scoped_ptr<std::string> download_data) { |
1008 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 1008 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
1009 if (delegate_) | 1009 if (delegate_) |
1010 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); | 1010 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); |
1011 } | 1011 } |
1012 | 1012 |
1013 } // namespace net | 1013 } // namespace net |
OLD | NEW |