[go: nahoru, domu]

[base] Remove MemoryPressureMonitor::SetDispatchCallback

In practice, SetDispatchCallback() was only used in the
MultiSourceMemoryPressureMonitor implementation. This CL removes that
method from the base class so that it becomes specific to
MultiSourceMemoryPressureMonitor.

In addition, this CL renames SetDispatchCallback() to
SetDispatchCallbackForTesting() as it is only used in unit tests.

Bug: None
Change-Id: If17e319e9cb11a80731115bc0d0e8c368493fa28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4209171
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1107036}
diff --git a/components/memory_pressure/multi_source_memory_pressure_monitor.cc b/components/memory_pressure/multi_source_memory_pressure_monitor.cc
index f37e4d1..3b94a77 100644
--- a/components/memory_pressure/multi_source_memory_pressure_monitor.cc
+++ b/components/memory_pressure/multi_source_memory_pressure_monitor.cc
@@ -36,7 +36,7 @@
   system_evaluator_.reset();
 }
 
-void MultiSourceMemoryPressureMonitor::Start() {
+void MultiSourceMemoryPressureMonitor::MaybeStartPlatformVoter() {
   system_evaluator_ =
       SystemMemoryPressureEvaluator::CreateDefaultSystemEvaluator(this);
 }
@@ -53,12 +53,6 @@
   return aggregator_.CreateVoter();
 }
 
-void MultiSourceMemoryPressureMonitor::SetDispatchCallback(
-    const DispatchCallback& callback) {
-  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-  dispatch_callback_ = callback;
-}
-
 void MultiSourceMemoryPressureMonitor::OnMemoryPressureLevelChanged(
     base::MemoryPressureListener::MemoryPressureLevel level) {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -89,4 +83,12 @@
   system_evaluator_ = std::move(evaluator);
 }
 
+void MultiSourceMemoryPressureMonitor::SetDispatchCallbackForTesting(
+    const DispatchCallback& callback) {
+  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+  // Must be called before `Start()`.
+  DCHECK(!system_evaluator_);
+  dispatch_callback_ = callback;
+}
+
 }  // namespace memory_pressure