[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / metrics / metrics_rotation_scheduler.cc
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.
4
5 #include "components/metrics/metrics_rotation_scheduler.h"
6
7 #include "base/metrics/histogram_macros.h"
8 #include "build/build_config.h"
9
10 namespace metrics {
11
12 MetricsRotationScheduler::MetricsRotationScheduler(
13     const base::RepeatingClosure& upload_callback,
14     const base::RepeatingCallback<base::TimeDelta(void)>&
15         upload_interval_callback,
16     bool fast_startup_for_testing)
17     : MetricsScheduler(upload_callback, fast_startup_for_testing),
18       init_task_complete_(false),
19       waiting_for_init_task_complete_(false),
20       upload_interval_callback_(upload_interval_callback) {}
21
22 MetricsRotationScheduler::~MetricsRotationScheduler() {}
23
24 void MetricsRotationScheduler::InitTaskComplete() {
25   DCHECK(!init_task_complete_);
26   init_task_complete_ = true;
27   if (waiting_for_init_task_complete_) {
28     waiting_for_init_task_complete_ = false;
29     TriggerTask();
30   } else {
31     LogMetricsInitSequence(INIT_TASK_COMPLETED_FIRST);
32   }
33 }
34
35 void MetricsRotationScheduler::RotationFinished() {
36   TaskDone(upload_interval_callback_.Run());
37 }
38
39 void MetricsRotationScheduler::LogMetricsInitSequence(InitSequence sequence) {
40   UMA_HISTOGRAM_ENUMERATION("UMA.InitSequence", sequence,
41                             INIT_SEQUENCE_ENUM_SIZE);
42 }
43
44 void MetricsRotationScheduler::TriggerTask() {
45   // If the timer fired before the init task has completed, don't trigger the
46   // upload yet - wait for the init task to complete and do it then.
47   if (!init_task_complete_) {
48     LogMetricsInitSequence(TIMER_FIRED_FIRST);
49     waiting_for_init_task_complete_ = true;
50     return;
51   }
52   MetricsScheduler::TriggerTask();
53 }
54
55 }  // namespace metrics