Skip to content

Make the UserAgent class a Singleton #21794

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 4 commits into from
Apr 11, 2025
Merged

Conversation

nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Apr 10, 2025

This small PR changes the UserAgent class to a singleton and uses a private setter for the user agent string. This was initially done as part of #21681, which retrieved the default user agent in the background, but after discussion it was decided this could cause more problems than it solves.

Note the reason for the previous PR was there is some overhead to calling WebSettings.getDefaultUserAgent() because as described here, the first time that's called requires loading WebView code. This PR doesn't address that overhead, but making the class a singleton gets us a step closer.

Also note avoiding calling WebSettings.getDefaultUserAgent() at startup so the delay isn't so noticeable isn't a solution since we set the user agent for our RestClientUtils here.

I'm not sure of testing steps, other than to verify that the correct user agent is being returned.

@dangermattic
Copy link
Collaborator

dangermattic commented Apr 10, 2025

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 10, 2025

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21794-33637e5
Commit33637e5
Direct Downloadjetpack-prototype-build-pr21794-33637e5.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 10, 2025

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21794-33637e5
Commit33637e5
Direct Downloadwordpress-prototype-build-pr21794-33637e5.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.32%. Comparing base (a9219ef) to head (33637e5).
Report is 3 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #21794   +/-   ##
=======================================
  Coverage   39.32%   39.32%           
=======================================
  Files        2125     2125           
  Lines       99871    99871           
  Branches    15385    15385           
=======================================
  Hits        39277    39277           
  Misses      57114    57114           
  Partials     3480     3480           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nbradbury nbradbury requested a review from dcalhoun April 10, 2025 12:52
@nbradbury nbradbury marked this pull request as ready for review April 10, 2025 13:25
Copy link

Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

I verified the user agent sent in Reader requests matched before and after these changes.

@nbradbury nbradbury merged commit aee2520 into trunk Apr 11, 2025
26 checks passed
@nbradbury nbradbury deleted the issue/user-agent-singleton branch April 11, 2025 14:28
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.

4 participants