OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/report_sender.h" | 5 #include "net/url_request/report_sender.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/elements_upload_data_stream.h" | 10 #include "net/base/elements_upload_data_stream.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const ErrorCallback& error_callback) | 25 const ErrorCallback& error_callback) |
26 : request_context_(request_context), | 26 : request_context_(request_context), |
27 cookies_preference_(cookies_preference), | 27 cookies_preference_(cookies_preference), |
28 error_callback_(error_callback) {} | 28 error_callback_(error_callback) {} |
29 | 29 |
30 ReportSender::~ReportSender() { | 30 ReportSender::~ReportSender() { |
31 // Cancel all of the uncompleted requests. | 31 // Cancel all of the uncompleted requests. |
32 base::STLDeleteElements(&inflight_requests_); | 32 base::STLDeleteElements(&inflight_requests_); |
33 } | 33 } |
34 | 34 |
35 void ReportSender::Send(const GURL& report_uri, const std::string& report) { | 35 void ReportSender::Send(const GURL& report_uri, |
| 36 const std::string& content_type, |
| 37 const std::string& report) { |
36 std::unique_ptr<URLRequest> url_request = | 38 std::unique_ptr<URLRequest> url_request = |
37 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | 39 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); |
38 | 40 |
39 int load_flags = | 41 int load_flags = |
40 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; | 42 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; |
41 if (cookies_preference_ != SEND_COOKIES) { | 43 if (cookies_preference_ != SEND_COOKIES) { |
42 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | 44 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; |
43 } | 45 } |
44 url_request->SetLoadFlags(load_flags); | 46 url_request->SetLoadFlags(load_flags); |
45 | 47 |
| 48 url_request->SetExtraRequestHeaderByName(HttpRequestHeaders::kContentType, |
| 49 content_type, true); |
| 50 |
46 url_request->set_method("POST"); | 51 url_request->set_method("POST"); |
47 | 52 |
48 std::unique_ptr<UploadElementReader> reader( | 53 std::unique_ptr<UploadElementReader> reader( |
49 UploadOwnedBytesElementReader::CreateWithString(report)); | 54 UploadOwnedBytesElementReader::CreateWithString(report)); |
50 url_request->set_upload( | 55 url_request->set_upload( |
51 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); | 56 ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); |
52 | 57 |
53 URLRequest* raw_url_request = url_request.get(); | 58 URLRequest* raw_url_request = url_request.get(); |
54 inflight_requests_.insert(url_request.release()); | 59 inflight_requests_.insert(url_request.release()); |
55 raw_url_request->Start(); | 60 raw_url_request->Start(); |
(...skipping 15 matching lines...) Expand all Loading... |
71 CHECK_GT(inflight_requests_.erase(request), 0u); | 76 CHECK_GT(inflight_requests_.erase(request), 0u); |
72 // Clean up the request, which cancels it. | 77 // Clean up the request, which cancels it. |
73 delete request; | 78 delete request; |
74 } | 79 } |
75 | 80 |
76 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { | 81 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { |
77 NOTREACHED(); | 82 NOTREACHED(); |
78 } | 83 } |
79 | 84 |
80 } // namespace net | 85 } // namespace net |
OLD | NEW |