metrics_log_manager.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2014 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_METRICS_METRICS_LOG_MANAGER_H_
  5. #define COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include "components/metrics/metrics_log.h"
  9. namespace metrics {
  10. class MetricsLogStore;
  11. // Manages all the log objects used by a MetricsService implementation. Keeps
  12. // track of an in-progress log and a paused log.
  13. class MetricsLogManager {
  14. public:
  15. MetricsLogManager();
  16. MetricsLogManager(const MetricsLogManager&) = delete;
  17. MetricsLogManager& operator=(const MetricsLogManager&) = delete;
  18. ~MetricsLogManager();
  19. // Makes |log| the current_log. This should only be called if there is not a
  20. // current log.
  21. void BeginLoggingWithLog(std::unique_ptr<MetricsLog> log);
  22. // Returns the in-progress log.
  23. MetricsLog* current_log() { return current_log_.get(); }
  24. // Closes |current_log_|, compresses it, and stores it in the |log_store| for
  25. // later, leaving |current_log_| nullptr.
  26. void FinishCurrentLog(MetricsLogStore* log_store);
  27. // Closes and discards |current_log|.
  28. void DiscardCurrentLog();
  29. // Sets current_log to nullptr, but saves the current log for future use with
  30. // ResumePausedLog(). Only one log may be paused at a time.
  31. // TODO(stuartmorgan): Pause/resume support is really a workaround for a
  32. // design issue in initial log writing; that should be fixed, and pause/resume
  33. // removed.
  34. void PauseCurrentLog();
  35. // Restores the previously paused log (if any) to current_log().
  36. // This should only be called if there is not a current log.
  37. void ResumePausedLog();
  38. private:
  39. // The log that we are still appending to.
  40. std::unique_ptr<MetricsLog> current_log_;
  41. // A paused, previously-current log.
  42. std::unique_ptr<MetricsLog> paused_log_;
  43. };
  44. } // namespace metrics
  45. #endif // COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_