| Index: chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
|
| diff --git a/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc b/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
|
| index bbb199e5172f52dfd27f31abd5c36d97643f35e5..6a76b7f39cf53eb6a36785dfb8493065f90d473c 100644
|
| --- a/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
|
| +++ b/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
|
| @@ -11,6 +11,7 @@
|
| #include "chrome/browser/profiles/profile_avatar_icon_util.h"
|
| #include "chrome/browser/signin/account_tracker_service_factory.h"
|
| #include "chrome/browser/signin/signin_manager_factory.h"
|
| +#include "chrome/browser/ui/browser_list.h"
|
| #include "chrome/browser/ui/browser_window.h"
|
| #include "chrome/browser/ui/signin_view_controller_delegate.h"
|
| #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
|
| @@ -22,12 +23,18 @@
|
|
|
| const int kProfileImageSize = 128;
|
|
|
| -SyncConfirmationHandler::SyncConfirmationHandler()
|
| - : did_user_explicitly_interact(false) {}
|
| +SyncConfirmationHandler::SyncConfirmationHandler(Browser* browser)
|
| + : profile_(browser->profile()),
|
| + browser_(browser),
|
| + did_user_explicitly_interact(false) {
|
| + DCHECK(profile_);
|
| + DCHECK(browser_);
|
| + BrowserList::AddObserver(this);
|
| +}
|
|
|
| SyncConfirmationHandler::~SyncConfirmationHandler() {
|
| - Profile* profile = Profile::FromWebUI(web_ui());
|
| - AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
|
| + BrowserList::RemoveObserver(this);
|
| + AccountTrackerServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
|
|
|
| // Abort signin and prevent sync from starting if none of the actions on the
|
| // sync confirmation dialog are taken by the user.
|
| @@ -37,6 +44,11 @@ SyncConfirmationHandler::~SyncConfirmationHandler() {
|
| }
|
| }
|
|
|
| +void SyncConfirmationHandler::OnBrowserRemoved(Browser* browser) {
|
| + if (browser_ == browser)
|
| + browser_ = nullptr;
|
| +}
|
| +
|
| void SyncConfirmationHandler::RegisterMessages() {
|
| web_ui()->RegisterMessageCallback("confirm",
|
| base::Bind(&SyncConfirmationHandler::HandleConfirm,
|
| @@ -64,15 +76,14 @@ void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) {
|
| void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) {
|
| did_user_explicitly_interact = true;
|
| base::RecordAction(base::UserMetricsAction("Signin_Undo_Signin"));
|
| - Browser* browser = signin::GetDesktopBrowser(web_ui());
|
| - if (browser) {
|
| - LoginUIServiceFactory::GetForProfile(browser->profile())->
|
| - SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN);
|
| - SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut(
|
| - signin_metrics::ABORT_SIGNIN,
|
| - signin_metrics::SignoutDelete::IGNORE_METRIC);
|
| - browser->CloseModalSigninWindow();
|
| - }
|
| + LoginUIServiceFactory::GetForProfile(profile_)->SyncConfirmationUIClosed(
|
| + LoginUIService::ABORT_SIGNIN);
|
| + SigninManagerFactory::GetForProfile(profile_)->SignOut(
|
| + signin_metrics::ABORT_SIGNIN,
|
| + signin_metrics::SignoutDelete::IGNORE_METRIC);
|
| +
|
| + if (browser_)
|
| + browser_->CloseModalSigninWindow();
|
| }
|
|
|
| void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) {
|
| @@ -95,41 +106,36 @@ void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) {
|
| if (!info.IsValid())
|
| return;
|
|
|
| - Profile* profile = Profile::FromWebUI(web_ui());
|
| - SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
|
| + SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile_);
|
| if (info.account_id != signin_manager->GetAuthenticatedAccountId())
|
| return;
|
|
|
| - AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
|
| + AccountTrackerServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
|
| SetUserImageURL(info.picture_url);
|
| }
|
|
|
| void SyncConfirmationHandler::CloseModalSigninWindow(
|
| LoginUIService::SyncConfirmationUIClosedResult result) {
|
| - Browser* browser = signin::GetDesktopBrowser(web_ui());
|
| - if (browser) {
|
| - LoginUIServiceFactory::GetForProfile(browser->profile())->
|
| - SyncConfirmationUIClosed(result);
|
| - browser->CloseModalSigninWindow();
|
| - }
|
| + LoginUIServiceFactory::GetForProfile(profile_)->SyncConfirmationUIClosed(
|
| + result);
|
| + if (browser_)
|
| + browser_->CloseModalSigninWindow();
|
| }
|
|
|
| void SyncConfirmationHandler::HandleInitializedWithSize(
|
| const base::ListValue* args) {
|
| - Browser* browser = signin::GetDesktopBrowser(web_ui());
|
| - if (!browser)
|
| + if (!browser_)
|
| return;
|
|
|
| - Profile* profile = browser->profile();
|
| - std::string account_id =
|
| - SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
|
| + std::string account_id = SigninManagerFactory::GetForProfile(profile_)
|
| + ->GetAuthenticatedAccountId();
|
| if (account_id.empty()) {
|
| // No account is signed in, so there is nothing to be displayed in the sync
|
| // confirmation dialog.
|
| return;
|
| }
|
| AccountTrackerService* account_tracker =
|
| - AccountTrackerServiceFactory::GetForProfile(profile);
|
| + AccountTrackerServiceFactory::GetForProfile(profile_);
|
| AccountInfo account_info = account_tracker->GetAccountInfo(account_id);
|
|
|
| if (!account_info.IsValid()) {
|
| @@ -139,7 +145,7 @@ void SyncConfirmationHandler::HandleInitializedWithSize(
|
| SetUserImageURL(account_info.picture_url);
|
| }
|
|
|
| - signin::SetInitializedModalHeight(web_ui(), args);
|
| + signin::SetInitializedModalHeight(browser_, web_ui(), args);
|
|
|
| // After the dialog is shown, some platforms might have an element focused.
|
| // To be consistent, clear the focused element on all platforms.
|
|
|