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

Unified 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: updates per robertshield and cl format Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/incident_reporting/incident_reporting_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
diff --git a/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc b/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
index 236aae45af138738b2594857ca3b508eb49e7d7c..f5bafc5eee4fcd780873baaa5c2bcdadf1ca0065 100644
--- a/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
+++ b/chrome/browser/safe_browsing/incident_reporting/incident_reporting_service.cc
@@ -132,6 +132,40 @@ void MarkIncidentsAsReported(const std::vector<PersistentIncidentState>& states,
}
}
+// Removes a profile's prune state for legacy incident types.
+void CleanLegacyPruneState(Profile* profile) {
+ static const IncidentType kLegacyTypes[] = {
+ // TODO(grt): remove in M44 (crbug.com/451173).
+ IncidentType::OMNIBOX_INTERACTION,
+ };
+
+ // Figure out if there are any values to remove before committing to making
+ // any changes since any use of DictionaryPrefUpdate will result in a full
+ // serialize-and-write operation on the preferences store.
+ const base::Value* value =
+ profile->GetPrefs()->GetUserPrefValue(prefs::kSafeBrowsingIncidentsSent);
+ const base::DictionaryValue* incidents_sent = NULL;
+ if (!value || !value->GetAsDictionary(&incidents_sent))
+ return;
+ std::vector<std::string> types_to_remove;
+ for (size_t i = 0; i < arraysize(kLegacyTypes); ++i) {
+ const std::string incident_type(
+ base::IntToString(static_cast<int32_t>(kLegacyTypes[i])));
+ const base::DictionaryValue* type_dict = NULL;
+ if (incidents_sent->GetDictionaryWithoutPathExpansion(incident_type,
+ &type_dict)) {
+ types_to_remove.push_back(incident_type);
+ }
+ }
+ if (types_to_remove.empty())
+ return;
+
+ DictionaryPrefUpdate pref_update(profile->GetPrefs(),
+ prefs::kSafeBrowsingIncidentsSent);
+ for (const auto& incident_type : types_to_remove)
+ pref_update.Get()->RemoveWithoutPathExpansion(incident_type, NULL);
+}
+
// Runs |callback| on the thread to which |thread_runner| belongs. The callback
// is run immediately if this function is called on |thread_runner|'s thread.
void AddIncidentOnOriginThread(
@@ -378,6 +412,8 @@ void IncidentReportingService::OnProfileAdded(Profile* profile) {
BeginReportProcessing();
}
+ CleanLegacyPruneState(profile);
+
// TODO(grt): register for pref change notifications to start delayed analysis
// and/or report processing if sb is currently disabled but subsequently
// enabled.
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/incident_reporting/incident_reporting_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698