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

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

Issue 880603002: Clean up pref state in the wake of removing the omnibox watcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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>
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (!incidents_sent->GetDictionaryWithoutPathExpansion(data.type, 125 if (!incidents_sent->GetDictionaryWithoutPathExpansion(data.type,
126 &type_dict)) { 126 &type_dict)) {
127 type_dict = new base::DictionaryValue(); 127 type_dict = new base::DictionaryValue();
128 incidents_sent->SetWithoutPathExpansion(data.type, type_dict); 128 incidents_sent->SetWithoutPathExpansion(data.type, type_dict);
129 } 129 }
130 type_dict->SetStringWithoutPathExpansion(data.key, 130 type_dict->SetStringWithoutPathExpansion(data.key,
131 base::UintToString(data.digest)); 131 base::UintToString(data.digest));
132 } 132 }
133 } 133 }
134 134
135 // Removes a profile's prune state for legacy incident types.
136 void CleanLegacyPruneState(Profile* profile) {
137 static const IncidentType kLegacyTypes[] = {
138 IncidentType::OMNIBOX_INTERACTION, // TODO(grt): remove in M44.
robertshield 2015/01/27 14:12:02 Reference bug with milestone?
grt (UTC plus 2) 2015/01/27 18:33:06 Done.
139 };
140
141 // Figure out if there are any values to remove before committing to making
142 // any changes since notifications are sent for pref dict modifications.
robertshield 2015/01/27 14:12:02 is this a performance concern or a functional one?
grt (UTC plus 2) 2015/01/27 18:33:06 Done.
143 const base::Value* value =
144 profile->GetPrefs()->GetUserPrefValue(prefs::kSafeBrowsingIncidentsSent);
145 const base::DictionaryValue* incidents_sent = NULL;
146 if (!value || !value->GetAsDictionary(&incidents_sent))
147 return;
148 std::vector<std::string> types_to_remove;
149 for (size_t i = 0; i < arraysize(kLegacyTypes); ++i) {
150 const std::string incident_type(
151 base::IntToString(static_cast<int32_t>(kLegacyTypes[i])));
152 const base::DictionaryValue* type_dict = NULL;
153 if (incidents_sent->GetDictionaryWithoutPathExpansion(incident_type,
154 &type_dict)) {
155 types_to_remove.push_back(incident_type);
156 }
157 }
158 if (types_to_remove.empty())
159 return;
160
161 DictionaryPrefUpdate pref_update(profile->GetPrefs(),
162 prefs::kSafeBrowsingIncidentsSent);
163 for (const auto& incident_type : types_to_remove)
164 pref_update.Get()->RemoveWithoutPathExpansion(incident_type, NULL);
165 }
166
135 // Runs |callback| on the thread to which |thread_runner| belongs. The callback 167 // Runs |callback| on the thread to which |thread_runner| belongs. The callback
136 // is run immediately if this function is called on |thread_runner|'s thread. 168 // is run immediately if this function is called on |thread_runner|'s thread.
137 void AddIncidentOnOriginThread( 169 void AddIncidentOnOriginThread(
138 const AddIncidentCallback& callback, 170 const AddIncidentCallback& callback,
139 scoped_refptr<base::SingleThreadTaskRunner> thread_runner, 171 scoped_refptr<base::SingleThreadTaskRunner> thread_runner,
140 scoped_ptr<Incident> incident) { 172 scoped_ptr<Incident> incident) {
141 if (thread_runner->BelongsToCurrentThread()) 173 if (thread_runner->BelongsToCurrentThread())
142 callback.Run(incident.Pass()); 174 callback.Run(incident.Pass());
143 else 175 else
144 thread_runner->PostTask(FROM_HERE, 176 thread_runner->PostTask(FROM_HERE,
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (safe_browsing_enabled) 403 if (safe_browsing_enabled)
372 delayed_analysis_callbacks_.Start(); 404 delayed_analysis_callbacks_.Start();
373 405
374 // Start a new report if this profile participates in safe browsing and there 406 // Start a new report if this profile participates in safe browsing and there
375 // are process-wide incidents. 407 // are process-wide incidents.
376 if (safe_browsing_enabled && GetProfileContext(NULL) && 408 if (safe_browsing_enabled && GetProfileContext(NULL) &&
377 GetProfileContext(NULL)->incidents.size()) { 409 GetProfileContext(NULL)->incidents.size()) {
378 BeginReportProcessing(); 410 BeginReportProcessing();
379 } 411 }
380 412
413 CleanLegacyPruneState(profile);
414
381 // TODO(grt): register for pref change notifications to start delayed analysis 415 // TODO(grt): register for pref change notifications to start delayed analysis
382 // and/or report processing if sb is currently disabled but subsequently 416 // and/or report processing if sb is currently disabled but subsequently
383 // enabled. 417 // enabled.
384 418
385 // Nothing else to do if a report is not being assembled. 419 // Nothing else to do if a report is not being assembled.
386 if (!report_) 420 if (!report_)
387 return; 421 return;
388 422
389 // Drop all incidents associated with this profile that were received prior to 423 // Drop all incidents associated with this profile that were received prior to
390 // its addition if the profile is not participating in safe browsing. 424 // its addition if the profile is not participating in safe browsing.
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 if (!profile->IsOffTheRecord()) 956 if (!profile->IsOffTheRecord())
923 OnProfileDestroyed(profile); 957 OnProfileDestroyed(profile);
924 break; 958 break;
925 } 959 }
926 default: 960 default:
927 break; 961 break;
928 } 962 }
929 } 963 }
930 964
931 } // namespace safe_browsing 965 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698