| 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 // This file implements the platform-neutral Load() and Store() functions for a | 5 // This file implements the platform-neutral Load() and Store() functions for a |
| 6 // profile's safebrowsing.incidents_sent preference dictionary. The preference | 6 // profile's safebrowsing.incidents_sent preference dictionary. The preference |
| 7 // dict is converted to a protocol buffer message which is then serialized into | 7 // dict is converted to a protocol buffer message which is then serialized into |
| 8 // a byte array. This serialized data is written to or read from some | 8 // a byte array. This serialized data is written to or read from some |
| 9 // platform-specific storage via {Read,Write}StoreData implemented elsewhere. | 9 // platform-specific storage via {Read,Write}StoreData implemented elsewhere. |
| 10 // | 10 // |
| 11 // A pref dict like so: | 11 // A pref dict like so: |
| 12 // { "0": {"key1": "1235"}, {"key2": "6789"}}} | 12 // { "0": {"key1": "1235"}, {"key2": "6789"}}} |
| 13 // is converted to an identical protocol buffer message, where the top-level | 13 // is converted to an identical protocol buffer message, where the top-level |
| 14 // mapping's keys are of type int, and the nested mappings' values are of type | 14 // mapping's keys are of type int, and the nested mappings' values are of type |
| 15 // uint32_t. | 15 // uint32_t. |
| 16 | 16 |
| 17 #include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h
" | 17 #include "chrome/browser/safe_browsing/incident_reporting/platform_state_store.h
" |
| 18 | 18 |
| 19 #include "base/memory/ptr_util.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 | 21 |
| 21 #if defined(USE_PLATFORM_STATE_STORE) | 22 #if defined(USE_PLATFORM_STATE_STORE) |
| 22 | 23 |
| 23 #include "base/metrics/histogram_macros.h" | 24 #include "base/metrics/histogram_macros.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 25 #include "chrome/browser/safe_browsing/incident_reporting/state_store_data.pb.h" | 26 #include "chrome/browser/safe_browsing/incident_reporting/state_store_data.pb.h" |
| 26 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | 27 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" |
| 27 | 28 |
| 28 #endif // USE_PLATFORM_STATE_STORE | 29 #endif // USE_PLATFORM_STATE_STORE |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 base::DictionaryValue* value_dict) { | 109 base::DictionaryValue* value_dict) { |
| 109 for (const auto& type_incidents : type_incidents_pairs) { | 110 for (const auto& type_incidents : type_incidents_pairs) { |
| 110 if (!type_incidents.has_type() || !type_incidents.has_incidents() || | 111 if (!type_incidents.has_type() || !type_incidents.has_incidents() || |
| 111 type_incidents.incidents().key_to_digest_size() == 0) { | 112 type_incidents.incidents().key_to_digest_size() == 0) { |
| 112 continue; | 113 continue; |
| 113 } | 114 } |
| 114 std::string type_string(base::IntToString(type_incidents.type())); | 115 std::string type_string(base::IntToString(type_incidents.type())); |
| 115 base::DictionaryValue* type_dict = nullptr; | 116 base::DictionaryValue* type_dict = nullptr; |
| 116 if (!value_dict->GetDictionaryWithoutPathExpansion(type_string, | 117 if (!value_dict->GetDictionaryWithoutPathExpansion(type_string, |
| 117 &type_dict)) { | 118 &type_dict)) { |
| 118 type_dict = new base::DictionaryValue(); | 119 type_dict = value_dict->SetDictionaryWithoutPathExpansion( |
| 119 value_dict->SetWithoutPathExpansion(type_string, type_dict); | 120 type_string, base::MakeUnique<base::DictionaryValue>()); |
| 120 } | 121 } |
| 121 RestoreOfTypeFromProtobuf(type_incidents.incidents().key_to_digest(), | 122 RestoreOfTypeFromProtobuf(type_incidents.incidents().key_to_digest(), |
| 122 type_dict); | 123 type_dict); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace | 127 } // namespace |
| 127 | 128 |
| 128 #endif // USE_PLATFORM_STATE_STORE | 129 #endif // USE_PLATFORM_STATE_STORE |
| 129 | 130 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return PlatformStateStoreLoadResult::PARSE_ERROR; | 194 return PlatformStateStoreLoadResult::PARSE_ERROR; |
| 194 value_dict->Clear(); | 195 value_dict->Clear(); |
| 195 RestoreFromProtobuf(store_data.type_to_incidents(), value_dict); | 196 RestoreFromProtobuf(store_data.type_to_incidents(), value_dict); |
| 196 return PlatformStateStoreLoadResult::SUCCESS; | 197 return PlatformStateStoreLoadResult::SUCCESS; |
| 197 } | 198 } |
| 198 | 199 |
| 199 #endif // USE_PLATFORM_STATE_STORE | 200 #endif // USE_PLATFORM_STATE_STORE |
| 200 | 201 |
| 201 } // namespace platform_state_store | 202 } // namespace platform_state_store |
| 202 } // namespace safe_browsing | 203 } // namespace safe_browsing |
| OLD | NEW |