performance_manager_lifetime.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_EMBEDDER_PERFORMANCE_MANAGER_LIFETIME_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_LIFETIME_H_
  6. #include <memory>
  7. #include "base/callback_forward.h"
  8. #include "components/performance_manager/embedder/performance_manager_registry.h"
  9. #include "components/performance_manager/public/performance_manager.h"
  10. namespace performance_manager {
  11. class Graph;
  12. class GraphFeatures;
  13. using GraphCreatedCallback = base::OnceCallback<void(Graph*)>;
  14. // A helper class that manages the lifetime of PerformanceManager
  15. // and PerformanceManagerRegistry.
  16. class PerformanceManagerLifetime {
  17. public:
  18. PerformanceManagerLifetime(const GraphFeatures&, GraphCreatedCallback);
  19. ~PerformanceManagerLifetime();
  20. // Allows specifying an additional callback that will be invoked in tests.
  21. static void SetAdditionalGraphCreatedCallbackForTesting(
  22. GraphCreatedCallback graph_created_callback);
  23. // Sets an override for the features enabled in testing. These will be used
  24. // instead of the features passed to the PerformanceManagerLifetime
  25. // constructor in tests. Individual tests can enable more features by
  26. // creating another GraphFeatures object and calling its ConfigureGraph
  27. // method.
  28. //
  29. // This needs to be set before any PerformanceManagerLifetime is created. In
  30. // browser tests this occurs as part of Chrome browser main parts.
  31. static void SetGraphFeaturesOverrideForTesting(const GraphFeatures&);
  32. private:
  33. std::unique_ptr<PerformanceManager> performance_manager_;
  34. std::unique_ptr<PerformanceManagerRegistry> performance_manager_registry_;
  35. };
  36. // Unregisters |instance| and arranges for its deletion on its sequence.
  37. void DestroyPerformanceManager(std::unique_ptr<PerformanceManager> instance);
  38. } // namespace performance_manager
  39. #endif // COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_LIFETIME_H_