system_memory_pressure_evaluator.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_MEMORY_PRESSURE_SYSTEM_MEMORY_PRESSURE_EVALUATOR_H_
  5. #define COMPONENTS_MEMORY_PRESSURE_SYSTEM_MEMORY_PRESSURE_EVALUATOR_H_
  6. #include "base/memory/memory_pressure_listener.h"
  7. #include "components/memory_pressure/memory_pressure_voter.h"
  8. #include "components/memory_pressure/multi_source_memory_pressure_monitor.h"
  9. namespace memory_pressure {
  10. // Base class for the platform SystemMemoryPressureEvaluators, which use
  11. // MemoryPressureVoters to cast their vote on the overall MemoryPressureLevel.
  12. class SystemMemoryPressureEvaluator {
  13. public:
  14. // Used by the MemoryPressureMonitor to create the correct Evaluator for the
  15. // platform in use.
  16. static std::unique_ptr<SystemMemoryPressureEvaluator>
  17. CreateDefaultSystemEvaluator(MultiSourceMemoryPressureMonitor* monitor);
  18. virtual ~SystemMemoryPressureEvaluator();
  19. SystemMemoryPressureEvaluator(const SystemMemoryPressureEvaluator&) = delete;
  20. SystemMemoryPressureEvaluator& operator=(
  21. const SystemMemoryPressureEvaluator&) = delete;
  22. base::MemoryPressureListener::MemoryPressureLevel current_vote() const {
  23. return current_vote_;
  24. }
  25. protected:
  26. explicit SystemMemoryPressureEvaluator(
  27. std::unique_ptr<MemoryPressureVoter> voter);
  28. // Sets the Evaluator's |current_vote_| member without casting vote to the
  29. // MemoryPressureVoteAggregator.
  30. void SetCurrentVote(base::MemoryPressureListener::MemoryPressureLevel level);
  31. // Uses the Evaluators' |voter_| to cast/update its vote on memory pressure
  32. // level. The MemoryPressureListeners will only be notified of the newly
  33. // calculated pressure level if |notify| is true.
  34. void SendCurrentVote(bool notify) const;
  35. private:
  36. base::MemoryPressureListener::MemoryPressureLevel current_vote_;
  37. // In charge of forwarding votes from here to the
  38. // MemoryPressureVoteAggregator.
  39. std::unique_ptr<MemoryPressureVoter> voter_;
  40. SEQUENCE_CHECKER(sequence_checker_);
  41. };
  42. } // namespace memory_pressure
  43. #endif // COMPONENTS_MEMORY_PRESSURE_SYSTEM_MEMORY_PRESSURE_EVALUATOR_H_