system_memory_pressure_evaluator_fuchsia.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2020 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_FUCHSIA_H_
  5. #define COMPONENTS_MEMORY_PRESSURE_SYSTEM_MEMORY_PRESSURE_EVALUATOR_FUCHSIA_H_
  6. #include <fuchsia/memorypressure/cpp/fidl.h>
  7. #include <lib/fidl/cpp/binding.h>
  8. #include "base/sequence_checker.h"
  9. #include "base/time/time.h"
  10. #include "base/timer/timer.h"
  11. #include "components/memory_pressure/system_memory_pressure_evaluator.h"
  12. namespace memory_pressure {
  13. class MemoryPressureVoter;
  14. // Registers with the fuchsia.memorypressure.Provider to be notified of changes
  15. // to the system memory pressure level. Votes are sent immediately when
  16. // memory pressure becomes MODERATE or CRITICAL, and periodically until
  17. // memory pressure drops back down to NONE. No notifications are sent at NONE
  18. // level.
  19. class SystemMemoryPressureEvaluatorFuchsia
  20. : public SystemMemoryPressureEvaluator,
  21. public fuchsia::memorypressure::Watcher {
  22. public:
  23. using SystemMemoryPressureEvaluator::SendCurrentVote;
  24. // The period at which the system is re-notified when the pressure is not
  25. // none.
  26. static const base::TimeDelta kRenotifyVotePeriod;
  27. explicit SystemMemoryPressureEvaluatorFuchsia(
  28. std::unique_ptr<memory_pressure::MemoryPressureVoter> voter);
  29. ~SystemMemoryPressureEvaluatorFuchsia() override;
  30. SystemMemoryPressureEvaluatorFuchsia(
  31. const SystemMemoryPressureEvaluatorFuchsia&) = delete;
  32. SystemMemoryPressureEvaluatorFuchsia& operator=(
  33. const SystemMemoryPressureEvaluatorFuchsia&) = delete;
  34. private:
  35. // fuchsia::memorypressure::Watcher implementation.
  36. void OnLevelChanged(fuchsia::memorypressure::Level level,
  37. OnLevelChangedCallback callback) override;
  38. fidl::Binding<fuchsia::memorypressure::Watcher> binding_;
  39. // Timer that will re-notify with the current vote at regular interval.
  40. base::RepeatingTimer renotify_current_vote_timer_;
  41. SEQUENCE_CHECKER(sequence_checker_);
  42. };
  43. } // namespace memory_pressure
  44. #endif // COMPONENTS_MEMORY_PRESSURE_SYSTEM_MEMORY_PRESSURE_EVALUATOR_FUCHSIA_H_