File: background_sync_metrics.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (98 lines) | stat: -rw-r--r-- 4,061 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_METRICS_H_
#define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_METRICS_H_

#include "base/time/time.h"
#include "content/browser/background_sync/background_sync.pb.h"
#include "content/browser/background_sync/background_sync_status.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h"

namespace content {

// This class contains the logic for recording usage metrics for the Background
// Sync API. It is stateless, containing only static methods, so it can be used
// by any of the Background Sync code, without needing to be instantiated
// explicitly.
class CONTENT_EXPORT BackgroundSyncMetrics {
 public:
  // ResultPattern is used by Histograms, append new entries at the end.
  enum ResultPattern {
    RESULT_PATTERN_SUCCESS_FOREGROUND = 0,
    RESULT_PATTERN_SUCCESS_BACKGROUND = 1,
    RESULT_PATTERN_FAILED_FOREGROUND = 2,
    RESULT_PATTERN_FAILED_BACKGROUND = 3,
    RESULT_PATTERN_MAX = RESULT_PATTERN_FAILED_BACKGROUND,
  };

  enum RegistrationCouldFire {
    REGISTRATION_COULD_NOT_FIRE,
    REGISTRATION_COULD_FIRE
  };

  enum RegistrationIsDuplicate {
    REGISTRATION_IS_NOT_DUPLICATE,
    REGISTRATION_IS_DUPLICATE
  };

  BackgroundSyncMetrics() = delete;
  BackgroundSyncMetrics(const BackgroundSyncMetrics&) = delete;
  BackgroundSyncMetrics& operator=(const BackgroundSyncMetrics&) = delete;

  // Records the start of a sync event.
  static void RecordEventStarted(blink::mojom::BackgroundSyncType sync_type,
                                 bool startedin_foreground);

  // Records the result of a single sync event firing.
  static void RecordEventResult(blink::mojom::BackgroundSyncType sync_type,
                                bool result,
                                bool finished_in_foreground);

  // Records, at the completion of a one-shot sync registration, whether the
  // sync event was successful, and how many attempts it took to get there.
  static void RecordRegistrationComplete(bool event_succeeded,
                                         int num_attempts_required);

  // Records the result of running a batch of sync events, including the total
  // time spent, the batch size, and whether the operation originated from a
  // wakeup task.
  static void RecordBatchSyncEventComplete(
      blink::mojom::BackgroundSyncType sync_type,
      const base::TimeDelta& time,
      bool from_wakeup_task,
      int number_of_batched_sync_events);

  // Records the result of successfully registering a sync. |could_fire|
  // indicates whether the conditions were sufficient for the sync to fire
  // immediately at the time it was registered. |could_fire| is only relevant to
  // and recorded for one-shot Background Sync registrations.
  // |min_interval_ms| is only recorded for Periodic Background Sync
  // registrations, and records the min_interval in ms requested for this
  // registration.
  static void CountRegisterSuccess(
      blink::mojom::BackgroundSyncType sync_type,
      int64_t min_interval_ms,
      RegistrationCouldFire could_fire,
      RegistrationIsDuplicate registration_is_duplicate);

  // Records the status of a failed sync registration.
  static void CountRegisterFailure(blink::mojom::BackgroundSyncType sync_type,
                                   BackgroundSyncStatus status);

  // Records the status of an attempt to remove a Periodic Background
  // Sync registration.
  static void CountUnregisterPeriodicSync(BackgroundSyncStatus status);

  // Records whether the Chrome wakeup task actually resulted in us firing
  // any sync events corresponding to |sync_type|.
  static void RecordEventsFiredFromWakeupTask(
      blink::mojom::BackgroundSyncType sync_type,
      bool fired_events);
};

}  // namespace content

#endif  // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_METRICS_H_