Commit b5418f5c authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Run ClearSigninProfile on user session start

Also, ClearSigninProfile now closes any browser window opened in the
profile. Ideally, no browsers would be open in the sign-in profile, but
we've had cases where that had happened.

BUG=906837,901768

Change-Id: Ia231d2ce3420c5c743bcd17f839ad00f4a851874
Reviewed-on: https://chromium-review.googlesource.com/c/1347105Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611442}
parent 5ffaaea7
......@@ -1448,7 +1448,7 @@ void UserSessionManager::PrepareTpmDeviceAndFinalizeProfile(Profile* profile) {
BootTimesRecorder::Get()->AddLoginTimeMarker("TPMOwn-Start", false);
if (!tpm_util::TpmIsEnabled() || tpm_util::TpmIsBeingOwned()) {
FinalizePrepareProfile(profile);
ClearSigninProfileAndFinalizePrepareProfile(profile);
return;
}
......@@ -1475,7 +1475,13 @@ void UserSessionManager::PrepareTpmDeviceAndFinalizeProfile(Profile* profile) {
void UserSessionManager::OnCryptohomeOperationCompleted(Profile* profile,
bool result) {
DCHECK(result);
FinalizePrepareProfile(profile);
ClearSigninProfileAndFinalizePrepareProfile(profile);
}
void UserSessionManager::ClearSigninProfileAndFinalizePrepareProfile(
Profile* profile) {
ProfileHelper::Get()->ClearSigninProfile(base::BindRepeating(
&UserSessionManager::FinalizePrepareProfile, AsWeakPtr(), profile));
}
void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
......
......@@ -389,6 +389,9 @@ class UserSessionManager
// Called on UI thread once Cryptohome operation completes.
void OnCryptohomeOperationCompleted(Profile* profile, bool result);
// Clears the sign-in profile, and initiates the user profile finalization.
void ClearSigninProfileAndFinalizePrepareProfile(Profile* profile);
// Finalized profile preparation.
void FinalizePrepareProfile(Profile* profile);
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/chromeos_constants.h"
......@@ -52,6 +53,11 @@ bool ShouldAddProfileDirPrefix(const std::string& user_id_hash) {
user_id_hash != chrome::kTestUserProfileDir;
}
void WrapAsBrowsersCloseCallback(const base::RepeatingClosure& callback,
const base::FilePath& path) {
callback.Run();
}
class UsernameHashMatcher {
public:
explicit UsernameHashMatcher(const std::string& h) : username_hash(h) {}
......@@ -286,7 +292,7 @@ void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) {
return;
}
on_clear_profile_stage_finished_ =
base::BarrierClosure(2, base::Bind(&ProfileHelper::OnSigninProfileCleared,
base::BarrierClosure(3, base::Bind(&ProfileHelper::OnSigninProfileCleared,
weak_factory_.GetWeakPtr()));
LOG_ASSERT(!browsing_data_remover_);
browsing_data_remover_ =
......@@ -302,6 +308,16 @@ void ProfileHelper::ClearSigninProfile(const base::Closure& on_clear_callback) {
login::SigninPartitionManager::Factory::GetForBrowserContext(
GetSigninProfile())
->CloseCurrentSigninSession(on_clear_profile_stage_finished_);
BrowserList::CloseAllBrowsersWithProfile(
GetSigninProfile(),
base::BindRepeating(
&WrapAsBrowsersCloseCallback,
on_clear_profile_stage_finished_) /* on_close_success */,
base::BindRepeating(
&WrapAsBrowsersCloseCallback,
on_clear_profile_stage_finished_) /* on_close_aborted */,
true /* skip_beforeunload */);
}
Profile* ProfileHelper::GetProfileByAccountId(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