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

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

Issue 6825052: Update the web store promo to be clearer and configurable at run-time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate Aaron's feedback. Created 9 years, 8 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 "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 targeting.
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
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:15",
111 164 // "question": "Browse thousands of apps and games for Chrome.",
112 void Init(); 165 // "inproduct_target": "Visit the Chrome Web Store",
113 166 // "inproduct": "https://chrome.google.com/webstore?hl=en",
114 // Schedule a notification that a web resource is either going to become 167 // "tooltip": "No thanks, hide this"
115 // available or be no longer valid. 168 // },
116 void ScheduleNotification(double ms_start_time, double ms_end_time); 169 // ...
170 // ]
171 // }
172 // }
173 // The properties are defined as follows:
174 // inproduct: the release channels targeted (bitwise or of BuildTypes)
175 // question: the promo header text
176 // inproduct_target: the promo button text
177 // inproduct: the promo button link
178 // tooltip: the text for the "hide this" link on the promo
179 // name: starts with "webstore_promo" to identify the signal. the second
180 // part contains the release channels targeted (bitwise or of
181 // BuildTypes)
182 // answer_id: the promo's id
183 void UnpackWebStoreSignal(const DictionaryValue& parsed_json);
117 184
118 // Gets mutable dictionary attached to user's preferences, so that we 185 // Gets mutable dictionary attached to user's preferences, so that we
119 // can write resource data back to user's pref file. 186 // can write resource data back to user's pref file.
120 DictionaryValue* web_resource_cache_; 187 DictionaryValue* web_resource_cache_;
121 188
189 // Overrides the current Chrome release channel for testing purposes.
190 const char* channel_;
191
122 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); 192 DISALLOW_COPY_AND_ASSIGN(PromoResourceService);
123 }; 193 };
124 194
125 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ 195 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_
126
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp_resource_cache.cc ('k') | chrome/browser/web_resource/promo_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698