| 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 #ifndef IOS_CHROME_BROWSER_NOTIFICATION_PROMO_H_ | 5 #ifndef IOS_CHROME_BROWSER_NOTIFICATION_PROMO_H_ |
| 6 #define IOS_CHROME_BROWSER_NOTIFICATION_PROMO_H_ | 6 #define IOS_CHROME_BROWSER_NOTIFICATION_PROMO_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 | 12 |
| 13 class PrefRegistrySimple; | 13 class PrefRegistrySimple; |
| 14 class PrefService; | 14 class PrefService; |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class DictionaryValue; | 17 class DictionaryValue; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace user_prefs { | 20 namespace user_prefs { |
| 21 class PrefRegistrySyncable; | 21 class PrefRegistrySyncable; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace ios { | 24 namespace ios { |
| 25 | 25 |
| 26 // Class that parses and manages promotion data from either a finch trial, json, | 26 // Class that parses and manages promotion data from either a finch trial, json, |
| 27 // or prefs. | 27 // or prefs. |
| 28 class NotificationPromo { | 28 class NotificationPromo { |
| 29 public: | 29 public: |
| 30 // TODO(crbug.com/608525): Remove when this code is refactored. | |
| 31 enum PromoType { | |
| 32 NO_PROMO, | |
| 33 NTP_NOTIFICATION_PROMO, | |
| 34 NTP_BUBBLE_PROMO, | |
| 35 MOBILE_NTP_SYNC_PROMO, | |
| 36 MOBILE_NTP_WHATS_NEW_PROMO, | |
| 37 }; | |
| 38 | |
| 39 explicit NotificationPromo(PrefService* local_state); | 30 explicit NotificationPromo(PrefService* local_state); |
| 40 ~NotificationPromo(); | 31 ~NotificationPromo(); |
| 41 | 32 |
| 42 // Initialize from finch parameters. | 33 // Initialize from finch parameters. |
| 43 void InitFromVariations(); | 34 void InitFromVariations(); |
| 44 | 35 |
| 45 // Initialize from json/prefs. | 36 // Initialize from json/prefs. |
| 46 void InitFromJson(const base::DictionaryValue& json, PromoType promo_type); | 37 void InitFromJson(const base::DictionaryValue& json); |
| 47 void InitFromPrefs(PromoType promo_type); | 38 void InitFromPrefs(); |
| 48 | 39 |
| 49 // Can this promo be shown? | 40 // Can this promo be shown? |
| 50 bool CanShow() const; | 41 bool CanShow() const; |
| 51 | 42 |
| 52 // The time when this promo can start being viewed. | 43 // The time when this promo can start being viewed. |
| 53 double StartTime() const; | 44 double StartTime() const; |
| 54 // The time after which this promo no longer can be viewed. | 45 // The time after which this promo no longer can be viewed. |
| 55 double EndTime() const; | 46 double EndTime() const; |
| 56 | 47 |
| 57 // Mark the promo as closed when the user dismisses it. | 48 // Mark the promo as closed when the user dismisses it. |
| 58 void HandleClosed(); | 49 void HandleClosed(); |
| 59 // Mark the promo has having been viewed. | 50 // Mark the promo has having been viewed. |
| 60 void HandleViewed(); | 51 void HandleViewed(); |
| 61 | 52 |
| 62 const std::string& promo_text() const { return promo_text_; } | 53 const std::string& promo_text() const { return promo_text_; } |
| 63 PromoType promo_type() const { return promo_type_; } | |
| 64 const base::DictionaryValue* promo_payload() const { | 54 const base::DictionaryValue* promo_payload() const { |
| 65 return promo_payload_.get(); | 55 return promo_payload_.get(); |
| 66 } | 56 } |
| 67 | 57 |
| 68 // Register preferences. | 58 // Register preferences. |
| 69 static void RegisterPrefs(PrefRegistrySimple* registry); | 59 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 70 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 71 static void MigrateUserPrefs(PrefService* user_prefs); | 61 static void MigrateUserPrefs(PrefService* user_prefs); |
| 72 | 62 |
| 73 private: | 63 private: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 93 bool IsPayloadParam(const std::string& param_name) const; | 83 bool IsPayloadParam(const std::string& param_name) const; |
| 94 | 84 |
| 95 // Transition data saved in old prefs structure to new structure that supports | 85 // Transition data saved in old prefs structure to new structure that supports |
| 96 // storing multiple promos. | 86 // storing multiple promos. |
| 97 // TODO(crbug.com/623726) Remove this method when migration is no longer | 87 // TODO(crbug.com/623726) Remove this method when migration is no longer |
| 98 // needed as most users have been upgraded to the new pref structure. | 88 // needed as most users have been upgraded to the new pref structure. |
| 99 void MigrateOldPrefs(); | 89 void MigrateOldPrefs(); |
| 100 | 90 |
| 101 PrefService* local_state_; | 91 PrefService* local_state_; |
| 102 | 92 |
| 103 PromoType promo_type_; | |
| 104 std::string promo_text_; | 93 std::string promo_text_; |
| 105 | 94 |
| 106 std::unique_ptr<const base::DictionaryValue> promo_payload_; | 95 std::unique_ptr<const base::DictionaryValue> promo_payload_; |
| 107 | 96 |
| 108 double start_; | 97 double start_; |
| 109 double end_; | 98 double end_; |
| 110 int promo_id_; | 99 int promo_id_; |
| 111 | 100 |
| 112 // When max_views_ is 0, we don't cap the number of views. | 101 // When max_views_ is 0, we don't cap the number of views. |
| 113 int max_views_; | 102 int max_views_; |
| 114 | 103 |
| 115 // When max_seconds_ is 0 or not set, we don't cap the number of seconds a | 104 // When max_seconds_ is 0 or not set, we don't cap the number of seconds a |
| 116 // promo can be visible. | 105 // promo can be visible. |
| 117 int max_seconds_; | 106 int max_seconds_; |
| 118 | 107 |
| 119 // Set when the promo is viewed for the first time. | 108 // Set when the promo is viewed for the first time. |
| 120 double first_view_time_; | 109 double first_view_time_; |
| 121 | 110 |
| 122 int views_; | 111 int views_; |
| 123 bool closed_; | 112 bool closed_; |
| 124 | 113 |
| 125 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); | 114 DISALLOW_COPY_AND_ASSIGN(NotificationPromo); |
| 126 }; | 115 }; |
| 127 | 116 |
| 128 } // namespace ios | 117 } // namespace ios |
| 129 | 118 |
| 130 #endif // IOS_CHROME_BROWSER_NOTIFICATION_PROMO_H_ | 119 #endif // IOS_CHROME_BROWSER_NOTIFICATION_PROMO_H_ |
| OLD | NEW |