Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc

Issue 433513008: Add blacklist incidents to incident reporting service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mattm feedback Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
11 11
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/process/process_info.h" 15 #include "base/process/process_info.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
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/environment_data_colle ction.h" 29 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle ction.h"
29 #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"
30 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_ delegate.h" 31 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_ delegate.h"
31 #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"
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 33 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
33 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
34 #include "chrome/common/safe_browsing/csd.pb.h" 35 #include "chrome/common/safe_browsing/csd.pb.h"
35 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "net/url_request/url_request_context_getter.h" 38 #include "net/url_request/url_request_context_getter.h"
38 39
39 namespace safe_browsing { 40 namespace safe_browsing {
40 41
41 namespace { 42 namespace {
42 43
43 // 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
44 // previously-reported incidents. 45 // previously-reported incidents.
45 enum IncidentType { 46 enum IncidentType {
46 // 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
47 // the histogram. 48 // the histogram.
48 TRACKED_PREFERENCE = 1, 49 TRACKED_PREFERENCE = 1,
49 BINARY_INTEGRITY = 2, 50 BINARY_INTEGRITY = 2,
51 BLACKLIST_LOAD = 3,
50 // Values for new incident types go here. 52 // Values for new incident types go here.
51 NUM_INCIDENT_TYPES 53 NUM_INCIDENT_TYPES = 4
52 }; 54 };
53 55
54 // The action taken for an incident; used for user metrics (see 56 // The action taken for an incident; used for user metrics (see
55 // LogIncidentDataType). 57 // LogIncidentDataType).
56 enum IncidentDisposition { 58 enum IncidentDisposition {
57 DROPPED, 59 DROPPED,
58 ACCEPTED, 60 ACCEPTED,
59 }; 61 };
60 62
61 // 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 16 matching lines...) Expand all
78 const int64 kDefaultCallbackIntervalMs = 1000 * 20; 80 const int64 kDefaultCallbackIntervalMs = 1000 * 20;
79 81
80 // Returns the number of incidents contained in |incident|. The result is 82 // Returns the number of incidents contained in |incident|. The result is
81 // expected to be 1. Used in DCHECKs. 83 // expected to be 1. Used in DCHECKs.
82 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) { 84 size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) {
83 size_t result = 0; 85 size_t result = 0;
84 if (incident.has_tracked_preference()) 86 if (incident.has_tracked_preference())
85 ++result; 87 ++result;
86 if (incident.has_binary_integrity()) 88 if (incident.has_binary_integrity())
87 ++result; 89 ++result;
90 if (incident.has_blacklist_load())
91 ++result;
88 // Add detection for new incident types here. 92 // Add detection for new incident types here.
89 return result; 93 return result;
90 } 94 }
91 95
92 // Returns the type of incident contained in |incident_data|. 96 // Returns the type of incident contained in |incident_data|.
93 IncidentType GetIncidentType( 97 IncidentType GetIncidentType(
94 const ClientIncidentReport_IncidentData& incident_data) { 98 const ClientIncidentReport_IncidentData& incident_data) {
95 if (incident_data.has_tracked_preference()) 99 if (incident_data.has_tracked_preference())
96 return TRACKED_PREFERENCE; 100 return TRACKED_PREFERENCE;
97 if (incident_data.has_binary_integrity()) 101 if (incident_data.has_binary_integrity())
98 return BINARY_INTEGRITY; 102 return BINARY_INTEGRITY;
103 if (incident_data.has_blacklist_load())
104 return BLACKLIST_LOAD;
99 105
100 // Add detection for new incident types here. 106 // Add detection for new incident types here.
101 COMPILE_ASSERT(BINARY_INTEGRITY + 1 == NUM_INCIDENT_TYPES, 107 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES,
102 add_support_for_new_types); 108 add_support_for_new_types);
103 NOTREACHED(); 109 NOTREACHED();
104 return NUM_INCIDENT_TYPES; 110 return NUM_INCIDENT_TYPES;
105 } 111 }
106 112
107 // 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.
108 void LogIncidentDataType( 114 void LogIncidentDataType(
109 IncidentDisposition disposition, 115 IncidentDisposition disposition,
110 const ClientIncidentReport_IncidentData& incident_data) { 116 const ClientIncidentReport_IncidentData& incident_data) {
111 IncidentType type = GetIncidentType(incident_data); 117 IncidentType type = GetIncidentType(incident_data);
(...skipping 12 matching lines...) Expand all
124 PersistentIncidentState state = {GetIncidentType(incident)}; 130 PersistentIncidentState state = {GetIncidentType(incident)};
125 switch (state.type) { 131 switch (state.type) {
126 case TRACKED_PREFERENCE: 132 case TRACKED_PREFERENCE:
127 state.key = GetTrackedPreferenceIncidentKey(incident); 133 state.key = GetTrackedPreferenceIncidentKey(incident);
128 state.digest = GetTrackedPreferenceIncidentDigest(incident); 134 state.digest = GetTrackedPreferenceIncidentDigest(incident);
129 break; 135 break;
130 case BINARY_INTEGRITY: 136 case BINARY_INTEGRITY:
131 state.key = GetBinaryIntegrityIncidentKey(incident); 137 state.key = GetBinaryIntegrityIncidentKey(incident);
132 state.digest = GetBinaryIntegrityIncidentDigest(incident); 138 state.digest = GetBinaryIntegrityIncidentDigest(incident);
133 break; 139 break;
140 case BLACKLIST_LOAD:
141 state.key = GetBlacklistLoadIncidentKey(incident);
142 state.digest = GetBlacklistLoadIncidentDigest(incident);
143 break;
134 // Add handling for new incident types here. 144 // Add handling for new incident types here.
135 default: 145 default:
136 COMPILE_ASSERT(BINARY_INTEGRITY + 1 == NUM_INCIDENT_TYPES, 146 COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES,
137 add_support_for_new_types); 147 add_support_for_new_types);
138 NOTREACHED(); 148 NOTREACHED();
139 break; 149 break;
140 } 150 }
141 return state; 151 return state;
142 } 152 }
143 153
144 // 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
145 // based on the bookkeeping in the |incidents_sent| preference dictionary. 155 // based on the bookkeeping in the |incidents_sent| preference dictionary.
146 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent, 156 bool IncidentHasBeenReported(const base::DictionaryValue* incidents_sent,
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 if (!profile->IsOffTheRecord()) 955 if (!profile->IsOffTheRecord())
946 OnProfileDestroyed(profile); 956 OnProfileDestroyed(profile);
947 break; 957 break;
948 } 958 }
949 default: 959 default:
950 break; 960 break;
951 } 961 }
952 } 962 }
953 963
954 } // namespace safe_browsing 964 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698