From 3b4a0d3345176796b254f37a293ae13e48e10876 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Tue, 10 Jul 2012 16:36:23 +0000 Subject: Remove browser::FindLastActiveWithProfile call in importer code. There are many ways to create an ImporterHost, but only when it's created from the webui do we give the option to import from Google Toolbar. In that case, pass the Browser* directly. BUG=129187 Review URL: https://chromiumcodereview.appspot.com/10750018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145890 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/importer/importer_host.cc | 15 ++++++++++----- chrome/browser/importer/importer_host.h | 12 +++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'chrome/browser/importer') diff --git a/chrome/browser/importer/importer_host.cc b/chrome/browser/importer/importer_host.cc index 4003c76..1485dca 100644 --- a/chrome/browser/importer/importer_host.cc +++ b/chrome/browser/importer/importer_host.cc @@ -20,7 +20,6 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/simple_message_box.h" #include "chrome/common/chrome_notification_types.h" @@ -40,7 +39,9 @@ ImporterHost::ImporterHost() importer_(NULL), headless_(false), parent_window_(NULL), + browser_(NULL), observer_(NULL) { + BrowserList::AddObserver(this); } void ImporterHost::ShowWarningDialog() { @@ -163,10 +164,8 @@ void ImporterHost::OnGoogleGAIACookieChecked(bool result) { chrome::MESSAGE_BOX_TYPE_INFORMATION); GURL url("https://accounts.google.com/ServiceLogin"); - DCHECK(profile_); - Browser* browser = browser::FindLastActiveWithProfile(profile_); - if (browser) - chrome::AddSelectedTabWithURL(browser, url, + if (browser_) + chrome::AddSelectedTabWithURL(browser_, url, content::PAGE_TRANSITION_TYPED); MessageLoop::current()->PostTask(FROM_HERE, base::Bind( @@ -184,6 +183,7 @@ void ImporterHost::Cancel() { } ImporterHost::~ImporterHost() { + BrowserList::RemoveObserver(this); if (NULL != importer_) importer_->Release(); @@ -266,3 +266,8 @@ void ImporterHost::Observe(int type, registrar_.RemoveAll(); InvokeTaskIfDone(); } + +void ImporterHost::OnBrowserRemoved(Browser* browser) { + if (browser_ == browser) + browser_ = NULL; +} diff --git a/chrome/browser/importer/importer_host.h b/chrome/browser/importer/importer_host.h index 18235eb..359f1d2 100644 --- a/chrome/browser/importer/importer_host.h +++ b/chrome/browser/importer/importer_host.h @@ -14,6 +14,7 @@ #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" #include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/importer/profile_writer.h" +#include "chrome/browser/ui/browser_list.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "ui/gfx/native_widget_types.h" @@ -31,7 +32,8 @@ class ImporterProgressObserver; // the import process is done, ImporterHost deletes itself. class ImporterHost : public base::RefCountedThreadSafe, public BaseBookmarkModelObserver, - public content::NotificationObserver { + public content::NotificationObserver, + public BrowserList::Observer { public: ImporterHost(); @@ -63,6 +65,8 @@ class ImporterHost : public base::RefCountedThreadSafe, parent_window_ = parent_window; } + void set_browser(Browser* browser) { browser_ = browser; } + // Starts the process of importing the settings and data depending on what the // user selected. // |source_profile| - importer profile to import. @@ -139,6 +143,9 @@ class ImporterHost : public base::RefCountedThreadSafe, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // BrowserList::Observer + virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; + // The task is the process of importing settings from other browsers. base::Closure task_; @@ -152,6 +159,9 @@ class ImporterHost : public base::RefCountedThreadSafe, // warning dialog). gfx::NativeWindow parent_window_; + // Used to add a new tab if we need the user to sign in. + Browser* browser_; + // The observer that we need to notify about changes in the import process. importer::ImporterProgressObserver* observer_; -- cgit v1.1