Skip to content

feat(ads-client): add data_dir support with context_id persistence#7221

Draft
Almaju wants to merge 1 commit intomozilla:mainfrom
Almaju:ads-client-data-dir
Draft

feat(ads-client): add data_dir support with context_id persistence#7221
Almaju wants to merge 1 commit intomozilla:mainfrom
Almaju:ads-client-data-dir

Conversation

@Almaju
Copy link
Contributor

@Almaju Almaju commented Feb 13, 2026

Introduce AdsClientBuilder with a data_dir option that allows the component to manage its own persistent files (cache DB, context_id) in a dedicated ads-client/ subdirectory.

Data dir resolution follows a fallback chain:

  1. Explicit data_dir provided via builder
  2. Parent directory of legacy cache_config.db_path
  3. $HOME environment variable (iOS, macOS, Linux, Windows)
  4. $APPDATA / $LOCALAPPDATA (Windows fallback)

When resolved, context_id is persisted to a file so the 3-day rotation actually works across app restarts (previously a fresh UUID was generated on every client init, making rotation meaningless).

Changes:

  • New client/builder.rs: AdsClientBuilder with all resolution, cache building, and context_id persistence logic
  • Simplified AdsClient::new() to accept pre-built components
  • Added try_build() to MozAdsClientBuilder (returns Result)
  • Deprecated build() in favor of try_build()
  • Added data_dir() method to MozAdsClientBuilder
  • Removed unused AdsCacheConfig and AdsClientConfig types
  • Added BuildError enum (NoDataDir, CreateDataDir)

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Introduce AdsClientBuilder with a data_dir option that allows the
component to manage its own persistent files (cache DB, context_id)
in a dedicated ads-client/ subdirectory.

Data dir resolution follows a fallback chain:
1. Explicit data_dir provided via builder
2. Parent directory of legacy cache_config.db_path
3. $HOME environment variable (iOS, macOS, Linux, Windows)
4. $APPDATA / $LOCALAPPDATA (Windows fallback)

When resolved, context_id is persisted to a file so the 3-day rotation
actually works across app restarts (previously a fresh UUID was generated
on every client init, making rotation meaningless).

Changes:
- New client/builder.rs: AdsClientBuilder with all resolution, cache
  building, and context_id persistence logic
- Simplified AdsClient::new() to accept pre-built components
- Added try_build() to MozAdsClientBuilder (returns Result)
- Deprecated build() in favor of try_build()
- Added data_dir() method to MozAdsClientBuilder
- Removed unused AdsCacheConfig and AdsClientConfig types
- Added BuildError enum (NoDataDir, CreateDataDir)
@Almaju Almaju requested a review from luc-lisi February 13, 2026 17:38
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.

1 participant