Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_
      6 #define CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_
      7 #pragma once
      8 
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/gtest_prod_util.h"
     13 #include "chrome/common/extensions/extension.h"
     14 
     15 class PrefService;
     16 
     17 // This encapsulates business logic for:
     18 // - Whether to show the apps promo in the launcher
     19 // - Whether to expire existing default apps
     20 class AppsPromo {
     21  public:
     22   // Register our preferences. Parts of the promo content are stored in Local
     23   // State since they're independent of the user profile.
     24   static void RegisterPrefs(PrefService* local_state);
     25   static void RegisterUserPrefs(PrefService* prefs);
     26 
     27   // Removes the current promo data.
     28   static void ClearPromo();
     29 
     30   // Gets the ID of the current promo.
     31   static std::string GetPromoId();
     32 
     33   // Gets the text for the promo button.
     34   static std::string GetPromoButtonText();
     35 
     36   // Gets the text for the promo header.
     37   static std::string GetPromoHeaderText();
     38 
     39   // Gets the promo link.
     40   static GURL GetPromoLink();
     41 
     42   // Gets the text for the promo "hide this" link.
     43   static std::string GetPromoExpireText();
     44 
     45   // Called to set the current promo data.
     46   static void SetPromo(const std::string& id,
     47                        const std::string& header_text,
     48                        const std::string& button_text,
     49                        const GURL& link,
     50                        const std::string& expire_text);
     51 
     52   explicit AppsPromo(PrefService* prefs);
     53   ~AppsPromo();
     54 
     55   // Gets the set of old default apps that may have been installed by previous
     56   // versions of Chrome.
     57   const ExtensionIdSet& old_default_apps() const {
     58     return old_default_app_ids_;
     59   }
     60 
     61   // Halts the special treatment of the default apps. The default apps may be
     62   // removed by the caller after calling this method. If the apps remain
     63   // installed, AppsPromo will no longer consider the apps "default".
     64   void ExpireDefaultApps();
     65 
     66   // Called to hide the promo from the apps section.
     67   void HidePromo();
     68 
     69   // Maximizes the apps section the first time this is called for a given promo.
     70   void MaximizeAppsIfFirstView();
     71 
     72   // Returns true if the app launcher should be displayed on the NTP.
     73   bool ShouldShowAppLauncher(const ExtensionIdSet& installed_ids);
     74 
     75   // Returns true if the apps promo should be displayed in the launcher.
     76   bool ShouldShowPromo(const ExtensionIdSet& installed_ids,
     77                        bool* just_expired);
     78 
     79  private:
     80   FRIEND_TEST_ALL_PREFIXES(ExtensionAppsPromo, HappyPath);
     81   FRIEND_TEST_ALL_PREFIXES(ExtensionAppsPromo, PromoPrefs);
     82   FRIEND_TEST_ALL_PREFIXES(ExtensionAppsPromo, UpdatePromoFocus);
     83 
     84   // The maximum number of times to show the apps promo. The promo counter
     85   // actually goes up to this number + 1 because we need to differentiate
     86   // between the first time we overflow and subsequent times.
     87   static const int kDefaultAppsCounterMax;
     88 
     89   // Returns true if a promo is available for the current locale.
     90   static bool IsPromoSupportedForLocale();
     91 
     92   bool GetDefaultAppsInstalled() const;
     93 
     94   // Gets/sets the ID of the last promo shown.
     95   std::string GetLastPromoId();
     96   void SetLastPromoId(const std::string& id);
     97 
     98   // Gets/sets the number of times the promo has been viewed. Promo views are
     99   // only counted when the default apps are installed.
    100   int GetPromoCounter() const;
    101   void SetPromoCounter(int val);
    102 
    103   // Our permanent state is stored in this PrefService instance.
    104   PrefService* prefs_;
    105 
    106   // The set of default extensions. Initialized to a static list in the
    107   // constructor.
    108   ExtensionIdSet old_default_app_ids_;
    109 
    110   DISALLOW_COPY_AND_ASSIGN(AppsPromo);
    111 };
    112 
    113 #endif  // CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_
    114