Commit 6cb96e83 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

ChromeUserManagerImpl: don't use NOTIFICATION_PROFILE_ADDED

Instead use OnProfileAdded

Bug: 268984
Change-Id: I733936856f025703272724349de3447aa5313dae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793930Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695380}
parent 8f0814e9
......@@ -368,11 +368,11 @@ ChromeUserManagerImpl::ChromeUserManagerImpl()
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DeviceSettingsService::Get()->AddObserver(this);
if (g_browser_process->profile_manager())
g_browser_process->profile_manager()->AddObserver(this);
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
content::NotificationService::AllSources());
// Since we're in ctor postpone any actions till this is fully created.
if (base::ThreadTaskRunnerHandle::IsSet()) {
......@@ -431,6 +431,8 @@ ChromeUserManagerImpl::ChromeUserManagerImpl()
}
ChromeUserManagerImpl::~ChromeUserManagerImpl() {
if (g_browser_process->profile_manager())
g_browser_process->profile_manager()->RemoveObserver(this);
if (DeviceSettingsService::IsInitialized())
DeviceSettingsService::Get()->RemoveObserver(this);
}
......@@ -632,45 +634,21 @@ void ChromeUserManagerImpl::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
Profile* profile = content::Details<Profile>(details).ptr();
if (IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsKioskApp() &&
!IsLoggedInAsArcKioskApp()) {
if (!profile->IsOffTheRecord()) {
if (AuthSyncObserver::ShouldObserve(profile)) {
AuthSyncObserver* sync_observer =
AuthSyncObserverFactory::GetInstance()->GetForProfile(profile);
sync_observer->StartObserving();
}
multi_profile_user_controller_->StartObserving(profile);
}
DCHECK_EQ(type, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED);
Profile* profile = content::Details<Profile>(details).ptr();
if (IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsKioskApp() &&
!IsLoggedInAsArcKioskApp()) {
if (!profile->IsOffTheRecord()) {
if (AuthSyncObserver::ShouldObserve(profile)) {
AuthSyncObserver* sync_observer =
AuthSyncObserverFactory::GetInstance()->GetForProfile(profile);
sync_observer->StartObserving();
}
system::UpdateSystemTimezone(profile);
UpdateUserTimeZoneRefresher(profile);
break;
multi_profile_user_controller_->StartObserving(profile);
}
case chrome::NOTIFICATION_PROFILE_ADDED: {
Profile* profile = content::Source<Profile>(source).ptr();
user_manager::User* user =
ProfileHelper::Get()->GetUserByProfile(profile);
if (user != NULL) {
user->SetProfileIsCreated();
if (user->HasGaiaAccount())
GetUserImageManager(user->GetAccountId())->UserProfileCreated();
}
// If there is pending user switch, do it now.
if (GetPendingUserSwitchID().is_valid()) {
SwitchActiveUser(GetPendingUserSwitchID());
SetPendingUserSwitchId(EmptyAccountId());
}
break;
}
default:
NOTREACHED();
}
system::UpdateSystemTimezone(profile);
UpdateUserTimeZoneRefresher(profile);
}
void ChromeUserManagerImpl::OwnershipStatusChanged() {
......@@ -1314,6 +1292,22 @@ void ChromeUserManagerImpl::OnMinimumVersionStateChanged() {
NotifyUsersSignInConstraintsChanged();
}
void ChromeUserManagerImpl::OnProfileAdded(Profile* profile) {
user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
if (user) {
user->SetProfileIsCreated();
if (user->HasGaiaAccount())
GetUserImageManager(user->GetAccountId())->UserProfileCreated();
}
// If there is pending user switch, do it now.
if (GetPendingUserSwitchID().is_valid()) {
SwitchActiveUser(GetPendingUserSwitchID());
SetPendingUserSwitchId(EmptyAccountId());
}
}
bool ChromeUserManagerImpl::IsUserAllowed(
const user_manager::User& user) const {
DCHECK(user.GetType() == user_manager::USER_TYPE_REGULAR ||
......
......@@ -27,6 +27,7 @@
#include "chrome/browser/chromeos/policy/minimum_version_policy_handler.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/user.h"
#include "content/public/browser/notification_observer.h"
......@@ -60,6 +61,7 @@ class ChromeUserManagerImpl
public DeviceSettingsService::Observer,
public policy::DeviceLocalAccountPolicyService::Observer,
public policy::MinimumVersionPolicyHandler::Observer,
public ProfileManagerObserver,
public MultiProfileUserControllerDelegate {
public:
~ChromeUserManagerImpl() override;
......@@ -112,28 +114,31 @@ class ChromeUserManagerImpl
std::string* out_resolved_locale) const override;
bool IsValidDefaultUserImageId(int image_index) const override;
// content::NotificationObserver implementation.
// content::NotificationObserver.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// DeviceSettingsService::Observer implementation:
// DeviceSettingsService::Observer:
void OwnershipStatusChanged() override;
// policy::DeviceLocalAccountPolicyService::Observer implementation.
// policy::DeviceLocalAccountPolicyService::Observer:
void OnPolicyUpdated(const std::string& user_id) override;
void OnDeviceLocalAccountsChanged() override;
void StopPolicyObserverForTesting();
// policy::MinimumVersionPolicyHandler::Observer implementation.
// policy::MinimumVersionPolicyHandler::Observer:
void OnMinimumVersionStateChanged() override;
// UserManagerBase implementation:
// ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override;
// UserManagerBase:
bool AreEphemeralUsersEnabled() const override;
void OnUserRemoved(const AccountId& account_id) override;
// ChromeUserManager implementation:
// ChromeUserManager:
bool IsEnterpriseManaged() const override;
void SetUserAffiliation(
const AccountId& account_id,
......
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