OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "chrome/browser/web_resource/notification_promo.h" | 12 #include "chrome/browser/web_resource/notification_promo.h" |
13 #include "chrome/browser/web_resource/web_resource_service.h" | 13 #include "chrome/browser/web_resource/web_resource_service.h" |
14 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class DictionaryValue; | 17 class DictionaryValue; |
18 } | 18 } |
19 | 19 |
20 class AppsPromoLogoFetcher; | 20 class AppsPromoLogoFetcher; |
21 class PrefService; | 21 class PrefService; |
22 class Profile; | 22 class Profile; |
| 23 |
23 // A PromoResourceService fetches data from a web resource server to be used to | 24 // A PromoResourceService fetches data from a web resource server to be used to |
24 // dynamically change the appearance of the New Tab Page. For example, it has | 25 // dynamically change the appearance of the New Tab Page. For example, it has |
25 // been used to fetch "tips" to be displayed on the NTP, or to display | 26 // been used to fetch "tips" to be displayed on the NTP, or to display |
26 // promotional messages to certain groups of Chrome users. | 27 // promotional messages to certain groups of Chrome users. |
27 // | 28 class PromoResourceService : public WebResourceService { |
28 // TODO(mirandac): Arrange for a server to be set up specifically for promo | |
29 // messages, which have until now been piggybacked onto the old tips server | |
30 // structure. (see http://crbug.com/70634 for details.) | |
31 class PromoResourceService | |
32 : public WebResourceService, | |
33 public NotificationPromo::Delegate { | |
34 public: | 29 public: |
35 // Identifies types of Chrome builds for promo targeting. | 30 // Identifies types of Chrome builds for promo targeting. |
36 enum BuildType { | 31 enum BuildType { |
37 NO_BUILD = 0, | 32 NO_BUILD = 0, |
38 DEV_BUILD = 1, | 33 DEV_BUILD = 1, |
39 BETA_BUILD = 1 << 1, | 34 BETA_BUILD = 1 << 1, |
40 STABLE_BUILD = 1 << 2, | 35 STABLE_BUILD = 1 << 2, |
41 CANARY_BUILD = 1 << 3, | 36 CANARY_BUILD = 1 << 3, |
42 ALL_BUILDS = (1 << 4) - 1, | 37 ALL_BUILDS = (1 << 4) - 1, |
43 }; | 38 }; |
44 | 39 |
45 // Checks for conditions to show promo: start/end times, channel, etc. | 40 // Checks for conditions to show promo: start/end times, channel, etc. |
46 static bool CanShowNotificationPromo(Profile* profile); | 41 static bool CanShowNotificationPromo(Profile* profile); |
47 | 42 |
48 static void RegisterPrefs(PrefService* local_state); | 43 static void RegisterPrefs(PrefService* local_state); |
49 | 44 |
50 static void RegisterUserPrefs(PrefService* prefs); | 45 static void RegisterUserPrefs(PrefService* prefs); |
51 | 46 |
52 explicit PromoResourceService(Profile* profile); | 47 explicit PromoResourceService(Profile* profile); |
53 | 48 |
54 static chrome::VersionInfo::Channel GetChannel(); | 49 static chrome::VersionInfo::Channel GetChannel(); |
55 static bool IsBuildTargeted(chrome::VersionInfo::Channel, int builds_allowed); | 50 static bool IsBuildTargeted(chrome::VersionInfo::Channel, int builds_allowed); |
56 | 51 |
57 // Default server of dynamically loaded NTP HTML elements. | |
58 static const char* kDefaultPromoResourceServer; | |
59 | |
60 private: | 52 private: |
61 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, IsBuildTargetedTest); | 53 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, IsBuildTargetedTest); |
62 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); | 54 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); |
63 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); | 55 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); |
64 FRIEND_TEST_ALL_PREFIXES( | 56 FRIEND_TEST_ALL_PREFIXES( |
65 PromoResourceServiceTest, UnpackPartialWebStoreSignal); | 57 PromoResourceServiceTest, UnpackPartialWebStoreSignal); |
66 FRIEND_TEST_ALL_PREFIXES( | 58 FRIEND_TEST_ALL_PREFIXES( |
67 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo); | 59 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo); |
68 FRIEND_TEST_ALL_PREFIXES( | 60 FRIEND_TEST_ALL_PREFIXES( |
69 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError); | 61 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError); |
(...skipping 30 matching lines...) Expand all Loading... |
100 | 92 |
101 // Notify listeners that the state of a web resource has changed. | 93 // Notify listeners that the state of a web resource has changed. |
102 void PromoResourceStateChange(); | 94 void PromoResourceStateChange(); |
103 | 95 |
104 // Overrides the current Chrome release channel for testing purposes. | 96 // Overrides the current Chrome release channel for testing purposes. |
105 void set_channel(chrome::VersionInfo::Channel channel) { channel_ = channel; } | 97 void set_channel(chrome::VersionInfo::Channel channel) { channel_ = channel; } |
106 | 98 |
107 // WebResourceService override. | 99 // WebResourceService override. |
108 virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE; | 100 virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE; |
109 | 101 |
110 // Unpack the web resource as a custom notification signal. Expects a start | 102 // Unpack the web resource as a custom notification signal. |
111 // and end signal, with the promo to be shown in the tooltip of the start | |
112 // signal field. Delivery will be in json in the form of: | |
113 // { | |
114 // "topic": { | |
115 // "answers": [ | |
116 // { | |
117 // "answer_id": "1067976", | |
118 // "name": "promo_start", | |
119 // "question": "1:24:10:20:7:0", | |
120 // "tooltip": | |
121 // "Click \u003ca href=http://www.google.com\u003ehere\u003c/a\u003e!", | |
122 // "inproduct": "10/8/09 12:00", | |
123 // "inproduct_target": null | |
124 // }, | |
125 // { | |
126 // "answer_id": "1067976", | |
127 // "name": "promo_end", | |
128 // "question": "", | |
129 // "tooltip": "", | |
130 // "inproduct": "10/8/11 12:00", | |
131 // "inproduct_target": null | |
132 // }, | |
133 // ... | |
134 // ] | |
135 // } | |
136 // } | |
137 // | |
138 // Because the promo signal data is piggybacked onto the tip server, the | |
139 // values don't exactly correspond with the field names: | |
140 // | |
141 // For "promo_start" or "promo_end", the date to start or stop showing the | |
142 // promotional line is given by the "inproduct" line. | |
143 // For "promo_start", the promotional line itself is given in the "tooltip" | |
144 // field. The "question" field gives the type of builds that should be shown | |
145 // this promo (see the BuildType enum in web_resource_service.cc), the | |
146 // number of hours that each promo group should see it, the maximum promo | |
147 // group that should see it, the maximum number of views of the promo,the | |
148 // platforms that this promo is suitable for, and a mask of features which | |
149 // must be present in order for the promo to be shown (0 => no feaures needed | |
150 // 1 => user must be logged in to gplus), separated by ":". | |
151 // For example, "7:24:5:10:7:0" would indicate that all groups with ids less | |
152 // than 5, and with dev, beta and stable builds on Windows, Mac and Linux, | |
153 // should see the promo a maximum of 10 times, the promo is suitable for Mac | |
154 // Linux and Windows platforms, and no features are required to show it. The | |
155 // groups ramp up so one additional group sees the promo every 24 hours. | |
156 // | |
157 void UnpackNotificationSignal(const base::DictionaryValue& parsed_json); | 103 void UnpackNotificationSignal(const base::DictionaryValue& parsed_json); |
158 | 104 |
159 // Unpack the promo resource as a custom logo signal. Expects a start and end | 105 // Unpack the promo resource as a custom logo signal. Expects a start and end |
160 // signal. Delivery will be in json in the form of: | 106 // signal. Delivery will be in json in the form of: |
161 // { | 107 // { |
162 // "topic": { | 108 // "topic": { |
163 // "answers": [ | 109 // "answers": [ |
164 // { | 110 // { |
165 // "answer_id": "107366", | 111 // "answer_id": "107366", |
166 // "name": "custom_logo_start", | 112 // "name": "custom_logo_start", |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // name: starts with "webstore_promo" to identify the signal. The second | 155 // name: starts with "webstore_promo" to identify the signal. The second |
210 // part contains the release channels targeted (bitwise or of | 156 // part contains the release channels targeted (bitwise or of |
211 // BuildTypes). The third part specifies what users should maximize | 157 // BuildTypes). The third part specifies what users should maximize |
212 // the apps section of the NTP when first loading the promo (bitwise | 158 // the apps section of the NTP when first loading the promo (bitwise |
213 // or of AppsPromo::UserGroup). The forth part is optional and | 159 // or of AppsPromo::UserGroup). The forth part is optional and |
214 // specifies the URL of the logo image. If left out, the default | 160 // specifies the URL of the logo image. If left out, the default |
215 // webstore logo will be used. The logo can be an HTTPS or DATA URL. | 161 // webstore logo will be used. The logo can be an HTTPS or DATA URL. |
216 // answer_id: the promo's id | 162 // answer_id: the promo's id |
217 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json); | 163 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json); |
218 | 164 |
219 // NotificationPromo::Delegate override. | |
220 virtual void OnNotificationParsed(double start, double end, | |
221 bool new_notification) OVERRIDE; | |
222 | |
223 // The profile this service belongs to. | 165 // The profile this service belongs to. |
224 Profile* profile_; | 166 Profile* profile_; |
225 | 167 |
226 // Overrides the current Chrome release channel for testing purposes. | 168 // Overrides the current Chrome release channel for testing purposes. |
227 chrome::VersionInfo::Channel channel_; | 169 chrome::VersionInfo::Channel channel_; |
228 | 170 |
229 // Allows the creation of tasks to send a notification. | 171 // Allows the creation of tasks to send a notification. |
230 // This allows the PromoResourceService to notify the New Tab Page immediately | 172 // This allows the PromoResourceService to notify the New Tab Page immediately |
231 // when a new web resource should be shown or removed. | 173 // when a new web resource should be shown or removed. |
232 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_; | 174 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_; |
233 | 175 |
234 // Notification type when an update is done. | 176 // Notification type when an update is done. |
235 int notification_type_; | 177 int notification_type_; |
236 | 178 |
237 // True if a task has been set to update the cache when a new web resource | 179 // True if a task has been set to update the cache when a new web resource |
238 // becomes available. | 180 // becomes available. |
239 bool web_resource_update_scheduled_; | 181 bool web_resource_update_scheduled_; |
240 | 182 |
241 // A helper that downloads the promo logo. | 183 // A helper that downloads the promo logo. |
242 scoped_ptr<AppsPromoLogoFetcher> apps_promo_logo_fetcher_; | 184 scoped_ptr<AppsPromoLogoFetcher> apps_promo_logo_fetcher_; |
243 | 185 |
244 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); | 186 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); |
245 }; | 187 }; |
246 | 188 |
247 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ | 189 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ |
OLD | NEW |