| 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" |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 g_ignore_certificate_requests = ignored; | 508 g_ignore_certificate_requests = ignored; |
| 508 } | 509 } |
| 509 | 510 |
| 510 URLFetcherCore::~URLFetcherCore() { | 511 URLFetcherCore::~URLFetcherCore() { |
| 511 // |request_| should be NULL. If not, it's unsafe to delete it here since we | 512 // |request_| should be NULL. If not, it's unsafe to delete it here since we |
| 512 // may not be on the IO thread. | 513 // may not be on the IO thread. |
| 513 DCHECK(!request_.get()); | 514 DCHECK(!request_.get()); |
| 514 } | 515 } |
| 515 | 516 |
| 516 void URLFetcherCore::StartOnIOThread() { | 517 void URLFetcherCore::StartOnIOThread() { |
| 518 TRACE_EVENT0("net", "URLFetcherCore::StartOnIOThread"); |
| 517 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 519 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 518 | 520 |
| 519 if (!response_writer_) | 521 if (!response_writer_) |
| 520 response_writer_.reset(new URLFetcherStringWriter); | 522 response_writer_.reset(new URLFetcherStringWriter); |
| 521 | 523 |
| 522 const int result = response_writer_->Initialize( | 524 const int result = response_writer_->Initialize( |
| 523 base::Bind(&URLFetcherCore::DidInitializeWriter, this)); | 525 base::Bind(&URLFetcherCore::DidInitializeWriter, this)); |
| 524 if (result != ERR_IO_PENDING) | 526 if (result != ERR_IO_PENDING) |
| 525 DidInitializeWriter(result); | 527 DidInitializeWriter(result); |
| 526 } | 528 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 void URLFetcherCore::DidFinishWriting(int result) { | 741 void URLFetcherCore::DidFinishWriting(int result) { |
| 740 if (result != OK) { | 742 if (result != OK) { |
| 741 CancelRequestAndInformDelegate(result); | 743 CancelRequestAndInformDelegate(result); |
| 742 return; | 744 return; |
| 743 } | 745 } |
| 744 // If the file was successfully closed, then the URL request is complete. | 746 // If the file was successfully closed, then the URL request is complete. |
| 745 RetryOrCompleteUrlFetch(); | 747 RetryOrCompleteUrlFetch(); |
| 746 } | 748 } |
| 747 | 749 |
| 748 void URLFetcherCore::RetryOrCompleteUrlFetch() { | 750 void URLFetcherCore::RetryOrCompleteUrlFetch() { |
| 751 TRACE_EVENT0("net", "URLFetcherCore::RetryOrCompleteUrlFetch"); |
| 749 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 752 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 750 base::TimeDelta backoff_delay; | 753 base::TimeDelta backoff_delay; |
| 751 | 754 |
| 752 // Checks the response from server. | 755 // Checks the response from server. |
| 753 if (response_code_ >= 500 || | 756 if (response_code_ >= 500 || |
| 754 status_.error() == ERR_TEMPORARILY_THROTTLED) { | 757 status_.error() == ERR_TEMPORARILY_THROTTLED) { |
| 755 // When encountering a server error, we will send the request again | 758 // When encountering a server error, we will send the request again |
| 756 // after backoff time. | 759 // after backoff time. |
| 757 ++num_retries_on_5xx_; | 760 ++num_retries_on_5xx_; |
| 758 | 761 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 } | 956 } |
| 954 | 957 |
| 955 void URLFetcherCore::AssertHasNoUploadData() const { | 958 void URLFetcherCore::AssertHasNoUploadData() const { |
| 956 DCHECK(!upload_content_set_); | 959 DCHECK(!upload_content_set_); |
| 957 DCHECK(upload_content_.empty()); | 960 DCHECK(upload_content_.empty()); |
| 958 DCHECK(upload_file_path_.empty()); | 961 DCHECK(upload_file_path_.empty()); |
| 959 DCHECK(upload_stream_factory_.is_null()); | 962 DCHECK(upload_stream_factory_.is_null()); |
| 960 } | 963 } |
| 961 | 964 |
| 962 } // namespace net | 965 } // namespace net |
| OLD | NEW |