File: metric_reporting_manager_delegate_base.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (128 lines) | stat: -rw-r--r-- 5,669 bytes parent folder | download | duplicates (6)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_REPORTING_METRIC_REPORTING_MANAGER_DELEGATE_BASE_H_
#define CHROME_BROWSER_CHROMEOS_REPORTING_METRIC_REPORTING_MANAGER_DELEGATE_BASE_H_

#include <memory>
#include <optional>

#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "components/reporting/client/report_queue_configuration.h"
#include "components/reporting/metrics/collector_base.h"
#include "components/reporting/metrics/event_driven_telemetry_collector_pool.h"
#include "components/reporting/metrics/metric_event_observer.h"
#include "components/reporting/metrics/metric_event_observer_manager.h"
#include "components/reporting/metrics/metric_report_queue.h"
#include "components/reporting/proto/synced/record.pb.h"
#include "components/reporting/util/rate_limiter_interface.h"
#include "components/reporting/util/rate_limiter_slide_window.h"

namespace reporting::metrics {

// Base class for the delegate used by the `MetricReportingManager` to
// initialize metric related components.
class MetricReportingManagerDelegateBase {
 public:
  MetricReportingManagerDelegateBase() = default;
  MetricReportingManagerDelegateBase(
      const MetricReportingManagerDelegateBase& other) = delete;
  MetricReportingManagerDelegateBase& operator=(
      const MetricReportingManagerDelegateBase& other) = delete;
  virtual ~MetricReportingManagerDelegateBase() = default;

  // Creates a new `MetricReportQueue` that can be used towards metrics
  // reporting. Specify a `RateLimiterInterface` implementation to enforce rate
  // limiting.
  virtual std::unique_ptr<MetricReportQueue> CreateMetricReportQueue(
      EventType event_type,
      Destination destination,
      Priority priority,
      std::unique_ptr<RateLimiterInterface> rate_limiter = nullptr,
      std::optional<SourceInfo> source_info = std::nullopt);

  // Creates a new `MetricReportQueue` for periodic uploads. The rate is
  // controlled by the specified setting and we fall back to the defaults
  // specified if none set by policy.
  virtual std::unique_ptr<MetricReportQueue> CreatePeriodicUploadReportQueue(
      EventType event_type,
      Destination destination,
      Priority priority,
      ReportingSettings* reporting_settings,
      const std::string& rate_setting_path,
      base::TimeDelta default_rate,
      int rate_unit_to_ms = 1,
      std::optional<SourceInfo> source_info = std::nullopt);

  // Creates a new collector for periodic metric collection. The rate is
  // controlled by the specified setting and we fall back to the defaults
  // specified if none set by policy.
  virtual std::unique_ptr<CollectorBase> CreatePeriodicCollector(
      Sampler* sampler,
      MetricReportQueue* metric_report_queue,
      ReportingSettings* reporting_settings,
      const std::string& enable_setting_path,
      bool setting_enabled_default_value,
      const std::string& rate_setting_path,
      base::TimeDelta default_rate,
      int rate_unit_to_ms,
      base::TimeDelta init_delay = base::TimeDelta());

  // Creates a new collector for one shot metric collection. The rate is
  // controlled by the specified setting and we fall back to the defaults
  // specified if none set by policy.
  virtual std::unique_ptr<CollectorBase> CreateOneShotCollector(
      Sampler* sampler,
      MetricReportQueue* metric_report_queue,
      ReportingSettings* reporting_settings,
      const std::string& enable_setting_path,
      bool setting_enabled_default_value,
      base::TimeDelta init_delay = base::TimeDelta());

  // Creates a new collector for manual collection. Does not automatically
  // collect data upon construction or on any time period. Only collects if the
  // appropriate settings are enabled when manual collection happens.
  virtual std::unique_ptr<CollectorBase> CreateManualCollector(
      Sampler* sampler,
      MetricReportQueue* metric_report_queue,
      ReportingSettings* reporting_settings,
      const std::string& enable_setting_path,
      bool setting_enabled_default_value);

  // Creates a new event observer manager to manage events reporting. The rate
  // is controlled by the specified setting and we fall back to the defaults
  // specified if none set by policy.
  virtual std::unique_ptr<MetricEventObserverManager>
  CreateEventObserverManager(
      std::unique_ptr<MetricEventObserver> event_observer,
      MetricReportQueue* metric_report_queue,
      ReportingSettings* reporting_settings,
      const std::string& enable_setting_path,
      bool setting_enabled_default_value,
      EventDrivenTelemetryCollectorPool* collector_pool,
      base::TimeDelta init_delay = base::TimeDelta());

  // Creates a new instance of the sliding window rate limiter with the
  // specified total size, time window and bucket count.
  virtual std::unique_ptr<RateLimiterSlideWindow>
  CreateSlidingWindowRateLimiter(size_t total_size,
                                 base::TimeDelta time_window,
                                 size_t bucket_count);

  // Checks for profile affiliation and returns true if affiliated. False
  // otherwise.
  virtual bool IsUserAffiliated(Profile& profile) const;

  // Returns the delay interval used with `MetricReportingManager`
  // initialization.
  base::TimeDelta GetInitDelay() const;

  // Returns the delay interval used with initial record uploads.
  base::TimeDelta GetInitialUploadDelay() const;
};

}  // namespace reporting::metrics

#endif  // CHROME_BROWSER_CHROMEOS_REPORTING_METRIC_REPORTING_MANAGER_DELEGATE_BASE_H_