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 "net/base/elements_upload_data_stream.h" | 9 #include "net/base/elements_upload_data_stream.h" |
10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 net::ReportSender::SuccessCallback success_callback_; | 35 net::ReportSender::SuccessCallback success_callback_; |
36 net::ReportSender::ErrorCallback error_callback_; | 36 net::ReportSender::ErrorCallback error_callback_; |
37 }; | 37 }; |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 namespace net { | 40 namespace net { |
41 | 41 |
42 ReportSender::ReportSender(URLRequestContext* request_context, | 42 ReportSender::ReportSender(URLRequestContext* request_context) |
43 CookiesPreference cookies_preference) | 43 : request_context_(request_context) {} |
44 : request_context_(request_context), | |
45 cookies_preference_(cookies_preference) {} | |
46 | 44 |
47 ReportSender::~ReportSender() { | 45 ReportSender::~ReportSender() { |
48 } | 46 } |
49 | 47 |
50 void ReportSender::Send(const GURL& report_uri, | 48 void ReportSender::Send(const GURL& report_uri, |
51 base::StringPiece content_type, | 49 base::StringPiece content_type, |
52 base::StringPiece report, | 50 base::StringPiece report, |
53 const SuccessCallback& success_callback, | 51 const SuccessCallback& success_callback, |
54 const ErrorCallback& error_callback) { | 52 const ErrorCallback& error_callback) { |
55 DCHECK(!content_type.empty()); | 53 DCHECK(!content_type.empty()); |
56 std::unique_ptr<URLRequest> url_request = | 54 std::unique_ptr<URLRequest> url_request = |
57 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | 55 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); |
58 url_request->SetUserData(&kUserDataKey, | 56 url_request->SetUserData(&kUserDataKey, |
59 new CallbackInfo(success_callback, error_callback)); | 57 new CallbackInfo(success_callback, error_callback)); |
60 | 58 |
61 int load_flags = | 59 url_request->SetLoadFlags( |
62 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; | 60 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA | |
63 if (cookies_preference_ != SEND_COOKIES) { | 61 LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES); |
64 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | |
65 } | |
66 url_request->SetLoadFlags(load_flags); | |
67 | 62 |
68 HttpRequestHeaders extra_headers; | 63 HttpRequestHeaders extra_headers; |
69 extra_headers.SetHeader(HttpRequestHeaders::kContentType, content_type); | 64 extra_headers.SetHeader(HttpRequestHeaders::kContentType, content_type); |
70 url_request->SetExtraRequestHeaders(extra_headers); | 65 url_request->SetExtraRequestHeaders(extra_headers); |
71 | 66 |
72 url_request->set_method("POST"); | 67 url_request->set_method("POST"); |
73 | 68 |
74 std::vector<char> report_data(report.begin(), report.end()); | 69 std::vector<char> report_data(report.begin(), report.end()); |
75 std::unique_ptr<UploadElementReader> reader( | 70 std::unique_ptr<UploadElementReader> reader( |
76 new UploadOwnedBytesElementReader(&report_data)); | 71 new UploadOwnedBytesElementReader(&report_data)); |
(...skipping 20 matching lines...) Expand all Loading... |
97 } | 92 } |
98 | 93 |
99 CHECK_GT(inflight_requests_.erase(request), 0u); | 94 CHECK_GT(inflight_requests_.erase(request), 0u); |
100 } | 95 } |
101 | 96 |
102 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { | 97 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { |
103 NOTREACHED(); | 98 NOTREACHED(); |
104 } | 99 } |
105 | 100 |
106 } // namespace net | 101 } // namespace net |
OLD | NEW |