diff --git a/components/p3a/features.cc b/components/p3a/features.cc index 5f274cf196be..5d24169532f3 100644 --- a/components/p3a/features.cc +++ b/components/p3a/features.cc @@ -4,6 +4,7 @@ * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "brave/components/p3a/features.h" +#include "brave/components/p3a/metric_log_type.h" namespace p3a { namespace features { @@ -14,6 +15,12 @@ BASE_FEATURE(kConstellation, BASE_FEATURE(kConstellationEnclaveAttestation, "BraveP3AConstellationEnclaveAttestation", base::FEATURE_DISABLED_BY_DEFAULT); +BASE_FEATURE(kTypicalJSONDeprecation, + "BraveP3ATypicalJSONDeprecation", + base::FEATURE_DISABLED_BY_DEFAULT); +BASE_FEATURE(kOtherJSONDeprecation, + "BraveP3AOtherJSONDeprecation", + base::FEATURE_DISABLED_BY_DEFAULT); bool IsConstellationEnabled() { return base::FeatureList::IsEnabled(features::kConstellation); @@ -24,5 +31,12 @@ bool IsConstellationEnclaveAttestationEnabled() { features::kConstellationEnclaveAttestation); } +bool IsJSONDeprecated(MetricLogType log_type) { + if (log_type == MetricLogType::kTypical) { + return base::FeatureList::IsEnabled(features::kTypicalJSONDeprecation); + } + return base::FeatureList::IsEnabled(features::kOtherJSONDeprecation); +} + } // namespace features } // namespace p3a diff --git a/components/p3a/features.h b/components/p3a/features.h index 4c0d61acf329..46b6a15e9463 100644 --- a/components/p3a/features.h +++ b/components/p3a/features.h @@ -7,6 +7,7 @@ #define BRAVE_COMPONENTS_P3A_FEATURES_H_ #include "base/feature_list.h" +#include "brave/components/p3a/metric_log_type.h" namespace p3a { namespace features { @@ -16,8 +17,15 @@ BASE_DECLARE_FEATURE(kConstellation); // See https://github.com/brave/brave-browser/issues/31718 for more info. BASE_DECLARE_FEATURE(kConstellationEnclaveAttestation); +// See https://github.com/brave/brave-browser/issues/34003 for more info. +// Disables JSON measurements for "typical" cadence. +BASE_DECLARE_FEATURE(kTypicalJSONDeprecation); +// Disables JSON measurements for all other cadences. +BASE_DECLARE_FEATURE(kOtherJSONDeprecation); + bool IsConstellationEnabled(); bool IsConstellationEnclaveAttestationEnabled(); +bool IsJSONDeprecated(MetricLogType log_type); } // namespace features } // namespace p3a diff --git a/components/p3a/message_manager.cc b/components/p3a/message_manager.cc index ad4601490764..7993941a0d73 100644 --- a/components/p3a/message_manager.cc +++ b/components/p3a/message_manager.cc @@ -45,9 +45,11 @@ MessageManager::MessageManager(PrefService& local_state, // Init log stores. for (MetricLogType log_type : kAllMetricLogTypes) { - json_log_stores_[log_type] = - std::make_unique(*this, *local_state_, false, log_type); - json_log_stores_[log_type]->LoadPersistedUnsentLogs(); + if (!features::IsJSONDeprecated(log_type)) { + json_log_stores_[log_type] = std::make_unique( + *this, *local_state_, false, log_type); + json_log_stores_[log_type]->LoadPersistedUnsentLogs(); + } if (features::IsConstellationEnabled()) { constellation_prep_log_stores_[log_type] = std::make_unique(*this, *local_state_, true, @@ -86,11 +88,13 @@ void MessageManager::Init( config_.get()); for (MetricLogType log_type : kAllMetricLogTypes) { - json_upload_schedulers_[log_type] = std::make_unique( - base::BindRepeating(&MessageManager::StartScheduledUpload, - base::Unretained(this), false, log_type), - config_->randomize_upload_interval, config_->average_upload_interval); - json_upload_schedulers_[log_type]->Start(); + if (!features::IsJSONDeprecated(log_type)) { + json_upload_schedulers_[log_type] = std::make_unique( + base::BindRepeating(&MessageManager::StartScheduledUpload, + base::Unretained(this), false, log_type), + config_->randomize_upload_interval, config_->average_upload_interval); + json_upload_schedulers_[log_type]->Start(); + } } rotation_scheduler_ = std::make_unique( @@ -128,9 +132,9 @@ void MessageManager::UpdateMetricValue( constellation_prep_log_stores_[log_type]->UpdateValue( std::string(histogram_name), bucket); } - if (update_for_all || !*only_update_for_constellation) { - json_log_stores_[log_type].get()->UpdateValue(std::string(histogram_name), - bucket); + auto* json_log_store = json_log_stores_[log_type].get(); + if ((update_for_all || !*only_update_for_constellation) && json_log_store) { + json_log_store->UpdateValue(std::string(histogram_name), bucket); } } @@ -139,9 +143,9 @@ void MessageManager::RemoveMetricValue( absl::optional only_update_for_constellation) { bool update_for_all = !only_update_for_constellation.has_value(); for (MetricLogType log_type : kAllMetricLogTypes) { - if (update_for_all || !*only_update_for_constellation) { - json_log_stores_[log_type]->RemoveValueIfExists( - std::string(histogram_name)); + auto* json_log_store = json_log_stores_[log_type].get(); + if ((update_for_all || !*only_update_for_constellation) && json_log_store) { + json_log_store->RemoveValueIfExists(std::string(histogram_name)); } if (features::IsConstellationEnabled() && (update_for_all || *only_update_for_constellation)) { @@ -153,7 +157,10 @@ void MessageManager::RemoveMetricValue( void MessageManager::DoJsonRotation(MetricLogType log_type) { VLOG(2) << "MessageManager doing json rotation at " << base::Time::Now(); - json_log_stores_[log_type]->ResetUploadStamps(); + auto* log_store = json_log_stores_[log_type].get(); + if (log_store) { + log_store->ResetUploadStamps(); + } delegate_->OnRotation(log_type, false); } @@ -185,11 +192,13 @@ void MessageManager::OnLogUploadComplete(bool is_ok, } else { log_store = (metrics::LogStore*)json_log_stores_[log_type].get(); scheduler = json_upload_schedulers_[log_type].get(); + CHECK(log_store); if (is_ok) { delegate_->OnMetricCycled(json_log_stores_[log_type]->staged_log_key(), false); } } + CHECK(scheduler); if (is_ok) { log_store->MarkStagedLogAsSent(); log_store->DiscardStagedLog(); @@ -257,6 +266,8 @@ void MessageManager::StartScheduledUpload(bool is_constellation, log_store = json_log_stores_[log_type].get(); scheduler = json_upload_schedulers_[log_type].get(); } + CHECK(log_store); + CHECK(scheduler); if (!is_constellation && base::Time::Now() -