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

Unified Diff: chrome/browser/safe_browsing/incident_reporting/state_store.cc

Issue 1243293003: Platform-specific prune state storage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prune1
Patch Set: moved uninstall cleanup to separate cl Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/incident_reporting/state_store.cc
diff --git a/chrome/browser/safe_browsing/incident_reporting/state_store.cc b/chrome/browser/safe_browsing/incident_reporting/state_store.cc
index 1822ab6117626490425a00d84afd33e2f92bceb5..51e125cea1c7754a2d27d211bca392215f7c5d5d 100644
--- a/chrome/browser/safe_browsing/incident_reporting/state_store.cc
+++ b/chrome/browser/safe_browsing/incident_reporting/state_store.cc
@@ -9,6 +9,7 @@
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/incident_reporting/incident.h"
+#include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h"
#include "chrome/common/pref_names.h"
namespace safe_browsing {
@@ -26,6 +27,8 @@ StateStore::Transaction::~Transaction() {
#if DCHECK_IS_ON()
store_->has_transaction_ = false;
#endif
+ if (pref_update_)
+ platform_state_store::Store(store_->profile_, store_->incidents_sent_);
}
void StateStore::Transaction::MarkAsReported(IncidentType type,
@@ -59,6 +62,15 @@ void StateStore::Transaction::ClearForType(IncidentType type) {
}
}
+void StateStore::Transaction::ClearAll() {
+ if (pref_update_)
+ pref_update_.reset();
+ if (store_->incidents_sent_) {
+ store_->incidents_sent_ = nullptr;
+ store_->profile_->GetPrefs()->ClearPref(prefs::kSafeBrowsingIncidentsSent);
+ }
+}
+
base::DictionaryValue* StateStore::Transaction::GetPrefDict() {
if (!pref_update_) {
pref_update_.reset(new DictionaryPrefUpdate(
@@ -71,6 +83,11 @@ base::DictionaryValue* StateStore::Transaction::GetPrefDict() {
return pref_update_->Get();
}
+void StateStore::Transaction::ReplacePrefDict(
+ scoped_ptr<base::DictionaryValue> pref_dict) {
+ GetPrefDict()->Swap(pref_dict.get());
+}
+
// StateStore ------------------------------------------------------------------
@@ -88,8 +105,19 @@ StateStore::StateStore(Profile* profile)
if (value)
value->GetAsDictionary(&incidents_sent_);
+ // Apply the platform data.
Transaction transaction(this);
- CleanLegacyValues(&transaction);
+ scoped_ptr<base::DictionaryValue> value_dict(
+ platform_state_store::Load(profile_));
+ if (value_dict) {
+ if (value_dict->empty())
+ transaction.ClearAll();
+ else if (!incidents_sent_ || !incidents_sent_->Equals(value_dict.get()))
+ transaction.ReplacePrefDict(value_dict.Pass());
+ }
+
+ if (incidents_sent_)
+ CleanLegacyValues(&transaction);
}
StateStore::~StateStore() {

Powered by Google App Engine
This is Rietveld 408576698