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

Side by Side Diff: chrome/browser/ui/webui/ntp/android/promo_handler.cc

Issue 11689004: Move PromoResourceService from Profile to BrowserProcessImpl/local_state(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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 #include "chrome/browser/ui/webui/ntp/android/promo_handler.h" 5 #include "chrome/browser/ui/webui/ntp/android/promo_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 PROMO_IMPRESSION_BUCKET_BOUNDARY = 5 43 PROMO_IMPRESSION_BUCKET_BOUNDARY = 5
44 }; 44 };
45 45
46 // Helper to record an impression in NewTabPage.MobilePromo histogram. 46 // Helper to record an impression in NewTabPage.MobilePromo histogram.
47 void RecordImpressionOnHistogram(PromoImpressionBuckets type) { 47 void RecordImpressionOnHistogram(PromoImpressionBuckets type) {
48 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MobilePromo", type, 48 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MobilePromo", type,
49 PROMO_IMPRESSION_BUCKET_BOUNDARY); 49 PROMO_IMPRESSION_BUCKET_BOUNDARY);
50 } 50 }
51 51
52 // Helper to ask whether the promo is active. 52 // Helper to ask whether the promo is active.
53 bool CanShowNotificationPromo(Profile* profile) { 53 bool CanShowNotificationPromo() {
54 NotificationPromo notification_promo(profile); 54 NotificationPromo notification_promo;
55 notification_promo.InitFromPrefs(NotificationPromo::MOBILE_NTP_SYNC_PROMO); 55 notification_promo.InitFromPrefs(NotificationPromo::MOBILE_NTP_SYNC_PROMO);
56 return notification_promo.CanShow(); 56 return notification_promo.CanShow();
57 } 57 }
58 58
59 // Helper to send out promo resource change notification. 59 // Helper to send out promo resource change notification.
60 void Notify(PromoHandler* ph, chrome::NotificationType notification_type) { 60 void Notify(PromoHandler* ph, chrome::NotificationType notification_type) {
61 content::NotificationService* service = 61 content::NotificationService* service =
62 content::NotificationService::current(); 62 content::NotificationService::current();
63 service->Notify(notification_type, 63 service->Notify(notification_type,
64 content::Source<PromoHandler>(ph), 64 content::Source<PromoHandler>(ph),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if (service && service->signin()) 168 if (service && service->signin())
169 data_email = service->signin()->GetAuthenticatedUsername(); 169 data_email = service->signin()->GetAuthenticatedUsername();
170 170
171 chrome::android::SendEmail( 171 chrome::android::SendEmail(
172 UTF8ToUTF16(data_email), data_subject, data_body, data_inv, 172 UTF8ToUTF16(data_email), data_subject, data_body, data_inv,
173 EmptyString16()); 173 EmptyString16());
174 RecordImpressionOnHistogram(PROMO_IMPRESSION_SEND_EMAIL_CLICKED); 174 RecordImpressionOnHistogram(PROMO_IMPRESSION_SEND_EMAIL_CLICKED);
175 } 175 }
176 176
177 void PromoHandler::HandlePromoActionTriggered(const base::ListValue* /*args*/) { 177 void PromoHandler::HandlePromoActionTriggered(const base::ListValue* /*args*/) {
178 Profile* profile = Profile::FromWebUI(web_ui()); 178 if (!CanShowNotificationPromo())
179 if (!profile || !CanShowNotificationPromo(profile))
180 return; 179 return;
181 180
182 NotificationPromoMobileNtp promo(profile); 181 NotificationPromoMobileNtp promo;
183 if (!promo.InitFromPrefs()) 182 if (!promo.InitFromPrefs())
184 return; 183 return;
185 184
186 if (promo.action_type() == "ACTION_EMAIL") 185 if (promo.action_type() == "ACTION_EMAIL")
187 HandlePromoSendEmail(promo.action_args()); 186 HandlePromoSendEmail(promo.action_args());
188 } 187 }
189 188
190 void PromoHandler::HandlePromoDisabled(const base::ListValue* /*args*/) { 189 void PromoHandler::HandlePromoDisabled(const base::ListValue* /*args*/) {
191 Profile* profile = Profile::FromWebUI(web_ui()); 190 if (!CanShowNotificationPromo())
192 if (!profile || !CanShowNotificationPromo(profile))
193 return; 191 return;
194 192
195 NotificationPromo::HandleClosed( 193 NotificationPromo::HandleClosed(NotificationPromo::MOBILE_NTP_SYNC_PROMO);
196 profile, NotificationPromo::MOBILE_NTP_SYNC_PROMO);
197 RecordImpressionOnHistogram(PROMO_IMPRESSION_CLOSE_PROMO_CLICKED); 194 RecordImpressionOnHistogram(PROMO_IMPRESSION_CLOSE_PROMO_CLICKED);
198 195
199 content::NotificationService* service = 196 content::NotificationService* service =
200 content::NotificationService::current(); 197 content::NotificationService::current();
201 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 198 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
202 content::Source<PromoHandler>(this), 199 content::Source<PromoHandler>(this),
203 content::NotificationService::NoDetails()); 200 content::NotificationService::NoDetails());
204 } 201 }
205 202
206 void PromoHandler::HandleGetPromotions(const base::ListValue* /*args*/) { 203 void PromoHandler::HandleGetPromotions(const base::ListValue* /*args*/) {
(...skipping 11 matching lines...) Expand all
218 DictionaryValue result; 215 DictionaryValue result;
219 if (FetchPromotion(&result)) 216 if (FetchPromotion(&result))
220 web_ui()->CallJavascriptFunction("ntp.setPromotions", result); 217 web_ui()->CallJavascriptFunction("ntp.setPromotions", result);
221 else 218 else
222 web_ui()->CallJavascriptFunction("ntp.clearPromotions"); 219 web_ui()->CallJavascriptFunction("ntp.clearPromotions");
223 } 220 }
224 221
225 void PromoHandler::RecordPromotionImpression(const std::string& id) { 222 void PromoHandler::RecordPromotionImpression(const std::string& id) {
226 // Update number of views a promotion has received and trigger refresh 223 // Update number of views a promotion has received and trigger refresh
227 // if it exceeded max_views set for the promotion. 224 // if it exceeded max_views set for the promotion.
228 Profile* profile = Profile::FromWebUI(web_ui()); 225 if (NotificationPromo::HandleViewed(
229 if (profile &&
230 NotificationPromo::HandleViewed(profile,
231 NotificationPromo::MOBILE_NTP_SYNC_PROMO)) { 226 NotificationPromo::MOBILE_NTP_SYNC_PROMO)) {
232 Notify(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); 227 Notify(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED);
233 } 228 }
234 229
235 if (id == "most_visited") 230 if (id == "most_visited")
236 RecordImpressionOnHistogram(PROMO_IMPRESSION_MOST_VISITED); 231 RecordImpressionOnHistogram(PROMO_IMPRESSION_MOST_VISITED);
237 else if (id == "open_tabs") 232 else if (id == "open_tabs")
238 RecordImpressionOnHistogram(PROMO_IMPRESSION_OPEN_TABS); 233 RecordImpressionOnHistogram(PROMO_IMPRESSION_OPEN_TABS);
239 else if (id == "sync_promo") 234 else if (id == "sync_promo")
240 RecordImpressionOnHistogram(PROMO_IMPRESSION_SYNC_PROMO); 235 RecordImpressionOnHistogram(PROMO_IMPRESSION_SYNC_PROMO);
241 else 236 else
242 NOTREACHED() << "Unknown promotion impression: " << id; 237 NOTREACHED() << "Unknown promotion impression: " << id;
243 } 238 }
244 239
245 bool PromoHandler::FetchPromotion(DictionaryValue* result) { 240 bool PromoHandler::FetchPromotion(DictionaryValue* result) {
246 DCHECK(result != NULL); 241 DCHECK(result != NULL);
247 Profile* profile = Profile::FromWebUI(web_ui()); 242 if (!CanShowNotificationPromo())
248 if (!profile || !CanShowNotificationPromo(profile))
249 return false; 243 return false;
250 244
251 NotificationPromoMobileNtp promo(profile); 245 NotificationPromoMobileNtp promo;
252 if (!promo.InitFromPrefs()) 246 if (!promo.InitFromPrefs())
253 return false; 247 return false;
254 248
255 DCHECK(!promo.text().empty()); 249 DCHECK(!promo.text().empty());
256 if (!DoesChromePromoMatchCurrentSync( 250 if (!DoesChromePromoMatchCurrentSync(
257 promo.requires_sync(), promo.requires_mobile_only_sync())) { 251 promo.requires_sync(), promo.requires_mobile_only_sync())) {
258 return false; 252 return false;
259 } 253 }
260 254
261 result->SetBoolean("promoIsAllowed", true); 255 result->SetBoolean("promoIsAllowed", true);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 sessions[i]->device_type; 325 sessions[i]->device_type;
332 if (device_type == browser_sync::SyncedSession::TYPE_WIN || 326 if (device_type == browser_sync::SyncedSession::TYPE_WIN ||
333 device_type == browser_sync::SyncedSession::TYPE_MACOSX || 327 device_type == browser_sync::SyncedSession::TYPE_MACOSX ||
334 device_type == browser_sync::SyncedSession::TYPE_LINUX) { 328 device_type == browser_sync::SyncedSession::TYPE_LINUX) {
335 // Found a desktop session: write out the pref. 329 // Found a desktop session: write out the pref.
336 prefs->SetBoolean(prefs::kNtpPromoDesktopSessionFound, true); 330 prefs->SetBoolean(prefs::kNtpPromoDesktopSessionFound, true);
337 return; 331 return;
338 } 332 }
339 } 333 }
340 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698