Home | History | Annotate | Download | only in app_list
      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.
      4 
      5 #include "chrome/browser/ui/app_list/app_list_util.h"
      6 
      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"
     13 
     14 namespace {
     15 
     16 #if defined(ENABLE_APP_LIST)
     17 // The field trial group name that enables showing the promo.
     18 const char kShowLauncherPromoOnceGroupName[] = "ShowPromoUntilDismissed";
     19 
     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";
     23 
     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)
     27 
     28 }  // namespace
     29 
     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);
     35   }
     36 #endif
     37 }
     38 
     39 bool IsAppLauncherEnabled() {
     40 #if !defined(ENABLE_APP_LIST)
     41   return false;
     42 
     43 #elif defined(OS_CHROMEOS)
     44   return true;
     45 
     46 #else  // defined(ENABLE_APP_LIST) && !defined(OS_CHROMEOS)
     47   if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH)
     48     return true;
     49 
     50   PrefService* prefs = g_browser_process->local_state();
     51   // In some tests, the prefs aren't initialised.
     52   return prefs && prefs->GetBoolean(prefs::kAppLauncherHasBeenEnabled);
     53 #endif
     54 }
     55 
     56 bool ShouldShowAppLauncherPromo() {
     57 #if !defined(ENABLE_APP_LIST)
     58   return false;
     59 #else
     60   PrefService* local_state = g_browser_process->local_state();
     61   // In some tests, the prefs aren't initialised.
     62   if (!local_state)
     63     return false;
     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);
     70 #endif
     71 }  // namespace apps
     72