| 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 16 matching lines...) Expand all Loading... |
| 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< | 34 using ErrorCallback = base::Callback< |
| 35 void(const GURL&, int /* net_error */, int /* http_response_code */)>; | 35 void(const GURL&, int /* net_error */, int /* http_response_code */)>; |
| 36 | 36 |
| 37 // Represents whether or not to send cookies along with reports. | |
| 38 enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES }; | |
| 39 | |
| 40 // Constructs a ReportSender that sends reports with the | 37 // Constructs a ReportSender that sends reports with the |
| 41 // given |request_context| and includes or excludes cookies based on | 38 // given |request_context|, always excluding cookies. |request_context| must |
| 42 // |cookies_preference|. |request_context| must outlive the | 39 // outlive the ReportSender. |
| 43 // ReportSender. | 40 explicit ReportSender(URLRequestContext* request_context); |
| 44 ReportSender(URLRequestContext* request_context, | |
| 45 CookiesPreference cookies_preference); | |
| 46 | 41 |
| 47 ~ReportSender() override; | 42 ~ReportSender() override; |
| 48 | 43 |
| 49 // TransportSecurityState::ReportSenderInterface implementation. | 44 // TransportSecurityState::ReportSenderInterface implementation. |
| 50 void Send(const GURL& report_uri, | 45 void Send(const GURL& report_uri, |
| 51 base::StringPiece content_type, | 46 base::StringPiece content_type, |
| 52 base::StringPiece report, | 47 base::StringPiece report, |
| 53 const SuccessCallback& success_callback, | 48 const SuccessCallback& success_callback, |
| 54 const ErrorCallback& error_callback) override; | 49 const ErrorCallback& error_callback) override; |
| 55 | 50 |
| 56 // net::URLRequest::Delegate implementation. | 51 // net::URLRequest::Delegate implementation. |
| 57 void OnResponseStarted(URLRequest* request, int net_error) override; | 52 void OnResponseStarted(URLRequest* request, int net_error) override; |
| 58 void OnReadCompleted(URLRequest* request, int bytes_read) override; | 53 void OnReadCompleted(URLRequest* request, int bytes_read) override; |
| 59 | 54 |
| 60 private: | 55 private: |
| 61 net::URLRequestContext* const request_context_; | 56 net::URLRequestContext* const request_context_; |
| 62 | |
| 63 CookiesPreference cookies_preference_; | |
| 64 | |
| 65 std::map<URLRequest*, std::unique_ptr<URLRequest>> inflight_requests_; | 57 std::map<URLRequest*, std::unique_ptr<URLRequest>> inflight_requests_; |
| 66 | 58 |
| 67 DISALLOW_COPY_AND_ASSIGN(ReportSender); | 59 DISALLOW_COPY_AND_ASSIGN(ReportSender); |
| 68 }; | 60 }; |
| 69 | 61 |
| 70 } // namespace net | 62 } // namespace net |
| 71 | 63 |
| 72 #endif // NET_URL_REQUEST_REPORT_SENDER_H_ | 64 #endif // NET_URL_REQUEST_REPORT_SENDER_H_ |
| OLD | NEW |