Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: chrome/browser/web_resource/promo_resource_service.h

Issue 7655008: promo_resource_service fixes/cleanup for promos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rename Ad->Notification Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 namespace base {
15 class DictionaryValue;
16 }
17
14 class AppsPromoLogoFetcher; 18 class AppsPromoLogoFetcher;
15 class PrefService; 19 class PrefService;
16 class Profile; 20 class Profile;
17
18 namespace PromoResourceServiceUtil {
19
20 // Certain promotions should only be shown to certain classes of users. This
21 // function will change to reflect each kind of promotion.
22 bool CanShowPromo(Profile* profile);
23
24 } // namespace PromoResourceServiceUtil
25
26 // 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
27 // 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
28 // 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
29 // promotional messages to certain groups of Chrome users. 24 // promotional messages to certain groups of Chrome users.
30 // 25 //
31 // 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
32 // 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
33 // structure. (see http://crbug.com/70634 for details.) 28 // structure. (see http://crbug.com/70634 for details.)
34 class PromoResourceService 29 class PromoResourceService
35 : public WebResourceService { 30 : public WebResourceService {
36 public: 31 public:
37 static bool IsBuildTargeted(chrome::VersionInfo::Channel channel, 32 // Checks for conditions to show promo: start/end times, channel, etc.
38 int builds_targeted); 33 static bool CanShowPromo(Profile* profile);
39 34
40 static void RegisterPrefs(PrefService* local_state); 35 static void RegisterPrefs(PrefService* local_state);
41 36
42 static void RegisterUserPrefs(PrefService* prefs); 37 static void RegisterUserPrefs(PrefService* prefs);
43 38
44 explicit PromoResourceService(Profile* profile); 39 explicit PromoResourceService(Profile* profile);
45 40
46 // Default server of dynamically loaded NTP HTML elements. 41 // Default server of dynamically loaded NTP HTML elements.
47 static const char* kDefaultPromoResourceServer; 42 static const char* kDefaultPromoResourceServer;
48 43
49 private: 44 private:
45 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, IsBuildTargeted);
50 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal); 46 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal);
51 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal); 47 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackAdSignal);
52 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal); 48 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal);
53 FRIEND_TEST_ALL_PREFIXES( 49 FRIEND_TEST_ALL_PREFIXES(
54 PromoResourceServiceTest, UnpackPartialWebStoreSignal); 50 PromoResourceServiceTest, UnpackPartialWebStoreSignal);
55 FRIEND_TEST_ALL_PREFIXES( 51 FRIEND_TEST_ALL_PREFIXES(
56 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo); 52 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo);
57 FRIEND_TEST_ALL_PREFIXES( 53 FRIEND_TEST_ALL_PREFIXES(
58 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError); 54 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError);
59 FRIEND_TEST_ALL_PREFIXES( 55 FRIEND_TEST_ALL_PREFIXES(
60 PromoResourceServiceTest, UnpackWebStoreSignalHttpLogo); 56 PromoResourceServiceTest, UnpackWebStoreSignalHttpLogo);
61 57
(...skipping 10 matching lines...) Expand all
72 virtual ~PromoResourceService(); 68 virtual ~PromoResourceService();
73 69
74 int GetPromoServiceVersion(); 70 int GetPromoServiceVersion();
75 71
76 // Gets the locale of the last promos fetched from the server. This is saved 72 // Gets the locale of the last promos fetched from the server. This is saved
77 // so we can fetch new data if the locale changes. 73 // so we can fetch new data if the locale changes.
78 std::string GetPromoLocale(); 74 std::string GetPromoLocale();
79 75
80 void Init(); 76 void Init();
81 77
78 static bool IsBuildTargeted(chrome::VersionInfo::Channel channel,
79 int builds_targeted);
80
82 // Returns true if |builds_targeted| includes the release channel Chrome 81 // Returns true if |builds_targeted| includes the release channel Chrome
83 // belongs to. For testing purposes, you can override the current channel 82 // belongs to. For testing purposes, you can override the current channel
84 // with set_channel. 83 // with set_channel.
85 bool IsThisBuildTargeted(int builds_targeted); 84 bool IsThisBuildTargeted(int builds_targeted);
86 85
87 // Schedule a notification that a web resource is either going to become 86 // Schedule a notification that a web resource is either going to become
88 // available or be no longer valid. 87 // available or be no longer valid.
89 void ScheduleNotification(double ms_start_time, double ms_end_time); 88 void ScheduleNotification(double ms_start_time, double ms_end_time);
90 89
91 // Schedules the initial notification for when the web resource is going 90 // Schedules the initial notification for when the web resource is going
92 // to become available or no longer valid. This performs a few additional 91 // to become available or no longer valid. This performs a few additional
93 // checks than ScheduleNotification, namely it schedules updates immediately 92 // checks than ScheduleNotification, namely it schedules updates immediately
94 // if the promo service or Chrome locale has changed. 93 // if the promo service or Chrome locale has changed.
95 void ScheduleNotificationOnInit(); 94 void ScheduleNotificationOnInit();
96 95
97 // Overrides the current Chrome release channel for testing purposes. 96 // Overrides the current Chrome release channel for testing purposes.
98 void set_channel(chrome::VersionInfo::Channel channel) { channel_ = channel; } 97 void set_channel(chrome::VersionInfo::Channel channel) { channel_ = channel; }
99 98
100 virtual void Unpack(const base::DictionaryValue& parsed_json); 99 virtual void Unpack(const base::DictionaryValue& parsed_json);
101 100
102 // Unpack the web resource as a custom promo signal. Expects a start and end 101 // Unpack the web resource as a custom promo signal. Expects a start and end
103 // signal, with the promo to be shown in the tooltip of the start signal 102 // signal, with the promo to be shown in the tooltip of the start signal
104 // field. Delivery will be in json in the form of: 103 // field. Delivery will be in json in the form of:
105 // { 104 // {
106 // "topic": { 105 // "topic": {
107 // "answers": [ 106 // "answers": [
108 // { 107 // {
109 // "answer_id": "1067976", 108 // "answer_id": "1067976",
110 // "name": "promo_start", 109 // "name": "promo_start",
111 // "question": "1:24", 110 // "question": "1:24:10",
112 // "tooltip": 111 // "tooltip":
113 // "Click \u003ca href=http://www.google.com\u003ehere\u003c/a\u003e!", 112 // "Click \u003ca href=http://www.google.com\u003ehere\u003c/a\u003e!",
114 // "inproduct": "10/8/09 12:00", 113 // "inproduct": "10/8/09 12:00",
115 // "inproduct_target": null 114 // "inproduct_target": null
116 // }, 115 // },
117 // { 116 // {
118 // "answer_id": "1067976", 117 // "answer_id": "1067976",
119 // "name": "promo_end", 118 // "name": "promo_end",
120 // "question": "", 119 // "question": "",
121 // "tooltip": "", 120 // "tooltip": "",
122 // "inproduct": "10/8/11 12:00", 121 // "inproduct": "10/8/11 12:00",
123 // "inproduct_target": null 122 // "inproduct_target": null
124 // }, 123 // },
125 // ... 124 // ...
126 // ] 125 // ]
127 // } 126 // }
128 // } 127 // }
129 // 128 //
130 // Because the promo signal data is piggybacked onto the tip server, the 129 // Because the promo signal data is piggybacked onto the tip server, the
131 // values don't exactly correspond with the field names: 130 // values don't exactly correspond with the field names:
132 // 131 //
133 // For "promo_start" or "promo_end", the date to start or stop showing the 132 // For "promo_start" or "promo_end", the date to start or stop showing the
134 // promotional line is given by the "inproduct" line. 133 // promotional line is given by the "inproduct" line.
135 // For "promo_start", the promotional line itself is given in the "tooltip" 134 // For "promo_start", the promotional line itself is given in the "tooltip"
136 // field. The "question" field gives the type of builds that should be shown 135 // field. The "question" field gives the type of builds that should be shown
137 // this promo (see the BuildType enum in web_resource_service.cc) and the 136 // this promo (see the BuildType enum in web_resource_service.cc), the
138 // number of hours that each promo group should see it, separated by ":". 137 // number of hours that each promo group should see it, and the maximum promo
139 // For example, "7:24" would indicate that all builds should see the promo, 138 // group that should see it, separated by ":".
140 // and each group should see it for 24 hours. 139 // For example, "7:24:5" would indicate that for 24 hours, all builds and all
140 // groups with ids less than 5 should see the promo.
jstritar 2011/09/15 15:42:27 I don't think this comment is accurate. I think 7
achuithb 2011/09/15 18:58:13 Done.
141 // 141 //
142 void UnpackPromoSignal(const base::DictionaryValue& parsed_json); 142 void UnpackAdSignal(const base::DictionaryValue& parsed_json);
Miranda Callahan 2011/09/15 08:21:30 nit: could you change this to UnpackNotificationSi
achuithb 2011/09/15 18:58:13 Done.
143 143
144 // Unpack the promo resource as a custom logo signal. Expects a start and end 144 // Unpack the promo resource as a custom logo signal. Expects a start and end
145 // signal. Delivery will be in json in the form of: 145 // signal. Delivery will be in json in the form of:
146 // { 146 // {
147 // "topic": { 147 // "topic": {
148 // "answers": [ 148 // "answers": [
149 // { 149 // {
150 // "answer_id": "107366", 150 // "answer_id": "107366",
151 // "name": "custom_logo_start", 151 // "name": "custom_logo_start",
152 // "question": "", 152 // "question": "",
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // name: starts with "webstore_promo" to identify the signal. The second 194 // name: starts with "webstore_promo" to identify the signal. The second
195 // part contains the release channels targeted (bitwise or of 195 // part contains the release channels targeted (bitwise or of
196 // BuildTypes). The third part specifies what users should maximize 196 // BuildTypes). The third part specifies what users should maximize
197 // the apps section of the NTP when first loading the promo (bitwise 197 // the apps section of the NTP when first loading the promo (bitwise
198 // or of AppsPromo::UserGroup). The forth part is optional and 198 // or of AppsPromo::UserGroup). The forth part is optional and
199 // specifies the URL of the logo image. If left out, the default 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. 200 // webstore logo will be used. The logo can be an HTTPS or DATA URL.
201 // answer_id: the promo's id 201 // answer_id: the promo's id
202 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json); 202 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json);
203 203
204 // Parse the answers array element.
205 void ParseNotification(base::DictionaryValue* a_dic,
206 std::string* promo_start_string,
207 std::string* promo_end_string);
208
209 // Set notification promo params from a question string, which is of the form
210 // <build_type>:<time_slice>:<max_group>.
211 void SetNotificationParams(base::DictionaryValue* a_dic);
212
213 // Extract the notification promo text from the tooltip string.
214 void SetNotificationLine(base::DictionaryValue* a_dic);
215
216 // Check if this notification promo is new based on start/end times,
217 // and trigger events accordingly.
218 void CheckForNewNotification(const std::string& promo_start_string,
219 const std::string& promo_end_string);
220
221 // Calculate the notification promo times, taking into account our group, and
222 // the group time slice.
223 void CalculateNewNotificationTimes(const std::string& promo_start_string,
224 const std::string& promo_end_string,
225 double* promo_start,
jstritar 2011/09/15 15:42:27 nit: indentation
achuithb 2011/09/15 18:58:13 Done.
226 double* promo_end);
227
228 // Calculates notification promo start time with group-based time slice
229 // offset.
230 static double GetNotificationStartTime(PrefService* prefs);
231
232 // Create a new notification promo group.
233 int ResetNotificationGroup();
234
235 // Get saved notification promo times.
236 void GetCurrentNotificationTimes(double* old_promo_start,
237 double* old_promo_end);
238
239 // Actions on receiving a new notification promo.
240 void OnNewNotification(double promo_start, double promo_end);
241
204 // The profile this service belongs to. 242 // The profile this service belongs to.
205 Profile* profile_; 243 Profile* profile_;
206 244
207 // Gets mutable dictionary attached to user's preferences, so that we
208 // can write resource data back to user's pref file.
209 base::DictionaryValue* web_resource_cache_;
210
211 // Overrides the current Chrome release channel for testing purposes. 245 // Overrides the current Chrome release channel for testing purposes.
212 chrome::VersionInfo::Channel channel_; 246 chrome::VersionInfo::Channel channel_;
213 247
214 // A helper that downloads the promo logo. 248 // A helper that downloads the promo logo.
215 scoped_ptr<AppsPromoLogoFetcher> apps_promo_logo_fetcher_; 249 scoped_ptr<AppsPromoLogoFetcher> apps_promo_logo_fetcher_;
216 250
217 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); 251 DISALLOW_COPY_AND_ASSIGN(PromoResourceService);
218 }; 252 };
219 253
220 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ 254 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698