-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add credential manager to AIChatMetrics
#34201
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,11 @@ | |
| #include <string> | ||
|
|
||
| #include "base/containers/flat_map.h" | ||
| #include "base/functional/callback.h" | ||
| #include "base/memory/raw_ptr.h" | ||
| #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" | ||
| #include "brave/components/ai_chat/core/browser/ai_chat_tab_focus_metrics.h" | ||
| #include "brave/components/ai_chat/core/browser/skills_metrics.h" | ||
| #include "brave/components/ai_chat/core/common/mojom/ai_chat.mojom.h" | ||
|
|
@@ -135,10 +135,9 @@ class AIChatMetrics : public mojom::Metrics, | |
| public AIChatTabFocusMetrics::Delegate, | ||
| public SkillsMetrics::Delegate { | ||
| public: | ||
| using RetrievePremiumStatusCallback = | ||
| base::OnceCallback<void(mojom::Service::GetPremiumStatusCallback)>; | ||
|
|
||
| AIChatMetrics(PrefService* local_state, PrefService* profile_prefs); | ||
| AIChatMetrics(PrefService* local_state, | ||
| PrefService* profile_prefs, | ||
| std::unique_ptr<AIChatCredentialManager> credential_manager); | ||
| ~AIChatMetrics() override; | ||
|
|
||
| AIChatMetrics(const AIChatMetrics&) = delete; | ||
|
|
@@ -152,10 +151,7 @@ class AIChatMetrics : public mojom::Metrics, | |
| return tab_focus_metrics_.get(); | ||
| } | ||
|
|
||
| void RecordEnabled( | ||
| bool is_enabled, | ||
| bool is_new_user, | ||
| RetrievePremiumStatusCallback retrieve_premium_status_callback); | ||
| void RecordEnabled(bool is_new_user); | ||
| void RecordReset(); | ||
|
|
||
| void RecordNewPrompt(ConversationHandlerForMetrics* handler, | ||
|
|
@@ -174,10 +170,6 @@ class AIChatMetrics : public mojom::Metrics, | |
| void RecordFullPageSwitch(); | ||
| #endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) | ||
|
|
||
| void OnPremiumStatusUpdated(bool is_enabled, | ||
| bool is_new_user, | ||
| mojom::PremiumStatus premium_status, | ||
| mojom::PremiumInfoPtr); | ||
| void MaybeRecordLastError(ConversationHandlerForMetrics* handler); | ||
|
|
||
| // Metrics: | ||
|
|
@@ -209,6 +201,13 @@ class AIChatMetrics : public mojom::Metrics, | |
| void ReportFullPageUsageMetric(); | ||
| #endif // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) | ||
|
|
||
| // If is_new_user is provided, RecordEnabled will be called after the check. | ||
| bool MaybeUpdatePremiumStatus(std::optional<bool> is_new_user); | ||
|
|
||
| void OnPremiumStatusUpdated(std::optional<bool> is_new_user, | ||
| mojom::PremiumStatus premium_status, | ||
| mojom::PremiumInfoPtr); | ||
|
|
||
| void MaybeReportFirstChatPrompts(bool new_prompt_made); | ||
| void RecordContextSource(ConversationHandlerForMetrics* handler, | ||
| mojom::ConversationTurnPtr& entry); | ||
|
|
@@ -252,6 +251,8 @@ class AIChatMetrics : public mojom::Metrics, | |
| raw_ptr<PrefService> local_state_; | ||
| raw_ptr<PrefService> profile_prefs_; | ||
|
|
||
| std::unique_ptr<AIChatCredentialManager> credential_manager_; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 The rationale is about destruction safety: C++ destroys members in reverse declaration order, so placing |
||
|
|
||
| mojo::ReceiverSet<mojom::Metrics> receivers_; | ||
|
|
||
| std::unique_ptr<AIChatTabFocusMetrics> tab_focus_metrics_; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AIChatCredentialManageris only used viastd::unique_ptrin this header, and~AIChatMetrics()is defined in the.ccfile. A forward declaration would suffice here and avoid pulling in heavy transitive includes fromai_chat_credential_manager.h(skus mojom, mojo remote/remote_set headers). Move the full#includeto the.ccfile. best practiceThere was a problem hiding this comment.
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.