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

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

Issue 2181833003: Defer effects of HandleViewed/HandleClosed until prefs are loaded again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "ios/chrome/browser/notification_promo.h" 5 #include "ios/chrome/browser/notification_promo.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 225
226 bool NotificationPromo::CanShow() const { 226 bool NotificationPromo::CanShow() const {
227 return !closed_ && !promo_text_.empty() && !ExceedsMaxViews() && 227 return !closed_ && !promo_text_.empty() && !ExceedsMaxViews() &&
228 !ExceedsMaxSeconds() && 228 !ExceedsMaxSeconds() &&
229 base::Time::FromDoubleT(StartTime()) < base::Time::Now() && 229 base::Time::FromDoubleT(StartTime()) < base::Time::Now() &&
230 base::Time::FromDoubleT(EndTime()) > base::Time::Now(); 230 base::Time::FromDoubleT(EndTime()) > base::Time::Now();
231 } 231 }
232 232
233 void NotificationPromo::HandleClosed() { 233 void NotificationPromo::HandleClosed() {
234 if (!closed_) { 234 if (!closed_) {
235 closed_ = true; 235 WritePrefs(promo_id_, first_view_time_, views_, true);
236 WritePrefs();
237 } 236 }
238 } 237 }
239 238
240 bool NotificationPromo::HandleViewed() { 239 void NotificationPromo::HandleViewed() {
241 ++views_; 240 int views = views_ + 1;
242 if (first_view_time_ == 0) { 241 double first_view_time = first_view_time_;
243 first_view_time_ = base::Time::Now().ToDoubleT(); 242 if (first_view_time == 0) {
243 first_view_time = base::Time::Now().ToDoubleT();
244 } 244 }
245 WritePrefs(); 245 WritePrefs(promo_id_, first_view_time, views, closed_);
246 return ExceedsMaxViews() || ExceedsMaxSeconds();
247 } 246 }
248 247
249 bool NotificationPromo::ExceedsMaxViews() const { 248 bool NotificationPromo::ExceedsMaxViews() const {
250 return (max_views_ == 0) ? false : views_ >= max_views_; 249 return (max_views_ == 0) ? false : views_ >= max_views_;
251 } 250 }
252 251
253 bool NotificationPromo::ExceedsMaxSeconds() const { 252 bool NotificationPromo::ExceedsMaxSeconds() const {
254 if (max_seconds_ == 0 || first_view_time_ == 0) 253 if (max_seconds_ == 0 || first_view_time_ == 0)
255 return false; 254 return false;
256 255
(...skipping 10 matching lines...) Expand all
267 266
268 double NotificationPromo::StartTime() const { 267 double NotificationPromo::StartTime() const {
269 return start_; 268 return start_;
270 } 269 }
271 270
272 double NotificationPromo::EndTime() const { 271 double NotificationPromo::EndTime() const {
273 return end_; 272 return end_;
274 } 273 }
275 274
276 } // namespace ios 275 } // namespace ios
OLDNEW
« no previous file with comments | « ios/chrome/browser/notification_promo.h ('k') | ios/chrome/browser/notification_promo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698