Chromium Code Reviews| Index: chrome/browser/web_resource/promo_resource_service.h |
| diff --git a/chrome/browser/web_resource/promo_resource_service.h b/chrome/browser/web_resource/promo_resource_service.h |
| index 733e6aef72f920440623ca7d5d7c9bbeef6f7048..6d74e9bc0c92a8ac0235cf4df76e0e59f8eb7f51 100644 |
| --- a/chrome/browser/web_resource/promo_resource_service.h |
| +++ b/chrome/browser/web_resource/promo_resource_service.h |
| @@ -16,6 +16,8 @@ bool CanShowPromo(Profile* profile); |
| } // namespace PromoResourceServiceUtil |
| +class PrefService; |
| + |
| // A PromoResourceService fetches data from a web resource server to be used to |
| // dynamically change the appearance of the New Tab Page. For example, it has |
| // been used to fetch "tips" to be displayed on the NTP, or to display |
| @@ -27,8 +29,61 @@ bool CanShowPromo(Profile* profile); |
| class PromoResourceService |
| : public WebResourceService { |
| public: |
| + static bool IsBuildTargeted(const std::string& channel, int builds_targeted); |
| + |
| + static void RegisterPrefs(PrefService* local_state); |
| + |
| + static void RegisterUserPrefs(PrefService* prefs); |
| + |
| explicit PromoResourceService(Profile* profile); |
| + // Default server of dynamically loaded NTP HTML elements. |
| + static const char* kDefaultPromoResourceServer; |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); |
| + FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); |
| + FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); |
| + |
| + // Identifies types of Chrome builds for promo targetting. |
|
Miranda Callahan
2011/04/13 14:29:29
s/targetting/targeting
jstritar
2011/04/13 19:52:27
Done.
|
| + enum BuildType { |
| + NO_BUILD = 0, |
| + DEV_BUILD = 1, |
| + BETA_BUILD = 1 << 1, |
| + STABLE_BUILD = 1 << 2, |
| + CANARY_BUILD = 1 << 3, |
| + }; |
| + |
| + virtual ~PromoResourceService(); |
| + |
| + int GetPromoServiceVersion(); |
| + |
| + // Gets the locale of the last promos fetched from the server. This is saved |
| + // so we can fetch new data if the locale changes. |
| + std::string GetPromoLocale(); |
| + |
| + void Init(); |
| + |
| + // Returns true if |builds_targeted| includes the release channel Chrome |
| + // belongs to. For testing purposes, you can override the current channel |
| + // with set_channel. |
| + bool IsThisBuildTargeted(int builds_targeted); |
| + |
| + // Schedule a notification that a web resource is either going to become |
| + // available or be no longer valid. |
| + void ScheduleNotification(double ms_start_time, double ms_end_time); |
| + |
| + // Schedules the initial notification for when the web resource is going |
| + // to become available or no longer valid. This performs a few additional |
| + // checks than ScheduleNotification, namely it schedules updates immediately |
| + // if the promo service or Chrome locale has changed. |
| + void ScheduleNotificationOnInit(); |
| + |
| + // Overrides the current Chrome release channel for testing purposes. |
| + void set_channel(const char* channel) { channel_ = channel; } |
| + |
| + virtual void Unpack(const DictionaryValue& parsed_json); |
| + |
| // Unpack the web resource as a custom promo signal. Expects a start and end |
| // signal, with the promo to be shown in the tooltip of the start signal |
| // field. Delivery will be in json in the form of: |
| @@ -69,7 +124,6 @@ class PromoResourceService |
| // For example, "7:24" would indicate that all builds should see the promo, |
| // and each group should see it for 24 hours. |
| // |
| - // Public for unit testing. |
| void UnpackPromoSignal(const DictionaryValue& parsed_json); |
| // Unpack the promo resource as a custom logo signal. Expects a start and end |
| @@ -98,29 +152,43 @@ class PromoResourceService |
| // } |
| // } |
| // |
| - // Public for unit testing. |
| void UnpackLogoSignal(const DictionaryValue& parsed_json); |
| - // Default server of dynamically loaded NTP HTML elements. |
| - static const char* kDefaultPromoResourceServer; |
| - |
| - private: |
| - virtual ~PromoResourceService(); |
| - |
| - virtual void Unpack(const DictionaryValue& parsed_json); |
| - |
| - void Init(); |
| - |
| - // Schedule a notification that a web resource is either going to become |
| - // available or be no longer valid. |
| - void ScheduleNotification(double ms_start_time, double ms_end_time); |
| + // Unpack the web store promo. Expects JSON delivery in the following format: |
| + // { |
| + // "topic": { |
| + // "answers": [ |
| + // { |
| + // "answer_id": "1143011", |
| + // "name": "webstore_promo", |
| + // "inproduct": "15", |
| + // "answer1": "Browse thousands of apps and games for Chrome.", |
| + // "answer2": "Visit the Chrome Web Store", |
| + // "answer3": "https://chrome.google.com/webstore?hl=en", |
| + // "answer4": "No thanks, hide this" |
| + // }, |
| + // ... |
| + // ] |
| + // } |
| + // } |
| + // The properties are defined as follows: |
| + // inproduct: the release channels targeted (bitwise or of BuildTypes) |
| + // answer1: the promo header text |
| + // answer2: the promo button text |
| + // answer3: the promo button link |
| + // answer4: the text for the "hide this" link on the promo |
| + // name: must be "webstore_promo" to identify it |
| + // answer_id: the promo's id |
| + void UnpackWebStoreSignal(const DictionaryValue& parsed_json); |
| // Gets mutable dictionary attached to user's preferences, so that we |
| // can write resource data back to user's pref file. |
| DictionaryValue* web_resource_cache_; |
| + // Overrides the current Chrome release channel for testing purposes. |
| + const char* channel_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
| }; |
| #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| - |