| 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 #ifndef NET_URL_REQUEST_REPORT_SENDER_H_ | 5 #ifndef NET_URL_REQUEST_REPORT_SENDER_H_ |
| 6 #define NET_URL_REQUEST_REPORT_SENDER_H_ | 6 #define NET_URL_REQUEST_REPORT_SENDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // the format of the report being sent (JSON, protobuf, etc.) and the particular | 26 // the format of the report being sent (JSON, protobuf, etc.) and the particular |
| 27 // data that it contains. Multiple reports can be in-flight at once. This class | 27 // data that it contains. Multiple reports can be in-flight at once. This class |
| 28 // owns inflight requests and cleans them up when necessary. | 28 // owns inflight requests and cleans them up when necessary. |
| 29 class NET_EXPORT ReportSender | 29 class NET_EXPORT ReportSender |
| 30 : public URLRequest::Delegate, | 30 : public URLRequest::Delegate, |
| 31 public TransportSecurityState::ReportSenderInterface { | 31 public TransportSecurityState::ReportSenderInterface { |
| 32 public: | 32 public: |
| 33 using SuccessCallback = base::Callback<void()>; | 33 using SuccessCallback = base::Callback<void()>; |
| 34 using ErrorCallback = base::Callback<void(const GURL&, int)>; | 34 using ErrorCallback = base::Callback<void(const GURL&, int)>; |
| 35 | 35 |
| 36 // Represents whether or not to send cookies along with reports. | |
| 37 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; | |
| 38 | |
| 39 // Constructs a ReportSender that sends reports with the | 36 // Constructs a ReportSender that sends reports with the |
| 40 // given |request_context| and includes or excludes cookies based on | 37 // given |request_context|, always excluding cookies. |request_context| must |
| 41 // |cookies_preference|. |request_context| must outlive the | 38 // outlive the ReportSender. |
| 42 // ReportSender. | 39 explicit ReportSender(URLRequestContext* request_context); |
| 43 ReportSender(URLRequestContext* request_context, | |
| 44 CookiesPreference cookies_preference); | |
| 45 | 40 |
| 46 ~ReportSender() override; | 41 ~ReportSender() override; |
| 47 | 42 |
| 48 // TransportSecurityState::ReportSenderInterface implementation. | 43 // TransportSecurityState::ReportSenderInterface implementation. |
| 49 void Send(const GURL& report_uri, | 44 void Send(const GURL& report_uri, |
| 50 base::StringPiece content_type, | 45 base::StringPiece content_type, |
| 51 base::StringPiece report, | 46 base::StringPiece report, |
| 52 const SuccessCallback& success_callback, | 47 const SuccessCallback& success_callback, |
| 53 const ErrorCallback& error_callback) override; | 48 const ErrorCallback& error_callback) override; |
| 54 | 49 |
| 55 // net::URLRequest::Delegate implementation. | 50 // net::URLRequest::Delegate implementation. |
| 56 void OnResponseStarted(URLRequest* request, int net_error) override; | 51 void OnResponseStarted(URLRequest* request, int net_error) override; |
| 57 void OnReadCompleted(URLRequest* request, int bytes_read) override; | 52 void OnReadCompleted(URLRequest* request, int bytes_read) override; |
| 58 | 53 |
| 59 private: | 54 private: |
| 60 net::URLRequestContext* const request_context_; | 55 net::URLRequestContext* const request_context_; |
| 61 | |
| 62 CookiesPreference cookies_preference_; | |
| 63 | |
| 64 std::map<URLRequest*, std::unique_ptr<URLRequest>> inflight_requests_; | 56 std::map<URLRequest*, std::unique_ptr<URLRequest>> inflight_requests_; |
| 65 | 57 |
| 66 DISALLOW_COPY_AND_ASSIGN(ReportSender); | 58 DISALLOW_COPY_AND_ASSIGN(ReportSender); |
| 67 }; | 59 }; |
| 68 | 60 |
| 69 } // namespace net | 61 } // namespace net |
| 70 | 62 |
| 71 #endif // NET_URL_REQUEST_REPORT_SENDER_H_ | 63 #endif // NET_URL_REQUEST_REPORT_SENDER_H_ |
| OLD | NEW |