From 9fd77ce12f8c6f7fdaa03eaea0dc1d363e84ed2a Mon Sep 17 00:00:00 2001 From: asharma Date: Mon, 7 Feb 2022 20:26:28 +0000 Subject: [PATCH] Bug 1752907: Cut over Hardware Concurrency to finer-grained RFP Check r=tjr Differential Revision: https://phabricator.services.mozilla.com/D137481 --- dom/base/Navigator.cpp | 3 ++- dom/workers/RuntimeService.cpp | 5 +++-- dom/workers/RuntimeService.h | 2 +- dom/workers/WorkerNavigator.cpp | 5 ++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 4d5a1dd6602c..b9b3fe6621d2 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -645,7 +645,8 @@ uint64_t Navigator::HardwareConcurrency() { return 1; } - return rts->ClampedHardwareConcurrency(); + return rts->ClampedHardwareConcurrency( + nsContentUtils::ShouldResistFingerprinting(mWindow->GetExtantDoc())); } namespace { diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 0ff821a12a6a..43d299aeba98 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -1994,11 +1994,12 @@ void RuntimeService::MemoryPressureAllWorkers() { BroadcastAllWorkers([](auto& worker) { worker.MemoryPressure(); }); } -uint32_t RuntimeService::ClampedHardwareConcurrency() const { +uint32_t RuntimeService::ClampedHardwareConcurrency( + bool aShouldResistFingerprinting) const { // The Firefox Hardware Report says 70% of Firefox users have exactly 2 cores. // When the resistFingerprinting pref is set, we want to blend into the crowd // so spoof navigator.hardwareConcurrency = 2 to reduce user uniqueness. - if (MOZ_UNLIKELY(nsContentUtils::ShouldResistFingerprinting())) { + if (MOZ_UNLIKELY(aShouldResistFingerprinting)) { return 2; } diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h index 0ca5f99fab6f..ecc0bf4a5b91 100644 --- a/dom/workers/RuntimeService.h +++ b/dom/workers/RuntimeService.h @@ -178,7 +178,7 @@ class RuntimeService final : public nsIObserver { void MemoryPressureAllWorkers(); - uint32_t ClampedHardwareConcurrency() const; + uint32_t ClampedHardwareConcurrency(bool aShouldResistFingerprinting) const; void CrashIfHanging(); diff --git a/dom/workers/WorkerNavigator.cpp b/dom/workers/WorkerNavigator.cpp index cb499d6bd7ae..dacef4227f7e 100644 --- a/dom/workers/WorkerNavigator.cpp +++ b/dom/workers/WorkerNavigator.cpp @@ -176,7 +176,10 @@ uint64_t WorkerNavigator::HardwareConcurrency() const { RuntimeService* rts = RuntimeService::GetService(); MOZ_ASSERT(rts); - return rts->ClampedHardwareConcurrency(); + WorkerPrivate* aWorkerPrivate = GetCurrentThreadWorkerPrivate(); + bool rfp = aWorkerPrivate->ShouldResistFingerprinting(); + + return rts->ClampedHardwareConcurrency(rfp); } StorageManager* WorkerNavigator::Storage() {