| 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 <utility> |
| 10 |
| 11 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 11 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 12 #include "base/values.h" | 15 #include "base/values.h" |
| 13 #include "components/pref_registry/pref_registry_syncable.h" | 16 #include "components/pref_registry/pref_registry_syncable.h" |
| 14 #include "components/prefs/pref_registry_simple.h" | 17 #include "components/prefs/pref_registry_simple.h" |
| 15 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 16 #include "components/variations/variations_associated_data.h" | 19 #include "components/variations/variations_associated_data.h" |
| 17 | 20 |
| 18 namespace ios { | 21 namespace ios { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Choose the dictionary to which parameter is added based on whether the | 72 // Choose the dictionary to which parameter is added based on whether the |
| 70 // parameter belongs in the payload or not. | 73 // parameter belongs in the payload or not. |
| 71 base::DictionaryValue& json_or_payload = | 74 base::DictionaryValue& json_or_payload = |
| 72 IsPayloadParam(iter->first) ? payload : json; | 75 IsPayloadParam(iter->first) ? payload : json; |
| 73 if (converted) { | 76 if (converted) { |
| 74 json_or_payload.SetInteger(iter->first, converted_number); | 77 json_or_payload.SetInteger(iter->first, converted_number); |
| 75 } else { | 78 } else { |
| 76 json_or_payload.SetString(iter->first, iter->second); | 79 json_or_payload.SetString(iter->first, iter->second); |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 json.Set("payload", payload.DeepCopy()); | 82 json.Set("payload", base::MakeUnique<base::Value>(payload)); |
| 80 | 83 |
| 81 InitFromJson(json); | 84 InitFromJson(json); |
| 82 } | 85 } |
| 83 | 86 |
| 84 void NotificationPromo::InitFromJson(const base::DictionaryValue& promo) { | 87 void NotificationPromo::InitFromJson(const base::DictionaryValue& promo) { |
| 85 std::string time_str; | 88 std::string time_str; |
| 86 base::Time time; | 89 base::Time time; |
| 87 if (promo.GetString("start", &time_str) && | 90 if (promo.GetString("start", &time_str) && |
| 88 base::Time::FromString(time_str.c_str(), &time)) { | 91 base::Time::FromString(time_str.c_str(), &time)) { |
| 89 start_ = time.ToDoubleT(); | 92 start_ = time.ToDoubleT(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 135 } |
| 133 | 136 |
| 134 void NotificationPromo::WritePrefs() { | 137 void NotificationPromo::WritePrefs() { |
| 135 WritePrefs(promo_id_, first_view_time_, views_, closed_); | 138 WritePrefs(promo_id_, first_view_time_, views_, closed_); |
| 136 } | 139 } |
| 137 | 140 |
| 138 void NotificationPromo::WritePrefs(int promo_id, | 141 void NotificationPromo::WritePrefs(int promo_id, |
| 139 double first_view_time, | 142 double first_view_time, |
| 140 int views, | 143 int views, |
| 141 bool closed) { | 144 bool closed) { |
| 142 base::DictionaryValue* ntp_promo = new base::DictionaryValue; | 145 auto ntp_promo = base::MakeUnique<base::DictionaryValue>(); |
| 143 ntp_promo->SetDouble(kPrefPromoFirstViewTime, first_view_time); | 146 ntp_promo->SetDouble(kPrefPromoFirstViewTime, first_view_time); |
| 144 ntp_promo->SetInteger(kPrefPromoViews, views); | 147 ntp_promo->SetInteger(kPrefPromoViews, views); |
| 145 ntp_promo->SetBoolean(kPrefPromoClosed, closed); | 148 ntp_promo->SetBoolean(kPrefPromoClosed, closed); |
| 146 | 149 |
| 147 base::DictionaryValue promo_dict; | 150 base::DictionaryValue promo_dict; |
| 148 promo_dict.MergeDictionary(local_state_->GetDictionary(kPrefPromoObject)); | 151 promo_dict.MergeDictionary(local_state_->GetDictionary(kPrefPromoObject)); |
| 149 promo_dict.Set(base::IntToString(promo_id), ntp_promo); | 152 promo_dict.Set(base::IntToString(promo_id), std::move(ntp_promo)); |
| 150 local_state_->Set(kPrefPromoObject, promo_dict); | 153 local_state_->Set(kPrefPromoObject, promo_dict); |
| 151 DVLOG(1) << "WritePrefs " << promo_dict; | 154 DVLOG(1) << "WritePrefs " << promo_dict; |
| 152 } | 155 } |
| 153 | 156 |
| 154 void NotificationPromo::InitFromPrefs() { | 157 void NotificationPromo::InitFromPrefs() { |
| 155 // Check if data is stored in the old prefs structure, and migrate it before | 158 // Check if data is stored in the old prefs structure, and migrate it before |
| 156 // reading from prefs. | 159 // reading from prefs. |
| 157 MigrateOldPrefs(); | 160 MigrateOldPrefs(); |
| 158 | 161 |
| 159 // If |promo_id_| is not set, do nothing. | 162 // If |promo_id_| is not set, do nothing. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 263 |
| 261 double NotificationPromo::StartTime() const { | 264 double NotificationPromo::StartTime() const { |
| 262 return start_; | 265 return start_; |
| 263 } | 266 } |
| 264 | 267 |
| 265 double NotificationPromo::EndTime() const { | 268 double NotificationPromo::EndTime() const { |
| 266 return end_; | 269 return end_; |
| 267 } | 270 } |
| 268 | 271 |
| 269 } // namespace ios | 272 } // namespace ios |
| OLD | NEW |