---
# System prepended metadata

title: UserType and Profile
tags: [Chromium-General, elkurin-daily-note]

---

# UserType and Profile

Today's goald is to understand the difference between [User::GetType](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.h;l=97;drc=ac5c909f35752226657bd1f9c0510fbdf6de3776) and [Profile::IsGuestSession](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile.h;l=424;drc=9914377b2843ace0beaa189ceb274c13152becdd).

## User type
[UserType](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user_type.h;l=18;drc=0cfb1b06652d6572895919e6564563a6761ca6fd) represents which kinds of user is.  
For example, `kGuest` representds the guest user, `kChild` represents the supervised user, and `kKioskApp` represents the Kiosk user whihc is used to launch applications in a single app mode without authentication.

Each [User](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.h;l=55;drc=ac5c909f35752226657bd1f9c0510fbdf6de3776) objects has single `type_`, and this is visible from outside via [User::GetType](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.h;l=97;drc=ac5c909f35752226657bd1f9c0510fbdf6de3776).  

`type_` is set on [construction](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.cc;l=61;drc=0cfb1b06652d6572895919e6564563a6761ca6fd) or from [User::UpdateType](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.cc;l=120;drc=0cfb1b06652d6572895919e6564563a6761ca6fd).  
This is only used from [UserLoggedIn](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user_manager_base.cc;l=188;drc=4384ef7d38df3d8e68691fe435c20544a0d7b744) with the user type of `kRegular` or `kChild`.  

By the way, `user_type` we are refering to inside [UserLoggedIn](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user_manager_base.cc;l=188;drc=4384ef7d38df3d8e68691fe435c20544a0d7b744) is computed from [CalculateUserType](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user_manager.cc;l=111;drc=0cfb1b06652d6572895919e6564563a6761ca6fd) using accoun id and user object. If the account id is the same as [`kGuestUserName`](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user_names.cc;l=58;drc=0cfb1b06652d6572895919e6564563a6761ca6fd), we consider the user is in guest mode.  
Guest user is created by calling [User::CreateGuestUser](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.cc;l=268;drc=0cfb1b06652d6572895919e6564563a6761ca6fd) with `type_` initialized as `UserType::kGuest`.  

## Profile guest session
From peofile, you check whether it's guest session or not by [Profile::IsGuestSession](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile.cc;l=401;drc=0fee5e14e040b7d974c662009faaec47ae033855) whoes implementation is like this:
```cpp!
bool Profile::IsGuestSession() const {
#if BUILDFLAG(IS_CHROMEOS_ASH)
  static bool is_guest_session =
      base::CommandLine::ForCurrentProcess()->HasSwitch(
          ash::switches::kGuestSession);
  return is_guest_session;
#else
#if BUILDFLAG(IS_CHROMEOS_LACROS)
  if (chromeos::BrowserParamsProxy::Get()->SessionType() ==
      crosapi::mojom::SessionType::kGuestSession) {
    return true;
  }
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)
  return profile_metrics::GetBrowserProfileType(this) ==
         profile_metrics::BrowserProfileType::kGuest;
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
}
```

For Ash, it checks the command line flag.  
For Lacros, it gets the session type from [BrowserParamsProxy](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/startup/browser_params_proxy.cc;l=49;drc=0fee5e14e040b7d974c662009faaec47ae033855) which stores the startup or postlogin data.  
For other, and also for TestingProfile, it compares with [GetBrowserProfileType](https://source.chromium.org/chromium/chromium/src/+/main:components/profile_metrics/browser_profile_type.cc;l=43;drc=0fee5e14e040b7d974c662009faaec47ae033855).  
This [BrowserProfileType](https://source.chromium.org/chromium/chromium/src/+/main:components/profile_metrics/browser_profile_type.h;l=18;drc=0fee5e14e040b7d974c662009faaec47ae033855) is stored in [ProfileTypeUserData](https://source.chromium.org/chromium/chromium/src/+/main:components/profile_metrics/browser_profile_type.cc;l=15;drc=0fee5e14e040b7d974c662009faaec47ae033855) that is tied with SupportsUserData. This is inheritted by [content::BrowserContext](https://source.chromium.org/chromium/chromium/src/+/main:content/public/browser/browser_context.h;l=108;drc=c686e8f4fd379312469fe018f5c390e9c8f20d0d) which corresponds to Profile in component/.

Why Ash refers to command line instead of GetBrowserProfileType?  
In my understanding, it's because the guest session condition depends on the browser's account for other platforms but not for ChromeOS. On Ash, you should refer to the account you logged in to the device, not the curret browser.  

## UserType and Command Line
Conceptually, UserType for the primary user should be `kGuest` if it has `kGuestSession` switch.

Profile path is taken from [ProfileManager::GetInitialProfileDir](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile_manager.cc;l=811;drc=0cfb1b06652d6572895919e6564563a6761ca6fd) for initial launch.  
It calls [GetUserBrowserContextDirName](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ash/components/browser_context_helper/browser_context_helper.cc;l=157;drc=0cfb1b06652d6572895919e6564563a6761ca6fd) against the current active user's username hash to get the path if you are already logged in.  
If the user has not yet logged in, it creates the initial profile which is [Default](https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/chrome_constants.cc;l=109;drc=0cfb1b06652d6572895919e6564563a6761ca6fd).  

So, if the user has already logged in as Guest user, then the profile path would be guest dir and it will creates the profile with Guest which sets GetBrowserProfileType as kGuest.  

## Conclusion
Checking command line for Profile::IsGuestSession looks incorrect? 