diff --git a/components/ai_chat/core/browser/ai_chat_service.cc b/components/ai_chat/core/browser/ai_chat_service.cc index d540c91c94b9..905e25f8de34 100644 --- a/components/ai_chat/core/browser/ai_chat_service.cc +++ b/components/ai_chat/core/browser/ai_chat_service.cc @@ -500,18 +500,8 @@ void AIChatService::OnConversationEntryAdded( CHECK(conversation_it != conversations_.end()); mojom::ConversationPtr& conversation = conversation_it->second; - auto& history = handler->GetConversationHistory(); - - if (!conversation->has_content && history.size() > 0) { + if (!conversation->has_content) { HandleFirstEntry(handler, entry, associated_content_value, conversation); - if (ai_chat_metrics_ != nullptr) { - if (handler->GetConversationHistory().size() == 1) { - ai_chat_metrics_->RecordNewChat(); - } - if (entry->character_type == mojom::CharacterType::HUMAN) { - ai_chat_metrics_->RecordNewPrompt(); - } - } } else { HandleNewEntry(handler, entry, associated_content_value, conversation); } @@ -546,6 +536,12 @@ void AIChatService::HandleFirstEntry( entry->Clone()) .Then(std::move(on_conversation_added)); } + // Record metrics + if (ai_chat_metrics_ != nullptr) { + if (handler->GetConversationHistory().size() == 1) { + ai_chat_metrics_->RecordNewChat(); + } + } } void AIChatService::HandleNewEntry( @@ -586,6 +582,12 @@ void AIChatService::HandleNewEntry( .Then(std::move(on_content_updated)); } } + + // Record metrics + if (ai_chat_metrics_ != nullptr && + entry->character_type == mojom::CharacterType::HUMAN) { + ai_chat_metrics_->RecordNewPrompt(); + } } void AIChatService::OnConversationEntryRemoved(ConversationHandler* handler,