Commit 1f5bbbc2 authored by gchatz's avatar gchatz Committed by Commit bot

Remove unnecessary promo_type_ field from notification_promo.h/.cc.

Removes the promo_type_ field from notification_promo.h/.cc
and uses of it. It is unnecessary as the only promo type in use is the
MOBILE_NTP_WHATS_NEW_PROMO.

BUG=608525

Review-Url: https://codereview.chromium.org/2805443007
Cr-Commit-Position: refs/heads/master@{#463344}
parent be2222ed
......@@ -34,7 +34,6 @@ const char kPrefPromoClosed[] = "closed";
NotificationPromo::NotificationPromo(PrefService* local_state)
: local_state_(local_state),
promo_type_(NO_PROMO),
promo_payload_(new base::DictionaryValue()),
start_(0.0),
end_(0.0),
......@@ -79,13 +78,10 @@ void NotificationPromo::InitFromVariations() {
}
json.Set("payload", payload.DeepCopy());
InitFromJson(json, MOBILE_NTP_WHATS_NEW_PROMO);
InitFromJson(json);
}
void NotificationPromo::InitFromJson(const base::DictionaryValue& promo,
PromoType promo_type) {
promo_type_ = promo_type;
void NotificationPromo::InitFromJson(const base::DictionaryValue& promo) {
std::string time_str;
base::Time time;
if (promo.GetString("start", &time_str) &&
......@@ -155,9 +151,7 @@ void NotificationPromo::WritePrefs(int promo_id,
DVLOG(1) << "WritePrefs " << promo_dict;
}
void NotificationPromo::InitFromPrefs(PromoType promo_type) {
promo_type_ = promo_type;
void NotificationPromo::InitFromPrefs() {
// Check if data is stored in the old prefs structure, and migrate it before
// reading from prefs.
MigrateOldPrefs();
......
......@@ -27,15 +27,6 @@ namespace ios {
// or prefs.
class NotificationPromo {
public:
// TODO(crbug.com/608525): Remove when this code is refactored.
enum PromoType {
NO_PROMO,
NTP_NOTIFICATION_PROMO,
NTP_BUBBLE_PROMO,
MOBILE_NTP_SYNC_PROMO,
MOBILE_NTP_WHATS_NEW_PROMO,
};
explicit NotificationPromo(PrefService* local_state);
~NotificationPromo();
......@@ -43,8 +34,8 @@ class NotificationPromo {
void InitFromVariations();
// Initialize from json/prefs.
void InitFromJson(const base::DictionaryValue& json, PromoType promo_type);
void InitFromPrefs(PromoType promo_type);
void InitFromJson(const base::DictionaryValue& json);
void InitFromPrefs();
// Can this promo be shown?
bool CanShow() const;
......@@ -60,7 +51,6 @@ class NotificationPromo {
void HandleViewed();
const std::string& promo_text() const { return promo_text_; }
PromoType promo_type() const { return promo_type_; }
const base::DictionaryValue* promo_payload() const {
return promo_payload_.get();
}
......@@ -100,7 +90,6 @@ class NotificationPromo {
PrefService* local_state_;
PromoType promo_type_;
std::string promo_text_;
std::unique_ptr<const base::DictionaryValue> promo_payload_;
......
......@@ -111,7 +111,6 @@ class NotificationPromoTest : public testing::Test {
field_trial_params);
base::FieldTrialList::CreateFieldTrial("IOSNTPPromotion", "Group1");
promo_type_ = NotificationPromo::MOBILE_NTP_WHATS_NEW_PROMO;
promo_text_ = promo_text;
start_ = start;
......@@ -133,7 +132,7 @@ class NotificationPromoTest : public testing::Test {
}
void InitPromoFromJson() {
notification_promo_.InitFromJson(*test_json_, promo_type_);
notification_promo_.InitFromJson(*test_json_);
// Test the fields.
TestServerProvidedParameters();
......@@ -158,7 +157,7 @@ class NotificationPromoTest : public testing::Test {
// Initialize promo from saved prefs and server params.
NotificationPromo first_promo(&local_state_);
first_promo.InitFromVariations();
first_promo.InitFromPrefs(promo_type_);
first_promo.InitFromPrefs();
EXPECT_EQ(first_promo.max_views_ - 2, first_promo.views_);
EXPECT_TRUE(first_promo.CanShow());
first_promo.HandleViewed();
......@@ -167,14 +166,14 @@ class NotificationPromoTest : public testing::Test {
// correctly in prefs.
NotificationPromo second_promo(&local_state_);
second_promo.InitFromVariations();
second_promo.InitFromPrefs(promo_type_);
second_promo.InitFromPrefs();
EXPECT_EQ(second_promo.max_views_ - 1, second_promo.views_);
EXPECT_TRUE(second_promo.CanShow());
second_promo.HandleViewed();
NotificationPromo third_promo(&local_state_);
third_promo.InitFromVariations();
third_promo.InitFromPrefs(promo_type_);
third_promo.InitFromPrefs();
EXPECT_EQ(third_promo.max_views_, third_promo.views_);
EXPECT_FALSE(third_promo.CanShow());
......@@ -199,7 +198,7 @@ class NotificationPromoTest : public testing::Test {
// Initialize promo from saved prefs and server params.
NotificationPromo first_promo(&local_state_);
first_promo.InitFromVariations();
first_promo.InitFromPrefs(promo_type_);
first_promo.InitFromPrefs();
EXPECT_FALSE(first_promo.closed_);
EXPECT_TRUE(first_promo.CanShow());
first_promo.HandleClosed();
......@@ -208,7 +207,7 @@ class NotificationPromoTest : public testing::Test {
// recorded correctly in prefs.
NotificationPromo second_promo(&local_state_);
second_promo.InitFromVariations();
second_promo.InitFromPrefs(promo_type_);
second_promo.InitFromPrefs();
EXPECT_TRUE(second_promo.closed_);
EXPECT_FALSE(second_promo.CanShow());
......@@ -276,7 +275,7 @@ class NotificationPromoTest : public testing::Test {
NotificationPromo temp_promo(&local_state_);
temp_promo.InitFromVariations();
temp_promo.InitFromPrefs(promo_type_);
temp_promo.InitFromPrefs();
EXPECT_NE(0, temp_promo.first_view_time_);
notification_promo_.views_ = 0;
......@@ -316,7 +315,7 @@ class NotificationPromoTest : public testing::Test {
// Initialize promo and verify that its instance variables match the data
// saved in the old structure.
promo.InitFromPrefs(promo_type_);
promo.InitFromPrefs();
EXPECT_DOUBLE_EQ(first_view_time, promo.first_view_time_);
EXPECT_EQ(views, promo.views_);
EXPECT_EQ(closed, promo.closed_);
......@@ -343,7 +342,6 @@ class NotificationPromoTest : public testing::Test {
bool received_notification_;
std::unique_ptr<base::DictionaryValue> test_json_;
NotificationPromo::PromoType promo_type_;
std::string promo_text_;
double start_;
......
......@@ -95,8 +95,7 @@ bool NotificationPromoWhatsNew::Init() {
}
}
notification_promo_.InitFromPrefs(
ios::NotificationPromo::MOBILE_NTP_WHATS_NEW_PROMO);
notification_promo_.InitFromPrefs();
return InitFromNotificationPromo();
}
......@@ -105,8 +104,7 @@ bool NotificationPromoWhatsNew::ClearAndInitFromJson(
// This clears away old promos.
notification_promo_.MigrateUserPrefs(local_state_);
notification_promo_.InitFromJson(
json, ios::NotificationPromo::MOBILE_NTP_WHATS_NEW_PROMO);
notification_promo_.InitFromJson(json);
return InitFromNotificationPromo();
}
......@@ -276,7 +274,6 @@ void NotificationPromoWhatsNew::InjectFakePromo(const std::string& promo_id,
base::JSONReader::Read(promo_json_filled_in));
base::DictionaryValue* dict = NULL;
if (value->GetAsDictionary(&dict)) {
notification_promo_.InitFromJson(
*dict, ios::NotificationPromo::MOBILE_NTP_WHATS_NEW_PROMO);
notification_promo_.InitFromJson(*dict);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment