-
Notifications
You must be signed in to change notification settings - Fork 920
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 Sponsored Images: Fix crash when using component with no data #4442
Conversation
7f337ce
to
32b653f
Compare
@@ -113,7 +116,8 @@ void ViewCounterService::RegisterPageView() { | |||
} | |||
|
|||
bool ViewCounterService::IsBrandedWallpaperActive() { | |||
return (is_supported_locale_ && IsOptedIn() && current_wallpaper()); | |||
return (is_supported_locale_ && IsOptedIn() && current_wallpaper() && | |||
current_wallpaper()->IsValid()); |
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.
This line fixes the issue for this PR. The others all just support adding the test.
|
||
NTPSponsoredImagesData* CreateGoodData() { | ||
NTPSponsoredImagesData* data = new NTPSponsoredImagesData; | ||
// static auto demo = std::make_unique<NTPSponsoredImagesData>(); |
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 think this make_unique
will work.
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.
done
data->logo_alt_text = "Technikke: For music lovers."; | ||
data->logo_company_name = "Technikke"; | ||
data->logo_destination_url = "https://brave.com"; | ||
// return demo.get(); |
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.
ditto.
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.
done
@@ -48,7 +49,8 @@ ViewCounterService::ViewCounterService( | |||
is_supported_locale_(is_supported_locale) { | |||
// If we have a wallpaper, store it as private var. | |||
// Set demo wallpaper if a flag is set. | |||
if (!base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaperDemo)) { | |||
if (!base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaperDemo) && | |||
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.
Why did you check |service_| is null?
I can't find anyplace that passing null 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.
changed to DCHECK
registry->RegisterBooleanPref( | ||
kNewTabPageShowBrandedBackgroundImage, true); | ||
user_prefs::PrefRegistrySyncable* registry) { | ||
RegisterSponsoredImagesProfilePrefs(registry); |
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.
can we use the common pattern of a static RegisterProfilePrefs
method on the 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.
done
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.
approved with discussed changes
32b653f
to
d5fdbfd
Compare
@@ -71,9 +83,10 @@ ViewCounterService::~ViewCounterService() = default; | |||
NTPSponsoredImagesData* ViewCounterService::current_wallpaper() { | |||
if (base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaperDemo)) { | |||
return GetDemoWallpaper(); | |||
} else { | |||
} else if (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 think we can delete this also because |service_| is always non-null.
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.
done
- Adds validity checker to wallpaper-is-active checker - Adds tests for this - Validity checker checks wallpapers _and_ logo destination url - Moves NTP sponsored images preferences to component so tests can use local component pref names
d5fdbfd
to
0be529e
Compare
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.
LGTM 👍
CI failed on iOS for some reason, during init? Going to restart CI only for that platform. Otherwise, ready to merge 😄👍 |
NTP Sponsored Images: Fix crash when using component with no data
NTP Sponsored Images: Fix crash when using component with no data
Fix brave/brave-browser#7928
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
On brave/brave-browser#7928
Reviewer Checklist:
After-merge Checklist:
changes has landed on.