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" |
| 32 #include "chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.h" |
31 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" | 33 #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" | 34 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident_handlers.h" |
33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/safe_browsing/csd.pb.h" | 37 #include "chrome/common/safe_browsing/csd.pb.h" |
36 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
38 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
39 | 41 |
40 namespace safe_browsing { | 42 namespace safe_browsing { |
41 | 43 |
42 namespace { | 44 namespace { |
43 | 45 |
44 // The type of an incident. Used for user metrics and for pruning of | 46 // The type of an incident. Used for user metrics and for pruning of |
45 // previously-reported incidents. | 47 // previously-reported incidents. |
46 enum IncidentType { | 48 enum IncidentType { |
47 // Start with 1 rather than zero; otherwise there won't be enough buckets for | 49 // Start with 1 rather than zero; otherwise there won't be enough buckets for |
48 // the histogram. | 50 // the histogram. |
49 TRACKED_PREFERENCE = 1, | 51 TRACKED_PREFERENCE = 1, |
50 BINARY_INTEGRITY = 2, | 52 BINARY_INTEGRITY = 2, |
51 BLACKLIST_LOAD = 3, | 53 BLACKLIST_LOAD = 3, |
| 54 OMNIBOX_INTERACTION = 4, |
52 // Values for new incident types go here. | 55 // Values for new incident types go here. |
53 NUM_INCIDENT_TYPES = 4 | 56 NUM_INCIDENT_TYPES = 5 |
54 }; | 57 }; |
55 | 58 |
56 // The action taken for an incident; used for user metrics (see | 59 // The action taken for an incident; used for user metrics (see |
57 // LogIncidentDataType). | 60 // LogIncidentDataType). |
58 enum IncidentDisposition { | 61 enum IncidentDisposition { |
59 RECEIVED, | 62 RECEIVED, |
60 DROPPED, | 63 DROPPED, |
61 ACCEPTED, | 64 ACCEPTED, |
62 PRUNED, | 65 PRUNED, |
63 DISCARDED, | 66 DISCARDED, |
(...skipping 22 matching lines...) Expand all Loading... |
86 // Returns the number of incidents contained in |incident|. The result is | 89 // Returns the number of incidents contained in |incident|. The result is |
87 // expected to be 1. Used in DCHECKs. | 90 // expected to be 1. Used in DCHECKs. |
88 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { | 91 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { |
89 size_t result = 0; | 92 size_t result = 0; |
90 if (incident.has_tracked_preference()) | 93 if (incident.has_tracked_preference()) |
91 ++result; | 94 ++result; |
92 if (incident.has_binary_integrity()) | 95 if (incident.has_binary_integrity()) |
93 ++result; | 96 ++result; |
94 if (incident.has_blacklist_load()) | 97 if (incident.has_blacklist_load()) |
95 ++result; | 98 ++result; |
| 99 if (incident.has_omnibox_interaction()) |
| 100 ++result; |
96 // Add detection for new incident types here. | 101 // Add detection for new incident types here. |
97 return result; | 102 return result; |
98 } | 103 } |
99 | 104 |
100 // Returns the type of incident contained in |incident_data|. | 105 // Returns the type of incident contained in |incident_data|. |
101 IncidentType GetIncidentType( | 106 IncidentType GetIncidentType( |
102 const ClientIncidentReport_IncidentData& incident_data) { | 107 const ClientIncidentReport_IncidentData& incident_data) { |
103 if (incident_data.has_tracked_preference()) | 108 if (incident_data.has_tracked_preference()) |
104 return TRACKED_PREFERENCE; | 109 return TRACKED_PREFERENCE; |
105 if (incident_data.has_binary_integrity()) | 110 if (incident_data.has_binary_integrity()) |
106 return BINARY_INTEGRITY; | 111 return BINARY_INTEGRITY; |
107 if (incident_data.has_blacklist_load()) | 112 if (incident_data.has_blacklist_load()) |
108 return BLACKLIST_LOAD; | 113 return BLACKLIST_LOAD; |
| 114 if (incident_data.has_omnibox_interaction()) |
| 115 return OMNIBOX_INTERACTION; |
109 | 116 |
110 // Add detection for new incident types here. | 117 // Add detection for new incident types here. |
111 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, | 118 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, |
112 add_support_for_new_types); | 119 add_support_for_new_types); |
113 NOTREACHED(); | 120 NOTREACHED(); |
114 return NUM_INCIDENT_TYPES; | 121 return NUM_INCIDENT_TYPES; |
115 } | 122 } |
116 | 123 |
117 // Logs the type of incident in |incident_data| to a user metrics histogram. | 124 // Logs the type of incident in |incident_data| to a user metrics histogram. |
118 void LogIncidentDataType( | 125 void LogIncidentDataType( |
119 IncidentDisposition disposition, | 126 IncidentDisposition disposition, |
120 const ClientIncidentReport_IncidentData& incident_data) { | 127 const ClientIncidentReport_IncidentData& incident_data) { |
121 static const char* const kHistogramNames[] = { | 128 static const char* const kHistogramNames[] = { |
(...skipping 26 matching lines...) Expand all Loading... |
148 state.digest = GetTrackedPreferenceIncidentDigest(incident); | 155 state.digest = GetTrackedPreferenceIncidentDigest(incident); |
149 break; | 156 break; |
150 case BINARY_INTEGRITY: | 157 case BINARY_INTEGRITY: |
151 state.key = GetBinaryIntegrityIncidentKey(incident); | 158 state.key = GetBinaryIntegrityIncidentKey(incident); |
152 state.digest = GetBinaryIntegrityIncidentDigest(incident); | 159 state.digest = GetBinaryIntegrityIncidentDigest(incident); |
153 break; | 160 break; |
154 case BLACKLIST_LOAD: | 161 case BLACKLIST_LOAD: |
155 state.key = GetBlacklistLoadIncidentKey(incident); | 162 state.key = GetBlacklistLoadIncidentKey(incident); |
156 state.digest = GetBlacklistLoadIncidentDigest(incident); | 163 state.digest = GetBlacklistLoadIncidentDigest(incident); |
157 break; | 164 break; |
| 165 case OMNIBOX_INTERACTION: |
| 166 state.key = GetOmniboxIncidentKey(incident); |
| 167 state.digest = GetOmniboxIncidentDigest(incident); |
| 168 break; |
158 // Add handling for new incident types here. | 169 // Add handling for new incident types here. |
159 default: | 170 default: |
160 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES, | 171 COMPILE_ASSERT(OMNIBOX_INTERACTION + 1 == NUM_INCIDENT_TYPES, |
161 add_support_for_new_types); | 172 add_support_for_new_types); |
162 NOTREACHED(); | 173 NOTREACHED(); |
163 break; | 174 break; |
164 } | 175 } |
165 return state; | 176 return state; |
166 } | 177 } |
167 | 178 |
168 // Returns true if the incident described by |state| has already been reported | 179 // Returns true if the incident described by |state| has already been reported |
169 // based on the bookkeeping in the |incidents_sent| preference dictionary. | 180 // based on the bookkeeping in the |incidents_sent| preference dictionary. |
170 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, | 181 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } // namespace | 223 } // namespace |
213 | 224 |
214 struct IncidentReportingService::ProfileContext { | 225 struct IncidentReportingService::ProfileContext { |
215 ProfileContext(); | 226 ProfileContext(); |
216 ~ProfileContext(); | 227 ~ProfileContext(); |
217 | 228 |
218 // The incidents collected for this profile pending creation and/or upload. | 229 // The incidents collected for this profile pending creation and/or upload. |
219 // Will contain null values for pruned incidents. | 230 // Will contain null values for pruned incidents. |
220 ScopedVector<ClientIncidentReport_IncidentData> incidents; | 231 ScopedVector<ClientIncidentReport_IncidentData> incidents; |
221 | 232 |
| 233 // Watches for suspicious omnibox interactions on this profile. |
| 234 scoped_ptr<OmniboxWatcher> omnibox_watcher; |
| 235 |
222 // False until PROFILE_ADDED notification is received. | 236 // False until PROFILE_ADDED notification is received. |
223 bool added; | 237 bool added; |
224 | 238 |
225 private: | 239 private: |
226 DISALLOW_COPY_AND_ASSIGN(ProfileContext); | 240 DISALLOW_COPY_AND_ASSIGN(ProfileContext); |
227 }; | 241 }; |
228 | 242 |
229 class IncidentReportingService::UploadContext { | 243 class IncidentReportingService::UploadContext { |
230 public: | 244 public: |
231 typedef std::map<Profile*, std::vector<PersistentIncidentState> > | 245 typedef std::map<Profile*, std::vector<PersistentIncidentState> > |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 430 } |
417 } | 431 } |
418 | 432 |
419 void IncidentReportingService::OnProfileAdded(Profile* profile) { | 433 void IncidentReportingService::OnProfileAdded(Profile* profile) { |
420 DCHECK(thread_checker_.CalledOnValidThread()); | 434 DCHECK(thread_checker_.CalledOnValidThread()); |
421 | 435 |
422 // Track the addition of all profiles even when no report is being assembled | 436 // Track the addition of all profiles even when no report is being assembled |
423 // so that the service can determine whether or not it can evaluate a | 437 // so that the service can determine whether or not it can evaluate a |
424 // profile's preferences at the time of incident addition. | 438 // profile's preferences at the time of incident addition. |
425 ProfileContext* context = GetOrCreateProfileContext(profile); | 439 ProfileContext* context = GetOrCreateProfileContext(profile); |
| 440 // Start watching the profile now if necessary. |
| 441 if (!context->omnibox_watcher) { |
| 442 context->omnibox_watcher.reset( |
| 443 new OmniboxWatcher(profile, GetAddIncidentCallback(profile))); |
| 444 } |
426 context->added = true; | 445 context->added = true; |
427 | 446 |
428 const bool safe_browsing_enabled = | 447 const bool safe_browsing_enabled = |
429 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled); | 448 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled); |
430 | 449 |
431 // Start processing delayed analysis callbacks if this new profile | 450 // Start processing delayed analysis callbacks if this new profile |
432 // participates in safe browsing. Start is idempotent, so this is safe even if | 451 // participates in safe browsing. Start is idempotent, so this is safe even if |
433 // they're already running. | 452 // they're already running. |
434 if (safe_browsing_enabled) | 453 if (safe_browsing_enabled) |
435 delayed_analysis_callbacks_.Start(); | 454 delayed_analysis_callbacks_.Start(); |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 if (!profile->IsOffTheRecord()) | 1007 if (!profile->IsOffTheRecord()) |
989 OnProfileDestroyed(profile); | 1008 OnProfileDestroyed(profile); |
990 break; | 1009 break; |
991 } | 1010 } |
992 default: | 1011 default: |
993 break; | 1012 break; |
994 } | 1013 } |
995 } | 1014 } |
996 | 1015 |
997 } // namespace safe_browsing | 1016 } // namespace safe_browsing |
OLD | NEW |