diff options
Diffstat (limited to 'chromium/components/ukm/ukm_service.cc')
-rw-r--r-- | chromium/components/ukm/ukm_service.cc | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/chromium/components/ukm/ukm_service.cc b/chromium/components/ukm/ukm_service.cc index 337cf3faa09..b285a1e319c 100644 --- a/chromium/components/ukm/ukm_service.cc +++ b/chromium/components/ukm/ukm_service.cc @@ -111,6 +111,7 @@ void PurgeExtensionDataFromUnsentLogStore( const std::string& compressed_log_data = ukm_log_store->GetLogAtIndex(index); std::string uncompressed_log_data; + // TODO(crbug/1086910): Use the utilities in log_decoder.h instead. const bool uncompress_successful = compression::GzipUncompress( compressed_log_data, &uncompressed_log_data); DCHECK(uncompress_successful); @@ -153,10 +154,14 @@ void PurgeExtensionDataFromUnsentLogStore( std::string reserialized_log_data; report.SerializeToString(&reserialized_log_data); + // This allows catching errors with bad UKM serialization we've seen before + // that would otherwise only be noticed on the server. + DCHECK(UkmService::LogCanBeParsed(reserialized_log_data)); // Replace the compressed log in the store by its filtered version. const std::string old_compressed_log_data = - ukm_log_store->ReplaceLogAtIndex(index, reserialized_log_data); + ukm_log_store->ReplaceLogAtIndex(index, reserialized_log_data, + base::nullopt); // Reached here only if extensions were found in the log, so data should now // be different after filtering. @@ -170,21 +175,32 @@ void PurgeExtensionDataFromUnsentLogStore( const base::Feature UkmService::kReportUserNoisedUserBirthYearAndGender = { "UkmReportNoisedUserBirthYearAndGender", base::FEATURE_ENABLED_BY_DEFAULT}; +bool UkmService::LogCanBeParsed(const std::string& serialized_data) { + Report report; + bool report_parse_successful = report.ParseFromString(serialized_data); + if (!report_parse_successful) + return false; + // Make sure the reserialzed log from this |report| matches the input + // |serialized_data|. + std::string reserialized_from_report; + report.SerializeToString(&reserialized_from_report); + return reserialized_from_report == serialized_data; +} + UkmService::UkmService(PrefService* pref_service, metrics::MetricsServiceClient* client, - bool restrict_to_whitelist_entries, std::unique_ptr<metrics::UkmDemographicMetricsProvider> demographics_provider) : pref_service_(pref_service), - restrict_to_whitelist_entries_(restrict_to_whitelist_entries), + // We only need to restrict to whitelisted Entries if metrics reporting is + // not forced. + restrict_to_whitelist_entries_(!client->IsMetricsReportingForceEnabled()), client_(client), demographics_provider_(std::move(demographics_provider)), reporting_service_(client, pref_service) { DCHECK(pref_service_); DCHECK(client_); - DCHECK(demographics_provider_); DVLOG(1) << "UkmService::Constructor"; - reporting_service_.Initialize(); base::RepeatingClosure rotate_callback = base::BindRepeating( @@ -361,8 +377,10 @@ void UkmService::RotateLog() { } void UkmService::AddSyncedUserNoiseBirthYearAndGenderToReport(Report* report) { - if (!base::FeatureList::IsEnabled(kReportUserNoisedUserBirthYearAndGender)) + if (!base::FeatureList::IsEnabled(kReportUserNoisedUserBirthYearAndGender) || + !demographics_provider_) { return; + } demographics_provider_->ProvideSyncedUserNoisedBirthYearAndGenderToReport( report); @@ -383,6 +401,12 @@ void UkmService::BuildAndStoreLog() { report.set_session_id(session_id_); report.set_report_id(++report_count_); + const auto product = static_cast<metrics::ChromeUserMetricsExtension_Product>( + client_->GetProduct()); + // Only set the product if it differs from the default value. + if (product != report.product()) + report.set_product(product); + StoreRecordingsInReport(&report); metrics::MetricsLog::RecordCoreSystemProfile(client_, @@ -395,7 +419,10 @@ void UkmService::BuildAndStoreLog() { std::string serialized_log; report.SerializeToString(&serialized_log); - reporting_service_.ukm_log_store()->StoreLog(serialized_log); + // This allows catching errors with bad UKM serialization we've seen before + // that would otherwise only be noticed on the server. + DCHECK(LogCanBeParsed(serialized_log)); + reporting_service_.ukm_log_store()->StoreLog(serialized_log, base::nullopt); } bool UkmService::ShouldRestrictToWhitelistedEntries() const { |