• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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/test/test_metrics_service_client.h"
6 
7 #include <memory>
8 #include <string_view>
9 #include <utility>
10 
11 #include "base/containers/contains.h"
12 #include "base/functional/callback.h"
13 #include "components/metrics/metrics_log_uploader.h"
14 #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
15 
16 namespace metrics {
17 
18 // static
19 const char TestMetricsServiceClient::kBrandForTesting[] = "brand_for_testing";
20 
21 TestMetricsServiceClient::TestMetricsServiceClient() = default;
22 TestMetricsServiceClient::~TestMetricsServiceClient() = default;
23 
24 variations::SyntheticTrialRegistry*
GetSyntheticTrialRegistry()25 TestMetricsServiceClient::GetSyntheticTrialRegistry() {
26   return synthetic_trial_registry_;
27 }
28 
GetMetricsService()29 metrics::MetricsService* TestMetricsServiceClient::GetMetricsService() {
30   return nullptr;
31 }
32 
SetMetricsClientId(const std::string & client_id)33 void TestMetricsServiceClient::SetMetricsClientId(
34     const std::string& client_id) {
35   client_id_ = client_id;
36 }
37 
ShouldUploadMetricsForUserId(uint64_t user_id)38 bool TestMetricsServiceClient::ShouldUploadMetricsForUserId(uint64_t user_id) {
39   return base::Contains(allowed_user_ids_, user_id);
40 }
41 
GetProduct()42 int32_t TestMetricsServiceClient::GetProduct() {
43   return product_;
44 }
45 
GetApplicationLocale()46 std::string TestMetricsServiceClient::GetApplicationLocale() {
47   return "en-US";
48 }
49 
GetBrand(std::string * brand_code)50 bool TestMetricsServiceClient::GetBrand(std::string* brand_code) {
51   *brand_code = kBrandForTesting;
52   return true;
53 }
54 
55 const network_time::NetworkTimeTracker*
GetNetworkTimeTracker()56 TestMetricsServiceClient::GetNetworkTimeTracker() {
57   return nullptr;
58 }
59 
GetChannel()60 SystemProfileProto::Channel TestMetricsServiceClient::GetChannel() {
61   return SystemProfileProto::CHANNEL_BETA;
62 }
63 
IsExtendedStableChannel()64 bool TestMetricsServiceClient::IsExtendedStableChannel() {
65   return is_extended_stable_channel_;
66 }
67 
GetVersionString()68 std::string TestMetricsServiceClient::GetVersionString() {
69   return version_string_;
70 }
71 
CollectFinalMetricsForLog(base::OnceClosure done_callback)72 void TestMetricsServiceClient::CollectFinalMetricsForLog(
73     base::OnceClosure done_callback) {
74   std::move(done_callback).Run();
75 }
76 
CreateUploader(const GURL & server_url,const GURL & insecure_server_url,std::string_view mime_type,MetricsLogUploader::MetricServiceType service_type,const MetricsLogUploader::UploadCallback & on_upload_complete)77 std::unique_ptr<MetricsLogUploader> TestMetricsServiceClient::CreateUploader(
78     const GURL& server_url,
79     const GURL& insecure_server_url,
80     std::string_view mime_type,
81     MetricsLogUploader::MetricServiceType service_type,
82     const MetricsLogUploader::UploadCallback& on_upload_complete) {
83   auto uploader = std::make_unique<TestMetricsLogUploader>(on_upload_complete);
84   uploader_ = uploader->AsWeakPtr();
85   return uploader;
86 }
87 
GetStandardUploadInterval()88 base::TimeDelta TestMetricsServiceClient::GetStandardUploadInterval() {
89   return base::Minutes(5);
90 }
91 
IsReportingPolicyManaged()92 bool TestMetricsServiceClient::IsReportingPolicyManaged() {
93   return reporting_is_managed_;
94 }
95 
96 EnableMetricsDefault
GetMetricsReportingDefaultState()97 TestMetricsServiceClient::GetMetricsReportingDefaultState() {
98   return enable_default_;
99 }
100 
GetAppPackageNameIfLoggable()101 std::string TestMetricsServiceClient::GetAppPackageNameIfLoggable() {
102   return "test app";
103 }
104 
ShouldResetClientIdsOnClonedInstall()105 bool TestMetricsServiceClient::ShouldResetClientIdsOnClonedInstall() {
106   return should_reset_client_ids_on_cloned_install_;
107 }
108 
GetStorageLimits() const109 MetricsLogStore::StorageLimits TestMetricsServiceClient::GetStorageLimits()
110     const {
111   return storage_limits_;
112 }
113 
AllowMetricUploadForUserId(uint64_t user_id)114 void TestMetricsServiceClient::AllowMetricUploadForUserId(uint64_t user_id) {
115   allowed_user_ids_.insert(user_id);
116 }
117 
RemoveMetricUploadForUserId(uint64_t user_id)118 void TestMetricsServiceClient::RemoveMetricUploadForUserId(uint64_t user_id) {
119   allowed_user_ids_.erase(user_id);
120 }
121 
122 }  // namespace metrics
123