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_SHARED_DICTIONARY_SHARED_DICTIONARY_H_ 6 #define NET_SHARED_DICTIONARY_SHARED_DICTIONARY_H_ 7 8 #include <string> 9 10 #include "base/functional/callback.h" 11 #include "base/memory/ref_counted.h" 12 #include "net/base/net_export.h" 13 14 namespace net { 15 class IOBuffer; 16 struct SHA256HashValue; 17 18 // This class is used to read the binary of the shared dictionary. 19 class NET_EXPORT SharedDictionary : public base::RefCounted<SharedDictionary> { 20 public: 21 // Reads the whole binary of the dictionary. If an error has occurred, returns 22 // ERR_FAILED. If the binary of the dictionary is already in the memory 23 // returns OK. Otherwise returns ERR_IO_PENDING and `callback` will be called 24 // asynchronously with OK or ERR_FAILED depending on the success status. 25 virtual int ReadAll(base::OnceCallback<void(int)> callback) = 0; 26 27 // Returns the buffer which contains the binary of the dictionary. 28 // ReadAll() must have succeeded before calling this method. 29 virtual scoped_refptr<IOBuffer> data() const = 0; 30 31 // Returns the binary size of the dictionary. It is safe to call this method 32 // before calling ReadAll(). 33 virtual size_t size() const = 0; 34 35 // Returns the hash of the binary of the dictionary. It is safe to call this 36 // method before calling ReadAll(). 37 virtual const SHA256HashValue& hash() const = 0; 38 39 // Returns the server-provided id of the dictionary. When this id is not 40 // empty, it will be serialized [RFC8941] and sent in "Dictionary-ID" request 41 // when Chrome can use the dictionary. 42 // https://www.rfc-editor.org/rfc/rfc8941#name-serializing-a-string 43 virtual const std::string& id() const = 0; 44 45 protected: 46 friend class base::RefCounted<SharedDictionary>; 47 virtual ~SharedDictionary() = default; 48 }; 49 50 } // namespace net 51 52 #endif // NET_SHARED_DICTIONARY_SHARED_DICTIONARY_H_ 53