OLD | NEW |
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/web_resource/notification_promo.h" | 5 #include "chrome/browser/web_resource/notification_promo.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile_impl.h" | 16 #include "chrome/browser/profiles/profile_impl.h" |
17 #include "chrome/browser/web_resource/promo_resource_service.h" | 17 #include "chrome/browser/web_resource/promo_resource_service.h" |
18 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/chrome_version_info.h" |
19 #include "chrome/common/net/url_util.h" | 19 #include "chrome/common/net/url_util.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
22 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
23 | 23 |
24 using content::UserMetricsAction; | 24 using content::UserMetricsAction; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Users are randomly assigned to one of kDefaultGroupSize + 1 buckets, in order | |
29 // to be able to roll out promos slowly, or display different promos to | |
30 // different groups. | |
31 const int kDefaultGroupSize = 100; | 28 const int kDefaultGroupSize = 100; |
32 | 29 |
33 bool OutOfBounds(int var, int min, int max) { | |
34 return var < min || var > max; | |
35 } | |
36 | |
37 const char kHeaderProperty[] = "topic"; | |
38 const char kArrayProperty[] = "answers"; | |
39 const char kIdentifierProperty[] = "name"; | |
40 const char kStartPropertyValue[] = "promo_start"; | |
41 const char kEndPropertyValue[] = "promo_end"; | |
42 const char kTextProperty[] = "tooltip"; | |
43 const char kTimeProperty[] = "inproduct"; | |
44 const char kParamsProperty[] = "question"; | |
45 | |
46 const char promo_server_url[] = "https://clients3.google.com/crsignal/client"; | 30 const char promo_server_url[] = "https://clients3.google.com/crsignal/client"; |
47 | 31 |
48 // Time getters. | |
49 double GetTimeFromDict(const DictionaryValue* dict) { | |
50 std::string time_str; | |
51 if (!dict->GetString(kTimeProperty, &time_str)) | |
52 return 0.0; | |
53 | |
54 base::Time time; | |
55 if (time_str.empty() || !base::Time::FromString(time_str.c_str(), &time)) | |
56 return 0.0; | |
57 | |
58 return time.ToDoubleT(); | |
59 } | |
60 | |
61 double GetTimeFromPrefs(PrefService* prefs, const char* pref) { | 32 double GetTimeFromPrefs(PrefService* prefs, const char* pref) { |
62 return prefs->HasPrefPath(pref) ? prefs->GetDouble(pref) : 0.0; | 33 return prefs->HasPrefPath(pref) ? prefs->GetDouble(pref) : 0.0; |
63 } | 34 } |
64 | 35 |
65 // Returns a string suitable for the Promo Server URL 'osname' value. | 36 // Returns a string suitable for the Promo Server URL 'osname' value. |
66 const char* PlatformString() { | 37 const char* PlatformString() { |
67 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
68 return "win"; | 39 return "win"; |
69 #elif defined(OS_MACOSX) | 40 #elif defined(OS_MACOSX) |
70 return "mac"; | 41 return "mac"; |
(...skipping 19 matching lines...) Expand all Loading... |
90 return "beta"; | 61 return "beta"; |
91 case chrome::VersionInfo::CHANNEL_STABLE: | 62 case chrome::VersionInfo::CHANNEL_STABLE: |
92 return "stable"; | 63 return "stable"; |
93 default: | 64 default: |
94 return "none"; | 65 return "none"; |
95 } | 66 } |
96 } | 67 } |
97 | 68 |
98 } // namespace | 69 } // namespace |
99 | 70 |
100 NotificationPromo::NotificationPromo(Profile* profile, Delegate* delegate) | 71 NotificationPromo::NotificationPromo(Profile* profile) |
101 : profile_(profile), | 72 : profile_(profile), |
102 delegate_(delegate), | |
103 prefs_(profile_->GetPrefs()), | 73 prefs_(profile_->GetPrefs()), |
104 start_(0.0), | 74 start_(0.0), |
105 end_(0.0), | 75 end_(0.0), |
106 num_groups_(kDefaultGroupSize), | 76 num_groups_(kDefaultGroupSize), |
107 initial_segment_(0), | 77 initial_segment_(0), |
108 increment_(1), | 78 increment_(1), |
109 time_slice_(0), | 79 time_slice_(0), |
110 max_group_(0), | 80 max_group_(0), |
111 max_views_(0), | 81 max_views_(0), |
112 group_(0), | 82 group_(0), |
113 views_(0), | 83 views_(0), |
114 closed_(false), | 84 closed_(false), |
115 build_(PromoResourceService::ALL_BUILDS), | 85 gplus_required_(false), |
116 platform_(PLATFORM_ALL), | 86 new_notification_(false) { |
117 gplus_required_(false) { | |
118 DCHECK(profile); | 87 DCHECK(profile); |
119 DCHECK(prefs_); | 88 DCHECK(prefs_); |
120 } | 89 } |
121 | 90 |
122 NotificationPromo::~NotificationPromo() {} | 91 NotificationPromo::~NotificationPromo() {} |
123 | 92 |
124 void NotificationPromo::InitFromJsonLegacy(const DictionaryValue& json) { | |
125 DictionaryValue* header = NULL; | |
126 if (json.GetDictionary(kHeaderProperty, &header)) { | |
127 ListValue* answers; | |
128 if (header->GetList(kArrayProperty, &answers)) { | |
129 for (ListValue::const_iterator it = answers->begin(); | |
130 it != answers->end(); | |
131 ++it) { | |
132 if ((*it)->IsType(Value::TYPE_DICTIONARY)) | |
133 Parse(static_cast<DictionaryValue*>(*it)); | |
134 } | |
135 } | |
136 } | |
137 CheckForNewNotification(); | |
138 } | |
139 | |
140 void NotificationPromo::InitFromJson(const DictionaryValue& json) { | 93 void NotificationPromo::InitFromJson(const DictionaryValue& json) { |
141 DictionaryValue* root = NULL; | 94 DictionaryValue* root = NULL; |
142 if (!json.GetDictionary("ntp_notification_promo", &root)) | 95 if (!json.GetDictionary("ntp_notification_promo", &root)) |
143 return; | 96 return; |
144 | 97 |
145 // Strings. Assume the first one is the promo text. | 98 // Strings. Assume the first one is the promo text. |
146 DictionaryValue* strings; | 99 DictionaryValue* strings; |
147 if (root->GetDictionary("strings", &strings)) { | 100 if (root->GetDictionary("strings", &strings)) { |
148 DictionaryValue::Iterator iter(*strings); | 101 DictionaryValue::Iterator iter(*strings); |
149 iter.value().GetAsString(&promo_text_); | 102 iter.value().GetAsString(&promo_text_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 148 |
196 DVLOG(1) << "gplus_required_ = " << gplus_required_; | 149 DVLOG(1) << "gplus_required_ = " << gplus_required_; |
197 } | 150 } |
198 | 151 |
199 root->GetInteger("max_views", &max_views_); | 152 root->GetInteger("max_views", &max_views_); |
200 DVLOG(1) << "max_views_ " << max_views_; | 153 DVLOG(1) << "max_views_ " << max_views_; |
201 | 154 |
202 CheckForNewNotification(); | 155 CheckForNewNotification(); |
203 } | 156 } |
204 | 157 |
205 void NotificationPromo::Parse(const DictionaryValue* dict) { | |
206 std::string key; | |
207 if (dict->GetString(kIdentifierProperty, &key)) { | |
208 if (key == kStartPropertyValue) { | |
209 ParseParams(dict); | |
210 dict->GetString(kTextProperty, &promo_text_); | |
211 start_ = GetTimeFromDict(dict); | |
212 } else if (key == kEndPropertyValue) { | |
213 end_ = GetTimeFromDict(dict); | |
214 } | |
215 } | |
216 } | |
217 | |
218 void NotificationPromo::ParseParams(const DictionaryValue* dict) { | |
219 std::string question; | |
220 if (!dict->GetString(kParamsProperty, &question)) | |
221 return; | |
222 | |
223 size_t index = 0; | |
224 bool err = false; | |
225 | |
226 build_ = GetNextQuestionValue(question, &index, &err); | |
227 time_slice_ = GetNextQuestionValue(question, &index, &err); | |
228 max_group_ = GetNextQuestionValue(question, &index, &err); | |
229 max_views_ = GetNextQuestionValue(question, &index, &err); | |
230 platform_ = GetNextQuestionValue(question, &index, &err); | |
231 | |
232 if (err || | |
233 OutOfBounds(build_, PromoResourceService::NO_BUILD, | |
234 PromoResourceService::ALL_BUILDS) || | |
235 OutOfBounds(max_group_, 0, kDefaultGroupSize) || | |
236 OutOfBounds(platform_, PLATFORM_NONE, PLATFORM_ALL)) { | |
237 // If values are not valid, do not show promo notification. | |
238 DLOG(ERROR) << "Invalid server data, question=" << question << | |
239 ", build=" << build_ << | |
240 ", time_slice=" << time_slice_ << | |
241 ", max_group=" << max_group_ << | |
242 ", max_views=" << max_views_ << | |
243 ", platform_=" << platform_; | |
244 build_ = PromoResourceService::NO_BUILD; | |
245 time_slice_ = 0; | |
246 max_group_ = 0; | |
247 max_views_ = 0; | |
248 platform_ = PLATFORM_NONE; | |
249 } | |
250 } | |
251 | |
252 void NotificationPromo::CheckForNewNotification() { | 158 void NotificationPromo::CheckForNewNotification() { |
253 double start = 0.0; | |
254 double end = 0.0; | |
255 bool new_notification = false; | |
256 | |
257 const double old_start = GetTimeFromPrefs(prefs_, prefs::kNtpPromoStart); | 159 const double old_start = GetTimeFromPrefs(prefs_, prefs::kNtpPromoStart); |
258 const double old_end = GetTimeFromPrefs(prefs_, prefs::kNtpPromoEnd); | 160 const double old_end = GetTimeFromPrefs(prefs_, prefs::kNtpPromoEnd); |
259 | 161 |
260 if (old_start != start_ || old_end != end_) { | 162 new_notification_ = old_start != start_ || old_end != end_; |
| 163 if (new_notification_) |
261 OnNewNotification(); | 164 OnNewNotification(); |
262 // For testing. | |
263 start = StartTimeForGroup(); | |
264 end = end_; | |
265 new_notification = true; | |
266 } | |
267 // For testing. | |
268 if (delegate_) { | |
269 // If no change needed, call delegate with default values. | |
270 delegate_->OnNotificationParsed(start, end, new_notification); | |
271 } | |
272 } | 165 } |
273 | 166 |
274 void NotificationPromo::OnNewNotification() { | 167 void NotificationPromo::OnNewNotification() { |
275 // Create a new promo group. | 168 // Create a new promo group. |
276 group_ = base::RandInt(0, num_groups_ - 1); | 169 group_ = base::RandInt(0, num_groups_ - 1); |
277 WritePrefs(); | 170 WritePrefs(); |
278 } | 171 } |
279 | 172 |
280 // static | 173 // static |
281 void NotificationPromo::RegisterUserPrefs(PrefService* prefs) { | 174 void NotificationPromo::RegisterUserPrefs(PrefService* prefs) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 prefs->RegisterIntegerPref(prefs::kNtpPromoGroup, | 206 prefs->RegisterIntegerPref(prefs::kNtpPromoGroup, |
314 0, | 207 0, |
315 PrefService::UNSYNCABLE_PREF); | 208 PrefService::UNSYNCABLE_PREF); |
316 prefs->RegisterIntegerPref(prefs::kNtpPromoViews, | 209 prefs->RegisterIntegerPref(prefs::kNtpPromoViews, |
317 0, | 210 0, |
318 PrefService::UNSYNCABLE_PREF); | 211 PrefService::UNSYNCABLE_PREF); |
319 prefs->RegisterBooleanPref(prefs::kNtpPromoClosed, | 212 prefs->RegisterBooleanPref(prefs::kNtpPromoClosed, |
320 false, | 213 false, |
321 PrefService::UNSYNCABLE_PREF); | 214 PrefService::UNSYNCABLE_PREF); |
322 | 215 |
323 prefs->RegisterIntegerPref(prefs::kNtpPromoBuild, | |
324 PromoResourceService::NO_BUILD, | |
325 PrefService::UNSYNCABLE_PREF); | |
326 prefs->RegisterIntegerPref(prefs::kNtpPromoPlatform, | |
327 PLATFORM_NONE, | |
328 PrefService::UNSYNCABLE_PREF); | |
329 | |
330 prefs->RegisterBooleanPref(prefs::kNtpPromoGplusRequired, | 216 prefs->RegisterBooleanPref(prefs::kNtpPromoGplusRequired, |
331 false, | 217 false, |
332 PrefService::UNSYNCABLE_PREF); | 218 PrefService::UNSYNCABLE_PREF); |
333 } | |
334 | 219 |
335 // static | 220 // TODO(achuith): Delete this in M22. |
336 NotificationPromo* NotificationPromo::Create(Profile *profile, | 221 prefs->RegisterIntegerPref(prefs::kNtpPromoBuild, |
337 NotificationPromo::Delegate * delegate) { | 222 0, |
338 return new NotificationPromo(profile, delegate); | 223 PrefService::UNSYNCABLE_PREF); |
| 224 prefs->RegisterIntegerPref(prefs::kNtpPromoPlatform, |
| 225 0, |
| 226 PrefService::UNSYNCABLE_PREF); |
| 227 prefs->ClearPref(prefs::kNtpPromoBuild); |
| 228 prefs->ClearPref(prefs::kNtpPromoPlatform); |
339 } | 229 } |
340 | 230 |
341 void NotificationPromo::WritePrefs() { | 231 void NotificationPromo::WritePrefs() { |
342 prefs_->SetString(prefs::kNtpPromoLine, promo_text_); | 232 prefs_->SetString(prefs::kNtpPromoLine, promo_text_); |
343 | 233 |
344 prefs_->SetDouble(prefs::kNtpPromoStart, start_); | 234 prefs_->SetDouble(prefs::kNtpPromoStart, start_); |
345 prefs_->SetDouble(prefs::kNtpPromoEnd, end_); | 235 prefs_->SetDouble(prefs::kNtpPromoEnd, end_); |
346 | 236 |
347 prefs_->SetInteger(prefs::kNtpPromoNumGroups, num_groups_); | 237 prefs_->SetInteger(prefs::kNtpPromoNumGroups, num_groups_); |
348 prefs_->SetInteger(prefs::kNtpPromoInitialSegment, initial_segment_); | 238 prefs_->SetInteger(prefs::kNtpPromoInitialSegment, initial_segment_); |
349 prefs_->SetInteger(prefs::kNtpPromoIncrement, increment_); | 239 prefs_->SetInteger(prefs::kNtpPromoIncrement, increment_); |
350 prefs_->SetInteger(prefs::kNtpPromoGroupTimeSlice, time_slice_); | 240 prefs_->SetInteger(prefs::kNtpPromoGroupTimeSlice, time_slice_); |
351 prefs_->SetInteger(prefs::kNtpPromoGroupMax, max_group_); | 241 prefs_->SetInteger(prefs::kNtpPromoGroupMax, max_group_); |
352 | 242 |
353 prefs_->SetInteger(prefs::kNtpPromoViewsMax, max_views_); | 243 prefs_->SetInteger(prefs::kNtpPromoViewsMax, max_views_); |
354 | 244 |
355 prefs_->SetInteger(prefs::kNtpPromoGroup, group_); | 245 prefs_->SetInteger(prefs::kNtpPromoGroup, group_); |
356 prefs_->SetInteger(prefs::kNtpPromoViews, views_); | 246 prefs_->SetInteger(prefs::kNtpPromoViews, views_); |
357 prefs_->SetBoolean(prefs::kNtpPromoClosed, closed_); | 247 prefs_->SetBoolean(prefs::kNtpPromoClosed, closed_); |
358 | 248 |
359 prefs_->SetInteger(prefs::kNtpPromoBuild, build_); | |
360 prefs_->SetInteger(prefs::kNtpPromoPlatform, platform_); | |
361 | |
362 prefs_->SetBoolean(prefs::kNtpPromoGplusRequired, gplus_required_); | 249 prefs_->SetBoolean(prefs::kNtpPromoGplusRequired, gplus_required_); |
363 } | 250 } |
364 | 251 |
365 void NotificationPromo::InitFromPrefs() { | 252 void NotificationPromo::InitFromPrefs() { |
366 promo_text_ = prefs_->GetString(prefs::kNtpPromoLine); | 253 promo_text_ = prefs_->GetString(prefs::kNtpPromoLine); |
367 | 254 |
368 start_ = prefs_->GetDouble(prefs::kNtpPromoStart); | 255 start_ = prefs_->GetDouble(prefs::kNtpPromoStart); |
369 end_ = prefs_->GetDouble(prefs::kNtpPromoEnd); | 256 end_ = prefs_->GetDouble(prefs::kNtpPromoEnd); |
370 | 257 |
371 num_groups_ = prefs_->GetInteger(prefs::kNtpPromoNumGroups); | 258 num_groups_ = prefs_->GetInteger(prefs::kNtpPromoNumGroups); |
372 initial_segment_ = prefs_->GetInteger(prefs::kNtpPromoInitialSegment); | 259 initial_segment_ = prefs_->GetInteger(prefs::kNtpPromoInitialSegment); |
373 increment_ = prefs_->GetInteger(prefs::kNtpPromoIncrement); | 260 increment_ = prefs_->GetInteger(prefs::kNtpPromoIncrement); |
374 time_slice_ = prefs_->GetInteger(prefs::kNtpPromoGroupTimeSlice); | 261 time_slice_ = prefs_->GetInteger(prefs::kNtpPromoGroupTimeSlice); |
375 max_group_ = prefs_->GetInteger(prefs::kNtpPromoGroupMax); | 262 max_group_ = prefs_->GetInteger(prefs::kNtpPromoGroupMax); |
376 | 263 |
377 max_views_ = prefs_->GetInteger(prefs::kNtpPromoViewsMax); | 264 max_views_ = prefs_->GetInteger(prefs::kNtpPromoViewsMax); |
378 | 265 |
379 group_ = prefs_->GetInteger(prefs::kNtpPromoGroup); | 266 group_ = prefs_->GetInteger(prefs::kNtpPromoGroup); |
380 views_ = prefs_->GetInteger(prefs::kNtpPromoViews); | 267 views_ = prefs_->GetInteger(prefs::kNtpPromoViews); |
381 closed_ = prefs_->GetBoolean(prefs::kNtpPromoClosed); | 268 closed_ = prefs_->GetBoolean(prefs::kNtpPromoClosed); |
382 | 269 |
383 build_ = prefs_->GetInteger(prefs::kNtpPromoBuild); | |
384 platform_ = prefs_->GetInteger(prefs::kNtpPromoPlatform); | |
385 | |
386 gplus_required_ = prefs_->GetBoolean(prefs::kNtpPromoGplusRequired); | 270 gplus_required_ = prefs_->GetBoolean(prefs::kNtpPromoGplusRequired); |
387 } | 271 } |
388 | 272 |
389 bool NotificationPromo::CanShow() const { | 273 bool NotificationPromo::CanShow() const { |
390 return !closed_ && | 274 return !closed_ && |
391 !promo_text_.empty() && | 275 !promo_text_.empty() && |
392 group_ < max_group_ && | 276 group_ < max_group_ && |
393 !ExceedsMaxViews() && | 277 !ExceedsMaxViews() && |
394 base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() && | 278 base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() && |
395 base::Time::FromDoubleT(end_) > base::Time::Now() && | 279 base::Time::FromDoubleT(EndTime()) > base::Time::Now() && |
396 IsBuildAllowed(build_) && | |
397 IsPlatformAllowed(platform_) && | |
398 IsGPlusRequired(); | 280 IsGPlusRequired(); |
399 } | 281 } |
400 | 282 |
401 void NotificationPromo::HandleClosed() { | 283 void NotificationPromo::HandleClosed() { |
402 content::RecordAction(UserMetricsAction("NTPPromoClosed")); | 284 content::RecordAction(UserMetricsAction("NTPPromoClosed")); |
403 prefs_->SetBoolean(prefs::kNtpPromoClosed, true); | 285 prefs_->SetBoolean(prefs::kNtpPromoClosed, true); |
404 } | 286 } |
405 | 287 |
406 bool NotificationPromo::HandleViewed() { | 288 bool NotificationPromo::HandleViewed() { |
407 content::RecordAction(UserMetricsAction("NTPPromoShown")); | 289 content::RecordAction(UserMetricsAction("NTPPromoShown")); |
408 if (prefs_->HasPrefPath(prefs::kNtpPromoViewsMax)) | 290 if (prefs_->HasPrefPath(prefs::kNtpPromoViewsMax)) |
409 max_views_ = prefs_->GetInteger(prefs::kNtpPromoViewsMax); | 291 max_views_ = prefs_->GetInteger(prefs::kNtpPromoViewsMax); |
410 | 292 |
411 if (prefs_->HasPrefPath(prefs::kNtpPromoViews)) | 293 if (prefs_->HasPrefPath(prefs::kNtpPromoViews)) |
412 views_ = prefs_->GetInteger(prefs::kNtpPromoViews); | 294 views_ = prefs_->GetInteger(prefs::kNtpPromoViews); |
413 | 295 |
414 prefs_->SetInteger(prefs::kNtpPromoViews, ++views_); | 296 prefs_->SetInteger(prefs::kNtpPromoViews, ++views_); |
415 return ExceedsMaxViews(); | 297 return ExceedsMaxViews(); |
416 } | 298 } |
417 | 299 |
418 bool NotificationPromo::ExceedsMaxViews() const { | 300 bool NotificationPromo::ExceedsMaxViews() const { |
419 return (max_views_ == 0) ? false : views_ >= max_views_; | 301 return (max_views_ == 0) ? false : views_ >= max_views_; |
420 } | 302 } |
421 | 303 |
422 bool NotificationPromo::IsBuildAllowed(int builds_allowed) const { | |
423 if (delegate_) // For testing. | |
424 return delegate_->IsBuildAllowed(builds_allowed); | |
425 else | |
426 return PromoResourceService::IsBuildTargeted( | |
427 PromoResourceService::GetChannel(), builds_allowed); | |
428 } | |
429 | |
430 bool NotificationPromo::IsPlatformAllowed(int target_platform) const { | |
431 const int current_platform = delegate_? delegate_->CurrentPlatform() | |
432 : CurrentPlatform(); | |
433 return (target_platform & current_platform) != 0; | |
434 } | |
435 | |
436 bool NotificationPromo::IsGPlusRequired() const { | 304 bool NotificationPromo::IsGPlusRequired() const { |
437 return !gplus_required_ || prefs_->GetBoolean(prefs::kIsGooglePlusUser); | 305 return !gplus_required_ || prefs_->GetBoolean(prefs::kIsGooglePlusUser); |
438 } | 306 } |
439 | 307 |
440 // static | 308 // static |
441 int NotificationPromo::CurrentPlatform() { | |
442 // Ignore OS_ANDROID, OS_FREEBSD, OS_OPENBSD, OS_SOLARIS, OS_NACL for now. | |
443 // Order is important - OS_LINUX and OS_CHROMEOS can both be defined. | |
444 #if defined(OS_WIN) | |
445 return PLATFORM_WIN; | |
446 #elif defined(OS_MACOSX) | |
447 return PLATFORM_MAC; | |
448 #elif defined(OS_CHROMEOS) | |
449 return PLATFORM_CHROMEOS; | |
450 #elif defined(OS_LINUX) | |
451 return PLATFORM_LINUX; | |
452 #else | |
453 return PLATFORM_NONE; | |
454 #endif | |
455 } | |
456 | |
457 // static | |
458 GURL NotificationPromo::PromoServerURL() { | 309 GURL NotificationPromo::PromoServerURL() { |
459 GURL url(promo_server_url); | 310 GURL url(promo_server_url); |
460 url = chrome_common_net::AppendQueryParameter( | 311 url = chrome_common_net::AppendQueryParameter( |
461 url, "dist", ChannelString()); | 312 url, "dist", ChannelString()); |
462 url = chrome_common_net::AppendQueryParameter( | 313 url = chrome_common_net::AppendQueryParameter( |
463 url, "osname", PlatformString()); | 314 url, "osname", PlatformString()); |
464 url = chrome_common_net::AppendQueryParameter( | 315 url = chrome_common_net::AppendQueryParameter( |
465 url, "branding", chrome::VersionInfo().Version()); | 316 url, "branding", chrome::VersionInfo().Version()); |
466 DVLOG(1) << "PromoServerURL=" << url.spec(); | 317 DVLOG(1) << "PromoServerURL=" << url.spec(); |
467 // Note that locale param is added by WebResourceService. | 318 // Note that locale param is added by WebResourceService. |
468 return url; | 319 return url; |
469 } | 320 } |
470 | 321 |
471 double NotificationPromo::StartTimeForGroup() const { | 322 double NotificationPromo::StartTimeForGroup() const { |
472 if (group_ < initial_segment_) | 323 if (group_ < initial_segment_) |
473 return start_; | 324 return start_; |
474 return start_ + | 325 return start_ + |
475 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 326 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
476 * time_slice_; | 327 * time_slice_; |
477 } | 328 } |
478 | 329 |
479 // static | 330 double NotificationPromo::EndTime() const { |
480 int NotificationPromo::GetNextQuestionValue(const std::string& question, | 331 return end_; |
481 size_t* index, | |
482 bool* err) { | |
483 if (*err) | |
484 return 0; | |
485 | |
486 size_t new_index = question.find(':', *index); | |
487 // Note that substr correctly handles npos. | |
488 std::string fragment(question.substr(*index, new_index - *index)); | |
489 *index = new_index + 1; | |
490 | |
491 int value; | |
492 *err = !base::StringToInt(fragment, &value); | |
493 return *err ? 0 : value; | |
494 } | 332 } |
OLD | NEW |