commit f136e151684b138a37b402503131207f9b428a0f
parent b0311449f92fbeb85e1b53f05bc2f831f4d26d8f
Author: Randell Jesup <rjesup@mozilla.com>
Date: Wed, 1 Oct 2025 18:45:57 +0000
Bug 1917975: Compression Dictionary initial metadata parsing r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D258127
Diffstat:
2 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/netwerk/cache2/Dictionary.cpp b/netwerk/cache2/Dictionary.cpp
@@ -369,6 +369,9 @@ nsresult DictionaryCache::AddEntry(nsIURI* aURI, const nsACString& aKey,
dict.get()));
list->insertFront(dict);
*aDictEntry = do_AddRef(dict).take();
+
+ // Queue event to flush dictionary metadata to the cache
+ // XXX
return NS_OK;
});
return NS_OK;
@@ -465,6 +468,68 @@ already_AddRefed<DictionaryCacheEntry> DictionaryCache::GetDictionaryFor(
return nullptr;
}
+static void MakeMetadataEntry() {
+ // XXX
+}
+
+bool DictionaryCache::ParseMetaDataEntry(const char* key, const char* value,
+ nsCString& uri, uint32_t& hitCount,
+ uint32_t& lastHit, uint32_t& flags) {
+ MOZ_ASSERT(NS_IsMainThread());
+
+ DICTIONARY_LOG(("Dictionary::ParseMetaDataEntry key=%s value=%s",
+ key ? key : "", value));
+
+ const char* comma = strchr(value, ',');
+ if (!comma) {
+ DICTIONARY_LOG((" could not find first comma"));
+ return false;
+ }
+
+ uint32_t version = static_cast<uint32_t>(atoi(value));
+ DICTIONARY_LOG((" version -> %u", version));
+
+ if (version != METADATA_DICTIONARY_VERSION) {
+ DICTIONARY_LOG((" metadata version mismatch %u != %u", version,
+ METADATA_DICTIONARY_VERSION));
+ return false;
+ }
+
+ value = comma + 1;
+ comma = strchr(value, ',');
+ if (!comma) {
+ DICTIONARY_LOG((" could not find second comma"));
+ return false;
+ }
+
+ hitCount = static_cast<uint32_t>(atoi(value));
+ DICTIONARY_LOG((" hitCount -> %u", hitCount));
+
+ value = comma + 1;
+ comma = strchr(value, ',');
+ if (!comma) {
+ DICTIONARY_LOG((" could not find third comma"));
+ return false;
+ }
+
+ lastHit = static_cast<uint32_t>(atoi(value));
+ DICTIONARY_LOG((" lastHit -> %u", lastHit));
+
+ value = comma + 1;
+ flags = static_cast<uint32_t>(atoi(value));
+ DICTIONARY_LOG((" flags -> %u", flags));
+
+ if (key) {
+ const char* uriStart = key + (sizeof(META_DICTIONARY_PREFIX) - 1);
+ uri.AssignASCII(uriStart);
+ DICTIONARY_LOG((" uri -> %s", uriStart));
+ } else {
+ uri.Truncate();
+ }
+
+ return true;
+}
+
// Overall structure:
// Dictionary:
// DictionaryCache:
diff --git a/netwerk/cache2/Dictionary.h b/netwerk/cache2/Dictionary.h
@@ -27,6 +27,10 @@ class nsIIOService;
class nsILoadContextInfo;
class nsITimer;
+// Version of metadata entries we expect
+static const uint32_t METADATA_DICTIONARY_VERSION = 1;
+#define META_DICTIONARY_PREFIX "dict:"_ns
+
namespace mozilla {
namespace net {
@@ -181,6 +185,10 @@ class DictionaryCache final {
}
private:
+ bool ParseMetaDataEntry(const char* key, const char* value, nsCString& uri,
+ uint32_t& hitCount, uint32_t& lastHit,
+ uint32_t& flags);
+
// In-memory cache of dictionary entries. HashMap, keyed by origin, of
// Linked list (LRU order) of valid dictionaries for the origin.
// We keep empty entries in there to avoid hitting the disk cache to find out