ash_tracing_handler.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 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 ASH_HUD_DISPLAY_ASH_TRACING_HANDLER_H_
  5. #define ASH_HUD_DISPLAY_ASH_TRACING_HANDLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "base/files/platform_file.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/sequence_checker.h"
  11. #include "base/trace_event/trace_config.h"
  12. namespace perfetto {
  13. class TracingSession;
  14. }
  15. namespace ash {
  16. namespace hud_display {
  17. class AshTracingRequest;
  18. // Only one instance of this object can exist at a time.
  19. class ASH_EXPORT AshTracingHandler {
  20. public:
  21. AshTracingHandler();
  22. AshTracingHandler(const AshTracingHandler&) = delete;
  23. AshTracingHandler& operator=(const AshTracingHandler&) = delete;
  24. ~AshTracingHandler();
  25. // Initiates tracing start. Observer will be notified with the result.
  26. void Start(AshTracingRequest* request);
  27. // Initiates tracing stop. Observer will be notified with the result.
  28. void Stop();
  29. // Returns true if tracing was started.
  30. bool IsStarted() const;
  31. // This allows to use fake Perfetto sessions for testing.
  32. static void SetPerfettoTracingSessionCreatorForTesting(
  33. std::unique_ptr<perfetto::TracingSession> (*creator)(void));
  34. static void ResetPerfettoTracingSessionCreatorForTesting();
  35. private:
  36. void OnTracingStarted();
  37. void OnTracingFinished();
  38. AshTracingRequest* request_ = nullptr;
  39. std::unique_ptr<perfetto::TracingSession> tracing_session_;
  40. SEQUENCE_CHECKER(my_sequence_checker_);
  41. base::WeakPtrFactory<AshTracingHandler> weak_factory_{this};
  42. };
  43. } // namespace hud_display
  44. } // namespace ash
  45. #endif // ASH_HUD_DISPLAY_ASH_TRACING_HANDLER_H_