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

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

Issue 10704143: Allow max_group = 0 to pass all groups. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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/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"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 // Grouping. 138 // Grouping.
139 DictionaryValue* grouping; 139 DictionaryValue* grouping;
140 if (promo->GetDictionary("grouping", &grouping)) { 140 if (promo->GetDictionary("grouping", &grouping)) {
141 grouping->GetInteger("buckets", &num_groups_); 141 grouping->GetInteger("buckets", &num_groups_);
142 grouping->GetInteger("segment", &initial_segment_); 142 grouping->GetInteger("segment", &initial_segment_);
143 grouping->GetInteger("increment", &increment_); 143 grouping->GetInteger("increment", &increment_);
144 grouping->GetInteger("increment_frequency", &time_slice_); 144 grouping->GetInteger("increment_frequency", &time_slice_);
145 grouping->GetInteger("increment_max", &max_group_); 145 grouping->GetInteger("increment_max", &max_group_);
146 146
147 DVLOG(1) << "num_groups_=" << num_groups_; 147 DVLOG(1) << "num_groups_ = " << num_groups_
148 DVLOG(1) << "initial_segment_ = " << initial_segment_; 148 << ", initial_segment_ = " << initial_segment_
149 DVLOG(1) << "increment_ = " << increment_; 149 << ", increment_ = " << increment_
150 DVLOG(1) << "time_slice_ = " << time_slice_; 150 << ", time_slice_ = " << time_slice_
151 DVLOG(1) << "max_group_ = " << max_group_; 151 << ", max_group_ = " << max_group_;
152 } 152 }
153 153
154 // Payload. 154 // Payload.
155 DictionaryValue* payload; 155 DictionaryValue* payload;
156 if (promo->GetDictionary("payload", &payload)) { 156 if (promo->GetDictionary("payload", &payload)) {
157 payload->GetBoolean("gplus_required", &gplus_required_); 157 payload->GetBoolean("gplus_required", &gplus_required_);
158 158
159 DVLOG(1) << "gplus_required_ = " << gplus_required_; 159 DVLOG(1) << "gplus_required_ = " << gplus_required_;
160 } 160 }
161 161
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 group_ = prefs_->GetInteger(prefs::kNtpPromoGroup); 276 group_ = prefs_->GetInteger(prefs::kNtpPromoGroup);
277 views_ = prefs_->GetInteger(prefs::kNtpPromoViews); 277 views_ = prefs_->GetInteger(prefs::kNtpPromoViews);
278 closed_ = prefs_->GetBoolean(prefs::kNtpPromoClosed); 278 closed_ = prefs_->GetBoolean(prefs::kNtpPromoClosed);
279 279
280 gplus_required_ = prefs_->GetBoolean(prefs::kNtpPromoGplusRequired); 280 gplus_required_ = prefs_->GetBoolean(prefs::kNtpPromoGplusRequired);
281 } 281 }
282 282
283 bool NotificationPromo::CanShow() const { 283 bool NotificationPromo::CanShow() const {
284 return !closed_ && 284 return !closed_ &&
285 !promo_text_.empty() && 285 !promo_text_.empty() &&
286 group_ < max_group_ && 286 !ExceedsMaxGroup() &&
287 !ExceedsMaxViews() && 287 !ExceedsMaxViews() &&
288 base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() && 288 base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() &&
289 base::Time::FromDoubleT(EndTime()) > base::Time::Now() && 289 base::Time::FromDoubleT(EndTime()) > base::Time::Now() &&
290 IsGPlusRequired(); 290 IsGPlusRequired();
291 } 291 }
292 292
293 void NotificationPromo::HandleClosed() { 293 void NotificationPromo::HandleClosed() {
294 content::RecordAction(UserMetricsAction("NTPPromoClosed")); 294 content::RecordAction(UserMetricsAction("NTPPromoClosed"));
295 prefs_->SetBoolean(prefs::kNtpPromoClosed, true); 295 prefs_->SetBoolean(prefs::kNtpPromoClosed, true);
296 } 296 }
297 297
298 bool NotificationPromo::HandleViewed() { 298 bool NotificationPromo::HandleViewed() {
299 content::RecordAction(UserMetricsAction("NTPPromoShown")); 299 content::RecordAction(UserMetricsAction("NTPPromoShown"));
300 if (prefs_->HasPrefPath(prefs::kNtpPromoViewsMax)) 300 if (prefs_->HasPrefPath(prefs::kNtpPromoViewsMax))
301 max_views_ = prefs_->GetInteger(prefs::kNtpPromoViewsMax); 301 max_views_ = prefs_->GetInteger(prefs::kNtpPromoViewsMax);
302 302
303 if (prefs_->HasPrefPath(prefs::kNtpPromoViews)) 303 if (prefs_->HasPrefPath(prefs::kNtpPromoViews))
304 views_ = prefs_->GetInteger(prefs::kNtpPromoViews); 304 views_ = prefs_->GetInteger(prefs::kNtpPromoViews);
305 305
306 prefs_->SetInteger(prefs::kNtpPromoViews, ++views_); 306 prefs_->SetInteger(prefs::kNtpPromoViews, ++views_);
307 return ExceedsMaxViews(); 307 return ExceedsMaxViews();
308 } 308 }
309 309
310 bool NotificationPromo::ExceedsMaxGroup() const {
311 return (max_group_ == 0) ? false : group_ >= max_group_;
312 }
313
310 bool NotificationPromo::ExceedsMaxViews() const { 314 bool NotificationPromo::ExceedsMaxViews() const {
311 return (max_views_ == 0) ? false : views_ >= max_views_; 315 return (max_views_ == 0) ? false : views_ >= max_views_;
312 } 316 }
313 317
314 bool NotificationPromo::IsGPlusRequired() const { 318 bool NotificationPromo::IsGPlusRequired() const {
315 return !gplus_required_ || prefs_->GetBoolean(prefs::kIsGooglePlusUser); 319 return !gplus_required_ || prefs_->GetBoolean(prefs::kIsGooglePlusUser);
316 } 320 }
317 321
318 // static 322 // static
319 GURL NotificationPromo::PromoServerURL() { 323 GURL NotificationPromo::PromoServerURL() {
(...skipping 13 matching lines...) Expand all
333 if (group_ < initial_segment_) 337 if (group_ < initial_segment_)
334 return start_; 338 return start_;
335 return start_ + 339 return start_ +
336 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) 340 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_)
337 * time_slice_; 341 * time_slice_;
338 } 342 }
339 343
340 double NotificationPromo::EndTime() const { 344 double NotificationPromo::EndTime() const {
341 return end_; 345 return end_;
342 } 346 }
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/notification_promo.h ('k') | chrome/browser/web_resource/promo_resource_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698