Commit 33e1dda2 authored by Kush Sinha's avatar Kush Sinha Committed by Commit Bot

Retry account migrations when ARC successfully starts

ARC's accounts' migrations to Chrome OS Account Manager can fail at the
start of a user session if ARC fails to properly start up. Retry
migrations after a successful ARC startup.

Bug: 998111
Change-Id: I466ef4fa698228d1ef10b8018e485461529d8eab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1773137Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Commit-Queue: Kush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691706}
parent da55f564
...@@ -47,10 +47,9 @@ namespace chromeos { ...@@ -47,10 +47,9 @@ namespace chromeos {
namespace { namespace {
// These names are used in histograms. // These names are used in histograms. Values should never be changed.
constexpr char kDeviceAccountMigration[] = "DeviceAccountMigration"; constexpr char kDeviceAccountMigration[] = "DeviceAccountMigration";
constexpr char kContentAreaAccountsMigration[] = "ContentAreaAccountsMigration"; constexpr char kContentAreaAccountsMigration[] = "ContentAreaAccountsMigration";
constexpr char kArcAccountsMigration[] = "ArcAccountsMigration";
constexpr char kSuccessStorage[] = "SuccessStorage"; constexpr char kSuccessStorage[] = "SuccessStorage";
constexpr char kMigrationResultMetricName[] = constexpr char kMigrationResultMetricName[] =
"AccountManager.Migrations.Result"; "AccountManager.Migrations.Result";
...@@ -344,9 +343,10 @@ class ArcAccountsMigration : public AccountMigrationBaseStep, ...@@ -344,9 +343,10 @@ class ArcAccountsMigration : public AccountMigrationBaseStep,
ArcAccountsMigration(AccountManager* account_manager, ArcAccountsMigration(AccountManager* account_manager,
signin::IdentityManager* identity_manager, signin::IdentityManager* identity_manager,
arc::ArcAuthService* arc_auth_service) arc::ArcAuthService* arc_auth_service)
: AccountMigrationBaseStep(kArcAccountsMigration, : AccountMigrationBaseStep(
account_manager, AccountManagerMigrator::kArcAccountsMigrationId,
identity_manager), account_manager,
identity_manager),
arc_auth_service_(arc_auth_service) {} arc_auth_service_(arc_auth_service) {}
~ArcAccountsMigration() override { Reset(); } ~ArcAccountsMigration() override { Reset(); }
...@@ -461,6 +461,11 @@ class SuccessStorage : public AccountMigrationRunner::Step { ...@@ -461,6 +461,11 @@ class SuccessStorage : public AccountMigrationRunner::Step {
} // namespace } // namespace
// Used in histograms and elsewhere. Never change this value.
// static
const char AccountManagerMigrator::kArcAccountsMigrationId[] =
"ArcAccountsMigration";
AccountManagerMigrator::AccountManagerMigrator(Profile* profile) AccountManagerMigrator::AccountManagerMigrator(Profile* profile)
: profile_(profile) {} : profile_(profile) {}
......
...@@ -25,6 +25,10 @@ namespace chromeos { ...@@ -25,6 +25,10 @@ namespace chromeos {
class AccountManagerMigrator : public KeyedService { class AccountManagerMigrator : public KeyedService {
public: public:
// Migration step id for ARC accounts migration. Used by |ArcAuthService| to
// figure out if ARC migrations should be retried.
static const char kArcAccountsMigrationId[];
explicit AccountManagerMigrator(Profile* profile); explicit AccountManagerMigrator(Profile* profile);
~AccountManagerMigrator() override; ~AccountManagerMigrator() override;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/account_manager/account_manager_migrator.h"
#include "chrome/browser/chromeos/account_manager/account_manager_util.h" #include "chrome/browser/chromeos/account_manager/account_manager_util.h"
#include "chrome/browser/chromeos/arc/arc_optin_uma.h" #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
...@@ -180,6 +181,41 @@ bool IsPrimaryOrDeviceLocalAccount( ...@@ -180,6 +181,41 @@ bool IsPrimaryOrDeviceLocalAccount(
return IsPrimaryGaiaAccount(gaia_id); return IsPrimaryGaiaAccount(gaia_id);
} }
void TriggerAccountManagerMigrationsIfRequired(Profile* profile) {
if (!chromeos::IsAccountManagerAvailable(profile))
return;
chromeos::AccountManagerMigrator* const migrator =
chromeos::AccountManagerMigratorFactory::GetForBrowserContext(profile);
if (!migrator) {
// Migrator can be null for ephemeral and kiosk sessions. Ignore those cases
// since there are no accounts to be migrated in that case.
return;
}
const base::Optional<chromeos::AccountMigrationRunner::MigrationResult>
last_migration_run_result = migrator->GetLastMigrationRunResult();
if (!last_migration_run_result)
return;
if (last_migration_run_result->final_status !=
chromeos::AccountMigrationRunner::Status::kFailure) {
return;
}
if (last_migration_run_result->failed_step_id !=
chromeos::AccountManagerMigrator::kArcAccountsMigrationId) {
// Migrations failed but not because of ARC. ARC should not try to re-run
// migrations in this case.
return;
}
// Migrations are idempotent and safe to run multiple times. It may have
// happened that ARC migrations timed out at the start of the session. Give
// it a chance to run again.
migrator->Start();
}
} // namespace } // namespace
// static // static
...@@ -239,8 +275,10 @@ void ArcAuthService::OnConnectionReady() { ...@@ -239,8 +275,10 @@ void ArcAuthService::OnConnectionReady() {
// provisioning. // provisioning.
// For the second and subsequent sessions, // For the second and subsequent sessions,
// |ArcSessionManager::Get()->IsArcProvisioned()| will be |true|. // |ArcSessionManager::Get()->IsArcProvisioned()| will be |true|.
if (arc::IsArcProvisioned(profile_)) if (arc::IsArcProvisioned(profile_)) {
TriggerAccountManagerMigrationsIfRequired(profile_);
TriggerAccountsPushToArc(); TriggerAccountsPushToArc();
}
if (pending_get_arc_accounts_callback_) if (pending_get_arc_accounts_callback_)
DispatchAccountsInArc(std::move(pending_get_arc_accounts_callback_)); DispatchAccountsInArc(std::move(pending_get_arc_accounts_callback_));
......
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