Commit 0e84a572 authored by gogerald's avatar gogerald Committed by Commit Bot

Add number of NTP tabs on start and resume histograms

Bug: 1136539
Change-Id: I1bd58115d0d2c0f4502049040181227bcee85d4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461709
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Auto-Submit: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816587}
parent feb8974e
......@@ -203,6 +203,7 @@ source_set("application_delegate_internal") {
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/main:scene",
"//ios/chrome/browser/ui/ntp:util",
"//ios/chrome/browser/ui/safe_mode",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:multiwindow_util",
......
......@@ -32,6 +32,7 @@
#import "ios/chrome/browser/ui/main/browser_interface_provider.h"
#import "ios/chrome/browser/ui/main/connection_information.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#include "ios/chrome/common/app_group/app_group_metrics_mainapp.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
......@@ -110,6 +111,10 @@ using metrics_mediator::kAppEnteredBackgroundDateKey;
+ (void)recordNumTabAtStartup:(int)numTabs;
// Logs the number of tabs with UMAHistogramCount100 and allows testing.
+ (void)recordNumTabAtResume:(int)numTabs;
// Logs the number of NTP tabs with UMAHistogramCount100 and allows testing.
+ (void)recordNumNTPTabAtStartup:(int)numTabs;
// Logs the number of NTP tabs with UMAHistogramCount100 and allows testing.
+ (void)recordNumNTPTabAtResume:(int)numTabs;
@end
......@@ -150,6 +155,7 @@ using metrics_mediator::kAppEnteredBackgroundDateKey;
(id<StartupInformation>)startupInformation
connectedScenes:(NSArray<SceneState*>*)scenes {
int numTabs = 0;
int numNTPTabs = 0;
for (SceneState* scene in scenes) {
if (!scene.interfaceProvider) {
// The scene might not yet be initiated.
......@@ -157,14 +163,23 @@ using metrics_mediator::kAppEnteredBackgroundDateKey;
// counted in sessions instead of scenes.
continue;
}
numTabs += scene.interfaceProvider.mainInterface.browser->GetWebStateList()
->count();
const WebStateList* web_state_list =
scene.interfaceProvider.mainInterface.browser->GetWebStateList();
numTabs += web_state_list->count();
for (int i = 0; i < web_state_list->count(); i++) {
if (IsURLNewTabPage(web_state_list->GetWebStateAt(i)->GetVisibleURL())) {
numNTPTabs++;
}
}
}
if (startupInformation.isColdStart) {
[self recordNumTabAtStartup:numTabs];
[self recordNumNTPTabAtStartup:numNTPTabs];
} else {
[self recordNumTabAtResume:numTabs];
[self recordNumNTPTabAtResume:numNTPTabs];
}
if (UIAccessibilityIsVoiceOverRunning()) {
......@@ -427,6 +442,14 @@ using metrics_mediator::kAppEnteredBackgroundDateKey;
base::UmaHistogramCounts100("Tabs.CountAtResume", numTabs);
}
+ (void)recordNumNTPTabAtStartup:(int)numTabs {
base::UmaHistogramCounts100("Tabs.NTPCountAtStartup", numTabs);
}
+ (void)recordNumNTPTabAtResume:(int)numTabs {
base::UmaHistogramCounts100("Tabs.NTPCountAtResume", numTabs);
}
- (void)setBreakpadUploadingEnabled:(BOOL)enableUploading {
breakpad_helper::SetUploadingEnabled(enableUploading);
}
......
......@@ -15,6 +15,8 @@
- (BOOL)isMetricsReportingEnabledWifiOnly;
+ (void)recordNumTabAtStartup:(int)numTabs;
+ (void)recordNumTabAtResume:(int)numTabs;
+ (void)recordNumNTPTabAtStartup:(int)numTabs;
+ (void)recordNumNTPTabAtResume:(int)numTabs;
@end
#endif // IOS_CHROME_APP_APPLICATION_DELEGATE_METRICS_MEDIATOR_TESTING_H_
......@@ -10,6 +10,7 @@
#include "components/metrics/metrics_service.h"
#import "ios/chrome/app/application_delegate/startup_information.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/main/test_browser.h"
#import "ios/chrome/browser/metrics/previous_session_info.h"
#import "ios/chrome/browser/metrics/previous_session_info_private.h"
......@@ -132,36 +133,55 @@ TEST_F(MetricsMediatorTest, connectionTypeChanged) {
// A block that takes as arguments the caller and the arguments from
// UserActivityHandler +handleStartupParameters and returns nothing.
typedef void (^logLaunchMetricsBlock)(id, const char*, int);
typedef void (^LogLaunchMetricsBlock)(id, const char*, int);
class MetricsMediatorLogLaunchTest : public PlatformTest {
protected:
MetricsMediatorLogLaunchTest() : has_been_called_(FALSE) {}
MetricsMediatorLogLaunchTest()
: num_tabs_has_been_called_(FALSE),
num_ntp_tabs_has_been_called_(FALSE) {}
void initiateMetricsMediator(BOOL coldStart, int tabCount) {
swizzle_block_ = [^(id self, int numTab) {
has_been_called_ = YES;
num_tabs_swizzle_block_ = [^(id self, int numTab) {
num_tabs_has_been_called_ = YES;
// Tests.
EXPECT_EQ(tabCount, numTab);
} copy];
num_ntp_tabs_swizzle_block_ = [^(id self, int numTab) {
num_ntp_tabs_has_been_called_ = YES;
// Tests.
EXPECT_EQ(tabCount, numTab);
} copy];
if (coldStart) {
uma_histogram_swizzler_.reset(new ScopedBlockSwizzler(
tabs_uma_histogram_swizzler_.reset(new ScopedBlockSwizzler(
[MetricsMediator class], @selector(recordNumTabAtStartup:),
swizzle_block_));
num_tabs_swizzle_block_));
ntp_tabs_uma_histogram_swizzler_.reset(new ScopedBlockSwizzler(
[MetricsMediator class], @selector(recordNumNTPTabAtStartup:),
num_ntp_tabs_swizzle_block_));
} else {
uma_histogram_swizzler_.reset(new ScopedBlockSwizzler(
tabs_uma_histogram_swizzler_.reset(new ScopedBlockSwizzler(
[MetricsMediator class], @selector(recordNumTabAtResume:),
swizzle_block_));
num_tabs_swizzle_block_));
ntp_tabs_uma_histogram_swizzler_.reset(new ScopedBlockSwizzler(
[MetricsMediator class], @selector(recordNumNTPTabAtResume:),
num_ntp_tabs_swizzle_block_));
}
}
void verifySwizzleHasBeenCalled() { EXPECT_TRUE(has_been_called_); }
void verifySwizzleHasBeenCalled() {
EXPECT_TRUE(num_tabs_has_been_called_);
EXPECT_TRUE(num_ntp_tabs_has_been_called_);
}
web::WebTaskEnvironment task_environment_;
NSArray<FakeSceneState*>* connected_scenes_;
__block BOOL has_been_called_;
logLaunchMetricsBlock swizzle_block_;
std::unique_ptr<ScopedBlockSwizzler> uma_histogram_swizzler_;
__block BOOL num_tabs_has_been_called_;
__block BOOL num_ntp_tabs_has_been_called_;
LogLaunchMetricsBlock num_tabs_swizzle_block_;
LogLaunchMetricsBlock num_ntp_tabs_swizzle_block_;
std::unique_ptr<ScopedBlockSwizzler> tabs_uma_histogram_swizzler_;
std::unique_ptr<ScopedBlockSwizzler> ntp_tabs_uma_histogram_swizzler_;
std::set<std::unique_ptr<TestBrowser>> browsers_;
};
......@@ -173,9 +193,12 @@ TEST_F(MetricsMediatorLogLaunchTest,
initiateMetricsMediator(coldStart, 23);
// 23 tabs across three scenes.
connected_scenes_ = [FakeSceneState sceneArrayWithCount:3];
[connected_scenes_[0] appendWebStatesWithURL:GURL() count:9];
[connected_scenes_[1] appendWebStatesWithURL:GURL() count:9];
[connected_scenes_[2] appendWebStatesWithURL:GURL() count:5];
[connected_scenes_[0] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:9];
[connected_scenes_[1] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:9];
[connected_scenes_[2] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:5];
// Mark one of the scenes as active.
connected_scenes_[0].activationLevel = SceneActivationLevelForegroundActive;
......@@ -211,11 +234,15 @@ TEST_F(MetricsMediatorLogLaunchTest, logLaunchMetricsNoBackgroundDate) {
initiateMetricsMediator(coldStart, 32);
// 32 tabs across five scenes.
connected_scenes_ = [FakeSceneState sceneArrayWithCount:5];
[connected_scenes_[0] appendWebStatesWithURL:GURL() count:8];
[connected_scenes_[1] appendWebStatesWithURL:GURL() count:8];
[connected_scenes_[0] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:8];
[connected_scenes_[1] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:8];
// Scene 2 has zero tabs.
[connected_scenes_[3] appendWebStatesWithURL:GURL() count:8];
[connected_scenes_[4] appendWebStatesWithURL:GURL() count:8];
[connected_scenes_[3] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:8];
[connected_scenes_[4] appendWebStatesWithURL:GURL(kChromeUINewTabURL)
count:8];
id startupInformation =
[OCMockObject mockForProtocol:@protocol(StartupInformation)];
......
......@@ -1218,6 +1218,20 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="Tabs.NTPCountAtResume" units="tabs" expires_after="M95">
<owner>gogerald@chromium.org</owner>
<owner>nasims@google.com</owner>
<summary>
[iOS] The number of NTP tabs open when the app comes out of the background.
</summary>
</histogram>
<histogram name="Tabs.NTPCountAtStartup" units="tabs" expires_after="M95">
<owner>gogerald@chromium.org</owner>
<owner>nasims@google.com</owner>
<summary>[iOS] The number of NTP tabs open at cold launch.</summary>
</histogram>
<histogram name="Tabs.NumberOfTabsOnResume" units="tabs" expires_after="never">
<!-- expires-never: https://crbug.com/966137 -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment