blob: 03d61a90bbb1c5f764f8742e153e30fce3b0bffd [file]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/logout_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/identity_manager/accounts_mutator.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/navigation_handle.h"
WEB_CONTENTS_USER_DATA_KEY_IMPL(LogoutTabHelper)
LogoutTabHelper::LogoutTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}
LogoutTabHelper::~LogoutTabHelper() = default;
void LogoutTabHelper::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
if (!navigation_handle->IsInMainFrame())
return;
if (navigation_handle->IsErrorPage()) {
// Failed to load the logout page, fallback to local signout.
Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
IdentityManagerFactory::GetForProfile(profile)
->GetAccountsMutator()
->RemoveAllAccounts(signin_metrics::SourceForRefreshTokenOperation::
kLogoutTabHelper_DidFinishNavigation);
}
// Delete this.
web_contents()->RemoveUserData(UserDataKey());
}