summaryrefslogtreecommitdiff
path: root/chromium/components/metrics/metrics_service_client.cc
blob: 9ad8361748c2da1f4b011641ada6af60f6358e36 (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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2014 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.

#include "components/metrics/metrics_service_client.h"

#include <algorithm>
#include <string>

#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "components/metrics/metrics_switches.h"
#include "components/metrics/url_constants.h"

namespace metrics {

namespace {

// The minimum time in seconds between consecutive metrics report uploads.
constexpr int kMetricsUploadIntervalSecMinimum = 20;

// If a metrics log upload fails, and the transmission is over this byte count,
// then we will discard the log, and not try to retransmit it. We also don't
// persist the log to the prefs for transmission during the next chrome session
// if this limit is exceeded.
constexpr size_t kMaxOngoingLogSize = 100 * 1024;  // 100 KiB

// The number of bytes of logs to save of each type (initial/ongoing). This
// ensures that a reasonable amount of history will be stored even if there is a
// long series of very small logs.
constexpr size_t kMinLogQueueSize = 300 * 1024;  // 300 KiB

// The minimum number of "initial" logs to save, and hope to send during a
// future Chrome session. Initial logs contain crash stats, and are pretty
// small.
constexpr size_t kMinInitialLogQueueCount = 20;

// The minimum number of ongoing logs to save persistently, and hope to send
// during a this or future sessions. Note that each log may be pretty large, as
// presumably the related "initial" log wasn't sent (probably nothing was, as
// the user was probably off-line). As a result, the log probably kept
// accumulating while the "initial" log was stalled, and couldn't be sent. As a
// result, we don't want to save too many of these mega-logs. A "standard
// shutdown" will create a small log, including just the data that was not yet
// been transmitted, and that is normal (to have exactly one ongoing_log_ at
// startup).
constexpr size_t kMinOngoingLogQueueCount = 8;

}  // namespace

MetricsServiceClient::MetricsServiceClient() {}

MetricsServiceClient::~MetricsServiceClient() {}

ukm::UkmService* MetricsServiceClient::GetUkmService() {
  return nullptr;
}

GURL MetricsServiceClient::GetMetricsServerUrl() {
  return GURL(kNewMetricsServerUrl);
}

GURL MetricsServiceClient::GetInsecureMetricsServerUrl() {
  return GURL(kNewMetricsServerUrlInsecure);
}

base::TimeDelta MetricsServiceClient::GetUploadInterval() {
  const base::CommandLine* command_line =
      base::CommandLine::ForCurrentProcess();
  // If an upload interval is set from the command line, use that value but
  // subject it to a minimum threshold to mitigate the risk of DDoS attack.
  if (command_line->HasSwitch(metrics::switches::kMetricsUploadIntervalSec)) {
    const std::string switch_value = command_line->GetSwitchValueASCII(
        metrics::switches::kMetricsUploadIntervalSec);
    int custom_upload_interval;
    if (base::StringToInt(switch_value, &custom_upload_interval)) {
      return base::TimeDelta::FromSeconds(
          std::max(custom_upload_interval, kMetricsUploadIntervalSecMinimum));
    }
    LOG(DFATAL) << "Malformed value for --metrics-upload-interval. "
                << "Expected int, got: " << switch_value;
  }
  return GetStandardUploadInterval();
}

bool MetricsServiceClient::ShouldStartUpFastForTesting() const {
  return false;
}

bool MetricsServiceClient::IsReportingPolicyManaged() {
  return false;
}

EnableMetricsDefault MetricsServiceClient::GetMetricsReportingDefaultState() {
  return EnableMetricsDefault::DEFAULT_UNKNOWN;
}

bool MetricsServiceClient::IsUMACellularUploadLogicEnabled() {
  return false;
}

bool MetricsServiceClient::IsExternalExperimentAllowlistEnabled() {
  return true;
}

bool MetricsServiceClient::IsUkmAllowedForAllProfiles() {
  return false;
}

bool MetricsServiceClient::IsUkmAllowedWithExtensionsForAllProfiles() {
  return false;
}

bool MetricsServiceClient::AreNotificationListenersEnabledOnAllProfiles() {
  return false;
}

std::string MetricsServiceClient::GetAppPackageName() {
  return std::string();
}

std::string MetricsServiceClient::GetUploadSigningKey() {
  return std::string();
}

bool MetricsServiceClient::ShouldResetClientIdsOnClonedInstall() {
  return false;
}

MetricsLogStore::StorageLimits MetricsServiceClient::GetStorageLimits() const {
  return {
      /*min_initial_log_queue_count=*/kMinInitialLogQueueCount,
      /*min_initial_log_queue_size=*/kMinLogQueueSize,
      /*min_ongoing_log_queue_count=*/kMinOngoingLogQueueCount,
      /*min_ongoing_log_queue_size=*/kMinLogQueueSize,
      /*max_ongoing_log_size=*/kMaxOngoingLogSize,
  };
}

void MetricsServiceClient::SetUpdateRunningServicesCallback(
    const base::RepeatingClosure& callback) {
  update_running_services_ = callback;
}

void MetricsServiceClient::UpdateRunningServices() {
  if (update_running_services_)
    update_running_services_.Run();
}

bool MetricsServiceClient::IsMetricsReportingForceEnabled() const {
  return base::CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kForceEnableMetricsReporting);
}

}  // namespace metrics