Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 // Keys in the kPrefPromoObject dictionary; used only here. | 27 // Keys in the kPrefPromoObject dictionary; used only here. |
| 28 const char kPrefPromoID[] = "id"; | 28 const char kPrefPromoID[] = "id"; |
| 29 const char kPrefPromoFirstViewTime[] = "first_view_time"; | 29 const char kPrefPromoFirstViewTime[] = "first_view_time"; |
| 30 const char kPrefPromoViews[] = "views"; | 30 const char kPrefPromoViews[] = "views"; |
| 31 const char kPrefPromoClosed[] = "closed"; | 31 const char kPrefPromoClosed[] = "closed"; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 NotificationPromo::NotificationPromo(PrefService* local_state) | 35 NotificationPromo::NotificationPromo(PrefService* local_state) |
| 36 : local_state_(local_state), | 36 : local_state_(local_state), |
| 37 promo_type_(NO_PROMO), | |
| 38 promo_payload_(new base::DictionaryValue()), | 37 promo_payload_(new base::DictionaryValue()), |
| 39 start_(0.0), | 38 start_(0.0), |
| 40 end_(0.0), | 39 end_(0.0), |
| 41 promo_id_(-1), | 40 promo_id_(-1), |
| 42 max_views_(0), | 41 max_views_(0), |
| 43 max_seconds_(0), | 42 max_seconds_(0), |
| 44 first_view_time_(0), | 43 first_view_time_(0), |
| 45 views_(0), | 44 views_(0), |
| 46 closed_(false) { | 45 closed_(false) { |
| 47 DCHECK(local_state_); | 46 DCHECK(local_state_); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 72 base::DictionaryValue& json_or_payload = | 71 base::DictionaryValue& json_or_payload = |
| 73 IsPayloadParam(iter->first) ? payload : json; | 72 IsPayloadParam(iter->first) ? payload : json; |
| 74 if (converted) { | 73 if (converted) { |
| 75 json_or_payload.SetInteger(iter->first, converted_number); | 74 json_or_payload.SetInteger(iter->first, converted_number); |
| 76 } else { | 75 } else { |
| 77 json_or_payload.SetString(iter->first, iter->second); | 76 json_or_payload.SetString(iter->first, iter->second); |
| 78 } | 77 } |
| 79 } | 78 } |
| 80 json.Set("payload", payload.DeepCopy()); | 79 json.Set("payload", payload.DeepCopy()); |
| 81 | 80 |
| 82 InitFromJson(json, MOBILE_NTP_WHATS_NEW_PROMO); | 81 InitFromJson(json); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void NotificationPromo::InitFromJson(const base::DictionaryValue& promo, | 84 void NotificationPromo::InitFromJson(const base::DictionaryValue& promo) { |
| 86 PromoType promo_type) { | |
| 87 promo_type_ = promo_type; | |
| 88 | |
| 89 std::string time_str; | 85 std::string time_str; |
| 90 base::Time time; | 86 base::Time time; |
| 91 if (promo.GetString("start", &time_str) && | 87 if (promo.GetString("start", &time_str) && |
| 92 base::Time::FromString(time_str.c_str(), &time)) { | 88 base::Time::FromString(time_str.c_str(), &time)) { |
| 93 start_ = time.ToDoubleT(); | 89 start_ = time.ToDoubleT(); |
| 94 DVLOG(1) << "start str=" << time_str | 90 DVLOG(1) << "start str=" << time_str |
| 95 << ", start_=" << base::DoubleToString(start_); | 91 << ", start_=" << base::DoubleToString(start_); |
| 96 } | 92 } |
| 97 if (promo.GetString("end", &time_str) && | 93 if (promo.GetString("end", &time_str) && |
| 98 base::Time::FromString(time_str.c_str(), &time)) { | 94 base::Time::FromString(time_str.c_str(), &time)) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 ntp_promo->SetInteger(kPrefPromoViews, views); | 144 ntp_promo->SetInteger(kPrefPromoViews, views); |
| 149 ntp_promo->SetBoolean(kPrefPromoClosed, closed); | 145 ntp_promo->SetBoolean(kPrefPromoClosed, closed); |
| 150 | 146 |
| 151 base::DictionaryValue promo_dict; | 147 base::DictionaryValue promo_dict; |
| 152 promo_dict.MergeDictionary(local_state_->GetDictionary(kPrefPromoObject)); | 148 promo_dict.MergeDictionary(local_state_->GetDictionary(kPrefPromoObject)); |
| 153 promo_dict.Set(base::IntToString(promo_id), ntp_promo); | 149 promo_dict.Set(base::IntToString(promo_id), ntp_promo); |
| 154 local_state_->Set(kPrefPromoObject, promo_dict); | 150 local_state_->Set(kPrefPromoObject, promo_dict); |
| 155 DVLOG(1) << "WritePrefs " << promo_dict; | 151 DVLOG(1) << "WritePrefs " << promo_dict; |
| 156 } | 152 } |
| 157 | 153 |
| 158 void NotificationPromo::InitFromPrefs(PromoType promo_type) { | 154 void NotificationPromo::InitFromPrefs() { |
| 159 promo_type_ = promo_type; | |
|
justincohen
2017/04/10 15:32:13
Was this data ever stored in prefs?
gchatz
2017/04/10 18:32:24
It was in the old pref structure, but not since we
| |
| 160 | |
| 161 // Check if data is stored in the old prefs structure, and migrate it before | 155 // Check if data is stored in the old prefs structure, and migrate it before |
| 162 // reading from prefs. | 156 // reading from prefs. |
| 163 MigrateOldPrefs(); | 157 MigrateOldPrefs(); |
| 164 | 158 |
| 165 // If |promo_id_| is not set, do nothing. | 159 // If |promo_id_| is not set, do nothing. |
| 166 if (promo_id_ == -1) | 160 if (promo_id_ == -1) |
| 167 return; | 161 return; |
| 168 | 162 |
| 169 const base::DictionaryValue* promo_dict = | 163 const base::DictionaryValue* promo_dict = |
| 170 local_state_->GetDictionary(kPrefPromoObject); | 164 local_state_->GetDictionary(kPrefPromoObject); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 260 |
| 267 double NotificationPromo::StartTime() const { | 261 double NotificationPromo::StartTime() const { |
| 268 return start_; | 262 return start_; |
| 269 } | 263 } |
| 270 | 264 |
| 271 double NotificationPromo::EndTime() const { | 265 double NotificationPromo::EndTime() const { |
| 272 return end_; | 266 return end_; |
| 273 } | 267 } |
| 274 | 268 |
| 275 } // namespace ios | 269 } // namespace ios |
| OLD | NEW |