OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "content/common/url_fetcher.h" | |
14 | 15 |
15 class PrefService; | 16 class PrefService; |
17 class Profile; | |
16 | 18 |
17 // This encapsulates business logic for: | 19 // This encapsulates business logic for: |
18 // - Whether to show the apps promo in the launcher | 20 // - Whether to show the apps promo in the launcher |
19 // - Whether to expire existing default apps | 21 // - Whether to expire existing default apps |
20 class AppsPromo { | 22 class AppsPromo { |
21 public: | 23 public: |
22 // Groups users by whether they have seen a web store promo before. This is | 24 // Groups users by whether they have seen a web store promo before. This is |
23 // used for deciding to maximize the promo and apps section on the NTP. | 25 // used for deciding to maximize the promo and apps section on the NTP. |
24 enum UserGroup { | 26 enum UserGroup { |
25 // Matches no users. | 27 // Matches no users. |
26 USERS_NONE = 0, | 28 USERS_NONE = 0, |
27 | 29 |
28 // Users who have not seen a promo (last promo id is default value). | 30 // Users who have not seen a promo (last promo id is default value). |
29 USERS_NEW = 1, | 31 USERS_NEW = 1, |
30 | 32 |
31 // Users who have already seen a promo (last promo id is non-default). | 33 // Users who have already seen a promo (last promo id is non-default). |
32 USERS_EXISTING = 1 << 1, | 34 USERS_EXISTING = 1 << 1, |
33 }; | 35 }; |
34 | 36 |
37 // Holds all the data that specifies a promo for the apps section of the NTP. | |
38 struct PromoData { | |
39 PromoData(); | |
40 PromoData(const std::string& id, | |
41 const std::string& header, | |
42 const std::string& button, | |
43 const GURL& link, | |
44 const std::string& expire, | |
45 const GURL& logo, | |
46 int user_group); | |
47 ~PromoData(); | |
48 | |
49 std::string id; | |
50 std::string header; | |
51 std::string button; | |
52 GURL link; | |
53 std::string expire; | |
Mihai Parparita -not on Chrome
2011/08/31 23:26:23
A comment pointing to PromoResourceService::Unpack
jstritar
2011/09/01 16:10:13
Done.
| |
54 GURL logo; | |
55 int user_group; | |
56 }; | |
57 | |
35 // Register our preferences. Parts of the promo content are stored in Local | 58 // Register our preferences. Parts of the promo content are stored in Local |
36 // State since they're independent of the user profile. | 59 // State since they're independent of the user profile. |
37 static void RegisterPrefs(PrefService* local_state); | 60 static void RegisterPrefs(PrefService* local_state); |
38 static void RegisterUserPrefs(PrefService* prefs); | 61 static void RegisterUserPrefs(PrefService* prefs); |
39 | 62 |
40 // Removes the current promo data. | |
41 static void ClearPromo(); | |
42 | |
43 // Returns true if a promo is available for the current locale. | 63 // Returns true if a promo is available for the current locale. |
44 static bool IsPromoSupportedForLocale(); | 64 static bool IsPromoSupportedForLocale(); |
45 | 65 |
46 // Returns true if the web store is active for the existing locale. | 66 // Returns true if the web store is active for the existing locale. |
47 static bool IsWebStoreSupportedForLocale(); | 67 static bool IsWebStoreSupportedForLocale(); |
48 | 68 |
49 // Gets the ID of the current promo. | |
50 static std::string GetPromoId(); | |
51 | |
52 // Gets the text for the promo button. | |
53 static std::string GetPromoButtonText(); | |
54 | |
55 // Gets the text for the promo header. | |
56 static std::string GetPromoHeaderText(); | |
57 | |
58 // Gets the promo link. | |
59 static GURL GetPromoLink(); | |
60 | |
61 // Gets the URL of the promo logo image. | |
62 static GURL GetPromoLogo(); | |
63 | |
64 // Gets the text for the promo "hide this" link. | |
65 static std::string GetPromoExpireText(); | |
66 | |
67 // Gets the user groups for which we should maximize the promo and apps | |
68 // section. The return value is a bitwise OR of UserGroup enums. | |
69 static int GetPromoUserGroup(); | |
70 | |
71 // Called to set the current promo data. The default web store logo will be | |
72 // used if |logo| is empty or not valid. | |
73 static void SetPromo(const std::string& id, | |
74 const std::string& header_text, | |
75 const std::string& button_text, | |
76 const GURL& link, | |
77 const std::string& expire_text, | |
78 const GURL& logo, | |
79 const int user_group); | |
80 | |
81 // Sets whether the web store and apps section is supported for the current | 69 // Sets whether the web store and apps section is supported for the current |
82 // locale. | 70 // locale. |
83 static void SetWebStoreSupportedForLocale(bool supported); | 71 static void SetWebStoreSupportedForLocale(bool supported); |
84 | 72 |
73 // Accesses the current promo data. The default logo will be used if | |
74 // |promo_data.logo| is empty or not a valid 'data' URL. | |
75 static void ClearPromo(); | |
76 static PromoData GetPromo(); | |
77 static void SetPromo(PromoData promo_data); | |
78 | |
79 // Gets the original URL of the logo. This should only be set when the logo | |
Mihai Parparita -not on Chrome
2011/08/31 23:26:23
"Source URL" might be a better name than "original
jstritar
2011/09/01 16:10:13
Done.
| |
80 // was served over https. | |
Mihai Parparita -not on Chrome
2011/08/31 23:26:23
Nit: capitalize HTTPS (applies to other parts of t
jstritar
2011/09/01 16:10:13
Done.
| |
81 static GURL GetPromoLogoOriginal(); | |
Mihai Parparita -not on Chrome
2011/08/31 23:26:23
Get/SetOriginalPromoLogoUrl reads a bit better.
jstritar
2011/09/01 16:10:13
Done. Updated to Get/SetSourcePromoLogoURL.
| |
82 static void SetPromoLogoOriginal(GURL original_url); | |
83 | |
85 explicit AppsPromo(PrefService* prefs); | 84 explicit AppsPromo(PrefService* prefs); |
86 ~AppsPromo(); | 85 ~AppsPromo(); |
87 | 86 |
88 // Gets the set of old default apps that may have been installed by previous | 87 // Gets the set of old default apps that may have been installed by previous |
89 // versions of Chrome. | 88 // versions of Chrome. |
90 const ExtensionIdSet& old_default_apps() const { | 89 const ExtensionIdSet& old_default_apps() const { |
91 return old_default_app_ids_; | 90 return old_default_app_ids_; |
92 } | 91 } |
93 | 92 |
94 // Halts the special treatment of the default apps. The default apps may be | 93 // Halts the special treatment of the default apps. The default apps may be |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 // Our permanent state is stored in this PrefService instance. | 137 // Our permanent state is stored in this PrefService instance. |
139 PrefService* prefs_; | 138 PrefService* prefs_; |
140 | 139 |
141 // The set of default extensions. Initialized to a static list in the | 140 // The set of default extensions. Initialized to a static list in the |
142 // constructor. | 141 // constructor. |
143 ExtensionIdSet old_default_app_ids_; | 142 ExtensionIdSet old_default_app_ids_; |
144 | 143 |
145 DISALLOW_COPY_AND_ASSIGN(AppsPromo); | 144 DISALLOW_COPY_AND_ASSIGN(AppsPromo); |
146 }; | 145 }; |
147 | 146 |
147 // Fetches logos over https, making sure we don't send cookies and that we | |
148 // cache the image as long as possible. | |
Mihai Parparita -not on Chrome
2011/08/31 23:26:23
Not seeing anything that would make us "cache the
jstritar
2011/09/01 16:10:13
Hehe, yeah I guess that isn't quite accurate. I up
| |
149 class AppsPromoLogoDownloader : public URLFetcher::Delegate { | |
150 public: | |
151 AppsPromoLogoDownloader(Profile* profile, | |
152 AppsPromo::PromoData promo_data); | |
153 ~AppsPromoLogoDownloader(); | |
154 | |
155 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | |
156 | |
157 private: | |
158 // Fetches the logo and stores the result as a data URL. | |
159 void FetchLogo(); | |
160 | |
161 // Sets the apps promo based on the current data and then issues the | |
162 // WEB_STORE_PROMO_LOADED notification so open NTPs can inject the promo. | |
163 void SavePromo(); | |
164 | |
165 // Returns true if the logo needs to be downloaded. | |
166 bool ShouldFetchLogo(); | |
167 | |
168 Profile* profile_; | |
169 AppsPromo::PromoData promo_data_; | |
170 scoped_ptr<URLFetcher> url_fetcher_; | |
171 }; | |
172 | |
148 #endif // CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ | 173 #endif // CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ |
OLD | NEW |