OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |