• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
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 NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_INFO_H_
6 #define NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_INFO_H_
7 
8 #include <string>
9 
10 #include "base/component_export.h"
11 #include "base/time/time.h"
12 #include "base/unguessable_token.h"
13 #include "net/base/hash_value.h"
14 #include "url/gurl.h"
15 #include "url/scheme_host_port.h"
16 
17 namespace net {
18 
19 // This class represents a shared dictionary information stored in a SQLite
20 // database for compression dictionary transport feature.
COMPONENT_EXPORT(NET_SHARED_DICTIONARY)21 class COMPONENT_EXPORT(NET_SHARED_DICTIONARY) SharedDictionaryInfo {
22  public:
23   SharedDictionaryInfo(const GURL& url,
24                        base::Time last_fetch_time,
25                        base::Time response_time,
26                        base::TimeDelta expiration,
27                        const std::string& match,
28                        const std::string& match_dest_string,
29                        const std::string& id,
30                        base::Time last_used_time,
31                        size_t size,
32                        const net::SHA256HashValue& hash,
33                        const base::UnguessableToken& disk_cache_key_token,
34                        const std::optional<int64_t>& primary_key_in_database);
35 
36   SharedDictionaryInfo(const SharedDictionaryInfo&);
37   SharedDictionaryInfo& operator=(const SharedDictionaryInfo&);
38 
39   SharedDictionaryInfo(SharedDictionaryInfo&& other);
40   SharedDictionaryInfo& operator=(SharedDictionaryInfo&& other);
41 
42   ~SharedDictionaryInfo();
43 
44   bool operator==(const SharedDictionaryInfo& other) const;
45 
46   const GURL& url() const { return url_; }
47   base::Time last_fetch_time() const { return last_fetch_time_; }
48   base::Time response_time() const { return response_time_; }
49   base::TimeDelta expiration() const { return expiration_; }
50   const std::string& match() const { return match_; }
51   const std::string& match_dest_string() const { return match_dest_string_; }
52   const std::string& id() const { return id_; }
53   base::Time last_used_time() const { return last_used_time_; }
54   size_t size() const { return size_; }
55   const net::SHA256HashValue& hash() const { return hash_; }
56   const base::UnguessableToken& disk_cache_key_token() const {
57     return disk_cache_key_token_;
58   }
59 
60   const std::optional<int64_t>& primary_key_in_database() const {
61     return primary_key_in_database_;
62   }
63   void set_primary_key_in_database(int64_t primary_key_in_database) {
64     primary_key_in_database_ = primary_key_in_database;
65   }
66 
67   void set_last_fetch_time(base::Time last_fetch_time) {
68     last_fetch_time_ = last_fetch_time;
69   }
70   void set_last_used_time(base::Time last_used_time) {
71     last_used_time_ = last_used_time;
72   }
73 
74   // An utility method that returns `response_time_` + `expiration_`.
75   base::Time GetExpirationTime() const;
76 
77  private:
78   // URL of the dictionary.
79   GURL url_;
80   // The time of when the dictionary was received from the network layer.
81   base::Time last_fetch_time_;
82   // The time of when the dictionary was received from the server. For cached
83   // responses, this time could be "far" in the past.
84   base::Time response_time_;
85   // The expiration time for the dictionary which was declared in
86   // 'use-as-dictionary' response header's `expires` option in seconds.
87   base::TimeDelta expiration_;
88   // The matching path pattern for the dictionary which was declared in
89   // 'use-as-dictionary' response header's `match` option.
90   std::string match_;
91   // The comma separated matching destinations for the dictionary which was
92   // declared in 'use-as-dictionary' response header's `match-dest` option.
93   std::string match_dest_string_;
94   // The Id for the dictionary which was declared in 'use-as-dictionary'
95   // response header's `id` option.
96   std::string id_;
97   // The time when the dictionary was last used.
98   base::Time last_used_time_;
99   // The size of the dictionary binary.
100   size_t size_;
101   // The sha256 hash of the dictionary binary.
102   net::SHA256HashValue hash_;
103   // The UnguessableToken used as a key in the DiskCache to store the dictionary
104   // binary.
105   base::UnguessableToken disk_cache_key_token_;
106   // The primary key in SQLite database. This is nullopt until it is stored to
107   // the database.
108   std::optional<int64_t> primary_key_in_database_;
109 };
110 
111 }  // namespace net
112 
113 #endif  // NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_INFO_H_
114