1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_METRICS_METRICS_ROTATION_SCHEDULER_H_
6 #define COMPONENTS_METRICS_METRICS_ROTATION_SCHEDULER_H_
8 #include "base/functional/callback.h"
9 #include "base/time/time.h"
10 #include "components/metrics/metrics_scheduler.h"
14 // Scheduler task to drive a MetricsService object's uploading.
15 class MetricsRotationScheduler : public MetricsScheduler {
17 // Creates MetricsRotationScheduler object with the given |rotation_callback|
18 // callback to call when log rotation should happen and |interval_callback|
19 // to determine the interval between rotations in steady state.
20 // |rotation_callback| must arrange to call RotationFinished on completion.
21 MetricsRotationScheduler(
22 const base::RepeatingClosure& rotation_callback,
23 const base::RepeatingCallback<base::TimeDelta(void)>& interval_callback,
24 bool fast_startup_for_testing);
26 MetricsRotationScheduler(const MetricsRotationScheduler&) = delete;
27 MetricsRotationScheduler& operator=(const MetricsRotationScheduler&) = delete;
29 ~MetricsRotationScheduler() override;
31 // Callback from MetricsService when the startup init task has completed.
32 void InitTaskComplete();
34 // Callback from MetricsService when a triggered rotation finishes.
35 void RotationFinished();
40 INIT_TASK_COMPLETED_FIRST,
41 INIT_SEQUENCE_ENUM_SIZE,
45 // Record the init sequence order histogram.
46 virtual void LogMetricsInitSequence(InitSequence sequence);
49 void TriggerTask() override;
51 // Whether the InitTaskComplete() callback has been called.
52 bool init_task_complete_;
54 // Whether the initial scheduled upload timer has fired before the init task
55 // has been completed.
56 bool waiting_for_init_task_complete_;
58 // Callback function used to get the standard upload time.
59 base::RepeatingCallback<base::TimeDelta(void)> upload_interval_callback_;
62 } // namespace metrics
64 #endif // COMPONENTS_METRICS_METRICS_ROTATION_SCHEDULER_H_