Chromium Code Reviews| 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 "chrome/browser/web_resource/web_resource_service.h" | 9 #include "chrome/browser/web_resource/web_resource_service.h" |
| 10 | 10 |
| 11 namespace PromoResourceServiceUtil { | 11 namespace PromoResourceServiceUtil { |
| 12 | 12 |
| 13 // Certain promotions should only be shown to certain classes of users. This | 13 // Certain promotions should only be shown to certain classes of users. This |
| 14 // function will change to reflect each kind of promotion. | 14 // function will change to reflect each kind of promotion. |
| 15 bool CanShowPromo(Profile* profile); | 15 bool CanShowPromo(Profile* profile); |
| 16 | 16 |
| 17 } // namespace PromoResourceServiceUtil | 17 } // namespace PromoResourceServiceUtil |
| 18 | 18 |
| 19 class PrefService; | |
| 20 | |
| 19 // A PromoResourceService fetches data from a web resource server to be used to | 21 // A PromoResourceService fetches data from a web resource server to be used to |
| 20 // dynamically change the appearance of the New Tab Page. For example, it has | 22 // dynamically change the appearance of the New Tab Page. For example, it has |
| 21 // been used to fetch "tips" to be displayed on the NTP, or to display | 23 // been used to fetch "tips" to be displayed on the NTP, or to display |
| 22 // promotional messages to certain groups of Chrome users. | 24 // promotional messages to certain groups of Chrome users. |
| 23 // | 25 // |
| 24 // TODO(mirandac): Arrange for a server to be set up specifically for promo | 26 // TODO(mirandac): Arrange for a server to be set up specifically for promo |
| 25 // messages, which have until now been piggybacked onto the old tips server | 27 // messages, which have until now been piggybacked onto the old tips server |
| 26 // structure. (see http://crbug.com/70634 for details.) | 28 // structure. (see http://crbug.com/70634 for details.) |
| 27 class PromoResourceService | 29 class PromoResourceService |
| 28 : public WebResourceService { | 30 : public WebResourceService { |
| 29 public: | 31 public: |
| 32 static bool IsBuildTargeted(const std::string& channel, int builds_targeted); | |
| 33 | |
| 34 static void RegisterPrefs(PrefService* local_state); | |
| 35 | |
| 36 static void RegisterUserPrefs(PrefService* prefs); | |
| 37 | |
| 30 explicit PromoResourceService(Profile* profile); | 38 explicit PromoResourceService(Profile* profile); |
| 31 | 39 |
| 40 // Default server of dynamically loaded NTP HTML elements. | |
| 41 static const char* kDefaultPromoResourceServer; | |
| 42 | |
| 43 private: | |
| 44 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); | |
| 45 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); | |
| 46 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); | |
| 47 | |
| 48 // 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.
| |
| 49 enum BuildType { | |
| 50 NO_BUILD = 0, | |
| 51 DEV_BUILD = 1, | |
| 52 BETA_BUILD = 1 << 1, | |
| 53 STABLE_BUILD = 1 << 2, | |
| 54 CANARY_BUILD = 1 << 3, | |
| 55 }; | |
| 56 | |
| 57 virtual ~PromoResourceService(); | |
| 58 | |
| 59 int GetPromoServiceVersion(); | |
| 60 | |
| 61 // Gets the locale of the last promos fetched from the server. This is saved | |
| 62 // so we can fetch new data if the locale changes. | |
| 63 std::string GetPromoLocale(); | |
| 64 | |
| 65 void Init(); | |
| 66 | |
| 67 // Returns true if |builds_targeted| includes the release channel Chrome | |
| 68 // belongs to. For testing purposes, you can override the current channel | |
| 69 // with set_channel. | |
| 70 bool IsThisBuildTargeted(int builds_targeted); | |
| 71 | |
| 72 // Schedule a notification that a web resource is either going to become | |
| 73 // available or be no longer valid. | |
| 74 void ScheduleNotification(double ms_start_time, double ms_end_time); | |
| 75 | |
| 76 // Schedules the initial notification for when the web resource is going | |
| 77 // to become available or no longer valid. This performs a few additional | |
| 78 // checks than ScheduleNotification, namely it schedules updates immediately | |
| 79 // if the promo service or Chrome locale has changed. | |
| 80 void ScheduleNotificationOnInit(); | |
| 81 | |
| 82 // Overrides the current Chrome release channel for testing purposes. | |
| 83 void set_channel(const char* channel) { channel_ = channel; } | |
| 84 | |
| 85 virtual void Unpack(const DictionaryValue& parsed_json); | |
| 86 | |
| 32 // Unpack the web resource as a custom promo signal. Expects a start and end | 87 // Unpack the web resource as a custom promo signal. Expects a start and end |
| 33 // signal, with the promo to be shown in the tooltip of the start signal | 88 // signal, with the promo to be shown in the tooltip of the start signal |
| 34 // field. Delivery will be in json in the form of: | 89 // field. Delivery will be in json in the form of: |
| 35 // { | 90 // { |
| 36 // "topic": { | 91 // "topic": { |
| 37 // "answers": [ | 92 // "answers": [ |
| 38 // { | 93 // { |
| 39 // "answer_id": "1067976", | 94 // "answer_id": "1067976", |
| 40 // "name": "promo_start", | 95 // "name": "promo_start", |
| 41 // "question": "1:24", | 96 // "question": "1:24", |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 62 // | 117 // |
| 63 // For "promo_start" or "promo_end", the date to start or stop showing the | 118 // For "promo_start" or "promo_end", the date to start or stop showing the |
| 64 // promotional line is given by the "inproduct" line. | 119 // promotional line is given by the "inproduct" line. |
| 65 // For "promo_start", the promotional line itself is given in the "tooltip" | 120 // For "promo_start", the promotional line itself is given in the "tooltip" |
| 66 // field. The "question" field gives the type of builds that should be shown | 121 // field. The "question" field gives the type of builds that should be shown |
| 67 // this promo (see the BuildType enum in web_resource_service.cc) and the | 122 // this promo (see the BuildType enum in web_resource_service.cc) and the |
| 68 // number of hours that each promo group should see it, separated by ":". | 123 // number of hours that each promo group should see it, separated by ":". |
| 69 // For example, "7:24" would indicate that all builds should see the promo, | 124 // For example, "7:24" would indicate that all builds should see the promo, |
| 70 // and each group should see it for 24 hours. | 125 // and each group should see it for 24 hours. |
| 71 // | 126 // |
| 72 // Public for unit testing. | |
| 73 void UnpackPromoSignal(const DictionaryValue& parsed_json); | 127 void UnpackPromoSignal(const DictionaryValue& parsed_json); |
| 74 | 128 |
| 75 // Unpack the promo resource as a custom logo signal. Expects a start and end | 129 // Unpack the promo resource as a custom logo signal. Expects a start and end |
| 76 // signal. Delivery will be in json in the form of: | 130 // signal. Delivery will be in json in the form of: |
| 77 // { | 131 // { |
| 78 // "topic": { | 132 // "topic": { |
| 79 // "answers": [ | 133 // "answers": [ |
| 80 // { | 134 // { |
| 81 // "answer_id": "107366", | 135 // "answer_id": "107366", |
| 82 // "name": "custom_logo_start", | 136 // "name": "custom_logo_start", |
| 83 // "question": "", | 137 // "question": "", |
| 84 // "tooltip": "", | 138 // "tooltip": "", |
| 85 // "inproduct": "10/8/09 12:00", | 139 // "inproduct": "10/8/09 12:00", |
| 86 // "inproduct_target": null | 140 // "inproduct_target": null |
| 87 // }, | 141 // }, |
| 88 // { | 142 // { |
| 89 // "answer_id": "107366", | 143 // "answer_id": "107366", |
| 90 // "name": "custom_logo_end", | 144 // "name": "custom_logo_end", |
| 91 // "question": "", | 145 // "question": "", |
| 92 // "tooltip": "", | 146 // "tooltip": "", |
| 93 // "inproduct": "10/8/09 12:00", | 147 // "inproduct": "10/8/09 12:00", |
| 94 // "inproduct_target": null | 148 // "inproduct_target": null |
| 95 // }, | 149 // }, |
| 96 // ... | 150 // ... |
| 97 // ] | 151 // ] |
| 98 // } | 152 // } |
| 99 // } | 153 // } |
| 100 // | 154 // |
| 101 // Public for unit testing. | |
| 102 void UnpackLogoSignal(const DictionaryValue& parsed_json); | 155 void UnpackLogoSignal(const DictionaryValue& parsed_json); |
| 103 | 156 |
| 104 // Default server of dynamically loaded NTP HTML elements. | 157 // Unpack the web store promo. Expects JSON delivery in the following format: |
| 105 static const char* kDefaultPromoResourceServer; | 158 // { |
| 106 | 159 // "topic": { |
| 107 private: | 160 // "answers": [ |
| 108 virtual ~PromoResourceService(); | 161 // { |
| 109 | 162 // "answer_id": "1143011", |
| 110 virtual void Unpack(const DictionaryValue& parsed_json); | 163 // "name": "webstore_promo", |
| 111 | 164 // "inproduct": "15", |
| 112 void Init(); | 165 // "answer1": "Browse thousands of apps and games for Chrome.", |
| 113 | 166 // "answer2": "Visit the Chrome Web Store", |
| 114 // Schedule a notification that a web resource is either going to become | 167 // "answer3": "https://chrome.google.com/webstore?hl=en", |
| 115 // available or be no longer valid. | 168 // "answer4": "No thanks, hide this" |
| 116 void ScheduleNotification(double ms_start_time, double ms_end_time); | 169 // }, |
| 170 // ... | |
| 171 // ] | |
| 172 // } | |
| 173 // } | |
| 174 // The properties are defined as follows: | |
| 175 // inproduct: the release channels targeted (bitwise or of BuildTypes) | |
| 176 // answer1: the promo header text | |
| 177 // answer2: the promo button text | |
| 178 // answer3: the promo button link | |
| 179 // answer4: the text for the "hide this" link on the promo | |
| 180 // name: must be "webstore_promo" to identify it | |
| 181 // answer_id: the promo's id | |
| 182 void UnpackWebStoreSignal(const DictionaryValue& parsed_json); | |
| 117 | 183 |
| 118 // Gets mutable dictionary attached to user's preferences, so that we | 184 // Gets mutable dictionary attached to user's preferences, so that we |
| 119 // can write resource data back to user's pref file. | 185 // can write resource data back to user's pref file. |
| 120 DictionaryValue* web_resource_cache_; | 186 DictionaryValue* web_resource_cache_; |
| 121 | 187 |
| 188 // Overrides the current Chrome release channel for testing purposes. | |
| 189 const char* channel_; | |
| 190 | |
| 122 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); | 191 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
| 123 }; | 192 }; |
| 124 | 193 |
| 125 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 194 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
| 126 | |
| OLD | NEW |