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
3 // found in the LICENSE file.
5 // Helper functions for SafeBrowsingApiHandlerImpl. Separated out for tests.
7 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_API_HANDLER_UTIL_H_
8 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_API_HANDLER_UTIL_H_
12 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
14 namespace safe_browsing
{
16 // These match what SafeBrowsingApiHandler.java uses for |resultStatus|
17 enum RemoteCallResultStatus
{
18 RESULT_STATUS_INTERNAL_ERROR
= -1,
19 RESULT_STATUS_SUCCESS
= 0,
20 RESULT_STATUS_TIMEOUT
= 1,
23 // Threat types as per the Java code.
24 // This must match those in GMS's SafeBrowsingThreatTypes.java.
25 enum JavaThreatTypes
{
26 JAVA_THREAT_TYPE_POTENTIALLY_HARMFUL_APPLICATION
= 4,
27 JAVA_THREAT_TYPE_SOCIAL_ENGINEERING
= 5,
30 // Do not reorder or delete entries, and make sure changes here are reflected
31 // in SB2RemoteCallResult histogram.
32 enum UmaRemoteCallResult
{
33 UMA_STATUS_INTERNAL_ERROR
= 0,
34 UMA_STATUS_TIMEOUT
= 1,
36 UMA_STATUS_UNSAFE
= 3,
37 UMA_STATUS_JSON_EMPTY
= 4,
38 UMA_STATUS_JSON_FAILED_TO_PARSE
= 5,
39 UMA_STATUS_JSON_UNKNOWN_THREAT
= 6,
40 UMA_STATUS_UNSUPPORTED
= 7,
44 // This parses the JSON from the GMSCore API and then:
45 // 1) Picks the most severe threat type
46 // 2) Parses remaining key/value pairs into a MalwarePatternType PB
47 // so DisplayBlockingPage() can unmarshal it. We make this string
48 // is binary compatible with the Pver3 API's metadata string even
49 // though it comes from Pver4.
51 // If anything fails to parse, this sets the threat to "safe". The caller
52 // should report the return value via UMA.
53 UmaRemoteCallResult
ParseJsonToThreatAndPB(const std::string
& metadata_str
,
54 SBThreatType
* worst_threat
,
55 std::string
* metadata_pb_str
);
56 } // namespace safe_browsing
58 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_API_HANDLER_UTIL_H_