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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // store. | 57 // store. |
58 std::string type_string(base::IntToString(static_cast<int32_t>(type))); | 58 std::string type_string(base::IntToString(static_cast<int32_t>(type))); |
59 const base::DictionaryValue* type_dict = nullptr; | 59 const base::DictionaryValue* type_dict = nullptr; |
60 if (store_->incidents_sent_->GetDictionaryWithoutPathExpansion(type_string, | 60 if (store_->incidents_sent_->GetDictionaryWithoutPathExpansion(type_string, |
61 &type_dict)) { | 61 &type_dict)) { |
62 GetPrefDict()->RemoveWithoutPathExpansion(type_string, nullptr); | 62 GetPrefDict()->RemoveWithoutPathExpansion(type_string, nullptr); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void StateStore::Transaction::ClearAll() { | 66 void StateStore::Transaction::ClearAll() { |
67 if (pref_update_) | 67 // Clear the preference if it exists and contains any values. |
68 pref_update_.reset(); | 68 if (store_->incidents_sent_ && !store_->incidents_sent_->empty()) |
69 if (store_->incidents_sent_) { | 69 GetPrefDict()->Clear(); |
70 store_->incidents_sent_ = nullptr; | |
71 store_->profile_->GetPrefs()->ClearPref(prefs::kSafeBrowsingIncidentsSent); | |
72 } | |
73 } | 70 } |
74 | 71 |
75 base::DictionaryValue* StateStore::Transaction::GetPrefDict() { | 72 base::DictionaryValue* StateStore::Transaction::GetPrefDict() { |
76 if (!pref_update_) { | 73 if (!pref_update_) { |
77 pref_update_.reset(new DictionaryPrefUpdate( | 74 pref_update_.reset(new DictionaryPrefUpdate( |
78 store_->profile_->GetPrefs(), prefs::kSafeBrowsingIncidentsSent)); | 75 store_->profile_->GetPrefs(), prefs::kSafeBrowsingIncidentsSent)); |
79 // Getting the dict will cause it to be created if it doesn't exist. | 76 // Getting the dict will cause it to be created if it doesn't exist. |
80 // Unconditionally refresh the store's read-only view on the preference so | 77 // Unconditionally refresh the store's read-only view on the preference so |
81 // that it will always be correct. | 78 // that it will always be correct. |
82 store_->incidents_sent_ = pref_update_->Get(); | 79 store_->incidents_sent_ = pref_update_->Get(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 static const IncidentType kLegacyTypes[] = { | 147 static const IncidentType kLegacyTypes[] = { |
151 // TODO(grt): remove in M44 (crbug.com/451173). | 148 // TODO(grt): remove in M44 (crbug.com/451173). |
152 IncidentType::OMNIBOX_INTERACTION, | 149 IncidentType::OMNIBOX_INTERACTION, |
153 }; | 150 }; |
154 | 151 |
155 for (IncidentType type : kLegacyTypes) | 152 for (IncidentType type : kLegacyTypes) |
156 transaction->ClearForType(type); | 153 transaction->ClearForType(type); |
157 } | 154 } |
158 | 155 |
159 } // namespace safe_browsing | 156 } // namespace safe_browsing |
OLD | NEW |