OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 | |
8 #include <string> | |
9 | |
10 #include "base/gtest_prod_util.h" | |
11 #include "chrome/common/extensions/extension.h" | |
12 | |
13 class PrefService; | |
14 class Profile; | |
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 // Groups users by whether they have seen a web store promo before. This is | |
22 // used for deciding to maximize the promo and apps section on the NTP. | |
23 enum UserGroup { | |
24 // Matches no users. | |
25 USERS_NONE = 0, | |
26 | |
27 // Users who have not seen a promo (last promo id is default value). | |
28 USERS_NEW = 1, | |
29 | |
30 // Users who have already seen a promo (last promo id is non-default). | |
31 USERS_EXISTING = 1 << 1, | |
32 }; | |
33 | |
34 // Holds all the data that specifies a promo for the apps section of the NTP. | |
35 struct PromoData { | |
36 PromoData(); | |
37 PromoData(const std::string& id, | |
38 const std::string& header, | |
39 const std::string& button, | |
40 const GURL& link, | |
41 const std::string& expire, | |
42 const GURL& logo, | |
43 int user_group); | |
44 ~PromoData(); | |
45 | |
46 // See PromoResourceService::UnpackWebStoreSignal for descriptions of these | |
47 // fields. | |
48 std::string id; | |
49 std::string header; | |
50 std::string button; | |
51 GURL link; | |
52 std::string expire; | |
53 GURL logo; | |
54 int user_group; | |
55 }; | |
56 | |
57 // Register our preferences. Parts of the promo content are stored in Local | |
58 // State since they're independent of the user profile. | |
59 static void RegisterPrefs(PrefService* local_state); | |
60 static void RegisterUserPrefs(PrefService* prefs); | |
61 | |
62 // Returns true if a promo is available for the current locale. | |
63 static bool IsPromoSupportedForLocale(); | |
64 | |
65 // Returns true if the web store is active for the existing locale. | |
66 static bool IsWebStoreSupportedForLocale(); | |
67 | |
68 // Sets whether the web store and apps section is supported for the current | |
69 // locale. | |
70 static void SetWebStoreSupportedForLocale(bool supported); | |
71 | |
72 // Accesses the current promo data. The default logo will be used if | |
73 // |promo_data.logo| is empty or not a valid 'data' URL. | |
74 static void ClearPromo(); | |
75 static PromoData GetPromo(); | |
76 static void SetPromo(const PromoData& promo_data); | |
77 | |
78 // Gets the original URL of the logo. This should only be set when the logo | |
79 // was served over HTTPS. | |
80 static GURL GetSourcePromoLogoURL(); | |
81 static void SetSourcePromoLogoURL(const GURL& original_url); | |
82 | |
83 explicit AppsPromo(PrefService* prefs); | |
84 ~AppsPromo(); | |
85 | |
86 // Gets the set of old default apps that may have been installed by previous | |
87 // versions of Chrome. | |
88 const extensions::ExtensionIdSet& old_default_apps() const { | |
89 return old_default_app_ids_; | |
90 } | |
91 | |
92 // Halts the special treatment of the default apps. The default apps may be | |
93 // removed by the caller after calling this method. If the apps remain | |
94 // installed, AppsPromo will no longer consider the apps "default". | |
95 void ExpireDefaultApps(); | |
96 | |
97 // Called to hide the promo from the apps section. | |
98 void HidePromo(); | |
99 | |
100 // Returns true if the app launcher should be displayed on the NTP. | |
101 bool ShouldShowAppLauncher(const extensions::ExtensionIdSet& installed_ids); | |
102 | |
103 // Returns true if the apps promo should be displayed in the launcher. | |
104 bool ShouldShowPromo(const extensions::ExtensionIdSet& installed_ids, | |
105 bool* just_expired); | |
106 | |
107 private: | |
108 FRIEND_TEST_ALL_PREFIXES(ExtensionAppsPromo, HappyPath); | |
109 FRIEND_TEST_ALL_PREFIXES(ExtensionAppsPromo, PromoPrefs); | |
110 FRIEND_TEST_ALL_PREFIXES(ExtensionAppsPromo, UpdatePromoFocus); | |
111 | |
112 // The maximum number of times to show the apps promo. The promo counter | |
113 // actually goes up to this number + 1 because we need to differentiate | |
114 // between the first time we overflow and subsequent times. | |
115 static const int kDefaultAppsCounterMax; | |
116 | |
117 bool GetDefaultAppsInstalled() const; | |
118 | |
119 // Gets the UserGroup classification of the current user. | |
120 UserGroup GetCurrentUserGroup() const; | |
121 | |
122 // Gets/sets the ID of the last promo shown. | |
123 std::string GetLastPromoId(); | |
124 void SetLastPromoId(const std::string& id); | |
125 | |
126 // Gets/sets the number of times the promo has been viewed. Promo views are | |
127 // only counted when the default apps are installed. | |
128 int GetPromoCounter() const; | |
129 void SetPromoCounter(int val); | |
130 | |
131 // Our permanent state is stored in this PrefService instance. | |
132 PrefService* prefs_; | |
133 | |
134 // The set of default extensions. Initialized to a static list in the | |
135 // constructor. | |
136 extensions::ExtensionIdSet old_default_app_ids_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(AppsPromo); | |
139 }; | |
140 | |
141 #endif // CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ | |
OLD | NEW |