Skip to content

Commit

Permalink
Fix crash when new avatar signin with cross account error
Browse files Browse the repository at this point in the history
OneClickSigninHelper::HandleCrossAccountError has an input parameter of web contents that may have been killed when the method is called, e.g. signin from the new avatar bubble. Instead this method should just use the current active tab, since it is only used to attach a tab-modal warning dialog.

BUG=388607

Review URL: https://codereview.chromium.org/444083003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287973 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
guohui@chromium.org committed Aug 7, 2014
1 parent 6a72afc commit c0e95eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions chrome/browser/ui/sync/one_click_signin_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ void OneClickSigninHelper::ShowSigninErrorBubble(Browser* browser,

// static
bool OneClickSigninHelper::HandleCrossAccountError(
content::WebContents* contents,
Profile* profile,
const std::string& session_index,
const std::string& email,
const std::string& password,
Expand All @@ -1171,20 +1171,22 @@ bool OneClickSigninHelper::HandleCrossAccountError(
signin::Source source,
OneClickSigninSyncStarter::StartSyncMode start_mode,
OneClickSigninSyncStarter::Callback sync_callback) {
Profile* profile =
Profile::FromBrowserContext(contents->GetBrowserContext());
std::string last_email =
profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername);

if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) {
// If the new email address is different from the email address that
// just signed in, show a confirmation dialog.
// just signed in, show a confirmation dialog on top of the current active
// tab.

// No need to display a second confirmation so pass false below.
// TODO(atwilson): Move this into OneClickSigninSyncStarter.
// The tab modal dialog always executes its callback before |contents|
// is deleted.
Browser* browser = chrome::FindBrowserWithWebContents(contents);
Browser* browser = chrome::FindLastActiveWithProfile(
profile, chrome::GetActiveDesktop());
content::WebContents* contents =
browser->tab_strip_model()->GetActiveWebContents();
ConfirmEmailDialogDelegate::AskForConfirmation(
contents,
last_email,
Expand Down Expand Up @@ -1550,7 +1552,7 @@ void OneClickSigninHelper::DidStopLoading(
OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST :
OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS;

if (!HandleCrossAccountError(contents, session_index_, email_, password_,
if (!HandleCrossAccountError(profile, session_index_, email_, password_,
"", auto_accept_, source_, start_mode,
CreateSyncStarterCallback())) {
if (!do_not_start_sync_for_testing_) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/sync/one_click_signin_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class OneClickSigninHelper
// confirmation dialog before starting sync. It returns true if there is a
// cross account error, and false otherwise.
static bool HandleCrossAccountError(
content::WebContents* contents,
Profile* profile,
const std::string& session_index,
const std::string& email,
const std::string& password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void InlineSigninHelper::OnSigninOAuthInformationAvailable(
OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
bool start_signin =
!OneClickSigninHelper::HandleCrossAccountError(
contents, "",
profile_, "",
email, password_, refresh_token,
OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT,
source, start_mode,
Expand Down

0 comments on commit c0e95eb

Please sign in to comment.