PHANTOM
🇮🇳 IN
Skip to content

Add credential manager to AIChatMetrics#34201

Open
DJAndries wants to merge 1 commit intomasterfrom
ai-chat-metrics-fix
Open

Add credential manager to AIChatMetrics#34201
DJAndries wants to merge 1 commit intomasterfrom
ai-chat-metrics-fix

Conversation

@DJAndries
Copy link
Collaborator

@DJAndries DJAndries requested a review from a team February 25, 2026 23:39
@DJAndries DJAndries requested a review from a team as a code owner February 25, 2026 23:39
@github-actions
Copy link
Contributor

📋 Code Owners Summary

8 file(s) changed, 1 with assigned owners

1 team(s) affected: @brave/brave-core-owners


Owners and Their Files

@brave/brave-core-owners — 1 file(s)

#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "base/timer/wall_clock_timer.h"
#include "brave/components/ai_chat/core/browser/ai_chat_credential_manager.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

AIChatCredentialManager is only used via std::unique_ptr in this header, and ~AIChatMetrics() is defined in the .cc file. A forward declaration would suffice here and avoid pulling in heavy transitive includes from ai_chat_credential_manager.h (skus mojom, mojo remote/remote_set headers). Move the full #include to the .cc file. best practice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we were including headers from another non-base target, I would agree, but this sort of include is quite ubiquitous.

raw_ptr<PrefService> local_state_;
raw_ptr<PrefService> profile_prefs_;

std::unique_ptr<AIChatCredentialManager> credential_manager_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: credential_manager_ is an owning unique_ptr placed after the non-owning raw_ptr<PrefService> members. Per convention, owning members should come before unowned raw_ptr members to make ownership semantics visually clear. Consider grouping it with the other unique_ptr members (tab_focus_metrics_, skills_metrics_) below. best practice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Curious how this guideline came about. Is this an upstream code style matter?

Copy link
Member

Choose a reason for hiding this comment

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

It's from https://chromium.googlesource.com/chromium/src/+/lkgr/docs/dangling_ptr_guide.md
It recommends placing owning members (std::unique_ptr, scoped_refptr) before unowned members (raw_ptr)

The rationale is about destruction safety: C++ destroys members in reverse declaration order, so placing raw_ptr members last means they are destroyed first. Before the owning members they may reference are freed. This prevents dangling pointer issues.

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.

Leo metric reporting delayed on Android startup

3 participants