diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 01:12:54 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-22 01:12:54 +0000 |
commit | e6eafada6bf8530fc66c3f36bc020492f5f9b352 (patch) | |
tree | 19d54e04ff323b7288f8ed35bb1f6d76ed046d2f /chrome | |
parent | 23c0944dfc6fc352aa3acdb01d733cc549cba7c6 (diff) | |
download | chromium_src-e6eafada6bf8530fc66c3f36bc020492f5f9b352.zip chromium_src-e6eafada6bf8530fc66c3f36bc020492f5f9b352.tar.gz chromium_src-e6eafada6bf8530fc66c3f36bc020492f5f9b352.tar.bz2 |
Revert "Revert "Use a NotificationRegistrar to listen for notifications. BUG=2381""
This reverts commit r16687 (i.e., relands r16666).
TBR=pkasting
Review URL: http://codereview.chromium.org/115686
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/import_dialog_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 32 | ||||
-rw-r--r-- | chrome/browser/importer/importer.h | 13 | ||||
-rw-r--r-- | chrome/browser/importer/importer_unittest.cc | 29 | ||||
-rw-r--r-- | chrome/browser/views/importing_progress_view.cc | 2 |
5 files changed, 18 insertions, 60 deletions
diff --git a/chrome/browser/gtk/import_dialog_gtk.cc b/chrome/browser/gtk/import_dialog_gtk.cc index 92e38b9..15f9438 100644 --- a/chrome/browser/gtk/import_dialog_gtk.cc +++ b/chrome/browser/gtk/import_dialog_gtk.cc @@ -99,7 +99,7 @@ void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { // TODO(rahulk): We should not do the import on this thread. Instead // we need to start this asynchronously and launch a UI that shows the // progress of import. - importer_host_->StartImportSettings(source_profile, items, + importer_host_->StartImportSettings(source_profile, profile_, items, new ProfileWriter(profile_), false); } diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 2bfb9f6..34906d6 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -51,23 +51,10 @@ bool ProfileWriter::BookmarkModelIsLoaded() const { return profile_->GetBookmarkModel()->IsLoaded(); } -void ProfileWriter::AddBookmarkModelObserver(BookmarkModelObserver* observer) { - profile_->GetBookmarkModel()->AddObserver(observer); -} - bool ProfileWriter::TemplateURLModelIsLoaded() const { return profile_->GetTemplateURLModel()->loaded(); } -void ProfileWriter::AddTemplateURLModelObserver( - NotificationObserver* observer) { - TemplateURLModel* model = profile_->GetTemplateURLModel(); - NotificationService::current()->AddObserver( - observer, NotificationType::TEMPLATE_URL_MODEL_LOADED, - Source<TemplateURLModel>(model)); - model->Load(); -} - void ProfileWriter::AddPasswordForm(const PasswordForm& form) { profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddLogin(form); } @@ -411,7 +398,6 @@ ImporterHost::ImporterHost() importer_(NULL), file_loop_(g_browser_process->file_thread()->message_loop()), waiting_for_bookmarkbar_model_(false), - waiting_for_template_url_model_(false), is_source_readable_(true), headless_(false) { DetectSourceProfiles(); @@ -423,7 +409,6 @@ ImporterHost::ImporterHost(MessageLoop* file_loop) importer_(NULL), file_loop_(file_loop), waiting_for_bookmarkbar_model_(false), - waiting_for_template_url_model_(false), is_source_readable_(true), headless_(false) { DetectSourceProfiles(); @@ -445,11 +430,7 @@ void ImporterHost::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED); - TemplateURLModel* model = Source<TemplateURLModel>(source).ptr(); - NotificationService::current()->RemoveObserver( - this, NotificationType::TEMPLATE_URL_MODEL_LOADED, - Source<TemplateURLModel>(model)); - waiting_for_template_url_model_ = false; + registrar_.RemoveAll(); InvokeTaskIfDone(); } @@ -490,6 +471,7 @@ void ImporterHost::OnLockViewEnd(bool is_continue) { } void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, + Profile* target_profile, uint16 items, ProfileWriter* writer, bool first_run) { @@ -544,7 +526,7 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, // BookmarkModel should be loaded before adding IE favorites. So we observe // the BookmarkModel if needed, and start the task after it has been loaded. if ((items & FAVORITES) && !writer_->BookmarkModelIsLoaded()) { - writer_->AddBookmarkModelObserver(this); + target_profile->GetBookmarkModel()->AddObserver(this); waiting_for_bookmarkbar_model_ = true; } @@ -553,8 +535,10 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, // we can import bookmark keywords from Firefox as search engines. if ((items & SEARCH_ENGINES) || (items & FAVORITES)) { if (!writer_->TemplateURLModelIsLoaded()) { - writer_->AddTemplateURLModelObserver(this); - waiting_for_template_url_model_ = true; + TemplateURLModel* model = target_profile->GetTemplateURLModel(); + registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED, + Source<TemplateURLModel>(model)); + model->Load(); } } @@ -572,7 +556,7 @@ void ImporterHost::SetObserver(Observer* observer) { } void ImporterHost::InvokeTaskIfDone() { - if (waiting_for_bookmarkbar_model_ || waiting_for_template_url_model_ || + if (waiting_for_bookmarkbar_model_ || !registrar_.IsEmpty() || !is_source_readable_) return; file_loop_->PostTask(FROM_HERE, task_); diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index 765df3c..420a733e 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -20,7 +20,7 @@ #endif #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" -#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" #include "webkit/glue/password_form.h" @@ -79,15 +79,8 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { explicit ProfileWriter(Profile* profile) : profile_(profile) { } virtual ~ProfileWriter() { } - // Methods for monitoring BookmarkModel status. virtual bool BookmarkModelIsLoaded() const; - virtual void AddBookmarkModelObserver( - BookmarkModelObserver* observer); - - // Methods for monitoring TemplateURLModel status. virtual bool TemplateURLModelIsLoaded() const; - virtual void AddTemplateURLModelObserver( - NotificationObserver* observer); // A bookmark entry. struct BookmarkEntry { @@ -212,6 +205,7 @@ class ImporterHost : public base::RefCounted<ImporterHost>, // Starts the process of importing the settings and data depending // on what the user selected. void StartImportSettings(const ProfileInfo& profile_info, + Profile* target_profile, uint16 items, ProfileWriter* writer, bool first_run); @@ -290,6 +284,8 @@ class ImporterHost : public base::RefCounted<ImporterHost>, void DetectFirefoxProfiles(); void DetectGoogleToolbarProfiles(); + NotificationRegistrar registrar_; + // The list of profiles with the default one first. std::vector<ProfileInfo*> source_profiles_; @@ -307,7 +303,6 @@ class ImporterHost : public base::RefCounted<ImporterHost>, // True if we're waiting for the model to finish loading. bool waiting_for_bookmarkbar_model_; - bool waiting_for_template_url_model_; // True if source profile is readable. bool is_source_readable_; diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index ebe23c8..e732365 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -158,18 +158,10 @@ class TestObserver : public ProfileWriter, return true; } - virtual void AddBookmarkModelObserver(BookmarkModelObserver* observer) { - NOTREACHED(); - } - virtual bool TemplateURLModelIsLoaded() const { return true; } - virtual void AddTemplateURLModelObserver(NotificationObserver* observer) { - NOTREACHED(); - } - virtual void AddPasswordForm(const PasswordForm& form) { // Importer should obtain this password form only. EXPECT_EQ(GURL("http://localhost:8080/security/index.htm"), form.origin); @@ -347,7 +339,8 @@ TEST_F(ImporterTest, IEImporter) { loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), &ImporterHost::StartImportSettings, profile_info, - HISTORY | PASSWORDS | FAVORITES, observer, true)); + static_cast<Profile*>(NULL), HISTORY | PASSWORDS | FAVORITES, observer, + true)); loop->Run(); // Cleans up. @@ -513,18 +506,10 @@ class FirefoxObserver : public ProfileWriter, return true; } - virtual void AddBookmarkModelObserver(BookmarkModelObserver* observer) { - NOTREACHED(); - } - virtual bool TemplateURLModelIsLoaded() const { return true; } - virtual void AddTemplateURLModelObserver(NotificationObserver* observer) { - NOTREACHED(); - } - virtual void AddPasswordForm(const PasswordForm& form) { PasswordList p = kFirefox2Passwords[password_count_]; EXPECT_EQ(p.origin, form.origin.spec()); @@ -630,6 +615,7 @@ TEST_F(ImporterTest, Firefox2Importer) { loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), &ImporterHost::StartImportSettings, profile_info, + static_cast<Profile*>(NULL), HISTORY | PASSWORDS | FAVORITES | SEARCH_ENGINES, observer, true)); loop->Run(); } @@ -710,18 +696,10 @@ class Firefox3Observer : public ProfileWriter, return true; } - virtual void AddBookmarkModelObserver(BookmarkModelObserver* observer) { - NOTREACHED(); - } - virtual bool TemplateURLModelIsLoaded() const { return true; } - virtual void AddTemplateURLModelObserver(NotificationObserver* observer) { - NOTREACHED(); - } - virtual void AddPasswordForm(const PasswordForm& form) { PasswordList p = kFirefox3Passwords[password_count_]; EXPECT_EQ(p.origin, form.origin.spec()); @@ -831,6 +809,7 @@ TEST_F(ImporterTest, Firefox3Importer) { host->SetObserver(observer); loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), &ImporterHost::StartImportSettings, profile_info, + static_cast<Profile*>(NULL), HISTORY | PASSWORDS | FAVORITES | SEARCH_ENGINES, observer, true)); loop->Run(); } diff --git a/chrome/browser/views/importing_progress_view.cc b/chrome/browser/views/importing_progress_view.cc index 8ed9bf8..d2545f6 100644 --- a/chrome/browser/views/importing_progress_view.cc +++ b/chrome/browser/views/importing_progress_view.cc @@ -308,7 +308,7 @@ void StartImportingWithUI(HWND parent_window, if (!coordinator->is_headless()) window->Show(); - coordinator->StartImportSettings(source_profile, items, + coordinator->StartImportSettings(source_profile, target_profile, items, new ProfileWriter(target_profile), first_run); } |