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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "base/tracked_objects.h" | 14 #include "base/tracked_objects.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/base/upload_data.h" | 18 #include "net/base/upload_bytes_element_reader.h" |
| 19 #include "net/base/upload_data_stream.h" |
19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
20 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
22 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
23 #include "net/url_request/url_request_throttler_manager.h" | 24 #include "net/url_request/url_request_throttler_manager.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const int kBufferSize = 4096; | 28 const int kBufferSize = 4096; |
28 const int kUploadProgressTimerInterval = 100; | 29 const int kUploadProgressTimerInterval = 100; |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 726 |
726 case URLFetcher::POST: | 727 case URLFetcher::POST: |
727 case URLFetcher::PUT: | 728 case URLFetcher::PUT: |
728 DCHECK(!upload_content_type_.empty()); | 729 DCHECK(!upload_content_type_.empty()); |
729 | 730 |
730 request_->set_method( | 731 request_->set_method( |
731 request_type_ == URLFetcher::POST ? "POST" : "PUT"); | 732 request_type_ == URLFetcher::POST ? "POST" : "PUT"); |
732 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, | 733 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, |
733 upload_content_type_); | 734 upload_content_type_); |
734 if (!upload_content_.empty()) { | 735 if (!upload_content_.empty()) { |
735 scoped_refptr<UploadData> upload_data(new UploadData()); | 736 scoped_ptr<UploadElementReader> reader(new UploadBytesElementReader( |
736 upload_data->AppendBytes(upload_content_.data(), | 737 upload_content_.data(), upload_content_.size())); |
737 upload_content_.length()); | 738 request_->set_upload(make_scoped_ptr( |
738 request_->set_upload(upload_data); | 739 UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
739 } | 740 } |
740 | 741 |
741 current_upload_bytes_ = -1; | 742 current_upload_bytes_ = -1; |
742 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the | 743 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the |
743 // layer and avoid using timer here. | 744 // layer and avoid using timer here. |
744 upload_progress_checker_timer_.reset( | 745 upload_progress_checker_timer_.reset( |
745 new base::RepeatingTimer<URLFetcherCore>()); | 746 new base::RepeatingTimer<URLFetcherCore>()); |
746 upload_progress_checker_timer_->Start( | 747 upload_progress_checker_timer_->Start( |
747 FROM_HERE, | 748 FROM_HERE, |
748 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), | 749 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 } | 1058 } |
1058 | 1059 |
1059 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( | 1060 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( |
1060 scoped_ptr<std::string> download_data) { | 1061 scoped_ptr<std::string> download_data) { |
1061 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 1062 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
1062 if (delegate_) | 1063 if (delegate_) |
1063 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); | 1064 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); |
1064 } | 1065 } |
1065 | 1066 |
1066 } // namespace net | 1067 } // namespace net |
OLD | NEW |