Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4838)

Unified Diff: chrome/browser/ui/webui/signin/sync_confirmation_handler.cc

Issue 2784823002: Reland "Use the same browser instance in the sync confirmation dialog. (Closed)
Patch Set: Rebase and fix conflicts Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 fcac3f8dc9f4c7a306a0e5d03b2d4dc2ad6c4406..e643dd690d3702191a1eb3423feb56041b8e9639 100644
--- a/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
+++ b/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
@@ -11,23 +11,31 @@
#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"
#include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "components/signin/core/browser/account_tracker_service.h"
+#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "url/gurl.h"
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 +45,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 +77,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->signin_view_controller()->CloseModalSignin();
- }
+ LoginUIServiceFactory::GetForProfile(profile_)->SyncConfirmationUIClosed(
+ LoginUIService::ABORT_SIGNIN);
+ SigninManagerFactory::GetForProfile(profile_)->SignOut(
+ signin_metrics::ABORT_SIGNIN,
+ signin_metrics::SignoutDelete::IGNORE_METRIC);
+
+ if (browser_)
+ browser_->signin_view_controller()->CloseModalSignin();
}
void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) {
@@ -95,41 +107,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->signin_view_controller()->CloseModalSignin();
- }
+ LoginUIServiceFactory::GetForProfile(profile_)->SyncConfirmationUIClosed(
+ result);
+ if (browser_)
+ browser_->signin_view_controller()->CloseModalSignin();
}
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 +146,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.

Powered by Google App Engine
This is Rietveld 408576698