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 DROPPED, | 61 DROPPED, |
60 ACCEPTED, | 62 ACCEPTED, |
61 }; | 63 }; |
62 | 64 |
63 // The state persisted for a specific instance of an incident to enable pruning | 65 // The state persisted for a specific instance of an incident to enable pruning |
(...skipping 18 matching lines...) Expand all Loading... |
82 // Returns the number of incidents contained in |incident|. The result is | 84 // Returns the number of incidents contained in |incident|. The result is |
83 // expected to be 1. Used in DCHECKs. | 85 // expected to be 1. Used in DCHECKs. |
84 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { | 86 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { |
85 size_t result = 0; | 87 size_t result = 0; |
86 if (incident.has_tracked_preference()) | 88 if (incident.has_tracked_preference()) |
87 ++result; | 89 ++result; |
88 if (incident.has_binary_integrity()) | 90 if (incident.has_binary_integrity()) |
89 ++result; | 91 ++result; |
90 if (incident.has_blacklist_load()) | 92 if (incident.has_blacklist_load()) |
91 ++result; | 93 ++result; |
| 94 if (incident.has_omnibox_interaction()) |
| 95 ++result; |
92 // Add detection for new incident types here. | 96 // Add detection for new incident types here. |
93 return result; | 97 return result; |
94 } | 98 } |
95 | 99 |
96 // Returns the type of incident contained in |incident_data|. | 100 // Returns the type of incident contained in |incident_data|. |
97 IncidentType GetIncidentType( | 101 IncidentType GetIncidentType( |
98 const ClientIncidentReport_IncidentData& incident_data) { | 102 const ClientIncidentReport_IncidentData& incident_data) { |
99 if (incident_data.has_tracked_preference()) | 103 if (incident_data.has_tracked_preference()) |
100 return TRACKED_PREFERENCE; | 104 return TRACKED_PREFERENCE; |
101 if (incident_data.has_binary_integrity()) | 105 if (incident_data.has_binary_integrity()) |
102 return BINARY_INTEGRITY; | 106 return BINARY_INTEGRITY; |
103 if (incident_data.has_blacklist_load()) | 107 if (incident_data.has_blacklist_load()) |
104 return BLACKLIST_LOAD; | 108 return BLACKLIST_LOAD; |
| 109 if (incident_data.has_omnibox_interaction()) |
| 110 return OMNIBOX_INTERACTION; |
105 | 111 |
106 // Add detection for new incident types here. | 112 // Add detection for new incident types here. |
107 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, | 113 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, |
108 add_support_for_new_types); | 114 add_support_for_new_types); |
109 NOTREACHED(); | 115 NOTREACHED(); |
110 return NUM_INCIDENT_TYPES; | 116 return NUM_INCIDENT_TYPES; |
111 } | 117 } |
112 | 118 |
113 // Logs the type of incident in |incident_data| to a user metrics histogram. | 119 // Logs the type of incident in |incident_data| to a user metrics histogram. |
114 void LogIncidentDataType( | 120 void LogIncidentDataType( |
115 IncidentDisposition disposition, | 121 IncidentDisposition disposition, |
116 const ClientIncidentReport_IncidentData& incident_data) { | 122 const ClientIncidentReport_IncidentData& incident_data) { |
117 IncidentType type = GetIncidentType(incident_data); | 123 IncidentType type = GetIncidentType(incident_data); |
(...skipping 16 matching lines...) Expand all Loading... |
134 state.digest = GetTrackedPreferenceIncidentDigest(incident); | 140 state.digest = GetTrackedPreferenceIncidentDigest(incident); |
135 break; | 141 break; |
136 case BINARY_INTEGRITY: | 142 case BINARY_INTEGRITY: |
137 state.key = GetBinaryIntegrityIncidentKey(incident); | 143 state.key = GetBinaryIntegrityIncidentKey(incident); |
138 state.digest = GetBinaryIntegrityIncidentDigest(incident); | 144 state.digest = GetBinaryIntegrityIncidentDigest(incident); |
139 break; | 145 break; |
140 case BLACKLIST_LOAD: | 146 case BLACKLIST_LOAD: |
141 state.key = GetBlacklistLoadIncidentKey(incident); | 147 state.key = GetBlacklistLoadIncidentKey(incident); |
142 state.digest = GetBlacklistLoadIncidentDigest(incident); | 148 state.digest = GetBlacklistLoadIncidentDigest(incident); |
143 break; | 149 break; |
| 150 case OMNIBOX_INTERACTION: |
| 151 state.key = GetOmniboxIncidentKey(incident); |
| 152 state.digest = GetOmniboxIncidentDigest(incident); |
| 153 break; |
144 // Add handling for new incident types here. | 154 // Add handling for new incident types here. |
145 default: | 155 default: |
146 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, | 156 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, |
147 add_support_for_new_types); | 157 add_support_for_new_types); |
148 NOTREACHED(); | 158 NOTREACHED(); |
149 break; | 159 break; |
150 } | 160 } |
151 return state; | 161 return state; |
152 } | 162 } |
153 | 163 |
154 // Returns true if the incident described by |state| has already been reported | 164 // Returns true if the incident described by |state| has already been reported |
155 // based on the bookkeeping in the |incidents_sent| preference dictionary. | 165 // based on the bookkeeping in the |incidents_sent| preference dictionary. |
156 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, | 166 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 if (!profile->IsOffTheRecord()) | 971 if (!profile->IsOffTheRecord()) |
962 OnProfileDestroyed(profile); | 972 OnProfileDestroyed(profile); |
963 break; | 973 break; |
964 } | 974 } |
965 default: | 975 default: |
966 break; | 976 break; |
967 } | 977 } |
968 } | 978 } |
969 | 979 |
970 } // namespace safe_browsing | 980 } // namespace safe_browsing |
OLD | NEW |