Commit 9705c2fc authored by fdoray@chromium.org's avatar fdoray@chromium.org

Make sure OneClickSigninSyncStarter detects Browser object being closed

Before this fix, OneClickSigninSyncStarter didn't detect when the Browser object it points to was closed. It could then cause a crash by making calls on the destroyed Browser object. OneClickSigninSyncStarter now observes the browser list to detect when the Browser it points to is closed.

BUG=235439

Review URL: https://chromiumcodereview.appspot.com/16092009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204021 0039d316-1c4b-4281-b951-d872f2087c98
parent e0419262
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -52,6 +54,8 @@ OneClickSigninSyncStarter::OneClickSigninSyncStarter( ...@@ -52,6 +54,8 @@ OneClickSigninSyncStarter::OneClickSigninSyncStarter(
confirmation_required_(confirmation_required), confirmation_required_(confirmation_required),
weak_pointer_factory_(this) { weak_pointer_factory_(this) {
DCHECK(profile); DCHECK(profile);
BrowserList::AddObserver(this);
Initialize(profile, browser); Initialize(profile, browser);
// Start the signin process using the cookies in the cookie jar. // Start the signin process using the cookies in the cookie jar.
...@@ -64,7 +68,13 @@ OneClickSigninSyncStarter::OneClickSigninSyncStarter( ...@@ -64,7 +68,13 @@ OneClickSigninSyncStarter::OneClickSigninSyncStarter(
manager->StartSignInWithCredentials(session_index, email, password, callback); manager->StartSignInWithCredentials(session_index, email, password, callback);
} }
void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) {
if (browser == browser_)
browser_ = NULL;
}
OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { OneClickSigninSyncStarter::~OneClickSigninSyncStarter() {
BrowserList::RemoveObserver(this);
} }
void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) {
...@@ -274,8 +284,8 @@ void OneClickSigninSyncStarter::CompleteInitForNewProfile( ...@@ -274,8 +284,8 @@ void OneClickSigninSyncStarter::CompleteInitForNewProfile(
void OneClickSigninSyncStarter::ConfirmAndSignin() { void OneClickSigninSyncStarter::ConfirmAndSignin() {
SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
// browser_ can be null for unit tests. if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) {
if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { EnsureBrowser();
// Display a confirmation dialog to the user. // Display a confirmation dialog to the user.
browser_->window()->ShowOneClickSigninBubble( browser_->window()->ShowOneClickSigninBubble(
BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG,
...@@ -368,13 +378,14 @@ void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( ...@@ -368,13 +378,14 @@ void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble(
void OneClickSigninSyncStarter::EnsureBrowser() { void OneClickSigninSyncStarter::EnsureBrowser() {
if (!browser_) { if (!browser_) {
// The user just created a new profile so we need to figure out what // The user just created a new profile or has closed the browser that
// browser to use to display settings. Grab the most recently active // we used previously. Grab the most recently active browser or else
// browser or else create a new one. // create a new one.
browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_);
if (!browser_) { if (!browser_) {
browser_ = new Browser(Browser::CreateParams(profile_, browser_ = new Browser(Browser::CreateParams(profile_,
desktop_type_)); desktop_type_));
chrome::AddBlankTabAt(browser_, -1, true);
} }
browser_->window()->Show(); browser_->window()->Show();
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_tracker.h" #include "chrome/browser/signin/signin_tracker.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/host_desktop.h"
class Browser; class Browser;
...@@ -22,7 +23,8 @@ class CloudPolicyClient; ...@@ -22,7 +23,8 @@ class CloudPolicyClient;
// Waits for successful singin notification from the signin manager and then // Waits for successful singin notification from the signin manager and then
// starts the sync machine. Instances of this class delete themselves once // starts the sync machine. Instances of this class delete themselves once
// the job is done. // the job is done.
class OneClickSigninSyncStarter : public SigninTracker::Observer { class OneClickSigninSyncStarter : public SigninTracker::Observer,
public chrome::BrowserListObserver {
public: public:
enum StartSyncMode { enum StartSyncMode {
// Starts the process of signing the user in with the SigninManager, and // Starts the process of signing the user in with the SigninManager, and
...@@ -64,6 +66,9 @@ class OneClickSigninSyncStarter : public SigninTracker::Observer { ...@@ -64,6 +66,9 @@ class OneClickSigninSyncStarter : public SigninTracker::Observer {
bool force_same_tab_navigation, bool force_same_tab_navigation,
ConfirmationRequired display_confirmation); ConfirmationRequired display_confirmation);
// chrome::BrowserListObserver override.
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
private: private:
virtual ~OneClickSigninSyncStarter(); virtual ~OneClickSigninSyncStarter();
......
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