Commit 1fbba037 authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

[Siri Shortcuts] Add metric for Siri Shortcuts count

Adds a metric to record the number of Chrome Siri Shortcuts the user has
created in the Siri Shortcuts app. This is recorded once at startup, as
a delayed startup task on the IO thread (to avoid hangs while querying
iOS for the list of shortcuts).

Bug: 935211
Change-Id: I70766050ba7faf5fb343e3515c98ff6ddca98bd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429306
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813030}
parent 408c0947
......@@ -138,6 +138,9 @@ NSString* const kDeleteDownloads = @"DeleteDownloads";
// Constants for deferred deletion of leftover temporary passwords files.
NSString* const kDeleteTempPasswords = @"DeleteTempPasswords";
// Constants for deferred UMA logging of existing Siri User shortcuts.
NSString* const kLogSiriShortcuts = @"LogSiriShortcuts";
// Constants for deferred sending of queued feedback.
NSString* const kSendQueuedFeedback = @"SendQueuedFeedback";
......@@ -984,6 +987,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self scheduleSpotlightResync];
[self scheduleDeleteTempDownloadsDirectory];
[self scheduleDeleteTempPasswordsDirectory];
[self scheduleLogSiriShortcuts];
[self scheduleStartupAttemptReset];
[self startFreeMemoryMonitoring];
[self scheduleAppDistributionPings];
......@@ -1020,6 +1024,15 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}];
}
- (void)scheduleLogSiriShortcuts {
__weak StartupTasks* startupTasks = _startupTasks;
[[DeferredInitializationRunner sharedInstance]
enqueueBlockNamed:kLogSiriShortcuts
block:^{
[startupTasks logSiriShortcuts];
}];
}
- (void)scheduleSpotlightResync {
if (!_spotlightManager) {
return;
......
......@@ -20,6 +20,8 @@ class ChromeBrowserState;
- (void)initializeOmaha;
// Registers to receive UIApplicationWillResignActiveNotification.
- (void)registerForApplicationWillResignActiveNotification;
// Logs the number of Chrome Siri Shortcuts to UMA.
- (void)logSiriShortcuts;
@end
......
......@@ -7,6 +7,8 @@
#import <MediaPlayer/MediaPlayer.h>
#include "base/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/post_task.h"
#import "ios/chrome/app/deferred_initialization_runner.h"
#include "ios/chrome/app/intents/SearchInChromeIntent.h"
#include "ios/chrome/browser/application_context.h"
......@@ -77,6 +79,26 @@ NSString* const kStartProfileStartupTaskRunners =
object:nil];
}
- (void)logSiriShortcuts {
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(^{
[[INVoiceShortcutCenter sharedCenter]
getAllVoiceShortcutsWithCompletion:^(
NSArray<INVoiceShortcut*>* voiceShortcuts, NSError* error) {
if (error || !voiceShortcuts) {
return;
}
// The 20 shortcuts cap is arbitrary but seems like a reasonable
// limit.
base::UmaHistogramExactLinear(
"IOS.SiriShortcuts.Count",
base::saturated_cast<int>([voiceShortcuts count]), 20);
}];
}));
}
#pragma mark - Private methods.
+ (void)performDeferredInitializationForBrowserState:
......
......@@ -700,6 +700,22 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="IOS.SiriShortcuts.Count" units="shortcuts"
expires_after="2021-02-28">
<owner>gujen@google.com</owner>
<owner>sebsg@chromium.org</owner>
<summary>
Counts the number of Chrome Siri Shortcuts that the user has created in the
Siri Shortcuts app. This is recorded once during startup. The histogram caps
at 20 shortcuts, which is an arbitrary but reasonable limit. Note that
shortcuts that have multiple actions are not counted if at least one action
isn't a Chrome-provided one. For example, a shortcut that opens URLs in
Chrome and then opens URLs in another app won't be counted. As such, this
metric undercounts the true number of Chrome shortcuts. This is a
restriction of the native Shortcuts API.
</summary>
</histogram>
<histogram name="IOS.Spotlight.Action" enum="IOSSpotlightAction"
expires_after="2021-02-28">
<owner>eugenebut@chromium.org</owner>
......
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