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 // |
(...skipping 28 matching lines...) Expand all Loading... |
39 // Copies the (key, digest) pairs from |keys_and_digests| (a dict of string | 39 // Copies the (key, digest) pairs from |keys_and_digests| (a dict of string |
40 // values) to the |key_digest_pairs| protobuf. | 40 // values) to the |key_digest_pairs| protobuf. |
41 void KeysAndDigestsToProtobuf( | 41 void KeysAndDigestsToProtobuf( |
42 const base::DictionaryValue& keys_and_digests, | 42 const base::DictionaryValue& keys_and_digests, |
43 RepeatedPtrField<StateStoreData::Incidents::KeyDigestMapFieldEntry>* | 43 RepeatedPtrField<StateStoreData::Incidents::KeyDigestMapFieldEntry>* |
44 key_digest_pairs) { | 44 key_digest_pairs) { |
45 std::string digest_value; | 45 std::string digest_value; |
46 for (base::DictionaryValue::Iterator iter(keys_and_digests); !iter.IsAtEnd(); | 46 for (base::DictionaryValue::Iterator iter(keys_and_digests); !iter.IsAtEnd(); |
47 iter.Advance()) { | 47 iter.Advance()) { |
48 uint32_t digest = 0; | 48 uint32_t digest = 0; |
49 if (iter.value().GetType() != base::Value::TYPE_STRING || | 49 if (iter.value().GetType() != base::Value::Type::STRING || |
50 !iter.value().GetAsString(&digest_value) || | 50 !iter.value().GetAsString(&digest_value) || |
51 !base::StringToUint(digest_value, &digest)) { | 51 !base::StringToUint(digest_value, &digest)) { |
52 NOTREACHED(); | 52 NOTREACHED(); |
53 continue; | 53 continue; |
54 } | 54 } |
55 StateStoreData::Incidents::KeyDigestMapFieldEntry* key_digest = | 55 StateStoreData::Incidents::KeyDigestMapFieldEntry* key_digest = |
56 key_digest_pairs->Add(); | 56 key_digest_pairs->Add(); |
57 key_digest->set_key(iter.key()); | 57 key_digest->set_key(iter.key()); |
58 key_digest->set_digest(digest); | 58 key_digest->set_digest(digest); |
59 } | 59 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return PlatformStateStoreLoadResult::PARSE_ERROR; | 193 return PlatformStateStoreLoadResult::PARSE_ERROR; |
194 value_dict->Clear(); | 194 value_dict->Clear(); |
195 RestoreFromProtobuf(store_data.type_to_incidents(), value_dict); | 195 RestoreFromProtobuf(store_data.type_to_incidents(), value_dict); |
196 return PlatformStateStoreLoadResult::SUCCESS; | 196 return PlatformStateStoreLoadResult::SUCCESS; |
197 } | 197 } |
198 | 198 |
199 #endif // USE_PLATFORM_STATE_STORE | 199 #endif // USE_PLATFORM_STATE_STORE |
200 | 200 |
201 } // namespace platform_state_store | 201 } // namespace platform_state_store |
202 } // namespace safe_browsing | 202 } // namespace safe_browsing |
OLD | NEW |