OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/state_store.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 store_->profile_->GetPrefs(), prefs::kSafeBrowsingIncidentsSent)); | 97 store_->profile_->GetPrefs(), prefs::kSafeBrowsingIncidentsSent)); |
98 // Getting the dict will cause it to be created if it doesn't exist. | 98 // Getting the dict will cause it to be created if it doesn't exist. |
99 // Unconditionally refresh the store's read-only view on the preference so | 99 // Unconditionally refresh the store's read-only view on the preference so |
100 // that it will always be correct. | 100 // that it will always be correct. |
101 store_->incidents_sent_ = pref_update_->Get(); | 101 store_->incidents_sent_ = pref_update_->Get(); |
102 } | 102 } |
103 return pref_update_->Get(); | 103 return pref_update_->Get(); |
104 } | 104 } |
105 | 105 |
106 void StateStore::Transaction::ReplacePrefDict( | 106 void StateStore::Transaction::ReplacePrefDict( |
107 scoped_ptr<base::DictionaryValue> pref_dict) { | 107 std::unique_ptr<base::DictionaryValue> pref_dict) { |
108 GetPrefDict()->Swap(pref_dict.get()); | 108 GetPrefDict()->Swap(pref_dict.get()); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 // StateStore ------------------------------------------------------------------ | 112 // StateStore ------------------------------------------------------------------ |
113 | 113 |
114 StateStore::StateStore(Profile* profile) | 114 StateStore::StateStore(Profile* profile) |
115 : profile_(profile), | 115 : profile_(profile), |
116 incidents_sent_(nullptr) | 116 incidents_sent_(nullptr) |
117 #if DCHECK_IS_ON() | 117 #if DCHECK_IS_ON() |
118 , | 118 , |
119 has_transaction_(false) | 119 has_transaction_(false) |
120 #endif | 120 #endif |
121 { | 121 { |
122 // Cache a read-only view of the preference. | 122 // Cache a read-only view of the preference. |
123 const base::Value* value = | 123 const base::Value* value = |
124 profile_->GetPrefs()->GetUserPrefValue(prefs::kSafeBrowsingIncidentsSent); | 124 profile_->GetPrefs()->GetUserPrefValue(prefs::kSafeBrowsingIncidentsSent); |
125 if (value) | 125 if (value) |
126 value->GetAsDictionary(&incidents_sent_); | 126 value->GetAsDictionary(&incidents_sent_); |
127 | 127 |
128 // Apply the platform data. | 128 // Apply the platform data. |
129 Transaction transaction(this); | 129 Transaction transaction(this); |
130 scoped_ptr<base::DictionaryValue> value_dict( | 130 std::unique_ptr<base::DictionaryValue> value_dict( |
131 platform_state_store::Load(profile_)); | 131 platform_state_store::Load(profile_)); |
132 | 132 |
133 InitializationResult state_store_init_result = PSS_MATCHES; | 133 InitializationResult state_store_init_result = PSS_MATCHES; |
134 if (!value_dict) { | 134 if (!value_dict) { |
135 state_store_init_result = PSS_NULL; | 135 state_store_init_result = PSS_NULL; |
136 } else if (value_dict->empty()) { | 136 } else if (value_dict->empty()) { |
137 if (incidents_sent_ && !incidents_sent_->empty()) | 137 if (incidents_sent_ && !incidents_sent_->empty()) |
138 state_store_init_result = PSS_EMPTY; | 138 state_store_init_result = PSS_EMPTY; |
139 transaction.ClearAll(); | 139 transaction.ClearAll(); |
140 } else if (!incidents_sent_ || !incidents_sent_->Equals(value_dict.get())) { | 140 } else if (!incidents_sent_ || !incidents_sent_->Equals(value_dict.get())) { |
(...skipping 28 matching lines...) Expand all Loading... |
169 static const IncidentType kLegacyTypes[] = { | 169 static const IncidentType kLegacyTypes[] = { |
170 // TODO(grt): remove in M44 (crbug.com/451173). | 170 // TODO(grt): remove in M44 (crbug.com/451173). |
171 IncidentType::OMNIBOX_INTERACTION, | 171 IncidentType::OMNIBOX_INTERACTION, |
172 }; | 172 }; |
173 | 173 |
174 for (IncidentType type : kLegacyTypes) | 174 for (IncidentType type : kLegacyTypes) |
175 transaction->ClearForType(type); | 175 transaction->ClearForType(type); |
176 } | 176 } |
177 | 177 |
178 } // namespace safe_browsing | 178 } // namespace safe_browsing |
OLD | NEW |