1 // Copyright 2016 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.
4 
5 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_SIGNATURES_UTIL_H_
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_SIGNATURES_UTIL_H_
7 
8 #include <stddef.h>
9 
10 #include <stdint.h>
11 #include <string>
12 
13 #include "base/strings/string16.h"
14 
15 namespace autofill {
16 
17 struct FormData;
18 struct FormFieldData;
19 
20 using FormSignature = uint64_t;
21 using FieldSignature = uint32_t;
22 
23 // Calculates form signature based on |form_data|.
24 FormSignature CalculateFormSignature(const FormData& form_data);
25 
26 // Calculates field signature based on |field_name| and |field_type|.
27 FieldSignature CalculateFieldSignatureByNameAndType(
28     const base::string16& field_name,
29     const std::string& field_type);
30 
31 // Calculates field signature based on |field_data|. This function is a proxy to
32 // |CalculateFieldSignatureByNameAndType|.
33 FieldSignature CalculateFieldSignatureForField(const FormFieldData& field_data);
34 
35 // Returns 64-bit hash of the string.
36 uint64_t StrToHash64Bit(const std::string& str);
37 
38 // Returns 32-bit hash of the string.
39 uint32_t StrToHash32Bit(const std::string& str);
40 
41 // Reduce FieldSignature space (in UKM) to a small range for privacy reasons.
42 int64_t HashFormSignature(autofill::FormSignature form_signature);
43 
44 // Reduce FieldSignature space (in UKM) to a small range for privacy reasons.
45 int64_t HashFieldSignature(autofill::FieldSignature field_signature);
46 }
47 
48 #endif  // COMPONENTS_AUTOFILL_CORE_COMMON_SIGNATURES_UTIL_H_
49