summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/welcome/nux_helper.cc
blob: ded62340fd983230ca60de1bce1167f43d41ffeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/welcome/nux_helper.h"

#include <string>

#include "base/feature_list.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/welcome/nux/constants.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"

#if defined(OS_MACOSX)
#include "base/enterprise_util.h"
#endif  // defined(OS_MACOSX)

namespace nux {
// This feature flag is used to force the feature to be turned on for non-win
// and non-branded builds, like with tests or development on other platforms.
const base::Feature kNuxOnboardingForceEnabled = {
    "NuxOnboardingForceEnabled", base::FEATURE_DISABLED_BY_DEFAULT};

// The value of these FeatureParam values should be a comma-delimited list
// of element names whitelisted in the MODULES_WHITELIST list, defined in
// chrome/browser/resources/welcome/onboarding_welcome/welcome_app.js
const base::FeatureParam<std::string> kNuxOnboardingForceEnabledNewUserModules =
    {&kNuxOnboardingForceEnabled, "new-user-modules",
     "nux-google-apps,nux-email,nux-set-as-default,signin-view"};
const base::FeatureParam<std::string>
    kNuxOnboardingForceEnabledReturningUserModules = {
        &kNuxOnboardingForceEnabled, "returning-user-modules",
        "nux-set-as-default"};
// TODO(hcarmona): remove this flag and all code behind it.
const base::FeatureParam<bool> kNuxOnboardingForceEnabledShowEmailInterstitial =
    {&kNuxOnboardingForceEnabled, "show-email-interstitial", true};

// Must match study name in configs.
const char kNuxOnboardingStudyName[] = "NaviOnboarding";

std::string GetOnboardingGroup() {
  // We need to use |base::GetFieldTrialParamValue| instead of
  // |base::FeatureParam| because our control group needs a custom value for
  // this param.
  return base::GetFieldTrialParamValue(kNuxOnboardingStudyName,
                                       "onboarding-group");
}

bool IsNuxOnboardingEnabled(Profile* profile) {
  if (base::FeatureList::IsEnabled(nux::kNuxOnboardingForceEnabled)) {
    return true;
  }

#if defined(GOOGLE_CHROME_BUILD)

#if defined(OS_MACOSX)
  return !base::IsMachineExternallyManaged();
#endif  // defined(OS_MACOSX)

#if defined(OS_WIN)
  // To avoid diluting data collection, existing users should not be assigned
  // an onboarding group. So, |prefs::kNaviOnboardGroup| is used to
  // short-circuit the feature checks below.
  PrefService* prefs = profile->GetPrefs();
  if (!prefs) {
    return false;
  }

  std::string onboard_group = prefs->GetString(prefs::kNaviOnboardGroup);

  if (onboard_group.empty()) {
    return false;
  }

  // User will be tied to their original onboarding group, even after
  // experiment ends.
  ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
      "NaviOnboardingSynthetic", onboard_group);

  if (base::FeatureList::IsEnabled(nux::kNuxOnboardingFeature)) {
    return true;
  }
#endif  // defined(OS_WIN)

#endif  // defined(GOOGLE_CHROME_BUILD)

  return false;
}

base::DictionaryValue GetNuxOnboardingModules(Profile* profile) {
  // This function should not be called when nux onboarding feature is not on.
  DCHECK(nux::IsNuxOnboardingEnabled(profile));

  base::DictionaryValue modules;

  if (base::FeatureList::IsEnabled(nux::kNuxOnboardingForceEnabled)) {
    modules.SetString("new-user",
                      kNuxOnboardingForceEnabledNewUserModules.Get());
    modules.SetString("returning-user",
                      kNuxOnboardingForceEnabledReturningUserModules.Get());
    modules.SetBoolean("show-email-interstitial",
                       kNuxOnboardingForceEnabledShowEmailInterstitial.Get());
  } else {  // This means |nux::kNuxOnboardingFeature| is enabled.
    modules.SetString("new-user", kNuxOnboardingNewUserModules.Get());
    modules.SetString("returning-user",
                      kNuxOnboardingReturningUserModules.Get());
    modules.SetBoolean("show-email-interstitial",
                       kNuxOnboardingShowEmailInterstitial.Get());
  }

  return modules;
}
}  // namespace nux