| 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 14 matching lines...) Expand all Loading... |
| 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/omnibox_incident_handl
ers.h" | 31 #include "chrome/browser/safe_browsing/incident_reporting/omnibox_incident_handl
ers.h" |
| 32 #include "chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.h" | 32 #include "chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.h" |
| 33 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" | 33 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" |
| 34 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident_handlers.h" | 34 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident_handlers.h" |
| 35 #include "chrome/browser/safe_browsing/incident_reporting/variations_seed_signat
ure_incident_handlers.h" |
| 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/common/safe_browsing/csd.pb.h" | 38 #include "chrome/common/safe_browsing/csd.pb.h" |
| 38 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 40 #include "net/url_request/url_request_context_getter.h" | 41 #include "net/url_request/url_request_context_getter.h" |
| 41 | 42 |
| 42 namespace safe_browsing { | 43 namespace safe_browsing { |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 // The type of an incident. Used for user metrics and for pruning of | 47 // The type of an incident. Used for user metrics and for pruning of |
| 47 // previously-reported incidents. | 48 // previously-reported incidents. |
| 48 enum IncidentType { | 49 enum IncidentType { |
| 49 // Start with 1 rather than zero; otherwise there won't be enough buckets for | 50 // Start with 1 rather than zero; otherwise there won't be enough buckets for |
| 50 // the histogram. | 51 // the histogram. |
| 51 TRACKED_PREFERENCE = 1, | 52 TRACKED_PREFERENCE = 1, |
| 52 BINARY_INTEGRITY = 2, | 53 BINARY_INTEGRITY = 2, |
| 53 BLACKLIST_LOAD = 3, | 54 BLACKLIST_LOAD = 3, |
| 54 OMNIBOX_INTERACTION = 4, | 55 OMNIBOX_INTERACTION = 4, |
| 56 VARIATIONS_SEED_SIGNATURE = 5, |
| 55 // Values for new incident types go here. | 57 // Values for new incident types go here. |
| 56 NUM_INCIDENT_TYPES = 5 | 58 NUM_INCIDENT_TYPES = 6 |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 // The action taken for an incident; used for user metrics (see | 61 // The action taken for an incident; used for user metrics (see |
| 60 // LogIncidentDataType). | 62 // LogIncidentDataType). |
| 61 enum IncidentDisposition { | 63 enum IncidentDisposition { |
| 62 RECEIVED, | 64 RECEIVED, |
| 63 DROPPED, | 65 DROPPED, |
| 64 ACCEPTED, | 66 ACCEPTED, |
| 65 PRUNED, | 67 PRUNED, |
| 66 DISCARDED, | 68 DISCARDED, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 91 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { | 93 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { |
| 92 size_t result = 0; | 94 size_t result = 0; |
| 93 if (incident.has_tracked_preference()) | 95 if (incident.has_tracked_preference()) |
| 94 ++result; | 96 ++result; |
| 95 if (incident.has_binary_integrity()) | 97 if (incident.has_binary_integrity()) |
| 96 ++result; | 98 ++result; |
| 97 if (incident.has_blacklist_load()) | 99 if (incident.has_blacklist_load()) |
| 98 ++result; | 100 ++result; |
| 99 if (incident.has_omnibox_interaction()) | 101 if (incident.has_omnibox_interaction()) |
| 100 ++result; | 102 ++result; |
| 103 if (incident.has_variations_seed_signature()) |
| 104 ++result; |
| 101 // Add detection for new incident types here. | 105 // Add detection for new incident types here. |
| 102 return result; | 106 return result; |
| 103 } | 107 } |
| 104 | 108 |
| 105 // Returns the type of incident contained in |incident_data|. | 109 // Returns the type of incident contained in |incident_data|. |
| 106 IncidentType GetIncidentType( | 110 IncidentType GetIncidentType( |
| 107 const ClientIncidentReport_IncidentData& incident_data) { | 111 const ClientIncidentReport_IncidentData& incident_data) { |
| 108 if (incident_data.has_tracked_preference()) | 112 if (incident_data.has_tracked_preference()) |
| 109 return TRACKED_PREFERENCE; | 113 return TRACKED_PREFERENCE; |
| 110 if (incident_data.has_binary_integrity()) | 114 if (incident_data.has_binary_integrity()) |
| 111 return BINARY_INTEGRITY; | 115 return BINARY_INTEGRITY; |
| 112 if (incident_data.has_blacklist_load()) | 116 if (incident_data.has_blacklist_load()) |
| 113 return BLACKLIST_LOAD; | 117 return BLACKLIST_LOAD; |
| 114 if (incident_data.has_omnibox_interaction()) | 118 if (incident_data.has_omnibox_interaction()) |
| 115 return OMNIBOX_INTERACTION; | 119 return OMNIBOX_INTERACTION; |
| 120 if (incident_data.has_variations_seed_signature()) |
| 121 return VARIATIONS_SEED_SIGNATURE; |
| 116 | 122 |
| 117 // Add detection for new incident types here. | 123 // Add detection for new incident types here. |
| 118 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, | 124 COMPILE_ASSERT(VARIATIONS_SEED_SIGNATURE + 1 == NUM_INCIDENT_TYPES, |
| 119 add_support_for_new_types); | 125 add_support_for_new_types); |
| 120 NOTREACHED(); | 126 NOTREACHED(); |
| 121 return NUM_INCIDENT_TYPES; | 127 return NUM_INCIDENT_TYPES; |
| 122 } | 128 } |
| 123 | 129 |
| 124 // Logs the type of incident in |incident_data| to a user metrics histogram. | 130 // Logs the type of incident in |incident_data| to a user metrics histogram. |
| 125 void LogIncidentDataType( | 131 void LogIncidentDataType( |
| 126 IncidentDisposition disposition, | 132 IncidentDisposition disposition, |
| 127 const ClientIncidentReport_IncidentData& incident_data) { | 133 const ClientIncidentReport_IncidentData& incident_data) { |
| 128 static const char* const kHistogramNames[] = { | 134 static const char* const kHistogramNames[] = { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 159 state.digest = GetBinaryIntegrityIncidentDigest(incident); | 165 state.digest = GetBinaryIntegrityIncidentDigest(incident); |
| 160 break; | 166 break; |
| 161 case BLACKLIST_LOAD: | 167 case BLACKLIST_LOAD: |
| 162 state.key = GetBlacklistLoadIncidentKey(incident); | 168 state.key = GetBlacklistLoadIncidentKey(incident); |
| 163 state.digest = GetBlacklistLoadIncidentDigest(incident); | 169 state.digest = GetBlacklistLoadIncidentDigest(incident); |
| 164 break; | 170 break; |
| 165 case OMNIBOX_INTERACTION: | 171 case OMNIBOX_INTERACTION: |
| 166 state.key = GetOmniboxIncidentKey(incident); | 172 state.key = GetOmniboxIncidentKey(incident); |
| 167 state.digest = GetOmniboxIncidentDigest(incident); | 173 state.digest = GetOmniboxIncidentDigest(incident); |
| 168 break; | 174 break; |
| 175 case VARIATIONS_SEED_SIGNATURE: |
| 176 state.key = GetVariationsSeedSignatureIncidentKey(incident); |
| 177 state.digest = GetVariationsSeedSignatureIncidentDigest(incident); |
| 178 break; |
| 169 // Add handling for new incident types here. | 179 // Add handling for new incident types here. |
| 170 default: | 180 case NUM_INCIDENT_TYPES: |
| 171 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, | |
| 172 add_support_for_new_types); | |
| 173 NOTREACHED(); | 181 NOTREACHED(); |
| 174 break; | 182 break; |
| 175 } | 183 } |
| 176 return state; | 184 return state; |
| 177 } | 185 } |
| 178 | 186 |
| 179 // Returns true if the incident described by |state| has already been reported | 187 // Returns true if the incident described by |state| has already been reported |
| 180 // based on the bookkeeping in the |incidents_sent| preference dictionary. | 188 // based on the bookkeeping in the |incidents_sent| preference dictionary. |
| 181 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, | 189 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, |
| 182 const PersistentIncidentState& state) { | 190 const PersistentIncidentState& state) { |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 if (!profile->IsOffTheRecord()) | 1015 if (!profile->IsOffTheRecord()) |
| 1008 OnProfileDestroyed(profile); | 1016 OnProfileDestroyed(profile); |
| 1009 break; | 1017 break; |
| 1010 } | 1018 } |
| 1011 default: | 1019 default: |
| 1012 break; | 1020 break; |
| 1013 } | 1021 } |
| 1014 } | 1022 } |
| 1015 | 1023 |
| 1016 } // namespace safe_browsing | 1024 } // namespace safe_browsing |
| OLD | NEW |