Chromium Code Reviews| 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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 | 697 |
| 697 case URLFetcher::POST: | 698 case URLFetcher::POST: |
| 698 case URLFetcher::PUT: | 699 case URLFetcher::PUT: |
| 699 DCHECK(!upload_content_type_.empty()); | 700 DCHECK(!upload_content_type_.empty()); |
| 700 | 701 |
| 701 request_->set_method( | 702 request_->set_method( |
| 702 request_type_ == URLFetcher::POST ? "POST" : "PUT"); | 703 request_type_ == URLFetcher::POST ? "POST" : "PUT"); |
| 703 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, | 704 extra_request_headers_.SetHeader(HttpRequestHeaders::kContentType, |
| 704 upload_content_type_); | 705 upload_content_type_); |
| 705 if (!upload_content_.empty()) { | 706 if (!upload_content_.empty()) { |
| 706 scoped_refptr<UploadData> upload_data(new UploadData()); | 707 ScopedVector<UploadElementReader> element_readers; |
| 707 upload_data->AppendBytes(upload_content_.data(), | 708 element_readers.push_back(new UploadBytesElementReader( |
| 708 upload_content_.length()); | 709 upload_content_.data(), upload_content_.size())); |
| 709 request_->set_upload(upload_data); | 710 request_->set_upload(new UploadDataStream(&element_readers, 0)); |
|
mmenke
2012/12/11 18:53:21
Life may be a bit simple if we have the UploadData
hashimoto
2012/12/12 10:29:07
Since the main user (webkit_glue::ResourceRequestB
mmenke
2012/12/12 19:26:41
Think your two new static methods do a lot to remo
| |
| 710 } | 711 } |
| 711 | 712 |
| 712 current_upload_bytes_ = -1; | 713 current_upload_bytes_ = -1; |
| 713 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the | 714 // TODO(kinaba): http://crbug.com/118103. Implement upload callback in the |
| 714 // layer and avoid using timer here. | 715 // layer and avoid using timer here. |
| 715 upload_progress_checker_timer_.reset( | 716 upload_progress_checker_timer_.reset( |
| 716 new base::RepeatingTimer<URLFetcherCore>()); | 717 new base::RepeatingTimer<URLFetcherCore>()); |
| 717 upload_progress_checker_timer_->Start( | 718 upload_progress_checker_timer_->Start( |
| 718 FROM_HERE, | 719 FROM_HERE, |
| 719 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), | 720 base::TimeDelta::FromMilliseconds(kUploadProgressTimerInterval), |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 } | 1008 } |
| 1008 | 1009 |
| 1009 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( | 1010 void URLFetcherCore::InformDelegateDownloadDataInDelegateThread( |
| 1010 scoped_ptr<std::string> download_data) { | 1011 scoped_ptr<std::string> download_data) { |
| 1011 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); | 1012 DCHECK(delegate_task_runner_->BelongsToCurrentThread()); |
| 1012 if (delegate_) | 1013 if (delegate_) |
| 1013 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); | 1014 delegate_->OnURLFetchDownloadData(fetcher_, download_data.Pass()); |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 } // namespace net | 1017 } // namespace net |
| OLD | NEW |