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

encapsulate rust json code in cpp #25975

Merged
merged 3 commits into from
Oct 15, 2024
Merged

encapsulate rust json code in cpp #25975

merged 3 commits into from
Oct 15, 2024

Conversation

bridiver
Copy link
Collaborator

@bridiver bridiver commented Oct 14, 2024

Resolves brave/brave-browser#41497

The original fix for 41497 was a workaround while we investigated the underlying issue

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • 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 wiki
    • npm run presubmit wiki, 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:

Copy link
Contributor

[puLL-Merge] - brave/brave-core@25975

Description

This PR refactors the JSON handling in the Brave Wallet component, moving from direct use of Rust-based JSON functions to a C++ wrapper. It introduces a new json component with a C++ interface, which internally uses the existing Rust implementation. This change aims to improve code organization and provide a more idiomatic C++ interface for JSON operations throughout the codebase.

Changes

Changes

  1. components/json/BUILD.gn:

    • Added a new json component target.
    • Updated the unit test dependencies.
  2. components/json/json_export.h:

    • New file defining export macros for the JSON component.
  3. components/json/json_helper.cc and components/json/json_helper.h:

    • New files implementing C++ wrapper functions for JSON operations.
  4. components/json/json_parser_unittest.cc:

    • Updated to use the new C++ interface instead of direct Rust calls.
  5. components/json/rs/BUILD.gn:

    • Updated visibility to restrict access to the Rust implementation.
  6. components/json/rs/src/lib.rs:

    • Changed the namespace of the Rust functions to rust_json.
  7. Multiple files in components/brave_wallet/browser/:

    • Updated to use the new json_helper.h instead of directly including the Rust implementation.
  8. components/brave_wallet/browser/BUILD.gn:

    • Updated dependencies to use the new json component.

Possible Issues

  1. There might be a slight performance overhead due to the additional C++ wrapper layer.
  2. The change is extensive and touches many files, which could potentially introduce subtle bugs if not thoroughly tested.

Security Hotspots

No significant security hotspots were identified. The changes primarily involve refactoring existing functionality rather than introducing new security-sensitive code. However, careful review of the JSON parsing and conversion functions is always recommended to ensure they handle edge cases and malformed input correctly.

@bridiver bridiver force-pushed the encapsulate-json-component branch from dbf9238 to e26b358 Compare October 14, 2024 20:16
@darkdh darkdh self-requested a review October 15, 2024 17:02
Copy link
Member

@darkdh darkdh left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Collaborator

@DJAndries DJAndries left a comment

Choose a reason for hiding this comment

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

rust++

@bridiver bridiver merged commit a327ced into master Oct 15, 2024
18 of 19 checks passed
@bridiver bridiver deleted the encapsulate-json-component branch October 15, 2024 17:26
@github-actions github-actions bot added this to the 1.73.x - Nightly milestone Oct 15, 2024
@brave-builds
Copy link
Collaborator

Released in v1.73.14

@bsclifton bsclifton modified the milestones: 1.73.x - Nightly, 1.74.x - Nightly Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants