| 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/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 14 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
| 14 #include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h
" | 15 #include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h
" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
| 17 | 18 |
| 18 namespace safe_browsing { | 19 namespace safe_browsing { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 } | 36 } |
| 36 | 37 |
| 37 void StateStore::Transaction::MarkAsReported(IncidentType type, | 38 void StateStore::Transaction::MarkAsReported(IncidentType type, |
| 38 const std::string& key, | 39 const std::string& key, |
| 39 IncidentDigest digest) { | 40 IncidentDigest digest) { |
| 40 std::string type_string(base::IntToString(static_cast<int32_t>(type))); | 41 std::string type_string(base::IntToString(static_cast<int32_t>(type))); |
| 41 base::DictionaryValue* incidents_sent = GetPrefDict(); | 42 base::DictionaryValue* incidents_sent = GetPrefDict(); |
| 42 base::DictionaryValue* type_dict = nullptr; | 43 base::DictionaryValue* type_dict = nullptr; |
| 43 if (!incidents_sent->GetDictionaryWithoutPathExpansion(type_string, | 44 if (!incidents_sent->GetDictionaryWithoutPathExpansion(type_string, |
| 44 &type_dict)) { | 45 &type_dict)) { |
| 45 type_dict = new base::DictionaryValue(); | 46 type_dict = incidents_sent->SetDictionaryWithoutPathExpansion( |
| 46 incidents_sent->SetWithoutPathExpansion(type_string, type_dict); | 47 type_string, base::MakeUnique<base::DictionaryValue>()); |
| 47 } | 48 } |
| 48 type_dict->SetStringWithoutPathExpansion(key, base::UintToString(digest)); | 49 type_dict->SetStringWithoutPathExpansion(key, base::UintToString(digest)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void StateStore::Transaction::Clear(IncidentType type, const std::string& key) { | 52 void StateStore::Transaction::Clear(IncidentType type, const std::string& key) { |
| 52 // Nothing to do if the pref dict does not exist. | 53 // Nothing to do if the pref dict does not exist. |
| 53 if (!store_->incidents_sent_) | 54 if (!store_->incidents_sent_) |
| 54 return; | 55 return; |
| 55 | 56 |
| 56 // Use the read-only view on the preference to figure out if there is a value | 57 // Use the read-only view on the preference to figure out if there is a value |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 static const IncidentType kLegacyTypes[] = { | 170 static const IncidentType kLegacyTypes[] = { |
| 170 // TODO(grt): remove in M44 (crbug.com/451173). | 171 // TODO(grt): remove in M44 (crbug.com/451173). |
| 171 IncidentType::OMNIBOX_INTERACTION, | 172 IncidentType::OMNIBOX_INTERACTION, |
| 172 }; | 173 }; |
| 173 | 174 |
| 174 for (IncidentType type : kLegacyTypes) | 175 for (IncidentType type : kLegacyTypes) |
| 175 transaction->ClearForType(type); | 176 transaction->ClearForType(type); |
| 176 } | 177 } |
| 177 | 178 |
| 178 } // namespace safe_browsing | 179 } // namespace safe_browsing |
| OLD | NEW |