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

Speedreader stylesheet from component updater #6257

Merged
merged 3 commits into from
Aug 3, 2020

Conversation

AndriusA
Copy link

@AndriusA AndriusA commented Jul 29, 2020

Resolves brave/brave-browser#11004

Partly addresses brave/brave-browser#9652

Submitter Checklist:

Test Plan:

For initial verification that the approach works, need to:

  • Start the browser, enable SpeedReader, verify it works
  • Update the stylesheet, publish updated via crx pacakger
  • Trigger the component update via brave://components, verify version number has changed
  • Verify styling of rewritten content has changed

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.

@AndriusA AndriusA self-assigned this Jul 29, 2020
@AndriusA AndriusA changed the title Speedreader stylesheet Speedreader stylesheet from component updater Jul 30, 2020
@AndriusA
Copy link
Author

Only unrelated RewardsBrowserTest.NotVerifiedWallet test failing and already known issue with document.body not being available in browser test after reload

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.

++ Can't find any comments from my side.
I'll pass final approve to @iefremov :)

@@ -10,29 +10,22 @@
#include <utility>

#include "base/bind.h"
#include "base/files/file_path.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

these two are unneeded?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

if (speedreader::IsWhitelistedForTest(handle->GetURL()) ||
whitelist->IsWhitelisted(handle->GetURL())) {
rewriter_service->IsWhitelisted(handle->GetURL())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now it's not super clear why IsWhitelisted belongs to "rewriter" service. Maybe we could rename to something generic, like SpeedreaderService

Copy link
Author

Choose a reason for hiding this comment

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

I'd agree, but we already have SpeedreaderService that does a very different function of controlling/tracking when the feature is enabled/disabled. Here it isWhitelisted for rewriting, so made sense to be more specific

AndriusA added 3 commits August 3, 2020 14:32
Refactors SpeedReader to separate component updater hooks from business logic.
Splits SpeedreaderWhitelist into SpeedreaderComponent (for component management) and SpeedreaderRewriterService for the rewriter.
"//brave/components/resources:static_resources_grit",
"//brave/components/resources",
"//brave/components/weekly_storage",
Copy link
Author

Choose a reason for hiding this comment

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

previously missed, not picked up by gn check

// Used in testing/development with custom rule set for auto-reloading
void OnWhitelistFileReady(const base::FilePath& path, bool error);

base::ObserverList<Observer> observers_;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can simplify by just holding a raw pointer, given that the only observer by design is an actual owner

Copy link
Contributor

Choose a reason for hiding this comment

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

You actually can pass this pointer to Component constructor

Copy link
Author

Choose a reason for hiding this comment

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

thought of that, but went for a solution that better abstracts away the specifics of speedreader and attempts to follow a more decoupled pattern of using component updater.

Happy to couple them up more if you prefer?

Perhaps might be even better to initialise SpeedreaderComponent outside of the SpeedreaderRewriterService altogether and just subscribe the service? Didn't want to add too much to the browser process either

GetDATFileDataResult result) {
VLOG(2) << "Speedreader loaded from DAT file";
if (result.first)
speedreader_ = std::move(result.first);
Copy link
Contributor

Choose a reason for hiding this comment

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

given that in any case we load the whole thing from disk into memory, we could move all work with files / DAT stuff to the component and only get final results in this class. But this would make SpeedreaderComponent aware of rust "client", so also doesn't look neat

Copy link
Author

Choose a reason for hiding this comment

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

it was previously in the component, but this moves it closer to where it is used, and as a next step would allow to more straightforwardly unload both from memory when the feature is disabled independently of component handling

Copy link
Contributor

@iefremov iefremov left a comment

Choose a reason for hiding this comment

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

Great that SpeedreaderComponent and rewriter service are decoupled now!

@AndriusA AndriusA merged commit 4ba56a8 into master Aug 3, 2020
@AndriusA AndriusA deleted the speedreader-stylesheet branch August 3, 2020 15:19
@AndriusA AndriusA added this to the 1.14.x - Nightly milestone Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Desktop] load SpeedReader transformed content stylesheet from component updater
3 participants