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