| 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_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 6 #define CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/web_resource/web_resource_service.h" | 11 #include "chrome/browser/web_resource/web_resource_service.h" |
| 12 #include "chrome/common/chrome_version_info.h" | 12 #include "chrome/common/chrome_version_info.h" |
| 13 | 13 |
| 14 class AppsPromoLogoFetcher; |
| 15 class PrefService; |
| 14 class Profile; | 16 class Profile; |
| 15 | 17 |
| 16 namespace PromoResourceServiceUtil { | 18 namespace PromoResourceServiceUtil { |
| 17 | 19 |
| 18 // Certain promotions should only be shown to certain classes of users. This | 20 // Certain promotions should only be shown to certain classes of users. This |
| 19 // function will change to reflect each kind of promotion. | 21 // function will change to reflect each kind of promotion. |
| 20 bool CanShowPromo(Profile* profile); | 22 bool CanShowPromo(Profile* profile); |
| 21 | 23 |
| 22 } // namespace PromoResourceServiceUtil | 24 } // namespace PromoResourceServiceUtil |
| 23 | 25 |
| 24 class PrefService; | |
| 25 | |
| 26 // A PromoResourceService fetches data from a web resource server to be used to | 26 // A PromoResourceService fetches data from a web resource server to be used to |
| 27 // dynamically change the appearance of the New Tab Page. For example, it has | 27 // dynamically change the appearance of the New Tab Page. For example, it has |
| 28 // been used to fetch "tips" to be displayed on the NTP, or to display | 28 // been used to fetch "tips" to be displayed on the NTP, or to display |
| 29 // promotional messages to certain groups of Chrome users. | 29 // promotional messages to certain groups of Chrome users. |
| 30 // | 30 // |
| 31 // TODO(mirandac): Arrange for a server to be set up specifically for promo | 31 // TODO(mirandac): Arrange for a server to be set up specifically for promo |
| 32 // messages, which have until now been piggybacked onto the old tips server | 32 // messages, which have until now been piggybacked onto the old tips server |
| 33 // structure. (see http://crbug.com/70634 for details.) | 33 // structure. (see http://crbug.com/70634 for details.) |
| 34 class PromoResourceService | 34 class PromoResourceService |
| 35 : public WebResourceService { | 35 : public WebResourceService { |
| 36 public: | 36 public: |
| 37 static bool IsBuildTargeted(chrome::VersionInfo::Channel channel, | 37 static bool IsBuildTargeted(chrome::VersionInfo::Channel channel, |
| 38 int builds_targeted); | 38 int builds_targeted); |
| 39 | 39 |
| 40 static void RegisterPrefs(PrefService* local_state); | 40 static void RegisterPrefs(PrefService* local_state); |
| 41 | 41 |
| 42 static void RegisterUserPrefs(PrefService* prefs); | 42 static void RegisterUserPrefs(PrefService* prefs); |
| 43 | 43 |
| 44 explicit PromoResourceService(Profile* profile); | 44 explicit PromoResourceService(Profile* profile); |
| 45 | 45 |
| 46 // Default server of dynamically loaded NTP HTML elements. | 46 // Default server of dynamically loaded NTP HTML elements. |
| 47 static const char* kDefaultPromoResourceServer; | 47 static const char* kDefaultPromoResourceServer; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); | 50 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); |
| 51 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); | 51 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); |
| 52 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); | 52 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); |
| 53 FRIEND_TEST_ALL_PREFIXES( | 53 FRIEND_TEST_ALL_PREFIXES( |
| 54 PromoResourceServiceTest, UnpackPartialWebStoreSignal); | 54 PromoResourceServiceTest, UnpackPartialWebStoreSignal); |
| 55 FRIEND_TEST_ALL_PREFIXES( |
| 56 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo); |
| 57 FRIEND_TEST_ALL_PREFIXES( |
| 58 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError); |
| 59 FRIEND_TEST_ALL_PREFIXES( |
| 60 PromoResourceServiceTest, UnpackWebStoreSignalHttpLogo); |
| 61 |
| 55 | 62 |
| 56 // Identifies types of Chrome builds for promo targeting. | 63 // Identifies types of Chrome builds for promo targeting. |
| 57 enum BuildType { | 64 enum BuildType { |
| 58 NO_BUILD = 0, | 65 NO_BUILD = 0, |
| 59 DEV_BUILD = 1, | 66 DEV_BUILD = 1, |
| 60 BETA_BUILD = 1 << 1, | 67 BETA_BUILD = 1 << 1, |
| 61 STABLE_BUILD = 1 << 2, | 68 STABLE_BUILD = 1 << 2, |
| 62 CANARY_BUILD = 1 << 3, | 69 CANARY_BUILD = 1 << 3, |
| 63 }; | 70 }; |
| 64 | 71 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // } | 168 // } |
| 162 // | 169 // |
| 163 void UnpackLogoSignal(const base::DictionaryValue& parsed_json); | 170 void UnpackLogoSignal(const base::DictionaryValue& parsed_json); |
| 164 | 171 |
| 165 // Unpack the web store promo. Expects JSON delivery in the following format: | 172 // Unpack the web store promo. Expects JSON delivery in the following format: |
| 166 // { | 173 // { |
| 167 // "topic": { | 174 // "topic": { |
| 168 // "answers": [ | 175 // "answers": [ |
| 169 // { | 176 // { |
| 170 // "answer_id": "1143011", | 177 // "answer_id": "1143011", |
| 171 // "name": "webstore_promo:15:", | 178 // "name": "webstore_promo:15:1:https://www.google.com/logo.png", |
| 172 // "question": "Browse thousands of apps and games for Chrome.", | 179 // "question": "Browse thousands of apps and games for Chrome.", |
| 173 // "inproduct_target": "Visit the Chrome Web Store", | 180 // "inproduct_target": "Visit the Chrome Web Store", |
| 174 // "inproduct": "https://chrome.google.com/webstore?hl=en", | 181 // "inproduct": "https://chrome.google.com/webstore?hl=en", |
| 175 // "tooltip": "No thanks, hide this" | 182 // "tooltip": "No thanks, hide this" |
| 176 // }, | 183 // }, |
| 177 // ... | 184 // ... |
| 178 // ] | 185 // ] |
| 179 // } | 186 // } |
| 180 // } | 187 // } |
| 181 // The properties are defined as follows: | 188 // The properties are defined as follows: |
| 182 // inproduct: the release channels targeted (bitwise or of BuildTypes) | 189 // inproduct: the release channels targeted (bitwise or of BuildTypes) |
| 183 // question: the promo header text | 190 // question: the promo header text |
| 184 // inproduct_target: the promo button text | 191 // inproduct_target: the promo button text |
| 185 // inproduct: the promo button link | 192 // inproduct: the promo button link |
| 186 // tooltip: the text for the "hide this" link on the promo | 193 // tooltip: the text for the "hide this" link on the promo |
| 187 // name: starts with "webstore_promo" to identify the signal. the second | 194 // name: starts with "webstore_promo" to identify the signal. The second |
| 188 // part contains the release channels targeted (bitwise or of | 195 // part contains the release channels targeted (bitwise or of |
| 189 // BuildTypes). The third part is optional and specifies the URL of | 196 // BuildTypes). The third part specifies what users should maximize |
| 190 // the logo image. In the example above, the URL is empty so the | 197 // the apps section of the NTP when first loading the promo (bitwise |
| 191 // default webstore logo will be used. | 198 // or of AppsPromo::UserGroup). The forth part is optional and |
| 199 // specifies the URL of the logo image. If left out, the default |
| 200 // webstore logo will be used. The logo can be an HTTPS or DATA URL. |
| 192 // answer_id: the promo's id | 201 // answer_id: the promo's id |
| 193 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json); | 202 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json); |
| 194 | 203 |
| 195 // The profile this service belongs to. | 204 // The profile this service belongs to. |
| 196 Profile* profile_; | 205 Profile* profile_; |
| 197 | 206 |
| 198 // Gets mutable dictionary attached to user's preferences, so that we | 207 // Gets mutable dictionary attached to user's preferences, so that we |
| 199 // can write resource data back to user's pref file. | 208 // can write resource data back to user's pref file. |
| 200 base::DictionaryValue* web_resource_cache_; | 209 base::DictionaryValue* web_resource_cache_; |
| 201 | 210 |
| 202 // Overrides the current Chrome release channel for testing purposes. | 211 // Overrides the current Chrome release channel for testing purposes. |
| 203 chrome::VersionInfo::Channel channel_; | 212 chrome::VersionInfo::Channel channel_; |
| 204 | 213 |
| 214 // A helper that downloads the promo logo. |
| 215 scoped_ptr<AppsPromoLogoFetcher> apps_promo_logo_fetcher_; |
| 216 |
| 205 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); | 217 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
| 206 }; | 218 }; |
| 207 | 219 |
| 208 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 220 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| OLD | NEW |