performance_manager_main_thread_observer.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_PERFORMANCE_MANAGER_PUBLIC_PERFORMANCE_MANAGER_MAIN_THREAD_OBSERVER_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_PERFORMANCE_MANAGER_MAIN_THREAD_OBSERVER_H_
  6. #include "base/observer_list_types.h"
  7. namespace content {
  8. class WebContents;
  9. } // namespace content
  10. namespace performance_manager {
  11. // Interface to observe PerformanceManager events that happen on the main
  12. // thread. All methods are invoked on the main thread.
  13. class PerformanceManagerMainThreadObserver : public base::CheckedObserver {
  14. public:
  15. ~PerformanceManagerMainThreadObserver() override = default;
  16. // Invoked when a PageNode is created for |web_contents|. The PageNode can be
  17. // retrieved via PerformanceManager::GetPageNodeForWebContents(). The PageNode
  18. // will be destroyed when |web_contents| is destroyed or when the
  19. // PerformanceManagerRegistry is destroyed, whichever comes first.
  20. virtual void OnPageNodeCreatedForWebContents(
  21. content::WebContents* web_contents) = 0;
  22. // Invoked before the PM is torn down on the main thread.
  23. virtual void OnBeforePerformanceManagerDestroyed() = 0;
  24. protected:
  25. PerformanceManagerMainThreadObserver() = default;
  26. };
  27. // A default implementation of the observer, with all methods stubbed out.
  28. class PerformanceManagerMainThreadObserverDefaultImpl
  29. : public PerformanceManagerMainThreadObserver {
  30. public:
  31. ~PerformanceManagerMainThreadObserverDefaultImpl() override = default;
  32. // PerformanceManagerMainThreadObserver implementation:
  33. void OnPageNodeCreatedForWebContents(
  34. content::WebContents* web_contents) override {}
  35. void OnBeforePerformanceManagerDestroyed() override {}
  36. protected:
  37. PerformanceManagerMainThreadObserverDefaultImpl() = default;
  38. };
  39. } // namespace performance_manager
  40. #endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_PERFORMANCE_MANAGER_MAIN_THREAD_OBSERVER_H_