summaryrefslogtreecommitdiff
path: root/chromium/content/browser/background_sync/background_sync_metrics.h
blob: f92a7c5b7a3f6dd6f1e26cf36d820132f309dbe0 (plain)
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
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/macros.h"
#include "base/time/time.h"
#include "content/browser/background_sync/background_sync.pb.h"
#include "content/browser/background_sync/background_sync_status.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 BackgroundSyncMetrics {
 public:
  enum RegistrationCouldFire {
    REGISTRATION_COULD_NOT_FIRE,
    REGISTRATION_COULD_FIRE
  };

  enum RegistrationIsDuplicate {
    REGISTRATION_IS_NOT_DUPLICATE,
    REGISTRATION_IS_DUPLICATE
  };

  // Records the start of a sync event.
  static void RecordEventStarted(SyncPeriodicity periodicity,
                                 bool startedin_foreground);

  // Records the result of a single sync event firing.
  static void RecordEventResult(SyncPeriodicity periodicity,
                                bool result,
                                bool finished_in_foreground);

  // Records the result of running a batch of sync events, including the total
  // time spent, and the batch size.
  static void RecordBatchSyncEventComplete(const base::TimeDelta& time,
                                           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.
  static void CountRegisterSuccess(
      SyncPeriodicity periodicity,
      RegistrationCouldFire could_fire,
      RegistrationIsDuplicate registration_is_duplicate);

  // Records the status of a failed sync registration.
  static void CountRegisterFailure(SyncPeriodicity periodicity,
                                   BackgroundSyncStatus status);

  // Records the result of trying to unregister a sync.
  static void CountUnregister(SyncPeriodicity periodicity,
                              BackgroundSyncStatus result);

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundSyncMetrics);
};

}  // namespace content

#endif  // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_METRICS_H_