diff --git a/components/p3a/brave_histogram_rewrite.cc b/components/p3a/brave_histogram_rewrite.cc index 24509cd3ac8..20b4b7bd369 100644 --- a/components/p3a/brave_histogram_rewrite.cc +++ b/components/p3a/brave_histogram_rewrite.cc @@ -24,9 +24,11 @@ constexpr const char* kBravezationHistograms[] = { // TODO(iefremov): Replace a bunch of 'if's with something more elegant. // Records the given sample using the proper Brave way. -void DoHistogramBravezation(base::StringPiece histogram_name, +void DoHistogramBravezation(const char* histogram_name, + uint64_t name_hash, base::HistogramBase::Sample sample) { - if ("Bookmarks.Count.OnProfileLoad" == histogram_name) { + DCHECK(histogram_name); + if (strcmp("Bookmarks.Count.OnProfileLoad", histogram_name) == 0) { constexpr int kIntervals[] = {5, 20, 100, 500, 1000, 5000, 10000}; const int* it = std::lower_bound(kIntervals, std::end(kIntervals), sample); @@ -36,7 +38,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name, return; } - if ("DefaultBrowser.State" == histogram_name) { + if (strcmp("DefaultBrowser.State", histogram_name) == 0) { int answer = 0; switch (sample) { case 0: // Not default. @@ -55,7 +57,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name, UMA_HISTOGRAM_BOOLEAN("Brave.Core.IsDefault", answer); } - if ("Extensions.LoadExtension" == histogram_name) { + if (strcmp("Extensions.LoadExtension", histogram_name) == 0) { int answer = 0; if (sample == 1) answer = 1; @@ -68,7 +70,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name, return; } - if ("Tabs.TabCount" == histogram_name) { + if (strcmp("Tabs.TabCount", histogram_name) == 0) { int answer = 0; if (0 <= sample && sample <= 1) { answer = 0; @@ -86,7 +88,7 @@ void DoHistogramBravezation(base::StringPiece histogram_name, return; } - if ("Tabs.WindowCount" == histogram_name) { + if (strcmp("Tabs.WindowCount", histogram_name) == 0) { int answer = 0; if (sample <= 0) { answer = 0; @@ -109,7 +111,7 @@ void SetupHistogramsBraveization() { for (const char* histogram_name : kBravezationHistograms) { base::StatisticsRecorder::SetCallback( histogram_name, - base::BindRepeating(&DoHistogramBravezation, histogram_name)); + base::BindRepeating(&DoHistogramBravezation)); } } diff --git a/components/p3a/brave_p3a_service.cc b/components/p3a/brave_p3a_service.cc index 7b5f3bd824f..8af675d911b 100644 --- a/components/p3a/brave_p3a_service.cc +++ b/components/p3a/brave_p3a_service.cc @@ -199,8 +199,7 @@ void BraveP3AService::InitCallbacks() { for (const char* histogram_name : kCollectedHistograms) { base::StatisticsRecorder::SetCallback( histogram_name, - base::BindRepeating(&BraveP3AService::OnHistogramChanged, this, - histogram_name)); + base::BindRepeating(&BraveP3AService::OnHistogramChanged, this)); } } @@ -380,7 +379,8 @@ void BraveP3AService::StartScheduledUpload() { } } -void BraveP3AService::OnHistogramChanged(base::StringPiece histogram_name, +void BraveP3AService::OnHistogramChanged(const char* histogram_name, + uint64_t name_hash, base::HistogramBase::Sample sample) { std::unique_ptr samples = base::StatisticsRecorder::FindHistogram(histogram_name)->SnapshotDelta(); @@ -392,7 +392,7 @@ void BraveP3AService::OnHistogramChanged(base::StringPiece histogram_name, base::PostTask(FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(&BraveP3AService::OnHistogramChangedOnUI, this, - histogram_name, + base::StringPiece(histogram_name), kSuspendedMetricValue, kSuspendedMetricBucket)); return; diff --git a/components/p3a/brave_p3a_service.h b/components/p3a/brave_p3a_service.h index 44fe786e6d0..9cbda8fdadd 100644 --- a/components/p3a/brave_p3a_service.h +++ b/components/p3a/brave_p3a_service.h @@ -66,7 +66,8 @@ class BraveP3AService : public base::RefCountedThreadSafe, // Invoked by callbacks registered by our service. Since these callbacks // can fire on any thread, this method reposts everything to UI thread. - void OnHistogramChanged(base::StringPiece histogram_name, + void OnHistogramChanged(const char* histogram_name, + uint64_t name_hash, base::HistogramBase::Sample sample); void OnHistogramChangedOnUI(base::StringPiece histogram_name,