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() ...@@ -368,11 +368,11 @@ ChromeUserManagerImpl::ChromeUserManagerImpl()
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DeviceSettingsService::Get()->AddObserver(this); 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, registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources()); 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. // Since we're in ctor postpone any actions till this is fully created.
if (base::ThreadTaskRunnerHandle::IsSet()) { if (base::ThreadTaskRunnerHandle::IsSet()) {
...@@ -431,6 +431,8 @@ ChromeUserManagerImpl::ChromeUserManagerImpl() ...@@ -431,6 +431,8 @@ ChromeUserManagerImpl::ChromeUserManagerImpl()
} }
ChromeUserManagerImpl::~ChromeUserManagerImpl() { ChromeUserManagerImpl::~ChromeUserManagerImpl() {
if (g_browser_process->profile_manager())
g_browser_process->profile_manager()->RemoveObserver(this);
if (DeviceSettingsService::IsInitialized()) if (DeviceSettingsService::IsInitialized())
DeviceSettingsService::Get()->RemoveObserver(this); DeviceSettingsService::Get()->RemoveObserver(this);
} }
...@@ -632,45 +634,21 @@ void ChromeUserManagerImpl::Observe( ...@@ -632,45 +634,21 @@ void ChromeUserManagerImpl::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { DCHECK_EQ(type, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED);
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: { Profile* profile = content::Details<Profile>(details).ptr();
Profile* profile = content::Details<Profile>(details).ptr(); if (IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsKioskApp() &&
if (IsUserLoggedIn() && !IsLoggedInAsGuest() && !IsLoggedInAsKioskApp() && !IsLoggedInAsArcKioskApp()) {
!IsLoggedInAsArcKioskApp()) { if (!profile->IsOffTheRecord()) {
if (!profile->IsOffTheRecord()) { if (AuthSyncObserver::ShouldObserve(profile)) {
if (AuthSyncObserver::ShouldObserve(profile)) { AuthSyncObserver* sync_observer =
AuthSyncObserver* sync_observer = AuthSyncObserverFactory::GetInstance()->GetForProfile(profile);
AuthSyncObserverFactory::GetInstance()->GetForProfile(profile); sync_observer->StartObserving();
sync_observer->StartObserving();
}
multi_profile_user_controller_->StartObserving(profile);
}
} }
system::UpdateSystemTimezone(profile); multi_profile_user_controller_->StartObserving(profile);
UpdateUserTimeZoneRefresher(profile);
break;
} }
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() { void ChromeUserManagerImpl::OwnershipStatusChanged() {
...@@ -1314,6 +1292,22 @@ void ChromeUserManagerImpl::OnMinimumVersionStateChanged() { ...@@ -1314,6 +1292,22 @@ void ChromeUserManagerImpl::OnMinimumVersionStateChanged() {
NotifyUsersSignInConstraintsChanged(); 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( bool ChromeUserManagerImpl::IsUserAllowed(
const user_manager::User& user) const { const user_manager::User& user) const {
DCHECK(user.GetType() == user_manager::USER_TYPE_REGULAR || DCHECK(user.GetType() == user_manager::USER_TYPE_REGULAR ||
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "chrome/browser/chromeos/policy/minimum_version_policy_handler.h" #include "chrome/browser/chromeos/policy/minimum_version_policy_handler.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.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/account_id/account_id.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
...@@ -60,6 +61,7 @@ class ChromeUserManagerImpl ...@@ -60,6 +61,7 @@ class ChromeUserManagerImpl
public DeviceSettingsService::Observer, public DeviceSettingsService::Observer,
public policy::DeviceLocalAccountPolicyService::Observer, public policy::DeviceLocalAccountPolicyService::Observer,
public policy::MinimumVersionPolicyHandler::Observer, public policy::MinimumVersionPolicyHandler::Observer,
public ProfileManagerObserver,
public MultiProfileUserControllerDelegate { public MultiProfileUserControllerDelegate {
public: public:
~ChromeUserManagerImpl() override; ~ChromeUserManagerImpl() override;
...@@ -112,28 +114,31 @@ class ChromeUserManagerImpl ...@@ -112,28 +114,31 @@ class ChromeUserManagerImpl
std::string* out_resolved_locale) const override; std::string* out_resolved_locale) const override;
bool IsValidDefaultUserImageId(int image_index) const override; bool IsValidDefaultUserImageId(int image_index) const override;
// content::NotificationObserver implementation. // content::NotificationObserver.
void Observe(int type, void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override; const content::NotificationDetails& details) override;
// DeviceSettingsService::Observer implementation: // DeviceSettingsService::Observer:
void OwnershipStatusChanged() override; void OwnershipStatusChanged() override;
// policy::DeviceLocalAccountPolicyService::Observer implementation. // policy::DeviceLocalAccountPolicyService::Observer:
void OnPolicyUpdated(const std::string& user_id) override; void OnPolicyUpdated(const std::string& user_id) override;
void OnDeviceLocalAccountsChanged() override; void OnDeviceLocalAccountsChanged() override;
void StopPolicyObserverForTesting(); void StopPolicyObserverForTesting();
// policy::MinimumVersionPolicyHandler::Observer implementation. // policy::MinimumVersionPolicyHandler::Observer:
void OnMinimumVersionStateChanged() override; void OnMinimumVersionStateChanged() override;
// UserManagerBase implementation: // ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override;
// UserManagerBase:
bool AreEphemeralUsersEnabled() const override; bool AreEphemeralUsersEnabled() const override;
void OnUserRemoved(const AccountId& account_id) override; void OnUserRemoved(const AccountId& account_id) override;
// ChromeUserManager implementation: // ChromeUserManager:
bool IsEnterpriseManaged() const override; bool IsEnterpriseManaged() const override;
void SetUserAffiliation( void SetUserAffiliation(
const AccountId& account_id, 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