| 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 "components/safe_browsing_db/safe_browsing_api_handler_util.h" | 5 #include "components/safe_browsing_db/safe_browsing_api_handler_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 ThreatMetadata* metadata) { | 150 ThreatMetadata* metadata) { |
| 151 *worst_threat = SB_THREAT_TYPE_SAFE; // Default to safe. | 151 *worst_threat = SB_THREAT_TYPE_SAFE; // Default to safe. |
| 152 *metadata = ThreatMetadata(); // Default values. | 152 *metadata = ThreatMetadata(); // Default values. |
| 153 | 153 |
| 154 if (metadata_str.empty()) | 154 if (metadata_str.empty()) |
| 155 return UMA_STATUS_JSON_EMPTY; | 155 return UMA_STATUS_JSON_EMPTY; |
| 156 | 156 |
| 157 // Pick out the "matches" list. | 157 // Pick out the "matches" list. |
| 158 std::unique_ptr<base::Value> value = base::JSONReader::Read(metadata_str); | 158 std::unique_ptr<base::Value> value = base::JSONReader::Read(metadata_str); |
| 159 const base::ListValue* matches = nullptr; | 159 const base::ListValue* matches = nullptr; |
| 160 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY) || | 160 if (!value.get() || !value->IsType(base::Value::Type::DICTIONARY) || |
| 161 !(static_cast<base::DictionaryValue*>(value.get())) | 161 !(static_cast<base::DictionaryValue*>(value.get())) |
| 162 ->GetList(kJsonKeyMatches, &matches) || | 162 ->GetList(kJsonKeyMatches, &matches) || |
| 163 !matches) { | 163 !matches) { |
| 164 return UMA_STATUS_JSON_FAILED_TO_PARSE; | 164 return UMA_STATUS_JSON_FAILED_TO_PARSE; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Go through each matched threat type and pick the most severe. | 167 // Go through each matched threat type and pick the most severe. |
| 168 int worst_threat_num = -1; | 168 int worst_threat_num = -1; |
| 169 const base::DictionaryValue* worst_match = nullptr; | 169 const base::DictionaryValue* worst_match = nullptr; |
| 170 for (size_t i = 0; i < matches->GetSize(); i++) { | 170 for (size_t i = 0; i < matches->GetSize(); i++) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 191 | 191 |
| 192 // Fill in the metadata | 192 // Fill in the metadata |
| 193 metadata->threat_pattern_type = | 193 metadata->threat_pattern_type = |
| 194 ParseThreatSubType(worst_match, *worst_threat); | 194 ParseThreatSubType(worst_match, *worst_threat); |
| 195 metadata->population_id = ParseUserPopulation(worst_match); | 195 metadata->population_id = ParseUserPopulation(worst_match); |
| 196 | 196 |
| 197 return UMA_STATUS_UNSAFE; // success | 197 return UMA_STATUS_UNSAFE; // success |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace safe_browsing | 200 } // namespace safe_browsing |
| OLD | NEW |