diff --git a/components/content_settings/core/common/host_indexed_content_settings.cc b/components/content_settings/core/common/host_indexed_content_settings.cc index 1f286ca1c49ea..04d7d4b259df9 100644 --- a/components/content_settings/core/common/host_indexed_content_settings.cc +++ b/components/content_settings/core/common/host_indexed_content_settings.cc @@ -13,6 +13,7 @@ #include "base/check_op.h" #include "base/feature_list.h" +#include "base/logging.h" #include "base/notreached.h" #include "base/time/clock.h" #include "base/time/default_clock.h" @@ -299,17 +300,48 @@ const RuleEntry* HostIndexedContentSettings::Find( const RuleEntry* found = FindInHostToContentSettings( primary_url, secondary_url, primary_host_indexed_, primary_url.host(), clock_, return_expired_settings_); - if (found) { - return found; + if (!found) { + found = FindInHostToContentSettings(primary_url, secondary_url, + secondary_host_indexed_, + secondary_url.host(), clock_, + return_expired_settings_); } - found = FindInHostToContentSettings( - primary_url, secondary_url, secondary_host_indexed_, secondary_url.host(), - clock_, return_expired_settings_); - if (found) { - return found; + if (!found) { + found = FindContentSetting(primary_url, secondary_url, wildcard_settings_, + clock_, return_expired_settings_); + } + // --------------------------------------------------------------------------- + // POC INSTRUMENTATION: re-adds the linear-scan equivalence check that was + // dropped after commit 1c1d85869069c. If the indexed lookup returns nullptr + // but a brute-force scan of the host buckets finds a matching rule, the + // index has diverged from the reference Matches() semantics and we abort. + // --------------------------------------------------------------------------- + if (!found) { + auto brute = [&](const HostToContentSettings& m) -> const RuleEntry* { + for (const auto& [host, rules] : m) { + const RuleEntry* r = FindContentSetting( + primary_url, secondary_url, rules, clock_, return_expired_settings_); + if (r) { + return r; + } + } + return nullptr; + }; + const RuleEntry* lin = brute(primary_host_indexed_); + if (!lin) { + lin = brute(secondary_host_indexed_); + } + if (lin) { + LOG(FATAL) + << "POC: HostIndexedContentSettings::Find divergence — indexed " + "lookup returned nullptr but linear scan matched rule (primary=" + << lin->first.primary_pattern.ToString() + << ", secondary=" << lin->first.secondary_pattern.ToString() + << ") for primary_url=" << primary_url.spec() + << " secondary_url=" << secondary_url.spec(); + } } - return FindContentSetting(primary_url, secondary_url, wildcard_settings_, - clock_, return_expired_settings_); + return found; } bool HostIndexedContentSettings::SetValue(