juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_REPORTING_REPORTING_HEADER_PARSER_H_ |
| 6 | #define NET_REPORTING_REPORTING_HEADER_PARSER_H_ |
| 7 | |
Julia Tuttle | ec467a5f | 2018-02-22 20:22:45 | [diff] [blame] | 8 | #include <memory> |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 9 | |
| 10 | #include "base/macros.h" |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 12 | #include "net/reporting/reporting_client.h" |
| 13 | #include "url/gurl.h" |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 14 | |
Julia Tuttle | ec467a5f | 2018-02-22 20:22:45 | [diff] [blame] | 15 | namespace base { |
| 16 | class Value; |
| 17 | } // namespace base |
| 18 | |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 19 | namespace net { |
| 20 | |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 21 | class ReportingContext; |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 22 | |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 23 | class NET_EXPORT ReportingHeaderParser { |
| 24 | public: |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 25 | // Histograms. These are mainly used in test cases to verify that interesting |
| 26 | // events occurred. |
| 27 | |
| 28 | static const char kHeaderOutcomeHistogram[]; |
| 29 | static const char kHeaderEndpointGroupOutcomeHistogram[]; |
| 30 | static const char kHeaderEndpointOutcomeHistogram[]; |
| 31 | |
| 32 | enum class HeaderOutcome { |
| 33 | DISCARDED_NO_REPORTING_SERVICE = 0, |
| 34 | DISCARDED_INVALID_SSL_INFO = 1, |
| 35 | DISCARDED_CERT_STATUS_ERROR = 2, |
| 36 | DISCARDED_JSON_TOO_BIG = 3, |
| 37 | DISCARDED_JSON_INVALID = 4, |
| 38 | PARSED = 5, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 39 | REMOVED_EMPTY = 6, |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 40 | MAX |
| 41 | }; |
| 42 | |
| 43 | enum class HeaderEndpointGroupOutcome { |
| 44 | DISCARDED_NOT_DICTIONARY = 0, |
| 45 | DISCARDED_GROUP_NOT_STRING = 1, |
| 46 | DISCARDED_TTL_MISSING = 2, |
| 47 | DISCARDED_TTL_NOT_INTEGER = 3, |
| 48 | DISCARDED_TTL_NEGATIVE = 4, |
| 49 | DISCARDED_ENDPOINTS_MISSING = 5, |
| 50 | DISCARDED_ENDPOINTS_NOT_LIST = 6, |
| 51 | |
| 52 | PARSED = 7, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 53 | REMOVED_TTL_ZERO = 8, |
| 54 | REMOVED_EMPTY = 9, |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 55 | MAX |
| 56 | }; |
| 57 | |
| 58 | enum class HeaderEndpointOutcome { |
| 59 | DISCARDED_NOT_DICTIONARY = 0, |
| 60 | DISCARDED_URL_MISSING = 1, |
| 61 | DISCARDED_URL_NOT_STRING = 2, |
| 62 | DISCARDED_URL_INVALID = 3, |
| 63 | DISCARDED_URL_INSECURE = 4, |
| 64 | DISCARDED_PRIORITY_NOT_INTEGER = 5, |
| 65 | DISCARDED_WEIGHT_NOT_INTEGER = 6, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 66 | DISCARDED_WEIGHT_NEGATIVE = 7, |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 67 | |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 68 | REMOVED = 8, // Obsolete: removing for max_age: 0 is done on a group basis. |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 69 | SET_REJECTED_BY_DELEGATE = 9, |
| 70 | SET = 10, |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame^] | 71 | DISCARDED_PRIORITY_NEGATIVE = 11, |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 72 | |
| 73 | MAX |
| 74 | }; |
| 75 | |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 76 | static void RecordHeaderDiscardedForNoReportingService(); |
| 77 | static void RecordHeaderDiscardedForInvalidSSLInfo(); |
| 78 | static void RecordHeaderDiscardedForCertStatusError(); |
Julia Tuttle | ef19cb5 | 2018-03-16 16:58:35 | [diff] [blame] | 79 | static void RecordHeaderDiscardedForJsonInvalid(); |
| 80 | static void RecordHeaderDiscardedForJsonTooBig(); |
juliatuttle | 667c0bb | 2017-07-06 15:17:13 | [diff] [blame] | 81 | |
juliatuttle | ee4b55e | 2017-04-07 17:09:45 | [diff] [blame] | 82 | static void ParseHeader(ReportingContext* context, |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 83 | const GURL& url, |
Julia Tuttle | ec467a5f | 2018-02-22 20:22:45 | [diff] [blame] | 84 | std::unique_ptr<base::Value> value); |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 85 | |
| 86 | private: |
juliatuttle | 1690bc6 | 2017-03-29 17:16:02 | [diff] [blame] | 87 | DISALLOW_IMPLICIT_CONSTRUCTORS(ReportingHeaderParser); |
| 88 | }; |
| 89 | |
| 90 | } // namespace net |
| 91 | |
| 92 | #endif // NET_REPORTING_REPORTING_HEADER_PARSER_H_ |