OLD | NEW |
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 Loading... |
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 ScheduleNotification(start, end); |
162 } | 162 } |
163 | 163 |
164 void PromoResourceService::ScheduleNotification(double promo_start, | 164 void PromoResourceService::ScheduleNotification(double promo_start, |
165 double promo_end) { | 165 double promo_end) { |
166 if (promo_start > 0 && promo_end > 0) { | 166 if (promo_start > 0 && promo_end > 0) { |
167 int64 ms_until_start = | 167 int64 ms_until_start = |
168 static_cast<int64>((base::Time::FromDoubleT( | 168 static_cast<int64>((base::Time::FromDoubleT( |
169 promo_start) - base::Time::Now()).InMilliseconds()); | 169 promo_start) - base::Time::Now()).InMilliseconds()); |
170 int64 ms_until_end = | 170 int64 ms_until_end = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return local_state->GetInteger(prefs::kNTPPromoVersion); | 208 return local_state->GetInteger(prefs::kNTPPromoVersion); |
209 } | 209 } |
210 | 210 |
211 std::string PromoResourceService::GetPromoLocale() { | 211 std::string PromoResourceService::GetPromoLocale() { |
212 PrefService* local_state = g_browser_process->local_state(); | 212 PrefService* local_state = g_browser_process->local_state(); |
213 return local_state->GetString(prefs::kNTPPromoLocale); | 213 return local_state->GetString(prefs::kNTPPromoLocale); |
214 } | 214 } |
215 | 215 |
216 void PromoResourceService::UnpackNotificationSignal( | 216 void PromoResourceService::UnpackNotificationSignal( |
217 const DictionaryValue& parsed_json) { | 217 const DictionaryValue& parsed_json) { |
218 NotificationPromo notification_promo(prefs_, this); | 218 scoped_refptr<NotificationPromo> notification_promo = |
219 notification_promo.InitFromJson(parsed_json); | 219 NotificationPromo::Factory(profile_, this); |
| 220 notification_promo->InitFromJson(parsed_json, false); |
220 } | 221 } |
221 | 222 |
222 bool PromoResourceService::CanShowNotificationPromo(Profile* profile) { | 223 bool PromoResourceService::CanShowNotificationPromo(Profile* profile) { |
223 NotificationPromo notification_promo(profile->GetPrefs(), NULL); | 224 scoped_refptr<NotificationPromo> notification_promo = |
224 notification_promo.InitFromPrefs(); | 225 NotificationPromo::Factory(profile, NULL); |
225 return notification_promo.CanShow(); | 226 notification_promo->InitFromPrefs(); |
| 227 return notification_promo->CanShow(); |
226 } | 228 } |
227 | 229 |
228 void PromoResourceService::UnpackWebStoreSignal( | 230 void PromoResourceService::UnpackWebStoreSignal( |
229 const DictionaryValue& parsed_json) { | 231 const DictionaryValue& parsed_json) { |
230 DictionaryValue* topic_dict; | 232 DictionaryValue* topic_dict; |
231 ListValue* answer_list; | 233 ListValue* answer_list; |
232 | 234 |
233 bool is_webstore_active = false; | 235 bool is_webstore_active = false; |
234 bool signal_found = false; | 236 bool signal_found = false; |
235 AppsPromo::PromoData promo_data; | 237 AppsPromo::PromoData promo_data; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (!prefs->HasPrefPath(prefs::kNTPSignInPromoGroup)) { | 450 if (!prefs->HasPrefPath(prefs::kNTPSignInPromoGroup)) { |
449 prefs->SetInteger(prefs::kNTPSignInPromoGroup, | 451 prefs->SetInteger(prefs::kNTPSignInPromoGroup, |
450 base::RandInt(1, kNTPSignInPromoNumberOfGroups)); | 452 base::RandInt(1, kNTPSignInPromoNumberOfGroups)); |
451 } | 453 } |
452 | 454 |
453 // A response is not kept if the build wasn't targeted, so the only thing | 455 // 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. | 456 // required to check is the group this client has been tagged in. |
455 return prefs->GetInteger(prefs::kNTPSignInPromoGroupMax) >= | 457 return prefs->GetInteger(prefs::kNTPSignInPromoGroupMax) >= |
456 prefs->GetInteger(prefs::kNTPSignInPromoGroup); | 458 prefs->GetInteger(prefs::kNTPSignInPromoGroup); |
457 } | 459 } |
OLD | NEW |