Skip to content
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

Merged
merged 1 commit into from
Jan 28, 2020

Conversation

petemill
Copy link
Member

  • 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

Fix brave/brave-browser#7928

Submitter Checklist:

Test Plan:

On brave/brave-browser#7928

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@petemill petemill self-assigned this Jan 28, 2020
@petemill petemill force-pushed the ntp-sbw-canada-crash branch from 7f337ce to 32b653f Compare January 28, 2020 00:07
@@ -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());
Copy link
Member Author

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>();
Copy link
Member

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.

Copy link
Member Author

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Member Author

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_) {
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

@bridiver bridiver left a 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

@petemill
Copy link
Member Author

petemill commented Jan 28, 2020

@petemill petemill force-pushed the ntp-sbw-canada-crash branch from 32b653f to d5fdbfd Compare January 28, 2020 04:55
@@ -71,9 +83,10 @@ ViewCounterService::~ViewCounterService() = default;
NTPSponsoredImagesData* ViewCounterService::current_wallpaper() {
if (base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaperDemo)) {
return GetDemoWallpaper();
} else {
} else if (service_) {
Copy link
Member

@simonhong simonhong Jan 28, 2020

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.

Copy link
Member Author

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
@petemill petemill force-pushed the ntp-sbw-canada-crash branch from d5fdbfd to 0be529e Compare January 28, 2020 05:34
Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@bsclifton bsclifton added CI/skip-android Do not run CI builds for Android CI/skip-linux CI/skip-macos-x64 Do not run CI builds for macOS x64 labels Jan 28, 2020
@bsclifton bsclifton added this to the 1.5.x - Nightly milestone Jan 28, 2020
@bsclifton
Copy link
Member

CI failed on iOS for some reason, during init? Going to restart CI only for that platform. Otherwise, ready to merge 😄👍

@petemill petemill merged commit a571132 into master Jan 28, 2020
@petemill petemill deleted the ntp-sbw-canada-crash branch January 28, 2020 18:02
petemill added a commit that referenced this pull request Jan 29, 2020
NTP Sponsored Images: Fix crash when using component with no data
This was referenced Jan 29, 2020
petemill added a commit that referenced this pull request Jan 29, 2020
NTP Sponsored Images: Fix crash when using component with no data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NTP SI crashes for non-US region
4 participants