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

Maintains Ads UI preference #1337

Merged
merged 1 commit into from
Jan 14, 2019
Merged

Maintains Ads UI preference #1337

merged 1 commit into from
Jan 14, 2019

Conversation

ryanml
Copy link
Contributor

@ryanml ryanml commented Jan 14, 2019

Fixes: brave/brave-browser#2888

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

  1. Launch from clean profile and enable Brave Rewards
  2. From brave://rewards, disable Ads via the settings box
  3. Disable Rewards from the main toggle
  4. Re-enable Rewards from the main toggle
  5. Confirm that Ads does not re-enable and ad service is shut down
  6. Enable Ads
  7. Disable Rewards from the main toggle
  8. Re-enable Rewards from the main toggle
  9. Confirm that Ads comes back on in UI and ad service is started

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

@ryanml ryanml merged commit 9c45f2f into master Jan 14, 2019
@ryanml ryanml deleted the fix-2888-2 branch January 14, 2019 21:11
ryanml added a commit that referenced this pull request Jan 14, 2019
Maintains Ads UI preference
if (ads_service_) {
if (rewards_enabled) {
// When Rewards are enabled, set Ads enabled to whatever UI value is
bool ads_ui_enabled = ads_service_->is_ui_enabled();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's better to use the buildflag for this. I would only use the ui_enabled stuff in js

Copy link
Collaborator

Choose a reason for hiding this comment

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

or is this something different? I guess I'm confused

Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the difference between enabled and ui_enabled?

Copy link
Collaborator

@bridiver bridiver Jan 14, 2019

Choose a reason for hiding this comment

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

actually I think I understand, but per the comment below I think ads service should have logic to check the status of rewards service enabled. Per discussions with @tmancey ads are going to be more tightly integrated inside the service process so eventually we might even move the check for rewards enabled/disabled into the lib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So enabled essentially means, "is the ad service enabled and running?" ui_enabled means, "have ads been explicitly enabled in the UI by the user?"

This may make it more clear

User has Rewards enabled via the main toggle, and the ads box enabled:
enabled -> true
ui_enabled -> true

The user then disables the main Rewards toggle
enabled -> false (Ads service is off as a result of shutting off rewards)
ui_enabled -> true (This is unchanged as just Rewards was disabled, not explicitly Ads)

With the above when one re-enables Rewards via the main toggle, we have the preference for Ads being on saved in ui_enabled, so we know we can turn Ads back on along with Rewards

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, what I'm suggesting is that ads is_enabled should check both the ads enabled preference and also RewardsService enabled status. That makes the logic simpler for the UI handler and remove the extra pref. Ideally I think we'd do that before it went to beta channel because otherwise we'd need extra logic to handle the ui enabled pref.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if ads is dependent on rewards then it makes sense to have AdsServiceFactory DependsOn for Rewards to make it explicit and keep the enable/disable logic in the service

Copy link
Contributor

Choose a reason for hiding this comment

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

this is what I wanted to do as well (brave/brave-browser#2888 (comment)), but because of time constrains we just added new pefr for now so that we could ship it today

ads_service_->set_ads_enabled(ads_ui_enabled);
} else {
// When Rewards are disabled, cache UI value and disable Ads
bool ads_enabled = ads_service_->is_enabled();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might be better to put this logic in rewards service and AdsServiceFactory should have a DependsOn for RewardsService

@ryanml ryanml added this to the 0.60.x - Dev milestone Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disabling Rewards should also disable Ads
3 participants