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

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

Issue 10539045: Purge Logo/WebstoreSignal. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: missed a file Created 8 years, 6 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) 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"
15 14
16 namespace base { 15 namespace base {
17 class DictionaryValue; 16 class DictionaryValue;
18 } 17 }
19 18
20 class AppsPromoLogoFetcher;
21 class PrefService; 19 class PrefService;
22 class Profile; 20 class Profile;
23 21
24 // A PromoResourceService fetches data from a web resource server to be used to 22 // A PromoResourceService fetches data from a web resource server to be used to
25 // dynamically change the appearance of the New Tab Page. For example, it has 23 // dynamically change the appearance of the New Tab Page. For example, it has
26 // been used to fetch "tips" to be displayed on the NTP, or to display 24 // been used to fetch "tips" to be displayed on the NTP, or to display
27 // promotional messages to certain groups of Chrome users. 25 // promotional messages to certain groups of Chrome users.
28 class PromoResourceService : public WebResourceService { 26 class PromoResourceService : public WebResourceService {
Dan Beam 2012/06/08 18:49:47 yay, it looks like a normal header now!
29 public: 27 public:
30 // Identifies types of Chrome builds for promo targeting. 28 // Checks for conditions to show promo.
31 enum BuildType {
32 NO_BUILD = 0,
33 DEV_BUILD = 1,
34 BETA_BUILD = 1 << 1,
35 STABLE_BUILD = 1 << 2,
36 CANARY_BUILD = 1 << 3,
37 ALL_BUILDS = (1 << 4) - 1,
38 };
39
40 // Checks for conditions to show promo: start/end times, channel, etc.
41 static bool CanShowNotificationPromo(Profile* profile); 29 static bool CanShowNotificationPromo(Profile* profile);
42 30
43 static void RegisterPrefs(PrefService* local_state); 31 static void RegisterPrefs(PrefService* local_state);
44 32
45 static void RegisterUserPrefs(PrefService* prefs); 33 static void RegisterUserPrefs(PrefService* prefs);
46 34
47 explicit PromoResourceService(Profile* profile); 35 explicit PromoResourceService(Profile* profile);
48 36
49 static chrome::VersionInfo::Channel GetChannel();
50 static bool IsBuildTargeted(chrome::VersionInfo::Channel, int builds_allowed);
51
52 private: 37 private:
53 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, IsBuildTargetedTest);
54 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal);
55 FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal);
56 FRIEND_TEST_ALL_PREFIXES(
57 PromoResourceServiceTest, UnpackPartialWebStoreSignal);
58 FRIEND_TEST_ALL_PREFIXES(
59 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo);
60 FRIEND_TEST_ALL_PREFIXES(
61 PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError);
62 FRIEND_TEST_ALL_PREFIXES(
63 PromoResourceServiceTest, UnpackWebStoreSignalHttpLogo);
64
65 virtual ~PromoResourceService(); 38 virtual ~PromoResourceService();
66 39
67 int GetPromoServiceVersion(); 40 int GetPromoServiceVersion();
68 41
69 // Gets the locale of the last promos fetched from the server. This is saved 42 // Gets the locale of the last promos fetched from the server. This is saved
70 // so we can fetch new data if the locale changes. 43 // so we can fetch new data if the locale changes.
71 std::string GetPromoLocale(); 44 std::string GetPromoLocale();
72 45
73 // Returns true if |builds_targeted| includes the release channel Chrome
74 // belongs to. For testing purposes, you can override the current channel
75 // with set_channel.
76 bool IsBuildTargeted(int builds_targeted);
77
78 // Schedule a notification that a web resource is either going to become 46 // Schedule a notification that a web resource is either going to become
79 // available or be no longer valid. 47 // available or be no longer valid.
80 void ScheduleNotification(double start, double end); 48 void ScheduleNotification(double start, double end);
81 49
82 // Schedules the initial notification for when the web resource is going 50 // Schedules the initial notification for when the web resource is going
83 // to become available or no longer valid. This performs a few additional 51 // to become available or no longer valid. This performs a few additional
84 // checks than ScheduleNotification, namely it schedules updates immediately 52 // checks than ScheduleNotification, namely it schedules updates immediately
85 // if the promo service or Chrome locale has changed. 53 // if the promo service or Chrome locale has changed.
86 void ScheduleNotificationOnInit(); 54 void ScheduleNotificationOnInit();
87 55
88 // If delay_ms is positive, schedule notification with the delay. 56 // If delay_ms is positive, schedule notification with the delay.
89 // If delay_ms is 0, notify immediately by calling WebResourceStateChange(). 57 // If delay_ms is 0, notify immediately by calling WebResourceStateChange().
90 // If delay_ms is negative, do nothing. 58 // If delay_ms is negative, do nothing.
91 void PostNotification(int64 delay_ms); 59 void PostNotification(int64 delay_ms);
92 60
93 // Notify listeners that the state of a web resource has changed. 61 // Notify listeners that the state of a web resource has changed.
94 void PromoResourceStateChange(); 62 void PromoResourceStateChange();
95 63
96 // Overrides the current Chrome release channel for testing purposes.
97 void set_channel(chrome::VersionInfo::Channel channel) { channel_ = channel; }
98
99 // WebResourceService override. 64 // WebResourceService override.
100 virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE; 65 virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE;
101 66
102 // Unpack the web resource as a custom notification signal.
103 void UnpackNotificationSignal(const base::DictionaryValue& parsed_json);
104
105 // Unpack the promo resource as a custom logo signal. Expects a start and end
106 // signal. Delivery will be in json in the form of:
107 // {
108 // "topic": {
109 // "answers": [
110 // {
111 // "answer_id": "107366",
112 // "name": "custom_logo_start",
113 // "question": "",
114 // "tooltip": "",
115 // "inproduct": "10/8/09 12:00",
116 // "inproduct_target": null
117 // },
118 // {
119 // "answer_id": "107366",
120 // "name": "custom_logo_end",
121 // "question": "",
122 // "tooltip": "",
123 // "inproduct": "10/8/09 12:00",
124 // "inproduct_target": null
125 // },
126 // ...
127 // ]
128 // }
129 // }
130 //
131 void UnpackLogoSignal(const base::DictionaryValue& parsed_json);
132
133 // Unpack the web store promo. Expects JSON delivery in the following format:
134 // {
135 // "topic": {
136 // "answers": [
137 // {
138 // "answer_id": "1143011",
139 // "name": "webstore_promo:15:1:https://www.google.com/logo.png",
140 // "question": "Browse thousands of apps and games for Chrome.",
141 // "inproduct_target": "Visit the Chrome Web Store",
142 // "inproduct": "https://chrome.google.com/webstore?hl=en",
143 // "tooltip": "No thanks, hide this"
144 // },
145 // ...
146 // ]
147 // }
148 // }
149 // The properties are defined as follows:
150 // inproduct: the release channels targeted (bitwise or of BuildTypes)
151 // question: the promo header text
152 // inproduct_target: the promo button text
153 // inproduct: the promo button link
154 // tooltip: the text for the "hide this" link on the promo
155 // name: starts with "webstore_promo" to identify the signal. The second
156 // part contains the release channels targeted (bitwise or of
157 // BuildTypes). The third part specifies what users should maximize
158 // the apps section of the NTP when first loading the promo (bitwise
159 // or of AppsPromo::UserGroup). The forth part is optional and
160 // specifies the URL of the logo image. If left out, the default
161 // webstore logo will be used. The logo can be an HTTPS or DATA URL.
162 // answer_id: the promo's id
163 void UnpackWebStoreSignal(const base::DictionaryValue& parsed_json);
164
165 // The profile this service belongs to. 67 // The profile this service belongs to.
166 Profile* profile_; 68 Profile* profile_;
167 69
168 // Overrides the current Chrome release channel for testing purposes.
169 chrome::VersionInfo::Channel channel_;
170
171 // Allows the creation of tasks to send a notification. 70 // Allows the creation of tasks to send a notification.
172 // This allows the PromoResourceService to notify the New Tab Page immediately 71 // This allows the PromoResourceService to notify the New Tab Page immediately
173 // when a new web resource should be shown or removed. 72 // when a new web resource should be shown or removed.
174 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_; 73 base::WeakPtrFactory<PromoResourceService> weak_ptr_factory_;
175 74
176 // Notification type when an update is done. 75 // Notification type when an update is done.
177 int notification_type_; 76 int notification_type_;
178 77
179 // True if a task has been set to update the cache when a new web resource 78 // True if a task has been set to update the cache when a new web resource
180 // becomes available. 79 // becomes available.
181 bool web_resource_update_scheduled_; 80 bool web_resource_update_scheduled_;
182 81
183 // A helper that downloads the promo logo.
184 scoped_ptr<AppsPromoLogoFetcher> apps_promo_logo_fetcher_;
185
186 DISALLOW_COPY_AND_ASSIGN(PromoResourceService); 82 DISALLOW_COPY_AND_ASSIGN(PromoResourceService);
187 }; 83 };
188 84
189 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_ 85 #endif // CHROME_BROWSER_WEB_RESOURCE_PROMO_RESOURCE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698