-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NTP SI: update default counts and reset to initial counts on SI data update, browser restart and every 24hr #19823
Changes from all commits
5f50755
124b6b8
c69a262
649c917
22c14c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,34 @@ | |
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/components/ntp_background_images/browser/view_counter_model.h" | ||
#include <algorithm> | ||
|
||
#include "base/check.h" | ||
#include "base/logging.h" | ||
#include "base/rand_util.h" | ||
#include "base/time/time.h" | ||
#include "brave/components/ntp_background_images/browser/features.h" | ||
#include "brave/components/ntp_background_images/common/pref_names.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
namespace ntp_background_images { | ||
|
||
namespace { | ||
|
||
constexpr base::TimeDelta kCountsResetTimeDelay = base::Days(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great to have this configurable via Griffin, so that if the value needs changing in the future we do not need to wait for the trains |
||
|
||
} // namespace | ||
|
||
ViewCounterModel::ViewCounterModel(PrefService* prefs) : prefs_(prefs) { | ||
CHECK(prefs); | ||
|
||
count_to_branded_wallpaper_ = | ||
prefs->GetInteger(prefs::kCountToBrandedWallpaper); | ||
// When browser is restarted we reset to "initial" count. This will also get | ||
// set again in the Reset() function, called e.g. when component is updated. | ||
count_to_branded_wallpaper_ = features::kInitialCountToBrandedWallpaper.Get(); | ||
|
||
// We also reset when a specific amount of time is elapsed when in SI mode | ||
timer_counts_reset_.Start(FROM_HERE, kCountsResetTimeDelay, this, | ||
&ViewCounterModel::OnTimerCountsResetExpired); | ||
} | ||
|
||
ViewCounterModel::~ViewCounterModel() = default; | ||
|
@@ -103,9 +116,6 @@ void ViewCounterModel::RegisterPageViewForBrandedImages() { | |
// Randomize campaign index for next time. | ||
current_campaign_index_ = base::RandInt(0, total_campaign_count_ - 1); | ||
} | ||
|
||
prefs_->SetInteger(prefs::kCountToBrandedWallpaper, | ||
count_to_branded_wallpaper_); | ||
} | ||
|
||
void ViewCounterModel::RegisterPageViewForBackgroundImages() { | ||
|
@@ -144,6 +154,16 @@ void ViewCounterModel::IncreaseBackgroundWallpaperImageIndex() { | |
current_wallpaper_image_index_ %= total_image_count_; | ||
} | ||
|
||
void ViewCounterModel::MaybeResetBrandedWallpaperCount() { | ||
// Set count so that user is more likely to see new branded data at least once | ||
// Only reset count for SI images | ||
if (!always_show_branded_wallpaper_ && show_branded_wallpaper_) { | ||
count_to_branded_wallpaper_ = | ||
std::min(count_to_branded_wallpaper_, | ||
features::kInitialCountToBrandedWallpaper.Get()); | ||
} | ||
} | ||
|
||
void ViewCounterModel::Reset() { | ||
current_wallpaper_image_index_ = 0; | ||
total_image_count_ = 0; | ||
|
@@ -152,6 +172,13 @@ void ViewCounterModel::Reset() { | |
total_campaign_count_ = 0; | ||
campaigns_total_branded_image_count_.clear(); | ||
campaigns_current_branded_image_index_.clear(); | ||
MaybeResetBrandedWallpaperCount(); | ||
// Restart timer with same parameters as set during this class' constructor | ||
timer_counts_reset_.Reset(); | ||
} | ||
|
||
void ViewCounterModel::OnTimerCountsResetExpired() { | ||
MaybeResetBrandedWallpaperCount(); | ||
} | ||
|
||
} // namespace ntp_background_images |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ constexpr char kSponsoredNewTabsHistogramName[] = | |
"Brave.NTP.SponsoredNewTabsCreated"; | ||
constexpr int kSponsoredNewTabsBuckets[] = {0, 10, 20, 30, 40, 50}; | ||
|
||
// Obsolete pref | ||
constexpr char kObsoleteCountToBrandedWallpaperPref[] = | ||
"brave.count_to_branded_wallpaper"; | ||
|
||
} // namespace | ||
|
||
namespace ntp_background_images { | ||
|
@@ -60,11 +64,8 @@ void ViewCounterService::RegisterLocalStatePrefs(PrefRegistrySimple* registry) { | |
|
||
void ViewCounterService::RegisterProfilePrefs( | ||
user_prefs::PrefRegistrySyncable* registry) { | ||
registry->RegisterBooleanPref( | ||
prefs::kBrandedWallpaperNotificationDismissed, false); | ||
registry->RegisterIntegerPref( | ||
prefs::kCountToBrandedWallpaper, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed via 22c14c5 |
||
features::kInitialCountToBrandedWallpaper.Get()); | ||
registry->RegisterBooleanPref(prefs::kBrandedWallpaperNotificationDismissed, | ||
false); | ||
registry->RegisterBooleanPref( | ||
prefs::kNewTabPageShowSponsoredImagesBackgroundImage, true); | ||
// Integer type is used because this pref is used by radio button group in | ||
|
@@ -75,6 +76,17 @@ void ViewCounterService::RegisterProfilePrefs( | |
prefs::kNewTabPageShowBackgroundImage, true); | ||
} | ||
|
||
void ViewCounterService::RegisterProfilePrefsForMigration( | ||
user_prefs::PrefRegistrySyncable* registry) { | ||
// Added 09/2023 | ||
registry->RegisterIntegerPref(kObsoleteCountToBrandedWallpaperPref, 0); | ||
} | ||
|
||
void ViewCounterService::MigrateObsoleteProfilePrefs(PrefService* prefs) { | ||
// Added 09/2023 | ||
prefs->ClearPref(kObsoleteCountToBrandedWallpaperPref); | ||
} | ||
|
||
ViewCounterService::ViewCounterService( | ||
NTPBackgroundImagesService* service, | ||
BraveNTPCustomBackgroundService* custom_service, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend leaving the default value and testing this count via this Griffin feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go to 2 I'm not sure I see us have the desire to go back to 3, since numbers would be worse and UX impact doesn't seem huge? Also it's less work and moving pieces in different repos syncing to when this PR hits various channels if we can combine with this PR, since we have to uplift anyway.