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

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: 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(grt): remove in M44 (crbug.com/451173).
139 IncidentType::OMNIBOX_INTERACTION,
140 };
141
142 // Figure out if there are any values to remove before committing to making
143 // any changes since any use of DictionaryPrefUpdate will result in a full
144 // serialize-and-write operation on the preferences store.
145 const base::Value* value =
146 profile->GetPrefs()->GetUserPrefValue(prefs::kSafeBrowsingIncidentsSent);
147 const base::DictionaryValue* incidents_sent = NULL;
148 if (!value || !value->GetAsDictionary(&incidents_sent))
149 return;
150 std::vector<std::string> types_to_remove;
151 for (size_t i = 0; i < arraysize(kLegacyTypes); ++i) {
152 const std::string incident_type(
153 base::IntToString(static_cast<int32_t>(kLegacyTypes[i])));
154 const base::DictionaryValue* type_dict = NULL;
155 if (incidents_sent->GetDictionaryWithoutPathExpansion(incident_type,
156 &type_dict)) {
157 types_to_remove.push_back(incident_type);
158 }
159 }
160 if (types_to_remove.empty())
161 return;
162
163 DictionaryPrefUpdate pref_update(profile->GetPrefs(),
164 prefs::kSafeBrowsingIncidentsSent);
165 for (const auto& incident_type : types_to_remove)
166 pref_update.Get()->RemoveWithoutPathExpansion(incident_type, NULL);
167 }
168
135 // Runs |callback| on the thread to which |thread_runner| belongs. The callback 169 // 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. 170 // is run immediately if this function is called on |thread_runner|'s thread.
137 void AddIncidentOnOriginThread( 171 void AddIncidentOnOriginThread(
138 const AddIncidentCallback& callback, 172 const AddIncidentCallback& callback,
139 scoped_refptr<base::SingleThreadTaskRunner> thread_runner, 173 scoped_refptr<base::SingleThreadTaskRunner> thread_runner,
140 scoped_ptr<Incident> incident) { 174 scoped_ptr<Incident> incident) {
141 if (thread_runner->BelongsToCurrentThread()) 175 if (thread_runner->BelongsToCurrentThread())
142 callback.Run(incident.Pass()); 176 callback.Run(incident.Pass());
143 else 177 else
144 thread_runner->PostTask(FROM_HERE, 178 thread_runner->PostTask(FROM_HERE,
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (safe_browsing_enabled) 405 if (safe_browsing_enabled)
372 delayed_analysis_callbacks_.Start(); 406 delayed_analysis_callbacks_.Start();
373 407
374 // Start a new report if this profile participates in safe browsing and there 408 // Start a new report if this profile participates in safe browsing and there
375 // are process-wide incidents. 409 // are process-wide incidents.
376 if (safe_browsing_enabled && GetProfileContext(NULL) && 410 if (safe_browsing_enabled && GetProfileContext(NULL) &&
377 GetProfileContext(NULL)->incidents.size()) { 411 GetProfileContext(NULL)->incidents.size()) {
378 BeginReportProcessing(); 412 BeginReportProcessing();
379 } 413 }
380 414
415 CleanLegacyPruneState(profile);
416
381 // TODO(grt): register for pref change notifications to start delayed analysis 417 // TODO(grt): register for pref change notifications to start delayed analysis
382 // and/or report processing if sb is currently disabled but subsequently 418 // and/or report processing if sb is currently disabled but subsequently
383 // enabled. 419 // enabled.
384 420
385 // Nothing else to do if a report is not being assembled. 421 // Nothing else to do if a report is not being assembled.
386 if (!report_) 422 if (!report_)
387 return; 423 return;
388 424
389 // Drop all incidents associated with this profile that were received prior to 425 // Drop all incidents associated with this profile that were received prior to
390 // its addition if the profile is not participating in safe browsing. 426 // 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()) 958 if (!profile->IsOffTheRecord())
923 OnProfileDestroyed(profile); 959 OnProfileDestroyed(profile);
924 break; 960 break;
925 } 961 }
926 default: 962 default:
927 break; 963 break;
928 } 964 }
929 } 965 }
930 966
931 } // namespace safe_browsing 967 } // namespace safe_browsing
OLDNEW
« 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