Chromium Code Reviews| Index: components/safe_browsing_db/safe_browsing_api_handler_util.cc |
| diff --git a/chrome/browser/safe_browsing/safe_browsing_api_handler_util.cc b/components/safe_browsing_db/safe_browsing_api_handler_util.cc |
| similarity index 82% |
| rename from chrome/browser/safe_browsing/safe_browsing_api_handler_util.cc |
| rename to components/safe_browsing_db/safe_browsing_api_handler_util.cc |
| index 897ad4079be90a83be1f1818220afd87eabcad7e..8b3b1914fdf6bda1ed73521dce72ddd679413618 100644 |
| --- a/chrome/browser/safe_browsing/safe_browsing_api_handler_util.cc |
| +++ b/components/safe_browsing_db/safe_browsing_api_handler_util.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/safe_browsing/safe_browsing_api_handler_util.h" |
| +#include "components/safe_browsing_db/safe_browsing_api_handler_util.h" |
| #include <stddef.h> |
| @@ -13,9 +13,8 @@ |
| #include "base/metrics/histogram_macros.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/values.h" |
| -#include "chrome/browser/safe_browsing/metadata.pb.h" |
| -#include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| - |
| +#include "components/safe_browsing_db/metadata.pb.h" |
| +#include "components/safe_browsing_db/util.h" |
| namespace safe_browsing { |
| namespace { |
| @@ -41,9 +40,8 @@ void ReportUmaThreatSubType(SBThreatType threat_type, |
| "SB2.RemoteCall.ThreatSubType.PotentiallyHarmfulApp", sub_type, |
| UMA_THREAT_SUB_TYPE_MAX_VALUE); |
| } else { |
| - UMA_HISTOGRAM_ENUMERATION( |
| - "SB2.RemoteCall.ThreatSubType.SocialEngineering", sub_type, |
| - UMA_THREAT_SUB_TYPE_MAX_VALUE); |
| + UMA_HISTOGRAM_ENUMERATION("SB2.RemoteCall.ThreatSubType.SocialEngineering", |
| + sub_type, UMA_THREAT_SUB_TYPE_MAX_VALUE); |
| } |
| } |
| @@ -111,7 +109,6 @@ SBThreatType JavaToSBThreatType(int java_threat_num) { |
| } // namespace |
| - |
| // Valid examples: |
| // {"matches":[{"threat_type":"5"}]} |
| // or |
| @@ -128,7 +125,7 @@ UmaRemoteCallResult ParseJsonToThreatAndPB(const std::string& metadata_str, |
| // Pick out the "matches" list. |
| scoped_ptr<base::Value> value = base::JSONReader::Read(metadata_str); |
| - const base::ListValue* matches; |
| + const base::ListValue* matches = nullptr; |
| if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY) || |
| !(static_cast<base::DictionaryValue*>(value.get())) |
| ->GetList(kJsonKeyMatches, &matches)) { |
| @@ -138,21 +135,23 @@ UmaRemoteCallResult ParseJsonToThreatAndPB(const std::string& metadata_str, |
| // Go through each matched threat type and pick the most severe. |
| int worst_threat_num = -1; |
| const base::DictionaryValue* worst_match = nullptr; |
| - for (size_t i = 0; i < matches->GetSize(); i++) { |
| - // Get the threat number |
| - const base::DictionaryValue* match; |
| - std::string threat_num_str; |
| - int java_threat_num = -1; |
| - if (!matches->GetDictionary(i, &match) || |
| - !match->GetString(kJsonKeyThreatType, &threat_num_str) || |
| - !base::StringToInt(threat_num_str, &java_threat_num)) { |
| - continue; // Skip malformed list entries |
| - } |
| - |
| - if (GetThreatSeverity(java_threat_num) > |
| - GetThreatSeverity(worst_threat_num)) { |
| - worst_threat_num = java_threat_num; |
| - worst_match = match; |
| + if (matches) { |
|
Nathan Parker
2016/01/22 22:46:19
How about instead adding a "|| !matches" at the en
|
| + for (size_t i = 0; i < matches->GetSize(); i++) { |
| + // Get the threat number |
| + const base::DictionaryValue* match; |
| + std::string threat_num_str; |
| + int java_threat_num = -1; |
| + if (!matches->GetDictionary(i, &match) || |
| + !match->GetString(kJsonKeyThreatType, &threat_num_str) || |
| + !base::StringToInt(threat_num_str, &java_threat_num)) { |
| + continue; // Skip malformed list entries |
| + } |
| + |
| + if (GetThreatSeverity(java_threat_num) > |
| + GetThreatSeverity(worst_threat_num)) { |
| + worst_threat_num = java_threat_num; |
| + worst_match = match; |
| + } |
| } |
| } |