Skip to content

Migrate brave ads from rapidjson to base::Value #14176

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

Merged
merged 15 commits into from
Jul 22, 2022

Conversation

cdesouza-chromium
Copy link
Collaborator

@cdesouza-chromium cdesouza-chromium commented Jul 14, 2022

This change removes the use of rapidjson in the types used by brave ads
for serialisation/deserialisation. The overall model of how these types
worked has been kept, with ToValue()/FromValue() pairs being introduced
to replace the pervasive use of FromJson()/ToJson(), which was the
common approach with rapidjson.

Resolves brave/brave-browser#21759

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@cdesouza-chromium cdesouza-chromium requested review from a team as code owners July 14, 2022 10:21
@cdesouza-chromium cdesouza-chromium force-pushed the brave-ads-base-value-refactor branch 3 times, most recently from 73056cb to 2638c82 Compare July 19, 2022 13:01
@cdesouza-chromium cdesouza-chromium requested a review from a team as a code owner July 19, 2022 13:01
@cdesouza-chromium cdesouza-chromium force-pushed the brave-ads-base-value-refactor branch 5 times, most recently from 91ef2bb to 1485d1d Compare July 19, 2022 22:14
Copy link
Contributor

@AlexeyBarabash AlexeyBarabash left a comment

Choose a reason for hiding this comment

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

++ for sync change

@szilardszaloki szilardszaloki mentioned this pull request Jul 21, 2022
25 tasks
Copy link
Collaborator

@szilardszaloki szilardszaloki left a comment

Choose a reason for hiding this comment

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

Rewards changes LGTM.

Copy link
Collaborator

@tmancey tmancey left a comment

Choose a reason for hiding this comment

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

LGTM++

@cdesouza-chromium cdesouza-chromium force-pushed the brave-ads-base-value-refactor branch from 0b48805 to 32eb339 Compare July 21, 2022 20:47
cdesouza-chromium and others added 15 commits July 21, 2022 22:01
This change removes the use of rapidjson in the types used by brave ads
for serialisation/deserialisation. The overall model of how these types
worked has been kept, with ToValue()/FromValue() pairs being introduced
to replace the pervasive use of FromJson()/ToJson(), which was the
common approach with rapidjson.
This change migrates the existing rapidjson code to use base::Value.
Replacing rapidjson with base:Value has caused a few tests to fail to
recognise that the contents of the JSON object in question is still the
same.
This has been triggered by the CI for some reason, so it is being
submitted in a separate change for correction.
This change removes the use of deprecated base::Value methods in
QrCodeData.
This change removes the use of deprecated classes/methods from
base::Value in NotificationAdManager. It also replaces the use of
pointers alongside boundaries where a reference for the specific type
was more appropriate.
This change simplifies the implementation for StatementInfo, as well as
removes the use of deprecated interfaces from base::Value.
This changes removes the use of base::ListValue, and
base::DictionaryValue, as well as of the deprecated base::Value
interface for ConfirmationStateManager, and all its associated
dependencies, in favour of statically-typed interfaces.
This change removes the use of any deprecated methods/interfaces from
base::Value in EpsilonGreedyBanditArmMap.
This change removes the use of rapidjson, and of all depreacted classes,
and methods from base::Value, occuring in ClientProperty, and
WalletInfoProperty.

With the removal of rapidjson, it is not necessary anymore to have the
parsing process decoupled from the actual data types.
The contents of these two classes have been moved to be part of the
actual corresponding data structure they were used to parse. This also
removes the use of rapidjson for serialisation/deserialisation.

Additionally, base::Value modernisations have been applied to remove the
use of any deprecated methods/interfaces.
For the types used by brave ads and ledger which we have to serialise,
it is possible to have failure, although we don't expect to see it. This
change adds a check to the result, so we may catch any cases in which it
might be taking place.
@cdesouza-chromium cdesouza-chromium force-pushed the brave-ads-base-value-refactor branch from 32eb339 to ee39677 Compare July 21, 2022 21:06
@cdesouza-chromium cdesouza-chromium merged commit a4ad957 into master Jul 22, 2022
@cdesouza-chromium cdesouza-chromium deleted the brave-ads-base-value-refactor branch July 22, 2022 10:32
@github-actions github-actions bot added this to the 1.43.x - Nightly milestone Jul 22, 2022
@mkarolin
Copy link
Collaborator

@cdesouza-chromium is there an uplift to 1.42.x for this?

@cdesouza-chromium
Copy link
Collaborator Author

@mkarolin I haven't put one in. Would it be necessary?

@mkarolin
Copy link
Collaborator

@cdesouza-chromium cr104 will be uplifted to 1.42.x, I am seeing errors with base::DictionaryValue in AdsServiceImpl::OnGetInlineContentAd. Perhaps I can work around that particular one.

@mkarolin
Copy link
Collaborator

@cdesouza-chromium got around it, no need to uplift.

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.

Refactor Brave Ads base::ListValue type to base::Value type
5 participants