Commit c4727b0c authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Add IsChromeLikelyDefaultBrowser

This new method will be used to determine if the user is likely
using Chrome as the default Browser for metrics logging
and when to present default browser promotional UI.

Bug: 1107489
Change-Id: I642a7de704f84c7564aea08d90a512cf08a1078a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2348207Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Auto-Submit: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797499}
parent 3fbd23bf
...@@ -38,10 +38,6 @@ enum MobileSessionCallerApp { ...@@ -38,10 +38,6 @@ enum MobileSessionCallerApp {
MOBILE_SESSION_CALLER_APP_COUNT, MOBILE_SESSION_CALLER_APP_COUNT,
}; };
// UserDefaults key that saves the last time an HTTP(S) link was sent and opened
// by the app.
extern NSString* const kLastHTTPURLOpenTime;
@interface ChromeAppStartupParameters : AppStartupParameters @interface ChromeAppStartupParameters : AppStartupParameters
- (instancetype)initWithExternalURL:(const GURL&)externalURL - (instancetype)initWithExternalURL:(const GURL&)externalURL
......
...@@ -78,8 +78,6 @@ enum SearchExtensionAction { ...@@ -78,8 +78,6 @@ enum SearchExtensionAction {
} // namespace } // namespace
NSString* const kLastHTTPURLOpenTime = @"lastHTTPURLOpenTime";
@implementation ChromeAppStartupParameters { @implementation ChromeAppStartupParameters {
NSString* _secureSourceApp; NSString* _secureSourceApp;
NSString* _declaredSourceApp; NSString* _declaredSourceApp;
......
...@@ -5,10 +5,20 @@ ...@@ -5,10 +5,20 @@
#ifndef IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_ #ifndef IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_
#define IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_ #define IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_
#import <UIKit/UIKit.h>
// UserDefaults key that saves the last time an HTTP(S) link was sent and opened
// by the app.
extern NSString* const kLastHTTPURLOpenTime;
// Logs the timestamp of user activity that is deemed to be an indication of // Logs the timestamp of user activity that is deemed to be an indication of
// a user that would likely benefit from having Chrome set as their default // a user that would likely benefit from having Chrome set as their default
// browser. Before logging the current activity, this method will also clear all // browser. Before logging the current activity, this method will also clear all
// past expired logs that have happened too far in the past. // past expired logs that have happened too far in the past.
void LogLikelyInterestedDefaultBrowserUserActivity(); void LogLikelyInterestedDefaultBrowserUserActivity();
// Returns True if the last URL open is within the time threshold that would
// indicate Chrome is likely still the default browser. Returns False otherwise.
bool IsChromeLikelyDefaultBrowser();
#endif // IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_ #endif // IOS_CHROME_BROWSER_UI_WHATS_NEW_DEFAULT_BROWSER_UTILS_H_
...@@ -16,8 +16,13 @@ NSString* const kLastSignificantUserEvent = @"lastSignificantUserEvent"; ...@@ -16,8 +16,13 @@ NSString* const kLastSignificantUserEvent = @"lastSignificantUserEvent";
// Time threshold before activity timestamps should be removed. Currently set to // Time threshold before activity timestamps should be removed. Currently set to
// seven days. // seven days.
const NSTimeInterval kUserActivityTimestampExpiration = 7 * 24 * 60 * 60; const NSTimeInterval kUserActivityTimestampExpiration = 7 * 24 * 60 * 60;
// Time threshold for the last URL open before no URL opens likely indicates
// Chrome is no longer the default browser.
const NSTimeInterval kLatestURLOpenForDefaultBrowser = 7 * 24 * 60 * 60;
} }
NSString* const kLastHTTPURLOpenTime = @"lastHTTPURLOpenTime";
void LogLikelyInterestedDefaultBrowserUserActivity() { void LogLikelyInterestedDefaultBrowserUserActivity() {
NSMutableArray<NSDate*>* pastUserEvents = NSMutableArray<NSDate*>* pastUserEvents =
[[[NSUserDefaults standardUserDefaults] [[[NSUserDefaults standardUserDefaults]
...@@ -42,3 +47,18 @@ void LogLikelyInterestedDefaultBrowserUserActivity() { ...@@ -42,3 +47,18 @@ void LogLikelyInterestedDefaultBrowserUserActivity() {
[[NSUserDefaults standardUserDefaults] setObject:pastUserEvents [[NSUserDefaults standardUserDefaults] setObject:pastUserEvents
forKey:kLastSignificantUserEvent]; forKey:kLastSignificantUserEvent];
} }
bool IsChromeLikelyDefaultBrowser() {
NSDate* lastURLOpen =
[[NSUserDefaults standardUserDefaults] objectForKey:kLastHTTPURLOpenTime];
if (!lastURLOpen) {
return false;
}
NSDate* sevenDaysAgoDate =
[NSDate dateWithTimeIntervalSinceNow:-kLatestURLOpenForDefaultBrowser];
if ([lastURLOpen laterDate:sevenDaysAgoDate] == sevenDaysAgoDate) {
return false;
}
return true;
}
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