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

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

Issue 8520009: Only show G+ promo for users logged into G+ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 #include "chrome/browser/web_resource/promo_resource_service.h" 5 #include "chrome/browser/web_resource/promo_resource_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return IsBuildTargeted(channel_, builds_targeted); 150 return IsBuildTargeted(channel_, builds_targeted);
151 } 151 }
152 152
153 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) { 153 void PromoResourceService::Unpack(const DictionaryValue& parsed_json) {
154 UnpackLogoSignal(parsed_json); 154 UnpackLogoSignal(parsed_json);
155 UnpackNotificationSignal(parsed_json); 155 UnpackNotificationSignal(parsed_json);
156 UnpackWebStoreSignal(parsed_json); 156 UnpackWebStoreSignal(parsed_json);
157 UnpackNTPSignInPromoSignal(parsed_json); 157 UnpackNTPSignInPromoSignal(parsed_json);
158 } 158 }
159 159
160 void PromoResourceService::OnNewNotification(double start, double end) { 160 void PromoResourceService::OnNotificationParsed(double start, double end,
161 ScheduleNotification(start, end); 161 bool new_notification) {
162 if (new_notification) {
163 ScheduleNotification(start, end);
164 }
162 } 165 }
163 166
164 void PromoResourceService::ScheduleNotification(double promo_start, 167 void PromoResourceService::ScheduleNotification(double promo_start,
165 double promo_end) { 168 double promo_end) {
166 if (promo_start > 0 && promo_end > 0) { 169 if (promo_start > 0 && promo_end > 0) {
167 int64 ms_until_start = 170 int64 ms_until_start =
168 static_cast<int64>((base::Time::FromDoubleT( 171 static_cast<int64>((base::Time::FromDoubleT(
169 promo_start) - base::Time::Now()).InMilliseconds()); 172 promo_start) - base::Time::Now()).InMilliseconds());
170 int64 ms_until_end = 173 int64 ms_until_end =
171 static_cast<int64>((base::Time::FromDoubleT( 174 static_cast<int64>((base::Time::FromDoubleT(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return local_state->GetInteger(prefs::kNTPPromoVersion); 211 return local_state->GetInteger(prefs::kNTPPromoVersion);
209 } 212 }
210 213
211 std::string PromoResourceService::GetPromoLocale() { 214 std::string PromoResourceService::GetPromoLocale() {
212 PrefService* local_state = g_browser_process->local_state(); 215 PrefService* local_state = g_browser_process->local_state();
213 return local_state->GetString(prefs::kNTPPromoLocale); 216 return local_state->GetString(prefs::kNTPPromoLocale);
214 } 217 }
215 218
216 void PromoResourceService::UnpackNotificationSignal( 219 void PromoResourceService::UnpackNotificationSignal(
217 const DictionaryValue& parsed_json) { 220 const DictionaryValue& parsed_json) {
218 NotificationPromo notification_promo(prefs_, this); 221 scoped_refptr<NotificationPromo> notification_promo =
219 notification_promo.InitFromJson(parsed_json); 222 NotificationPromo::Create(profile_, this);
223 notification_promo->InitFromJson(parsed_json, false);
220 } 224 }
221 225
222 bool PromoResourceService::CanShowNotificationPromo(Profile* profile) { 226 bool PromoResourceService::CanShowNotificationPromo(Profile* profile) {
223 NotificationPromo notification_promo(profile->GetPrefs(), NULL); 227 scoped_refptr<NotificationPromo> notification_promo =
224 notification_promo.InitFromPrefs(); 228 NotificationPromo::Create(profile, NULL);
225 return notification_promo.CanShow(); 229 notification_promo->InitFromPrefs();
230 return notification_promo->CanShow();
226 } 231 }
227 232
228 void PromoResourceService::UnpackWebStoreSignal( 233 void PromoResourceService::UnpackWebStoreSignal(
229 const DictionaryValue& parsed_json) { 234 const DictionaryValue& parsed_json) {
230 DictionaryValue* topic_dict; 235 DictionaryValue* topic_dict;
231 ListValue* answer_list; 236 ListValue* answer_list;
232 237
233 bool is_webstore_active = false; 238 bool is_webstore_active = false;
234 bool signal_found = false; 239 bool signal_found = false;
235 AppsPromo::PromoData promo_data; 240 AppsPromo::PromoData promo_data;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (!prefs->HasPrefPath(prefs::kNTPSignInPromoGroup)) { 453 if (!prefs->HasPrefPath(prefs::kNTPSignInPromoGroup)) {
449 prefs->SetInteger(prefs::kNTPSignInPromoGroup, 454 prefs->SetInteger(prefs::kNTPSignInPromoGroup,
450 base::RandInt(1, kNTPSignInPromoNumberOfGroups)); 455 base::RandInt(1, kNTPSignInPromoNumberOfGroups));
451 } 456 }
452 457
453 // A response is not kept if the build wasn't targeted, so the only thing 458 // A response is not kept if the build wasn't targeted, so the only thing
454 // required to check is the group this client has been tagged in. 459 // required to check is the group this client has been tagged in.
455 return prefs->GetInteger(prefs::kNTPSignInPromoGroupMax) >= 460 return prefs->GetInteger(prefs::kNTPSignInPromoGroupMax) >=
456 prefs->GetInteger(prefs::kNTPSignInPromoGroup); 461 prefs->GetInteger(prefs::kNTPSignInPromoGroup);
457 } 462 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698