| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/trace_event.h" |
| 18 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
| 19 #include "net/base/elements_upload_data_stream.h" | 20 #include "net/base/elements_upload_data_stream.h" |
| 20 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
| 24 #include "net/base/upload_bytes_element_reader.h" | 25 #include "net/base/upload_bytes_element_reader.h" |
| 25 #include "net/base/upload_data_stream.h" | 26 #include "net/base/upload_data_stream.h" |
| 26 #include "net/base/upload_file_element_reader.h" | 27 #include "net/base/upload_file_element_reader.h" |
| 27 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 28 #include "net/url_request/redirect_info.h" | 29 #include "net/url_request/redirect_info.h" |
| 29 #include "net/url_request/url_fetcher_delegate.h" | 30 #include "net/url_request/url_fetcher_delegate.h" |
| 30 #include "net/url_request/url_fetcher_response_writer.h" | 31 #include "net/url_request/url_fetcher_response_writer.h" |
| 31 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
| 32 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
| 33 #include "net/url_request/url_request_throttler_manager.h" | 34 #include "net/url_request/url_request_throttler_manager.h" |
| 34 | 35 |
| 36 #include "base/trace_event/trace_event.h" |
| 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 const int kBufferSize = 4096; | 40 const int kBufferSize = 4096; |
| 38 const int kUploadProgressTimerInterval = 100; | 41 const int kUploadProgressTimerInterval = 100; |
| 39 bool g_ignore_certificate_requests = false; | 42 bool g_ignore_certificate_requests = false; |
| 40 | 43 |
| 41 void EmptyCompletionCallback(int result) {} | 44 void EmptyCompletionCallback(int result) {} |
| 42 | 45 |
| 43 } // namespace | 46 } // namespace |
| 44 | 47 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 g_ignore_certificate_requests = ignored; | 510 g_ignore_certificate_requests = ignored; |
| 508 } | 511 } |
| 509 | 512 |
| 510 URLFetcherCore::~URLFetcherCore() { | 513 URLFetcherCore::~URLFetcherCore() { |
| 511 // |request_| should be NULL. If not, it's unsafe to delete it here since we | 514 // |request_| should be NULL. If not, it's unsafe to delete it here since we |
| 512 // may not be on the IO thread. | 515 // may not be on the IO thread. |
| 513 DCHECK(!request_.get()); | 516 DCHECK(!request_.get()); |
| 514 } | 517 } |
| 515 | 518 |
| 516 void URLFetcherCore::StartOnIOThread() { | 519 void URLFetcherCore::StartOnIOThread() { |
| 520 TRACE_EVENT0("net", "URLFetcherCore::StartOnIOThread"); |
| 517 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 521 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 518 | 522 |
| 519 if (!response_writer_) | 523 if (!response_writer_) |
| 520 response_writer_.reset(new URLFetcherStringWriter); | 524 response_writer_.reset(new URLFetcherStringWriter); |
| 521 | 525 |
| 522 const int result = response_writer_->Initialize( | 526 const int result = response_writer_->Initialize( |
| 523 base::Bind(&URLFetcherCore::DidInitializeWriter, this)); | 527 base::Bind(&URLFetcherCore::DidInitializeWriter, this)); |
| 524 if (result != ERR_IO_PENDING) | 528 if (result != ERR_IO_PENDING) |
| 525 DidInitializeWriter(result); | 529 DidInitializeWriter(result); |
| 526 } | 530 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 void URLFetcherCore::DidFinishWriting(int result) { | 743 void URLFetcherCore::DidFinishWriting(int result) { |
| 740 if (result != OK) { | 744 if (result != OK) { |
| 741 CancelRequestAndInformDelegate(result); | 745 CancelRequestAndInformDelegate(result); |
| 742 return; | 746 return; |
| 743 } | 747 } |
| 744 // If the file was successfully closed, then the URL request is complete. | 748 // If the file was successfully closed, then the URL request is complete. |
| 745 RetryOrCompleteUrlFetch(); | 749 RetryOrCompleteUrlFetch(); |
| 746 } | 750 } |
| 747 | 751 |
| 748 void URLFetcherCore::RetryOrCompleteUrlFetch() { | 752 void URLFetcherCore::RetryOrCompleteUrlFetch() { |
| 753 TRACE_EVENT0("net", "net::URLFetcherCore::RetryOrCompleteUrlFetch"); |
| 749 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 754 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 750 base::TimeDelta backoff_delay; | 755 base::TimeDelta backoff_delay; |
| 751 | 756 |
| 752 // Checks the response from server. | 757 // Checks the response from server. |
| 753 if (response_code_ >= 500 || | 758 if (response_code_ >= 500 || |
| 754 status_.error() == ERR_TEMPORARILY_THROTTLED) { | 759 status_.error() == ERR_TEMPORARILY_THROTTLED) { |
| 755 // When encountering a server error, we will send the request again | 760 // When encountering a server error, we will send the request again |
| 756 // after backoff time. | 761 // after backoff time. |
| 757 ++num_retries_on_5xx_; | 762 ++num_retries_on_5xx_; |
| 758 | 763 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 } | 958 } |
| 954 | 959 |
| 955 void URLFetcherCore::AssertHasNoUploadData() const { | 960 void URLFetcherCore::AssertHasNoUploadData() const { |
| 956 DCHECK(!upload_content_set_); | 961 DCHECK(!upload_content_set_); |
| 957 DCHECK(upload_content_.empty()); | 962 DCHECK(upload_content_.empty()); |
| 958 DCHECK(upload_file_path_.empty()); | 963 DCHECK(upload_file_path_.empty()); |
| 959 DCHECK(upload_stream_factory_.is_null()); | 964 DCHECK(upload_stream_factory_.is_null()); |
| 960 } | 965 } |
| 961 | 966 |
| 962 } // namespace net | 967 } // namespace net |
| OLD | NEW |