| 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 10 matching lines...) Expand all Loading... |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 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/omnibox_incident_handl
ers.h" |
| 31 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" | 32 #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" | 33 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident_handlers.h" |
| 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/safe_browsing/csd.pb.h" | 36 #include "chrome/common/safe_browsing/csd.pb.h" |
| 36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 38 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
| 39 | 40 |
| 40 namespace safe_browsing { | 41 namespace safe_browsing { |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 // The type of an incident. Used for user metrics and for pruning of | 45 // The type of an incident. Used for user metrics and for pruning of |
| 45 // previously-reported incidents. | 46 // previously-reported incidents. |
| 46 enum IncidentType { | 47 enum IncidentType { |
| 47 // Start with 1 rather than zero; otherwise there won't be enough buckets for | 48 // Start with 1 rather than zero; otherwise there won't be enough buckets for |
| 48 // the histogram. | 49 // the histogram. |
| 49 TRACKED_PREFERENCE = 1, | 50 TRACKED_PREFERENCE = 1, |
| 50 BINARY_INTEGRITY = 2, | 51 BINARY_INTEGRITY = 2, |
| 51 BLACKLIST_LOAD = 3, | 52 BLACKLIST_LOAD = 3, |
| 53 OMNIBOX_INTERACTION = 4, |
| 52 // Values for new incident types go here. | 54 // Values for new incident types go here. |
| 53 NUM_INCIDENT_TYPES = 4 | 55 NUM_INCIDENT_TYPES = 5 |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 // The action taken for an incident; used for user metrics (see | 58 // The action taken for an incident; used for user metrics (see |
| 57 // LogIncidentDataType). | 59 // LogIncidentDataType). |
| 58 enum IncidentDisposition { | 60 enum IncidentDisposition { |
| 59 RECEIVED, | 61 RECEIVED, |
| 60 DROPPED, | 62 DROPPED, |
| 61 ACCEPTED, | 63 ACCEPTED, |
| 62 PRUNED, | 64 PRUNED, |
| 63 DISCARDED, | 65 DISCARDED, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 // Returns the number of incidents contained in |incident|. The result is | 88 // Returns the number of incidents contained in |incident|. The result is |
| 87 // expected to be 1. Used in DCHECKs. | 89 // expected to be 1. Used in DCHECKs. |
| 88 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { | 90 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { |
| 89 size_t result = 0; | 91 size_t result = 0; |
| 90 if (incident.has_tracked_preference()) | 92 if (incident.has_tracked_preference()) |
| 91 ++result; | 93 ++result; |
| 92 if (incident.has_binary_integrity()) | 94 if (incident.has_binary_integrity()) |
| 93 ++result; | 95 ++result; |
| 94 if (incident.has_blacklist_load()) | 96 if (incident.has_blacklist_load()) |
| 95 ++result; | 97 ++result; |
| 98 if (incident.has_omnibox_interaction()) |
| 99 ++result; |
| 96 // Add detection for new incident types here. | 100 // Add detection for new incident types here. |
| 97 return result; | 101 return result; |
| 98 } | 102 } |
| 99 | 103 |
| 100 // Returns the type of incident contained in |incident_data|. | 104 // Returns the type of incident contained in |incident_data|. |
| 101 IncidentType GetIncidentType( | 105 IncidentType GetIncidentType( |
| 102 const ClientIncidentReport_IncidentData& incident_data) { | 106 const ClientIncidentReport_IncidentData& incident_data) { |
| 103 if (incident_data.has_tracked_preference()) | 107 if (incident_data.has_tracked_preference()) |
| 104 return TRACKED_PREFERENCE; | 108 return TRACKED_PREFERENCE; |
| 105 if (incident_data.has_binary_integrity()) | 109 if (incident_data.has_binary_integrity()) |
| 106 return BINARY_INTEGRITY; | 110 return BINARY_INTEGRITY; |
| 107 if (incident_data.has_blacklist_load()) | 111 if (incident_data.has_blacklist_load()) |
| 108 return BLACKLIST_LOAD; | 112 return BLACKLIST_LOAD; |
| 113 if (incident_data.has_omnibox_interaction()) |
| 114 return OMNIBOX_INTERACTION; |
| 109 | 115 |
| 110 // Add detection for new incident types here. | 116 // Add detection for new incident types here. |
| 111 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, | 117 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, |
| 112 add_support_for_new_types); | 118 add_support_for_new_types); |
| 113 NOTREACHED(); | 119 NOTREACHED(); |
| 114 return NUM_INCIDENT_TYPES; | 120 return NUM_INCIDENT_TYPES; |
| 115 } | 121 } |
| 116 | 122 |
| 117 // Logs the type of incident in |incident_data| to a user metrics histogram. | 123 // Logs the type of incident in |incident_data| to a user metrics histogram. |
| 118 void LogIncidentDataType( | 124 void LogIncidentDataType( |
| 119 IncidentDisposition disposition, | 125 IncidentDisposition disposition, |
| 120 const ClientIncidentReport_IncidentData& incident_data) { | 126 const ClientIncidentReport_IncidentData& incident_data) { |
| 121 static const char* const kHistogramNames[] = { | 127 static const char* const kHistogramNames[] = { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 148 state.digest = GetTrackedPreferenceIncidentDigest(incident); | 154 state.digest = GetTrackedPreferenceIncidentDigest(incident); |
| 149 break; | 155 break; |
| 150 case BINARY_INTEGRITY: | 156 case BINARY_INTEGRITY: |
| 151 state.key = GetBinaryIntegrityIncidentKey(incident); | 157 state.key = GetBinaryIntegrityIncidentKey(incident); |
| 152 state.digest = GetBinaryIntegrityIncidentDigest(incident); | 158 state.digest = GetBinaryIntegrityIncidentDigest(incident); |
| 153 break; | 159 break; |
| 154 case BLACKLIST_LOAD: | 160 case BLACKLIST_LOAD: |
| 155 state.key = GetBlacklistLoadIncidentKey(incident); | 161 state.key = GetBlacklistLoadIncidentKey(incident); |
| 156 state.digest = GetBlacklistLoadIncidentDigest(incident); | 162 state.digest = GetBlacklistLoadIncidentDigest(incident); |
| 157 break; | 163 break; |
| 164 case OMNIBOX_INTERACTION: |
| 165 state.key = GetOmniboxIncidentKey(incident); |
| 166 state.digest = GetOmniboxIncidentDigest(incident); |
| 167 break; |
| 158 // Add handling for new incident types here. | 168 // Add handling for new incident types here. |
| 159 default: | 169 default: |
| 160 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, | 170 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, |
| 161 add_support_for_new_types); | 171 add_support_for_new_types); |
| 162 NOTREACHED(); | 172 NOTREACHED(); |
| 163 break; | 173 break; |
| 164 } | 174 } |
| 165 return state; | 175 return state; |
| 166 } | 176 } |
| 167 | 177 |
| 168 // Returns true if the incident described by |state| has already been reported | 178 // Returns true if the incident described by |state| has already been reported |
| 169 // based on the bookkeeping in the |incidents_sent| preference dictionary. | 179 // based on the bookkeeping in the |incidents_sent| preference dictionary. |
| 170 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, | 180 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 if (!profile->IsOffTheRecord()) | 998 if (!profile->IsOffTheRecord()) |
| 989 OnProfileDestroyed(profile); | 999 OnProfileDestroyed(profile); |
| 990 break; | 1000 break; |
| 991 } | 1001 } |
| 992 default: | 1002 default: |
| 993 break; | 1003 break; |
| 994 } | 1004 } |
| 995 } | 1005 } |
| 996 | 1006 |
| 997 } // namespace safe_browsing | 1007 } // namespace safe_browsing |
| OLD | NEW |