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