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 // See PromoResourceService::UnpackWebStoreSignal for descriptions of these |
| 50 // fields. |
| 51 std::string id; |
| 52 std::string header; |
| 53 std::string button; |
| 54 GURL link; |
| 55 std::string expire; |
| 56 GURL logo; |
| 57 int user_group; |
| 58 }; |
| 59 |
35 // Register our preferences. Parts of the promo content are stored in Local | 60 // Register our preferences. Parts of the promo content are stored in Local |
36 // State since they're independent of the user profile. | 61 // State since they're independent of the user profile. |
37 static void RegisterPrefs(PrefService* local_state); | 62 static void RegisterPrefs(PrefService* local_state); |
38 static void RegisterUserPrefs(PrefService* prefs); | 63 static void RegisterUserPrefs(PrefService* prefs); |
39 | 64 |
40 // Removes the current promo data. | |
41 static void ClearPromo(); | |
42 | |
43 // Returns true if a promo is available for the current locale. | 65 // Returns true if a promo is available for the current locale. |
44 static bool IsPromoSupportedForLocale(); | 66 static bool IsPromoSupportedForLocale(); |
45 | 67 |
46 // Returns true if the web store is active for the existing locale. | 68 // Returns true if the web store is active for the existing locale. |
47 static bool IsWebStoreSupportedForLocale(); | 69 static bool IsWebStoreSupportedForLocale(); |
48 | 70 |
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 | 71 // Sets whether the web store and apps section is supported for the current |
82 // locale. | 72 // locale. |
83 static void SetWebStoreSupportedForLocale(bool supported); | 73 static void SetWebStoreSupportedForLocale(bool supported); |
84 | 74 |
| 75 // Accesses the current promo data. The default logo will be used if |
| 76 // |promo_data.logo| is empty or not a valid 'data' URL. |
| 77 static void ClearPromo(); |
| 78 static PromoData GetPromo(); |
| 79 static void SetPromo(PromoData promo_data); |
| 80 |
| 81 // Gets the original URL of the logo. This should only be set when the logo |
| 82 // was served over HTTPS. |
| 83 static GURL GetSourcePromoLogoURL(); |
| 84 static void SetSourcePromoLogoURL(GURL original_url); |
| 85 |
85 explicit AppsPromo(PrefService* prefs); | 86 explicit AppsPromo(PrefService* prefs); |
86 ~AppsPromo(); | 87 ~AppsPromo(); |
87 | 88 |
88 // Gets the set of old default apps that may have been installed by previous | 89 // Gets the set of old default apps that may have been installed by previous |
89 // versions of Chrome. | 90 // versions of Chrome. |
90 const ExtensionIdSet& old_default_apps() const { | 91 const ExtensionIdSet& old_default_apps() const { |
91 return old_default_app_ids_; | 92 return old_default_app_ids_; |
92 } | 93 } |
93 | 94 |
94 // Halts the special treatment of the default apps. The default apps may be | 95 // 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. | 139 // Our permanent state is stored in this PrefService instance. |
139 PrefService* prefs_; | 140 PrefService* prefs_; |
140 | 141 |
141 // The set of default extensions. Initialized to a static list in the | 142 // The set of default extensions. Initialized to a static list in the |
142 // constructor. | 143 // constructor. |
143 ExtensionIdSet old_default_app_ids_; | 144 ExtensionIdSet old_default_app_ids_; |
144 | 145 |
145 DISALLOW_COPY_AND_ASSIGN(AppsPromo); | 146 DISALLOW_COPY_AND_ASSIGN(AppsPromo); |
146 }; | 147 }; |
147 | 148 |
| 149 // Fetches logos over HTTPS, making sure we don't send cookies and that we |
| 150 // cache the image until its source URL changes. |
| 151 class AppsPromoLogoFetcher : public URLFetcher::Delegate { |
| 152 public: |
| 153 AppsPromoLogoFetcher(Profile* profile, |
| 154 AppsPromo::PromoData promo_data); |
| 155 virtual ~AppsPromoLogoFetcher(); |
| 156 |
| 157 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 158 |
| 159 private: |
| 160 // Fetches the logo and stores the result as a data URL. |
| 161 void FetchLogo(); |
| 162 |
| 163 // Checks if the logo was downloaded previously. |
| 164 bool HaveCachedLogo(); |
| 165 |
| 166 // Sets the apps promo based on the current data and then issues the |
| 167 // WEB_STORE_PROMO_LOADED notification so open NTPs can inject the promo. |
| 168 void SavePromo(); |
| 169 |
| 170 // Checks if the promo logo matches https://*.google.com/*.png. |
| 171 bool SupportsLogoURL(); |
| 172 |
| 173 Profile* profile_; |
| 174 AppsPromo::PromoData promo_data_; |
| 175 scoped_ptr<URLFetcher> url_fetcher_; |
| 176 }; |
| 177 |
148 #endif // CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ | 178 #endif // CHROME_BROWSER_EXTENSIONS_APPS_PROMO_H_ |
OLD | NEW |