1 // Copyright 2018 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_URL_FORMATTER_SPOOF_CHECKS_TOP_DOMAINS_TRIE_ENTRY_H_
6 #define COMPONENTS_URL_FORMATTER_SPOOF_CHECKS_TOP_DOMAINS_TRIE_ENTRY_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "net/tools/huffman_trie/huffman/huffman_builder.h"
12 #include "net/tools/huffman_trie/trie_entry.h"
13 
14 namespace url_formatter {
15 
16 // The |SkeletonType| and |TopDomainEntry| are mirrored in trie_entry.h. These
17 // are used to insert and read nodes from the Trie.
18 // The type of skeleton in the trie node. This type is encoded by 2 bits in the
19 // trie.
20 enum SkeletonType {
21   // The skeleton represents the full domain (e.g. google.corn).
22   kFull = 0,
23   // The skeleton represents the domain with '.'s and '-'s removed (e.g.
24   // googlecorn).
25   kSeparatorsRemoved = 1,
26   // Max value used to determine the number of different types. Update this and
27   // |kSkeletonTypeBitLength| when new SkeletonTypes are added.
28   kMaxValue = kSeparatorsRemoved
29 };
30 
31 const uint8_t kSkeletonTypeBitLength = 1;
32 
33 namespace top_domains {
34 
35 struct TopDomainEntry {
36   std::string skeleton;
37   std::string top_domain;
38   bool is_top_500;
39   SkeletonType skeleton_type;
40 };
41 
42 class TopDomainTrieEntry : public net::huffman_trie::TrieEntry {
43  public:
44   explicit TopDomainTrieEntry(
45       const net::huffman_trie::HuffmanRepresentationTable& huffman_table,
46       net::huffman_trie::HuffmanBuilder* huffman_builder,
47       TopDomainEntry* entry);
48   ~TopDomainTrieEntry() override;
49 
50   // huffman_trie::TrieEntry:
51   std::string name() const override;
52   bool WriteEntry(net::huffman_trie::TrieBitBuffer* writer) const override;
53 
54  private:
55   const net::huffman_trie::HuffmanRepresentationTable& huffman_table_;
56   net::huffman_trie::HuffmanBuilder* huffman_builder_;
57   TopDomainEntry* entry_;
58 };
59 
60 using TopDomainEntries = std::vector<std::unique_ptr<TopDomainEntry>>;
61 
62 }  // namespace top_domains
63 
64 }  // namespace url_formatter
65 
66 #endif  // COMPONENTS_URL_FORMATTER_SPOOF_CHECKS_TOP_DOMAINS_TRIE_ENTRY_H_
67