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)21class COMPONENT_EXPORT(NET_SHARED_DICTIONARY) SharedDictionaryInfo { 22 public: 23 SharedDictionaryInfo(const GURL& url, 24 base::Time response_time, 25 base::TimeDelta expiration, 26 const std::string& match, 27 base::Time last_used_time, 28 size_t size, 29 const net::SHA256HashValue& hash, 30 const base::UnguessableToken& disk_cache_key_token, 31 const absl::optional<int64_t>& primary_key_in_database); 32 33 SharedDictionaryInfo(const SharedDictionaryInfo&); 34 SharedDictionaryInfo& operator=(const SharedDictionaryInfo&); 35 36 SharedDictionaryInfo(SharedDictionaryInfo&& other); 37 SharedDictionaryInfo& operator=(SharedDictionaryInfo&& other); 38 39 ~SharedDictionaryInfo(); 40 41 bool operator==(const SharedDictionaryInfo& other) const; 42 43 const GURL& url() const { return url_; } 44 base::Time response_time() const { return response_time_; } 45 base::TimeDelta expiration() const { return expiration_; } 46 const std::string& match() const { return match_; } 47 base::Time last_used_time() const { return last_used_time_; } 48 size_t size() const { return size_; } 49 const net::SHA256HashValue& hash() const { return hash_; } 50 const base::UnguessableToken& disk_cache_key_token() const { 51 return disk_cache_key_token_; 52 } 53 54 const absl::optional<int64_t>& primary_key_in_database() const { 55 return primary_key_in_database_; 56 } 57 void set_primary_key_in_database(int64_t primary_key_in_database) { 58 primary_key_in_database_ = primary_key_in_database; 59 } 60 61 void set_last_used_time(base::Time last_used_time) { 62 last_used_time_ = last_used_time; 63 } 64 65 // An utility method that returns `response_time_` + `expiration_`. 66 base::Time GetExpirationTime() const; 67 68 private: 69 // URL of the dictionary. 70 GURL url_; 71 // The time of when the dictionary was received from the server. 72 base::Time response_time_; 73 // The expiration time for the dictionary which was declared in 74 // 'use-as-dictionary' response header's `expires` option in seconds. 75 base::TimeDelta expiration_; 76 // The matching path pattern for the dictionary which was declared in 77 // 'use-as-dictionary' response header's `match` option. 78 std::string match_; 79 // The time when the dictionary was last used. 80 base::Time last_used_time_; 81 // The size of the dictionary binary. 82 size_t size_; 83 // The sha256 hash of the dictionary binary. 84 net::SHA256HashValue hash_; 85 // The UnguessableToken used as a key in the DiskCache to store the dictionary 86 // binary. 87 base::UnguessableToken disk_cache_key_token_; 88 // The primary key in SQLite database. This is nullopt until it is stored to 89 // the database. 90 absl::optional<int64_t> primary_key_in_database_; 91 }; 92 93 } // namespace net 94 95 #endif // NET_EXTRAS_SHARED_DICTIONARY_SHARED_DICTIONARY_INFO_H_ 96