Commit 82a2c848 authored by Cooper Knaak's avatar Cooper Knaak Committed by Commit Bot

[iOS] Notify FeatureEngagementTracker of Chrome Opened Event

This CL sends a notification to the FeatureEngagementTracker when
the user opens Chrome both from a cold start and a warm start.

Warm starts include backgrounding the app and reopening it, launching
another app from Chrome and returning to it, and locking then unlocking
the screen when Chrome is in the foreground.

-[AppState applicationWillEnterForeground: ... ] handles the warm
start event because it is called whenever the app is taken out of
the background (except on the initial launch, which is a cold start).

The cold start event must occur in the startup flow, a complex process,
so finding a good place for the notification is tricky. It needs to
be called exactly once, and it needs a ChromeBrowserState object.
-[MainController startUpBrowserForegroundInitialization] was chosen
for a couple reasons.
 * It's called as part of the startup flow (necessary to make the
   chrome launched event accurate).
 * It's only called once. startUpBrowserToStage, which calls
   startUpBrowserForegroundInitialization, keeps track of what stage
   of initialization the app is in and makes sure it is not called
   twice.
 * This is where the ChromeBrowserState object is initialized. The
   FeatureEngagementTrackerFactory uses ChromeBrowserState to store
   and retrieve the FeatureEngagementTracker.

Locking then unlocking the screen with Chrome in the foreground is
considered a warm start because applicationWillEnterForeground is
called. Although this is not necessarily desired behavior, there's no
way to determine whether the app is returning from the lock screen.
This slightly increases the potential number of times the Chrome
Opened Event is fired, so in-product help promotions relying on this
event should increase the number of times this event must have fired
to compensate.

R=edchin@chromium.org, gchatz@chromium.org

Bug: 738164
Change-Id: I656297a800600672931c785fcac0fd6dcd4996aa
Reviewed-on: https://chromium-review.googlesource.com/558666
Commit-Queue: Cooper Knaak <cooperknaak@google.com>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarEd Chin <edchin@chromium.org>
Reviewed-by: default avatarGregory Chatzinoff <gchatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486644}
parent 3cecd807
......@@ -145,6 +145,7 @@ source_set("app_internal") {
"//components/crash/core/common",
"//components/favicon/core",
"//components/favicon_base",
"//components/feature_engagement_tracker",
"//components/handoff",
"//components/history/core/browser",
"//components/infobars/core",
......@@ -177,6 +178,7 @@ source_set("app_internal") {
"//ios/chrome/browser/crash_report",
"//ios/chrome/browser/crash_report:crash_report_internal",
"//ios/chrome/browser/favicon",
"//ios/chrome/browser/feature_engagement_tracker",
"//ios/chrome/browser/first_run",
"//ios/chrome/browser/geolocation",
"//ios/chrome/browser/geolocation:geolocation_internal",
......
......@@ -9,6 +9,7 @@ include_rules = [
"+components/crash/core/common",
"+components/favicon/core",
"+components/favicon_base",
"+components/feature_engagement_tracker",
"+components/handoff",
"+components/history/core/browser",
"+components/metrics",
......@@ -21,6 +22,7 @@ include_rules = [
"+components/url_formatter",
"+components/web_resource",
"+ios/chrome/browser",
"+ios/chrome/browser/feature_engagement_tracker",
"+ios/net",
"+ios/public/provider/chrome",
"+ios/web/public",
......
......@@ -96,6 +96,7 @@ source_set("application_delegate_internal") {
":application_delegate",
"//base",
"//components/crash/core/common",
"//components/feature_engagement_tracker",
"//components/handoff",
"//components/metrics",
"//components/prefs",
......@@ -107,6 +108,7 @@ source_set("application_delegate_internal") {
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/crash_report",
"//ios/chrome/browser/device_sharing",
"//ios/chrome/browser/feature_engagement_tracker",
"//ios/chrome/browser/geolocation",
"//ios/chrome/browser/metrics",
"//ios/chrome/browser/metrics:metrics_internal",
......
......@@ -10,6 +10,8 @@
#include "base/critical_closure.h"
#import "base/mac/bind_objc_block.h"
#include "base/metrics/histogram_macros.h"
#include "components/feature_engagement_tracker/public/event_constants.h"
#include "components/feature_engagement_tracker/public/feature_engagement_tracker.h"
#include "components/metrics/metrics_service.h"
#import "ios/chrome/app/application_delegate/app_navigation.h"
#import "ios/chrome/app/application_delegate/browser_launcher.h"
......@@ -31,6 +33,7 @@
#include "ios/chrome/browser/crash_report/breakpad_helper.h"
#import "ios/chrome/browser/crash_report/crash_report_background_uploader.h"
#import "ios/chrome/browser/device_sharing/device_sharing_manager.h"
#include "ios/chrome/browser/feature_engagement_tracker/feature_engagement_tracker_factory.h"
#import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h"
#import "ios/chrome/browser/metrics/previous_session_info.h"
#import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.h"
......@@ -325,6 +328,13 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
net::CheckForCookieLoss(cookie_count,
net::COOKIES_APPLICATION_FOREGROUNDED);
}
if (currentBrowserState) {
// Send the "Chrome Opened" event to the FeatureEngagementTracker on a warm
// start.
FeatureEngagementTrackerFactory::GetForBrowserState(currentBrowserState)
->NotifyEvent(feature_engagement_tracker::events::kChromeOpened);
}
}
- (void)resumeSessionWithTabOpener:(id<TabOpening>)tabOpener
......
......@@ -25,6 +25,8 @@
#include "base/time/time.h"
#include "components/component_updater/component_updater_service.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/feature_engagement_tracker/public/event_constants.h"
#include "components/feature_engagement_tracker/public/feature_engagement_tracker.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/prefs/pref_change_registrar.h"
......@@ -71,6 +73,7 @@
#import "ios/chrome/browser/crash_report/crash_report_background_uploader.h"
#import "ios/chrome/browser/crash_report/crash_restore_helper.h"
#include "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/feature_engagement_tracker/feature_engagement_tracker_factory.h"
#include "ios/chrome/browser/file_metadata_util.h"
#import "ios/chrome/browser/first_run/first_run.h"
#include "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
......@@ -682,6 +685,11 @@ enum class StackViewDismissalMode { NONE, NORMAL, INCOGNITO };
[[BrowserViewWrangler alloc] initWithBrowserState:_mainBrowserState
tabModelObserver:self
applicationCommandEndpoint:self];
// Send "Chrome Opened" event to the FeatureEngagementTracker on cold start.
FeatureEngagementTrackerFactory::GetForBrowserState(chromeBrowserState)
->NotifyEvent(feature_engagement_tracker::events::kChromeOpened);
// Ensure the main tab model is created.
ignore_result([_browserViewWrangler mainTabModel]);
......
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