Commit 16bb182f authored by Toby Huang's avatar Toby Huang Committed by Commit Bot

[Metrics] Fix DCHECK failure in FamilyUserMetricsProvider

Sometimes ProvideCurrentSessionData() gets called at a bad time when
the user has finished logging in but the user profile has not finished
loading. This scenario causes a DCHECK failure. This CL returns
prematurely if the user profile has not finished loading, and
retrieves the primary profile manually.

Bug: 1136561
Change-Id: Ibd4845b92c3284bd856f0a152618bb7abe5c44bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462632Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Toby Huang <tobyhuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816758}
parent 15ceed94
......@@ -15,10 +15,10 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
namespace {
......@@ -64,7 +64,12 @@ void FamilyUserMetricsProvider::ProvideCurrentSessionData(
return;
if (!IsLoggedIn())
return;
Profile* profile = ProfileManager::GetPrimaryUserProfile();
const user_manager::User* primary_user =
user_manager::UserManager::Get()->GetPrimaryUser();
if (!primary_user || !primary_user->is_profile_created())
return;
Profile* profile =
chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user);
DCHECK(profile);
DCHECK(chromeos::ProfileHelper::IsRegularProfile(profile));
signin::IdentityManager* identity_manager =
......
......@@ -94,6 +94,10 @@ IN_PROC_BROWSER_TEST_P(FamilyUserMetricsProviderTest, UserCategory) {
// This call should return prematurely.
provider.ProvideCurrentSessionData(/*uma_proto_unused=*/nullptr);
// No metrics were recorded.
histogram_tester.ExpectTotalCount(
FamilyUserMetricsProvider::kFamilyUserLogSegmentHistogramName, 0);
logged_in_user_mixin_.LogInUser();
const FamilyUserMetricsProvider::LogSegment log_segment = GetParam();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment