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

Rewards Extension: delay loading until enabled #3698

Merged
merged 8 commits into from
Oct 24, 2019

Conversation

petemill
Copy link
Member

@petemill petemill commented Oct 15, 2019

Replaces the rewards toolbar icon with a non-extension-related Button. When the button is clicked, the Rewards extension will be loaded. The extension browser action button will replace the previous 'stub' button and the popup will automatically open.

If the profile starts with rewards already enabled then the extension is immediately started.

Fix brave/brave-browser#3436

  • Delay extension loading until rewards is enabled
  • Implement 'stub' native button
  • Open popup when extension is installed after 'stub' button click
  • Fix extension data is out of sync because it doesn't 'sync' state at startup (see related issues).
  • Verify disable-rewards cli flag
  • Badge text '1' and image scaling
  • Rewards team to verify that panel does not need to 'sync' more data to state, and fix any impacted browser tests due to extension install delay.

Related but (probably) not blocking:

  • Rewards extension can't handle any gap in events. <-- should be fixed in this PR, please check @NejcZdovc @ryanml.
  • Rewards extension UI should get neccessary data (publisher, currency and settings for current tab) when panel opens, and not constantly in the background for every tab.
  • Rewards background script should only get data which is required for the badge (i.e. when a publisher has been found for a tab, or the notification count changes). The badge does not need to be updated every time active tab or window changes.
  • Rewards extension should not concern itself with active tab or active windows. It is unneccessary processing, code complexity, and can become out of sync.

Submitter Checklist:

Test Plan:

1. Panel works on fresh data directory

  1. Fresh user data directory
  2. Toolbar Rewards button and icon should be visible
  3. Button should have badge with "1" text content (extension is not loaded)
  4. Clicking button once should open Rewards extension panel (extension has loaded)
    Can also verify extension loaded status in Brave Task Manager

2. Existing rewards profile

  1. Existing data directory with 1 profile with rewards enabled
  2. Toolbar Rewards icon should be visible
  3. Toolbar Rewards icon should not have "1" in badge
  4. Clicking rewards icon should open panel, which should show wallet and active tab publisher

Additional profiles in same data directory

Verify 1. and 2. but with new profiles in the same browser session. (App Menu -> Create New Profile). Each profile should have or not have its own copy of the brave rewards extension, and behave as per test 1. and 2.

cli flag to disable

  1. Fresh profile
  2. Launch with --disable-brave-rewards-extension
  3. Rewards toolbar button is not visible
  4. Go to brave://rewards
  5. Enable rewards
  6. Rewards toolbar button is still not visible

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 requested a review from NejcZdovc as a code owner October 15, 2019 07:01
@petemill petemill changed the title Rewards delay extension Rewards delay extension [WIP] Oct 15, 2019
@petemill petemill changed the title Rewards delay extension [WIP] Rewards Extension: delay loading until enabled [WIP] Oct 15, 2019
@petemill petemill self-assigned this Oct 15, 2019
@@ -78,6 +78,7 @@ source_set("extensions") {

if (brave_rewards_enabled) {
deps += [
"//brave/components/brave_rewards/browser",
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is an existing missing dep since brave_rewards_api.cc gets data from the rewards service. However, I also believe there's a circular dependency since there is a class within rewards which fires extension events.

@petemill petemill force-pushed the rewards-delay-extension branch from 6611baa to 2cc0fa7 Compare October 16, 2019 05:23
@petemill petemill requested a review from bridiver as a code owner October 16, 2019 05:23
@petemill petemill force-pushed the rewards-delay-extension branch from 2cc0fa7 to 6b91526 Compare October 16, 2019 20:52
return rect.size();
// Width > Height to give space for a large bubble (especially for shields).
// TODO(petemill): Generate based on toolbar size.
return gfx::Size(34, 24);
Copy link
Member Author

Choose a reason for hiding this comment

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

The removed code was actually generating a very incorrect size (height() here is very small, likely because nothing is making the height of the container fill the height of the toolbar). This explicit size is moved from https://github.com/brave/brave-core/pull/3698/files#diff-469d5e5a21b50831d605cce6cae56765L160


namespace {
constexpr SkColor kRewardsBadgeBg = SkColorSetRGB(0xfb, 0x54, 0x2b);
const std::string kRewardsInitialBadgeText = "1";
Copy link
Member Author

Choose a reason for hiding this comment

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

Hard-coded string moved from the extension background script, which always ensured that it said "1" until the panel was opened.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good change 👍

@petemill petemill changed the title Rewards Extension: delay loading until enabled [WIP] Rewards Extension: delay loading until enabled Oct 16, 2019
@petemill petemill force-pushed the rewards-delay-extension branch from 6b91526 to 84a4825 Compare October 17, 2019 17:58
ExtensionAction::ActionIconSize(),
ExtensionAction::FallbackIcon().AsImageSkia(), nullptr));
}
+ BRAVE_GET_EXTENSION_ACTION
Copy link
Member Author

@petemill petemill Oct 17, 2019

Choose a reason for hiding this comment

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

See chromium_src override. This is something that was technically 'broken' with the shields and rewards icons previously, but not noticeable. Now that the extension load happens sometimes after window creation and especially whilst the user is focusing on the button, the jump between image sizes was noticeable.

profile_, &extension, *action->default_icon(), \
brave_actions::kBraveActionGraphicSize, \
ExtensionAction::FallbackIcon().AsImageSkia(), nullptr)); \
}
Copy link
Member Author

Choose a reason for hiding this comment

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

See 84a4825#r336149378

See chromium_src override. This is something that was technically 'broken' with the shields and rewards icons previously, but not noticeable. Now that the extension load happens sometimes after window creation and especially whilst the user is focusing on the button, the jump between image sizes was noticeable.

@petemill petemill requested review from mkarolin and ryanml October 17, 2019 18:06
Add(IDR_BRAVE_REWARDS, brave_rewards_path);
}
// Enable rewards extension if already opted-in
HandleRewardsEnabledStatus();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit OnBraveRewardsEnabled would be more conventional here

Copy link
Member Author

Choose a reason for hiding this comment

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

@bridiver even if that function handles both enabled and disabled?

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.

there are some issues with this approach (enables rewards extension when clicked even if rewards doesn't get enabled), but @petemill and I have discussed options moving forward so this is fine as a temporary fix

Copy link
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

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

Per comment above we should fetch recurring tip data after enabling, else it looks fine to me.

@petemill
Copy link
Member Author

@ryanml please can you add that or point to the API

@ryanml ryanml self-requested a review October 19, 2019 00:07
Copy link
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

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

I pushed the change which fetches recurring tips on enable, all looks good to me nice work!

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

A lot of browser tests are broken. https://staging.ci.brave.com/job/brave-browser-build-pr/job/rewards-delay-extension/5/execution/node/436/log/

12 tests failed:
02:59:58      BraveRewardsBrowserTest.AutoContribution (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1715)
02:59:58      BraveRewardsBrowserTest.ClaimGrantViaPanel (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1601)
02:59:58      BraveRewardsBrowserTest.ContributionWithLowAmount (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1830)
02:59:58      BraveRewardsBrowserTest.InsufficientNotificationForInsufficientAmount (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2157)
02:59:58      BraveRewardsBrowserTest.InsufficientNotificationForVerifiedInsufficientAmount (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2198)
02:59:58      BraveRewardsBrowserTest.PendingContributionTip (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2027)
02:59:58      BraveRewardsBrowserTest.RecurringTipForUnverifiedPublisher (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1809)
02:59:58      BraveRewardsBrowserTest.RecurringTipForVerifiedPublisher (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1788)
02:59:58      BraveRewardsBrowserTest.TipConnectedPublisherAnon (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2408)
02:59:58      BraveRewardsBrowserTest.TipConnectedPublisherAnonAndConnected (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2428)
02:59:58      BraveRewardsBrowserTest.TipUnverifiedPublisher (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1768)
02:59:58      BraveRewardsBrowserTest.TipVerifiedPublisher (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:1749)
02:59:58  3 tests timed out:
02:59:58      BraveRewardsBrowserTest.MultipleRecurringOverBudgetAndPartialAutoContribution (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2559)
02:59:58      BraveRewardsBrowserTest.ProcessPendingContributions (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2251)
02:59:58      BraveRewardsBrowserTest.RecurringAndPartialAutoContribution (../../brave/components/brave_rewards/browser/rewards_service_browsertest.cc:2512)

@ryanml can you please help @petemill with them. Thank you

@NejcZdovc
Copy link
Contributor

@petemill should I still see extension in Task manager?

image

I just build the PR on clean profile and opened task manager

@ryanml
Copy link
Contributor

ryanml commented Oct 19, 2019

Unable to reproduce test failures locally, @petemill are you?

@NejcZdovc
Copy link
Contributor

@ryanml one thing could be that locally you are building as debug where CI is doing release which is a lot faster and you probably don't see this race condition on slower build

@petemill petemill force-pushed the rewards-delay-extension branch from c8b0db9 to c8df68b Compare October 22, 2019 22:45
@petemill
Copy link
Member Author

Fixed some of the panel issues via c8df68b

Still some test issues, especially wrt the grant-finished UI showing when the grant is solved elsewhere. Pinged @ryanml and @NejcZdovc about it.

…ound script

This is now controlled by native 'stub' button
The default extension browser action image was set to 16dp when brave browser actions currently uses 18dp. This was barely noticeable when the extensions were loaded on profile creation since only the first window would make this jump and it would happen when the window is opening whilst other paints are occurring. Now that the rewards extension is delay-loaded when the button is clicked, it is more noticeable.
Adds call to braveRewards.getGrants() if rewards is already enabled at extension startup.
Puts get* calls after on* calls so that there is no possibility for items to be missed
ClaimGrant function was clicking on the Finish button. Occasionally this would work because the UI was still there, but since the 'finish' happens from C++, the UI proceeds on its own
@petemill petemill force-pushed the rewards-delay-extension branch from c8df68b to 221129c Compare October 23, 2019 06:24
@petemill
Copy link
Member Author

petemill commented Oct 23, 2019

@petemill should I still see extension in Task manager?

image

I just build the PR on clean profile and opened task manager

No, that's weird @NejcZdovc . Very weird. I cannot replicate. could you try again?

@petemill
Copy link
Member Author

So I fixed the only remaining browser test by removing the forced button click to move from captcha to 'celebration' screen (or whatever you call that!). Not sure why clicking that button worked in master and not on this branch.
On this branch, clicking the button was actually dismissing the celebration screen!
221129c

@petemill
Copy link
Member Author

Looks like all tests passed on this one now

00:02:49  SUCCESS: all tests passed.

Just got the normal lint failure.

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

rewards side looks good

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.

Rewards extension process needs to be terminated when disabled, Follow up to #1475
4 participants