OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
24 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" | 24 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" |
25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/safe_browsing/database_manager.h" | 26 #include "chrome/browser/safe_browsing/database_manager.h" |
27 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid
ent_handlers.h" | 27 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid
ent_handlers.h" |
28 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_inciden
t_handlers.h" | 28 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_inciden
t_handlers.h" |
29 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle
ction.h" | 29 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle
ction.h" |
30 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er_impl.h" | 30 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er_impl.h" |
31 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" | 31 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" |
32 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident_handlers.h" | 32 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident_handlers.h" |
33 #include "chrome/browser/safe_browsing/incident_reporting/variations_seed_signat
ure_incident_handlers.h" | |
34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
35 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/safe_browsing/csd.pb.h" | 35 #include "chrome/common/safe_browsing/csd.pb.h" |
37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
39 #include "net/url_request/url_request_context_getter.h" | 38 #include "net/url_request/url_request_context_getter.h" |
40 | 39 |
41 namespace safe_browsing { | 40 namespace safe_browsing { |
42 | 41 |
43 namespace { | 42 namespace { |
44 | 43 |
45 // The type of an incident. Used for user metrics and for pruning of | 44 // The type of an incident. Used for user metrics and for pruning of |
46 // previously-reported incidents. | 45 // previously-reported incidents. |
47 enum IncidentType { | 46 enum IncidentType { |
48 // Start with 1 rather than zero; otherwise there won't be enough buckets for | 47 // Start with 1 rather than zero; otherwise there won't be enough buckets for |
49 // the histogram. | 48 // the histogram. |
50 TRACKED_PREFERENCE = 1, | 49 TRACKED_PREFERENCE = 1, |
51 BINARY_INTEGRITY = 2, | 50 BINARY_INTEGRITY = 2, |
52 BLACKLIST_LOAD = 3, | 51 BLACKLIST_LOAD = 3, |
53 VARIATIONS_SEED_SIGNATURE = 4, | |
54 // Values for new incident types go here. | 52 // Values for new incident types go here. |
55 NUM_INCIDENT_TYPES = 5 | 53 NUM_INCIDENT_TYPES = 4 |
56 }; | 54 }; |
57 | 55 |
58 // The action taken for an incident; used for user metrics (see | 56 // The action taken for an incident; used for user metrics (see |
59 // LogIncidentDataType). | 57 // LogIncidentDataType). |
60 enum IncidentDisposition { | 58 enum IncidentDisposition { |
61 DROPPED, | 59 DROPPED, |
62 ACCEPTED, | 60 ACCEPTED, |
63 }; | 61 }; |
64 | 62 |
65 // The state persisted for a specific instance of an incident to enable pruning | 63 // The state persisted for a specific instance of an incident to enable pruning |
(...skipping 18 matching lines...) Expand all Loading... |
84 // Returns the number of incidents contained in |incident|. The result is | 82 // Returns the number of incidents contained in |incident|. The result is |
85 // expected to be 1. Used in DCHECKs. | 83 // expected to be 1. Used in DCHECKs. |
86 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { | 84 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { |
87 size_t result = 0; | 85 size_t result = 0; |
88 if (incident.has_tracked_preference()) | 86 if (incident.has_tracked_preference()) |
89 ++result; | 87 ++result; |
90 if (incident.has_binary_integrity()) | 88 if (incident.has_binary_integrity()) |
91 ++result; | 89 ++result; |
92 if (incident.has_blacklist_load()) | 90 if (incident.has_blacklist_load()) |
93 ++result; | 91 ++result; |
94 if (incident.has_variations_seed_signature()) | |
95 ++result; | |
96 // Add detection for new incident types here. | 92 // Add detection for new incident types here. |
97 return result; | 93 return result; |
98 } | 94 } |
99 | 95 |
100 // Returns the type of incident contained in |incident_data|. | 96 // Returns the type of incident contained in |incident_data|. |
101 IncidentType GetIncidentType( | 97 IncidentType GetIncidentType( |
102 const ClientIncidentReport_IncidentData& incident_data) { | 98 const ClientIncidentReport_IncidentData& incident_data) { |
103 if (incident_data.has_tracked_preference()) | 99 if (incident_data.has_tracked_preference()) |
104 return TRACKED_PREFERENCE; | 100 return TRACKED_PREFERENCE; |
105 if (incident_data.has_binary_integrity()) | 101 if (incident_data.has_binary_integrity()) |
106 return BINARY_INTEGRITY; | 102 return BINARY_INTEGRITY; |
107 if (incident_data.has_blacklist_load()) | 103 if (incident_data.has_blacklist_load()) |
108 return BLACKLIST_LOAD; | 104 return BLACKLIST_LOAD; |
109 if (incident_data.has_variations_seed_signature()) | |
110 return VARIATIONS_SEED_SIGNATURE; | |
111 | 105 |
112 // Add detection for new incident types here. | 106 // Add detection for new incident types here. |
113 COMPILE_ASSERT(VARIATIONS_SEED_SIGNATURE + 1 == NUM_INCIDENT_TYPES, | 107 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, |
114 add_support_for_new_types); | 108 add_support_for_new_types); |
115 NOTREACHED(); | 109 NOTREACHED(); |
116 return NUM_INCIDENT_TYPES; | 110 return NUM_INCIDENT_TYPES; |
117 } | 111 } |
118 | 112 |
119 // Logs the type of incident in |incident_data| to a user metrics histogram. | 113 // Logs the type of incident in |incident_data| to a user metrics histogram. |
120 void LogIncidentDataType( | 114 void LogIncidentDataType( |
121 IncidentDisposition disposition, | 115 IncidentDisposition disposition, |
122 const ClientIncidentReport_IncidentData& incident_data) { | 116 const ClientIncidentReport_IncidentData& incident_data) { |
123 IncidentType type = GetIncidentType(incident_data); | 117 IncidentType type = GetIncidentType(incident_data); |
(...skipping 16 matching lines...) Expand all Loading... |
140 state.digest = GetTrackedPreferenceIncidentDigest(incident); | 134 state.digest = GetTrackedPreferenceIncidentDigest(incident); |
141 break; | 135 break; |
142 case BINARY_INTEGRITY: | 136 case BINARY_INTEGRITY: |
143 state.key = GetBinaryIntegrityIncidentKey(incident); | 137 state.key = GetBinaryIntegrityIncidentKey(incident); |
144 state.digest = GetBinaryIntegrityIncidentDigest(incident); | 138 state.digest = GetBinaryIntegrityIncidentDigest(incident); |
145 break; | 139 break; |
146 case BLACKLIST_LOAD: | 140 case BLACKLIST_LOAD: |
147 state.key = GetBlacklistLoadIncidentKey(incident); | 141 state.key = GetBlacklistLoadIncidentKey(incident); |
148 state.digest = GetBlacklistLoadIncidentDigest(incident); | 142 state.digest = GetBlacklistLoadIncidentDigest(incident); |
149 break; | 143 break; |
150 case VARIATIONS_SEED_SIGNATURE: | |
151 state.key = GetVariationsSeedSignatureIncidentKey(incident); | |
152 state.digest = GetVariationsSeedSignatureIncidentDigest(incident); | |
153 break; | |
154 // Add handling for new incident types here. | 144 // Add handling for new incident types here. |
155 default: | 145 default: |
156 COMPILE_ASSERT(VARIATIONS_SEED_SIGNATURE + 1 == NUM_INCIDENT_TYPES, | 146 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, |
157 add_support_for_new_types); | 147 add_support_for_new_types); |
158 NOTREACHED(); | 148 NOTREACHED(); |
159 break; | 149 break; |
160 } | 150 } |
161 return state; | 151 return state; |
162 } | 152 } |
163 | 153 |
164 // Returns true if the incident described by |state| has already been reported | 154 // Returns true if the incident described by |state| has already been reported |
165 // based on the bookkeeping in the |incidents_sent| preference dictionary. | 155 // based on the bookkeeping in the |incidents_sent| preference dictionary. |
166 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, | 156 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 if (!profile->IsOffTheRecord()) | 961 if (!profile->IsOffTheRecord()) |
972 OnProfileDestroyed(profile); | 962 OnProfileDestroyed(profile); |
973 break; | 963 break; |
974 } | 964 } |
975 default: | 965 default: |
976 break; | 966 break; |
977 } | 967 } |
978 } | 968 } |
979 | 969 |
980 } // namespace safe_browsing | 970 } // namespace safe_browsing |
OLD | NEW |