Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ReArchPPV] Move utils out of
ProfileCreationSignedInFlowController
This is done in preparation of extracting the SAML-related steps out of the regular post sign-in step. The extracted utilities cover obtaining the profile name, which can be also used during the FRE, and transitioning temporary profiles into fully-fledged oncs once the creation is confirmed. Bug: 1358843 Change-Id: I13e3f04deaf83bc5579649f2e03776a182d26605 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3928737 Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org> Reviewed-by: David Roger <droger@chromium.org> Cr-Commit-Position: refs/heads/main@{#1054105}
- Loading branch information
Nicolas Dossou-Gbete
authored and
Chromium LUCI CQ
committed
Oct 3, 2022
1 parent
4466776
commit c00b988
Showing
6 changed files
with
266 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
chrome/browser/ui/views/profiles/profile_management_utils.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/views/profiles/profile_management_utils.h" | ||
|
||
#include "base/auto_reset.h" | ||
#include "base/functional/bind.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "chrome/browser/profiles/profile_attributes_entry.h" | ||
#include "chrome/browser/profiles/profile_attributes_storage.h" | ||
#include "chrome/browser/profiles/profile_manager.h" | ||
#include "chrome/browser/profiles/profiles_state.h" | ||
#include "chrome/common/pref_names.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
namespace { | ||
|
||
constexpr base::TimeDelta kDefaultExtendedAccountInfoTimeout = | ||
base::Seconds(10); | ||
|
||
absl::optional<base::TimeDelta> g_extended_account_info_timeout_for_testing = | ||
absl::nullopt; | ||
|
||
} // namespace | ||
|
||
// -- Helper functions --------------------------------------------------------- | ||
|
||
void FinalizeNewProfileSetup(Profile* profile, | ||
const std::u16string& profile_name) { | ||
ProfileAttributesEntry* entry = | ||
g_browser_process->profile_manager() | ||
->GetProfileAttributesStorage() | ||
.GetProfileAttributesWithPath(profile->GetPath()); | ||
CHECK(entry); | ||
|
||
entry->SetIsOmitted(false); | ||
if (!profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) { | ||
// Unmark this profile ephemeral so that it isn't deleted upon next startup. | ||
// Profiles should never be made non-ephemeral if ephemeral mode is forced | ||
// by policy. | ||
entry->SetIsEphemeral(false); | ||
} | ||
entry->SetLocalProfileName(profile_name, | ||
/*is_default_name=*/false); | ||
|
||
// Skip the welcome page for this profile as we already showed a profile setup | ||
// experience. | ||
profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); | ||
} | ||
|
||
// -- ProfileNameResolver ------------------------------------------------------ | ||
|
||
// static | ||
ProfileNameResolver::ScopedInfoFetchTimeoutOverride | ||
ProfileNameResolver::CreateScopedInfoFetchTimeoutOverrideForTesting( | ||
base::TimeDelta timeout) { | ||
return base::AutoReset<absl::optional<base::TimeDelta>>( | ||
&g_extended_account_info_timeout_for_testing, timeout); | ||
} | ||
|
||
ProfileNameResolver::ProfileNameResolver( | ||
signin::IdentityManager* identity_manager) { | ||
// Listen for extended account info getting fetched. | ||
identity_manager_observation_.Observe(identity_manager); | ||
|
||
// Set up a timeout for extended account info (which cancels any existing | ||
// timeout closure). | ||
const CoreAccountInfo& account_info = | ||
identity_manager->GetPrimaryAccountInfo(signin::ConsentLevel::kSignin); | ||
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | ||
FROM_HERE, | ||
base::BindOnce( | ||
&ProfileNameResolver::OnProfileNameResolved, | ||
weak_ptr_factory_.GetWeakPtr(), | ||
profiles::GetDefaultNameForNewSignedInProfileWithIncompleteInfo( | ||
account_info)), | ||
g_extended_account_info_timeout_for_testing.value_or( | ||
kDefaultExtendedAccountInfoTimeout)); | ||
} | ||
|
||
ProfileNameResolver::~ProfileNameResolver() = default; | ||
|
||
void ProfileNameResolver::OnExtendedAccountInfoUpdated( | ||
const AccountInfo& account_info) { | ||
if (!account_info.IsValid()) | ||
return; | ||
|
||
OnProfileNameResolved( | ||
profiles::GetDefaultNameForNewSignedInProfile(account_info)); | ||
} | ||
|
||
void ProfileNameResolver::OnProfileNameResolved( | ||
const std::u16string& profile_name) { | ||
// Stop listening to further changes. | ||
identity_manager_observation_.Reset(); | ||
|
||
resolved_profile_name_ = profile_name; | ||
if (on_profile_name_resolved_callback_) | ||
std::move(on_profile_name_resolved_callback_).Run(); | ||
} |
Oops, something went wrong.