Commit 3e80dd3c authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove some instances of NOTIFICATION_SESSION_STARTED

This patch changes SessionManagerObserver::OnPrimaryUserSessionStarted
to notify for non-primary user sessions as well. This makes it align
with NOTIFICATION_SESSION_STARTED.

Two notification observers are updated:
- LocaleChangeGuard
- first_run.cc (some dead code is also deleted)

On[Primary]UserSessionStarted(), and NOTIFICATION_SESSION_STARTED,
are different from UserSessionStateObserver::OnActiveUserChanged
in that they are called when the UI is fully ready. This is appropriate
for the two observers that are updated in this CL, both of which want
to show UI right after login.

Bug: 268984

Change-Id: Iac5ba9541e99a74a29758db6e3c678e1dcbfa630
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767494Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690074}
parent 455a5779
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "chrome/browser/apps/app_service/app_launch_params.h" #include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_service.h" #include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/first_run/first_run_controller.h" #include "chrome/browser/chromeos/first_run/first_run_controller.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h"
...@@ -25,17 +24,17 @@ ...@@ -25,17 +24,17 @@
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/login/login_state/login_state.h"
#include "components/arc/arc_prefs.h" #include "components/arc/arc_prefs.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
...@@ -106,34 +105,25 @@ void TryLaunchFirstRunDialog(Profile* profile) { ...@@ -106,34 +105,25 @@ void TryLaunchFirstRunDialog(Profile* profile) {
// Object of this class waits for session start. Then it launches or not // Object of this class waits for session start. Then it launches or not
// launches first-run dialog depending on user prefs and flags. Than object // launches first-run dialog depending on user prefs and flags. Than object
// deletes itself. // deletes itself.
class DialogLauncher : public content::NotificationObserver { class DialogLauncher : public session_manager::SessionManagerObserver {
public: public:
explicit DialogLauncher(Profile* profile) DialogLauncher() {
: profile_(profile) { session_manager::SessionManager::Get()->AddObserver(this);
DCHECK(profile);
registrar_.Add(this,
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
} }
~DialogLauncher() override {} ~DialogLauncher() override {
session_manager::SessionManager::Get()->RemoveObserver(this);
void Observe(int type, }
const content::NotificationSource& source,
const content::NotificationDetails& details) override {
DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED);
DCHECK(content::Details<const user_manager::User>(details).ptr() ==
ProfileHelper::Get()->GetUserByProfile(profile_));
TryLaunchFirstRunDialog(profile_);
// session_manager::SessionManagerObserver:
void OnUserSessionStarted(bool is_primary_user) override {
auto* profile = ProfileHelper::Get()->GetProfileByUser(
user_manager::UserManager::Get()->GetActiveUser());
TryLaunchFirstRunDialog(profile);
delete this; delete this;
} }
private: private:
Profile* profile_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(DialogLauncher); DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
}; };
...@@ -147,13 +137,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { ...@@ -147,13 +137,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
} }
void MaybeLaunchDialogAfterSessionStart() { void MaybeLaunchDialogAfterSessionStart() {
new DialogLauncher(ProfileHelper::Get()->GetProfileByUserUnsafe( new DialogLauncher();
user_manager::UserManager::Get()->GetActiveUser()));
}
void MaybeLaunchDialogImmediately() {
TryLaunchFirstRunDialog(ProfileHelper::Get()->GetProfileByUser(
user_manager::UserManager::Get()->GetActiveUser()));
} }
void LaunchTutorial() { void LaunchTutorial() {
......
...@@ -15,11 +15,6 @@ namespace first_run { ...@@ -15,11 +15,6 @@ namespace first_run {
// Registers preferences related to ChromeOS first-run tutorial. // Registers preferences related to ChromeOS first-run tutorial.
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// Launches the first-run dialog, based on synced user prefs. Unlike
// MaybeLaunchDialogAfterSessionStart, this function can launch the dialog
// at any point instead of just before session start.
void MaybeLaunchDialogImmediately();
// Probably launches first-run dialog after session start depending on synced // Probably launches first-run dialog after session start depending on synced
// user prefs. This method should be called after user already logged in but // user prefs. This method should be called after user already logged in but
// session didn't started yet. // session didn't started yet.
......
...@@ -43,11 +43,7 @@ const char* const kSkipShowNotificationLanguages[4] = {"en", "de", "fr", "it"}; ...@@ -43,11 +43,7 @@ const char* const kSkipShowNotificationLanguages[4] = {"en", "de", "fr", "it"};
} // anonymous namespace } // anonymous namespace
LocaleChangeGuard::LocaleChangeGuard(Profile* profile) LocaleChangeGuard::LocaleChangeGuard(Profile* profile) : profile_(profile) {
: profile_(profile),
reverted_(false),
session_started_(false),
main_frame_loaded_(false) {
DCHECK(profile_); DCHECK(profile_);
DeviceSettingsService::Get()->AddObserver(this); DeviceSettingsService::Get()->AddObserver(this);
} }
...@@ -58,16 +54,13 @@ LocaleChangeGuard::~LocaleChangeGuard() { ...@@ -58,16 +54,13 @@ LocaleChangeGuard::~LocaleChangeGuard() {
} }
void LocaleChangeGuard::OnLogin() { void LocaleChangeGuard::OnLogin() {
registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, session_observer_.Add(session_manager::SessionManager::Get());
content::NotificationService::AllSources());
registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllBrowserContextsAndSources()); content::NotificationService::AllBrowserContextsAndSources());
} }
void LocaleChangeGuard::RevertLocaleChange() { void LocaleChangeGuard::RevertLocaleChange() {
if (profile_ == NULL || if (from_locale_.empty() || to_locale_.empty()) {
from_locale_.empty() ||
to_locale_.empty()) {
NOTREACHED(); NOTREACHED();
return; return;
} }
...@@ -75,44 +68,30 @@ void LocaleChangeGuard::RevertLocaleChange() { ...@@ -75,44 +68,30 @@ void LocaleChangeGuard::RevertLocaleChange() {
return; return;
reverted_ = true; reverted_ = true;
base::RecordAction(UserMetricsAction("LanguageChange_Revert")); base::RecordAction(UserMetricsAction("LanguageChange_Revert"));
profile_->ChangeAppLocale( profile_->ChangeAppLocale(from_locale_,
from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); Profile::APP_LOCALE_CHANGED_VIA_REVERT);
chrome::AttemptUserExit(); chrome::AttemptUserExit();
} }
void LocaleChangeGuard::Observe(int type, void LocaleChangeGuard::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (profile_ == NULL) { DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
NOTREACHED(); if (profile_ != content::Source<WebContents>(source)->GetBrowserContext())
return; return;
}
switch (type) { main_frame_loaded_ = true;
case chrome::NOTIFICATION_SESSION_STARTED: { // We need to perform locale change check only once, so unsubscribe.
session_started_ = true; registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
registrar_.Remove(this, chrome::NOTIFICATION_SESSION_STARTED, content::NotificationService::AllSources());
content::NotificationService::AllSources()); if (session_manager::SessionManager::Get()->IsSessionStarted())
if (main_frame_loaded_) Check();
Check(); }
break;
} void LocaleChangeGuard::OnUserSessionStarted(bool is_primary_user) {
case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { session_observer_.RemoveAll();
if (profile_ == if (main_frame_loaded_)
content::Source<WebContents>(source)->GetBrowserContext()) { Check();
main_frame_loaded_ = true;
// We need to perform locale change check only once, so unsubscribe.
registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
if (session_started_)
Check();
}
break;
}
default: {
NOTREACHED();
break;
}
}
} }
void LocaleChangeGuard::OwnershipStatusChanged() { void LocaleChangeGuard::OwnershipStatusChanged() {
...@@ -171,8 +150,8 @@ void LocaleChangeGuard::Check() { ...@@ -171,8 +150,8 @@ void LocaleChangeGuard::Check() {
// Showing notification. // Showing notification.
if (from_locale_ != from_locale || to_locale_ != to_locale) { if (from_locale_ != from_locale || to_locale_ != to_locale) {
// Falling back to showing message in current locale. // Falling back to showing message in current locale.
LOG(ERROR) << LOG(ERROR) << "Showing locale change notification in current (not "
"Showing locale change notification in current (not previous) language"; "previous) language";
PrepareChangingLocale(from_locale, to_locale); PrepareChangingLocale(from_locale, to_locale);
} }
...@@ -193,9 +172,7 @@ void LocaleChangeGuard::OnResult(ash::LocaleNotificationResult result) { ...@@ -193,9 +172,7 @@ void LocaleChangeGuard::OnResult(ash::LocaleNotificationResult result) {
} }
void LocaleChangeGuard::AcceptLocaleChange() { void LocaleChangeGuard::AcceptLocaleChange() {
if (profile_ == NULL || if (from_locale_.empty() || to_locale_.empty()) {
from_locale_.empty() ||
to_locale_.empty()) {
NOTREACHED(); NOTREACHED();
return; return;
} }
...@@ -216,8 +193,8 @@ void LocaleChangeGuard::AcceptLocaleChange() { ...@@ -216,8 +193,8 @@ void LocaleChangeGuard::AcceptLocaleChange() {
prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_);
} }
void LocaleChangeGuard::PrepareChangingLocale( void LocaleChangeGuard::PrepareChangingLocale(const std::string& from_locale,
const std::string& from_locale, const std::string& to_locale) { const std::string& to_locale) {
std::string cur_locale = g_browser_process->GetApplicationLocale(); std::string cur_locale = g_browser_process->GetApplicationLocale();
if (!from_locale.empty()) if (!from_locale.empty())
from_locale_ = from_locale; from_locale_ = from_locale;
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h" #include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "components/session_manager/core/session_manager.h"
#include "components/session_manager/core/session_manager_observer.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
...@@ -29,6 +32,7 @@ namespace chromeos { ...@@ -29,6 +32,7 @@ namespace chromeos {
// (based on synchronized user preference). If so: shows notification that // (based on synchronized user preference). If so: shows notification that
// allows user to revert change. // allows user to revert change.
class LocaleChangeGuard : public content::NotificationObserver, class LocaleChangeGuard : public content::NotificationObserver,
public session_manager::SessionManagerObserver,
public DeviceSettingsService::Observer, public DeviceSettingsService::Observer,
public base::SupportsWeakPtr<LocaleChangeGuard> { public base::SupportsWeakPtr<LocaleChangeGuard> {
public: public:
...@@ -59,6 +63,9 @@ class LocaleChangeGuard : public content::NotificationObserver, ...@@ -59,6 +63,9 @@ class LocaleChangeGuard : public content::NotificationObserver,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override; const content::NotificationDetails& details) override;
// session_manager::SessionManagerObserver:
void OnUserSessionStarted(bool is_primary_user) override;
// DeviceSettingsService::Observer // DeviceSettingsService::Observer
void OwnershipStatusChanged() override; void OwnershipStatusChanged() override;
...@@ -72,10 +79,12 @@ class LocaleChangeGuard : public content::NotificationObserver, ...@@ -72,10 +79,12 @@ class LocaleChangeGuard : public content::NotificationObserver,
std::string from_locale_; std::string from_locale_;
std::string to_locale_; std::string to_locale_;
Profile* profile_; Profile* profile_;
bool reverted_; bool reverted_ = false;
bool session_started_; bool main_frame_loaded_ = false;
bool main_frame_loaded_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
ScopedObserver<session_manager::SessionManager,
session_manager::SessionManagerObserver>
session_observer_{this};
DISALLOW_COPY_AND_ASSIGN(LocaleChangeGuard); DISALLOW_COPY_AND_ASSIGN(LocaleChangeGuard);
}; };
......
...@@ -246,7 +246,10 @@ void AutomaticRebootManager::OnUserActivity(const ui::Event* event) { ...@@ -246,7 +246,10 @@ void AutomaticRebootManager::OnUserActivity(const ui::Event* event) {
false)); false));
} }
void AutomaticRebootManager::OnPrimaryUserSessionStarted() { void AutomaticRebootManager::OnUserSessionStarted(bool is_primary_user) {
if (!is_primary_user)
return;
// A session is starting. Stop listening for user activity as it no longer is // A session is starting. Stop listening for user activity as it no longer is
// a relevant criterion. // a relevant criterion.
if (ui::UserActivityDetector::Get()) if (ui::UserActivityDetector::Get())
......
...@@ -109,7 +109,7 @@ class AutomaticRebootManager : public PowerManagerClient::Observer, ...@@ -109,7 +109,7 @@ class AutomaticRebootManager : public PowerManagerClient::Observer,
void OnUserActivity(const ui::Event* event) override; void OnUserActivity(const ui::Event* event) override;
// session_manager::SessionManagerObserver: // session_manager::SessionManagerObserver:
void OnPrimaryUserSessionStarted() override; void OnUserSessionStarted(bool is_primary_user) override;
// content::NotificationObserver: // content::NotificationObserver:
void Observe(int type, void Observe(int type,
......
...@@ -251,7 +251,7 @@ void AssistantClient::OnUserProfileLoaded(const AccountId& account_id) { ...@@ -251,7 +251,7 @@ void AssistantClient::OnUserProfileLoaded(const AccountId& account_id) {
return; return;
// Initialize Assistant when primary user profile is loaded so that it could // Initialize Assistant when primary user profile is loaded so that it could
// be used in post oobe steps. OnPrimaryUserSessionStarted() is too late // be used in post oobe steps. OnUserSessionStarted() is too late
// because it happens after post oobe steps // because it happens after post oobe steps
Profile* user_profile = Profile* user_profile =
chromeos::ProfileHelper::Get()->GetProfileByAccountId(account_id); chromeos::ProfileHelper::Get()->GetProfileByAccountId(account_id);
...@@ -261,7 +261,7 @@ void AssistantClient::OnUserProfileLoaded(const AccountId& account_id) { ...@@ -261,7 +261,7 @@ void AssistantClient::OnUserProfileLoaded(const AccountId& account_id) {
MaybeInit(user_profile); MaybeInit(user_profile);
} }
void AssistantClient::OnPrimaryUserSessionStarted() { void AssistantClient::OnUserSessionStarted(bool is_primary_user) {
if (!chromeos::switches::ShouldSkipOobePostLogin()) if (is_primary_user && !chromeos::switches::ShouldSkipOobePostLogin())
MaybeStartAssistantOptInFlow(); MaybeStartAssistantOptInFlow();
} }
...@@ -97,7 +97,7 @@ class AssistantClient : chromeos::assistant::mojom::Client, ...@@ -97,7 +97,7 @@ class AssistantClient : chromeos::assistant::mojom::Client,
// session_manager::SessionManagerObserver: // session_manager::SessionManagerObserver:
void OnUserProfileLoaded(const AccountId& account_id) override; void OnUserProfileLoaded(const AccountId& account_id) override;
void OnPrimaryUserSessionStarted() override; void OnUserSessionStarted(bool is_primary_user) override;
mojo::Binding<chromeos::assistant::mojom::Client> client_binding_{this}; mojo::Binding<chromeos::assistant::mojom::Client> client_binding_{this};
......
...@@ -72,9 +72,9 @@ void SessionManager::SessionStarted() { ...@@ -72,9 +72,9 @@ void SessionManager::SessionStarted() {
session_started_ = true; session_started_ = true;
// SessionStarted() could be called in tests without any session created. bool is_primary = sessions_.size() == 1;
if (sessions_.size() == 1) for (auto& observer : observers_)
NotifyPrimaryUserSessionStarted(); observer.OnUserSessionStarted(is_primary);
} }
bool SessionManager::HasSessionForAccountId( bool SessionManager::HasSessionForAccountId(
...@@ -110,11 +110,6 @@ void SessionManager::NotifyUserProfileLoaded(const AccountId& account_id) { ...@@ -110,11 +110,6 @@ void SessionManager::NotifyUserProfileLoaded(const AccountId& account_id) {
observer.OnUserProfileLoaded(account_id); observer.OnUserProfileLoaded(account_id);
} }
void SessionManager::NotifyPrimaryUserSessionStarted() {
for (auto& observer : observers_)
observer.OnPrimaryUserSessionStarted();
}
void SessionManager::NotifyUserLoggedIn(const AccountId& user_account_id, void SessionManager::NotifyUserLoggedIn(const AccountId& user_account_id,
const std::string& user_id_hash, const std::string& user_id_hash,
bool browser_restart, bool browser_restart,
......
...@@ -64,7 +64,6 @@ class SESSION_EXPORT SessionManager { ...@@ -64,7 +64,6 @@ class SESSION_EXPORT SessionManager {
// Various helpers to notify observers. // Various helpers to notify observers.
void NotifyUserProfileLoaded(const AccountId& account_id); void NotifyUserProfileLoaded(const AccountId& account_id);
void NotifyPrimaryUserSessionStarted();
SessionState session_state() const { return session_state_; } SessionState session_state() const { return session_state_; }
const std::vector<Session>& sessions() const { return sessions_; } const std::vector<Session>& sessions() const { return sessions_; }
......
...@@ -22,8 +22,12 @@ class SessionManagerObserver : public base::CheckedObserver { ...@@ -22,8 +22,12 @@ class SessionManagerObserver : public base::CheckedObserver {
// Invoked when a user profile is loaded. // Invoked when a user profile is loaded.
virtual void OnUserProfileLoaded(const AccountId& account_id) {} virtual void OnUserProfileLoaded(const AccountId& account_id) {}
// Invoked when the primary user session is started. // Invoked when a user session is started. If this is a new user on the
virtual void OnPrimaryUserSessionStarted() {} // machine this will not be called until after post-login steps are finished
// (for example a profile picture has been selected). In contrast,
// UserSessionStateObserver::OnActiveUserChanged() is invoked immediately
// after the user has logged in.
virtual void OnUserSessionStarted(bool is_primary_user) {}
}; };
} // namespace session_manager } // namespace session_manager
......
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