1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/app_list/app_list_util.h"
7 #include "base/metrics/field_trial.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/ui/host_desktop.h"
12 #include "chrome/common/pref_names.h"
16 #if defined(ENABLE_APP_LIST)
17 // The field trial group name that enables showing the promo.
18 const char kShowLauncherPromoOnceGroupName
[] = "ShowPromoUntilDismissed";
20 // The field trial group name that resets the pref to show the app launcher
21 // promo on every session startup.
22 const char kResetShowLauncherPromoPrefGroupName
[] = "ResetShowPromoPref";
24 // The name of the field trial that controls showing the app launcher promo.
25 const char kLauncherPromoTrialName
[] = "ShowAppLauncherPromo";
26 #endif // defined(ENABLE_APP_LIST)
30 void SetupShowAppLauncherPromoFieldTrial(PrefService
* local_state
) {
31 #if defined(ENABLE_APP_LIST)
32 if (base::FieldTrialList::FindFullName(kLauncherPromoTrialName
) ==
33 kResetShowLauncherPromoPrefGroupName
) {
34 local_state
->SetBoolean(prefs::kShowAppLauncherPromo
, true);
39 bool IsAppLauncherEnabled() {
40 #if !defined(ENABLE_APP_LIST)
43 #elif defined(OS_CHROMEOS)
46 #else // defined(ENABLE_APP_LIST) && !defined(OS_CHROMEOS)
47 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
)
50 PrefService
* prefs
= g_browser_process
->local_state();
51 // In some tests, the prefs aren't initialised.
52 return prefs
&& prefs
->GetBoolean(prefs::kAppLauncherHasBeenEnabled
);
56 bool ShouldShowAppLauncherPromo() {
57 #if !defined(ENABLE_APP_LIST)
60 PrefService
* local_state
= g_browser_process
->local_state();
61 // In some tests, the prefs aren't initialised.
64 std::string app_launcher_promo_group_name
=
65 base::FieldTrialList::FindFullName(kLauncherPromoTrialName
);
66 return !IsAppLauncherEnabled() &&
67 local_state
->GetBoolean(prefs::kShowAppLauncherPromo
) &&
68 (app_launcher_promo_group_name
== kShowLauncherPromoOnceGroupName
||
69 app_launcher_promo_group_name
== kResetShowLauncherPromoPrefGroupName
);