Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Helper reporter class for the activity buckets metric filter.
Created a new helper reporter to be able to accurately upload activity bucket information to UMA for filter purposes. (cherry picked from commit ad1102b) Bug: 1446085 Change-Id: I2f189e4e057535d7d29a66f4cc406047ffff3eba Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4562740 Reviewed-by: Adam Arcaro <adamta@google.com> Commit-Queue: Guillem Perez <guiperez@google.com> Cr-Original-Commit-Position: refs/heads/main@{#1153357} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4593806 Reviewed-by: Sergio Collazos <sczs@chromium.org> Auto-Submit: Guillem Perez <guiperez@google.com> Commit-Queue: Justin DeWitt <dewittj@chromium.org> Reviewed-by: Justin DeWitt <dewittj@chromium.org> Cr-Commit-Position: refs/branch-heads/5790@{#431} Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
- Loading branch information
Guillem Perez
authored and
Chromium LUCI CQ
committed
Jun 7, 2023
1 parent
0329f0e
commit 6a991a3
Showing
7 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_UI_NTP_METRICS_FEED_METRICS_PROVIDER_H_ | ||
#define IOS_CHROME_BROWSER_UI_NTP_METRICS_FEED_METRICS_PROVIDER_H_ | ||
|
||
#import "components/metrics/metrics_provider.h" | ||
|
||
class FeedMetricsProvider : public metrics::MetricsProvider { | ||
public: | ||
explicit FeedMetricsProvider(); | ||
FeedMetricsProvider(const FeedMetricsProvider&) = delete; | ||
FeedMetricsProvider& operator=(const FeedMetricsProvider&) = delete; | ||
|
||
~FeedMetricsProvider() override; | ||
|
||
// metrics::MetricsProvider | ||
void ProvideCurrentSessionData( | ||
metrics::ChromeUserMetricsExtension* uma_proto) override; | ||
}; | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_NTP_METRICS_FEED_METRICS_PROVIDER_H_ |
25 changes: 25 additions & 0 deletions
25
ios/chrome/browser/ui/ntp/metrics/feed_metrics_provider.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/chrome/browser/ui/ntp/metrics/feed_metrics_provider.h" | ||
|
||
#import "base/metrics/histogram_functions.h" | ||
#import "ios/chrome/browser/ui/ntp/metrics/feed_metrics_constants.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
FeedMetricsProvider::FeedMetricsProvider() {} | ||
|
||
FeedMetricsProvider::~FeedMetricsProvider() {} | ||
|
||
void FeedMetricsProvider::ProvideCurrentSessionData( | ||
metrics::ChromeUserMetricsExtension* uma_proto) { | ||
// Retrieve activity bucket from storage. | ||
FeedActivityBucket activityBucket = (FeedActivityBucket) | ||
[[NSUserDefaults standardUserDefaults] integerForKey:kActivityBucketKey]; | ||
base::UmaHistogramEnumeration(kAllFeedsActivityBucketsByProviderHistogram, | ||
activityBucket); | ||
} |
37 changes: 37 additions & 0 deletions
37
ios/chrome/browser/ui/ntp/metrics/feed_metrics_provider_unittest.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/chrome/browser/ui/ntp/metrics/feed_metrics_provider.h" | ||
|
||
#import "base/test/metrics/histogram_tester.h" | ||
#import "ios/chrome/browser/ui/ntp/metrics/feed_metrics_constants.h" | ||
#import "testing/platform_test.h" | ||
#import "third_party/ocmock/OCMock/OCMock.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
// Tests metrics that are recorded and uploaded by | ||
// FeedMetricsProvider. | ||
class FeedMetricsProviderTest : public PlatformTest { | ||
public: | ||
FeedMetricsProviderTest() { | ||
histogram_tester_.reset(new base::HistogramTester()); | ||
} | ||
|
||
protected: | ||
void TearDown() override { PlatformTest::TearDown(); } | ||
std::unique_ptr<base::HistogramTester> histogram_tester_; | ||
}; | ||
|
||
// Tests the implementation of ProvideCurrentSessionData | ||
TEST_F(FeedMetricsProviderTest, ProvideCurrentSessionData) { | ||
FeedMetricsProvider provider; | ||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
[defaults setInteger:1 forKey:kActivityBucketKey]; | ||
provider.ProvideCurrentSessionData(nullptr /* uma_proto */); | ||
histogram_tester_->ExpectBucketCount( | ||
kAllFeedsActivityBucketsByProviderHistogram, 1, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters