performance_manager_owned.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_PERFORMANCE_MANAGER_PUBLIC_PERFORMANCE_MANAGER_OWNED_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_PERFORMANCE_MANAGER_OWNED_H_
  6. namespace performance_manager {
  7. // Helper class for passing ownership of objects to the PerformanceManager.
  8. // The object is expected to live on the main thread.
  9. class PerformanceManagerOwned {
  10. public:
  11. virtual ~PerformanceManagerOwned() = default;
  12. PerformanceManagerOwned(const PerformanceManagerOwned&) = delete;
  13. PerformanceManagerOwned& operator=(const PerformanceManagerOwned&) = delete;
  14. // Called when the object is passed into the PerformanceManager.
  15. virtual void OnPassedToPM() = 0;
  16. // Called when the object is removed from the PerformanceManager, either via
  17. // an explicit call to TakeFromPM, or prior to the PerformanceManager being
  18. // destroyed.
  19. virtual void OnTakenFromPM() = 0;
  20. protected:
  21. PerformanceManagerOwned() = default;
  22. };
  23. // A default implementation of PerformanceManagerOwned.
  24. class PerformanceManagerOwnedDefaultImpl : public PerformanceManagerOwned {
  25. public:
  26. ~PerformanceManagerOwnedDefaultImpl() override = default;
  27. PerformanceManagerOwnedDefaultImpl(
  28. const PerformanceManagerOwnedDefaultImpl&) = delete;
  29. PerformanceManagerOwnedDefaultImpl& operator=(
  30. const PerformanceManagerOwnedDefaultImpl*) = delete;
  31. // PerformanceManagerOwned implementation:
  32. void OnPassedToPM() override {}
  33. void OnTakenFromPM() override {}
  34. protected:
  35. PerformanceManagerOwnedDefaultImpl() = default;
  36. };
  37. } // namespace performance_manager
  38. #endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_PERFORMANCE_MANAGER_OWNED_H_