Commit 168f5eca authored by Kush Sinha's avatar Kush Sinha Committed by Commit Bot

crOS Account Manager: Fix sign-in error notification

Display a notification informing users about Chrome OS's change in
sign-in behaviour, if there are any unmigrated accounts in Chrome OS
Account Manager. This notification should supersede the default
re-authentication notification.

Bug: 962287
Change-Id: Ib8bffa6756727f77e6abe77f21a0b865b94824a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1615142Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Kush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660792}
parent 0fdb0f7b
......@@ -1269,6 +1269,12 @@
<message name="IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_BUBBLE_VIEW_MESSAGE" desc="Message in the sign-in error bubble view for Chrome OS Secondary Accounts.">
Your Google Account(s) need attention
</message>
<message name="IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_MIGRATION_BUBBLE_VIEW_TITLE" desc="Title in the sign-in error bubble view/notification for Chrome OS Secondary Accounts that have not been migrated to Chrome OS Account Manager.">
Sign-in has changed
</message>
<message name="IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_MIGRATION_BUBBLE_VIEW_MESSAGE" desc="Message in the sign-in error bubble view for Chrome OS Secondary Accounts that have not been migrated to Chrome OS Account Manager.">
Account update required
</message>
<!-- Strings used in <cr-network-list>, used in Settings and OOBE -->
<message name="IDS_NETWORK_LIST_INITIALIZING" desc="Text in the network list element when a Cellular network is initiailizing.">
......
......@@ -14,6 +14,7 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/account_manager/account_manager_util.h"
#include "chrome/browser/chromeos/login/user_flow.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
......@@ -32,6 +33,7 @@
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "chromeos/components/account_manager/account_manager_factory.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/user_manager.h"
#include "services/identity/public/cpp/identity_manager.h"
......@@ -50,6 +52,17 @@ void HandleDeviceAccountReauthNotificationClick(
chrome::AttemptUserExit();
}
bool AreAllAccountsMigrated(
const chromeos::AccountManager* const account_manager,
const std::vector<chromeos::AccountManager::Account>& accounts) {
for (const auto& account : accounts) {
if (account_manager->HasDummyGaiaToken(account.key)) {
return false;
}
}
return true;
}
} // namespace
SigninErrorNotifier::SigninErrorNotifier(SigninErrorController* controller,
......@@ -57,7 +70,11 @@ SigninErrorNotifier::SigninErrorNotifier(SigninErrorController* controller,
: error_controller_(controller),
profile_(profile),
identity_manager_(IdentityManagerFactory::GetForProfile(profile_)),
account_manager_(g_browser_process->platform_part()
->GetAccountManagerFactory()
->GetAccountManager(profile_->GetPath().value())),
weak_factory_(this) {
DCHECK(account_manager_);
// Create a unique notification ID for this profile.
device_account_notification_id_ =
kProfileSigninNotificationId + profile->GetProfileUserName();
......@@ -152,6 +169,12 @@ void SigninErrorNotifier::HandleDeviceAccountError() {
void SigninErrorNotifier::HandleSecondaryAccountError(
const std::string& account_id) {
account_manager_->GetAccounts(base::BindOnce(
&SigninErrorNotifier::OnGetAccounts, weak_factory_.GetWeakPtr()));
}
void SigninErrorNotifier::OnGetAccounts(
const std::vector<chromeos::AccountManager::Account>& accounts) {
message_center::NotifierId notifier_id(
message_center::NotifierType::SYSTEM_COMPONENT,
kProfileSigninNotificationId);
......@@ -161,13 +184,24 @@ void SigninErrorNotifier::HandleSecondaryAccountError(
notifier_id.profile_id =
multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail();
const bool are_all_accounts_migrated =
AreAllAccountsMigrated(account_manager_, accounts);
const base::string16 message_title =
are_all_accounts_migrated
? l10n_util::GetStringUTF16(
IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_BUBBLE_VIEW_TITLE)
: l10n_util::GetStringUTF16(
IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_MIGRATION_BUBBLE_VIEW_TITLE);
const base::string16 message_body =
are_all_accounts_migrated
? GetMessageBody(true /* is_secondary_account_error */)
: l10n_util::GetStringUTF16(
IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_MIGRATION_BUBBLE_VIEW_MESSAGE);
std::unique_ptr<message_center::Notification> notification =
ash::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
secondary_account_notification_id_,
l10n_util::GetStringUTF16(
IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_BUBBLE_VIEW_TITLE),
GetMessageBody(true /* is_secondary_account_error */),
secondary_account_notification_id_, message_title, message_body,
l10n_util::GetStringUTF16(
IDS_SIGNIN_ERROR_SECONDARY_ACCOUNT_DISPLAY_SOURCE),
GURL(secondary_account_notification_id_), notifier_id,
......
......@@ -6,11 +6,13 @@
#define CHROME_BROWSER_SIGNIN_SIGNIN_ERROR_NOTIFIER_ASH_H_
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "chromeos/components/account_manager/account_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
......@@ -44,6 +46,10 @@ class SigninErrorNotifier : public SigninErrorController::Observer,
// for the Secondary Account which received an error.
void HandleSecondaryAccountError(const std::string& account_id);
// |chromeos::AccountManager::GetAccounts| callback handler.
void OnGetAccounts(
const std::vector<chromeos::AccountManager::Account>& accounts);
// Handles clicks on the Secondary Account reauth notification. See
// |message_center::HandleNotificationClickDelegate|.
void HandleSecondaryAccountReauthNotificationClick(
......@@ -60,6 +66,9 @@ class SigninErrorNotifier : public SigninErrorController::Observer,
// A non-owning pointer to IdentityManager.
identity::IdentityManager* const identity_manager_;
// A non-owning pointer.
chromeos::AccountManager* const account_manager_;
// Used to keep track of the message center notifications.
std::string device_account_notification_id_;
std::string secondary_account_notification_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