summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/gtk/import_dialog_gtk.cc2
-rw-r--r--chrome/browser/importer/importer.cc32
-rw-r--r--chrome/browser/importer/importer.h13
-rw-r--r--chrome/browser/importer/importer_unittest.cc29
-rw-r--r--chrome/browser/views/importing_progress_view.cc2
5 files changed, 60 insertions, 18 deletions
diff --git a/chrome/browser/gtk/import_dialog_gtk.cc b/chrome/browser/gtk/import_dialog_gtk.cc
index 15f9438..92e38b9 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, profile_, items,
+ importer_host_->StartImportSettings(source_profile, items,
new ProfileWriter(profile_), false);
}
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 34906d6..2bfb9f6 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -51,10 +51,23 @@ 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);
}
@@ -398,6 +411,7 @@ 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();
@@ -409,6 +423,7 @@ 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();
@@ -430,7 +445,11 @@ void ImporterHost::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED);
- registrar_.RemoveAll();
+ TemplateURLModel* model = Source<TemplateURLModel>(source).ptr();
+ NotificationService::current()->RemoveObserver(
+ this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
+ Source<TemplateURLModel>(model));
+ waiting_for_template_url_model_ = false;
InvokeTaskIfDone();
}
@@ -471,7 +490,6 @@ void ImporterHost::OnLockViewEnd(bool is_continue) {
}
void ImporterHost::StartImportSettings(const ProfileInfo& profile_info,
- Profile* target_profile,
uint16 items,
ProfileWriter* writer,
bool first_run) {
@@ -526,7 +544,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()) {
- target_profile->GetBookmarkModel()->AddObserver(this);
+ writer_->AddBookmarkModelObserver(this);
waiting_for_bookmarkbar_model_ = true;
}
@@ -535,10 +553,8 @@ 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()) {
- TemplateURLModel* model = target_profile->GetTemplateURLModel();
- registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
- Source<TemplateURLModel>(model));
- model->Load();
+ writer_->AddTemplateURLModelObserver(this);
+ waiting_for_template_url_model_ = true;
}
}
@@ -556,7 +572,7 @@ void ImporterHost::SetObserver(Observer* observer) {
}
void ImporterHost::InvokeTaskIfDone() {
- if (waiting_for_bookmarkbar_model_ || !registrar_.IsEmpty() ||
+ if (waiting_for_bookmarkbar_model_ || waiting_for_template_url_model_ ||
!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 420a733e..765df3c 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_registrar.h"
+#include "chrome/common/notification_observer.h"
#include "googleurl/src/gurl.h"
#include "webkit/glue/password_form.h"
@@ -79,8 +79,15 @@ 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 {
@@ -205,7 +212,6 @@ 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);
@@ -284,8 +290,6 @@ 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_;
@@ -303,6 +307,7 @@ 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 e732365..ebe23c8 100644
--- a/chrome/browser/importer/importer_unittest.cc
+++ b/chrome/browser/importer/importer_unittest.cc
@@ -158,10 +158,18 @@ 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);
@@ -339,8 +347,7 @@ TEST_F(ImporterTest, IEImporter) {
loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(),
&ImporterHost::StartImportSettings, profile_info,
- static_cast<Profile*>(NULL), HISTORY | PASSWORDS | FAVORITES, observer,
- true));
+ HISTORY | PASSWORDS | FAVORITES, observer, true));
loop->Run();
// Cleans up.
@@ -506,10 +513,18 @@ 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());
@@ -615,7 +630,6 @@ 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();
}
@@ -696,10 +710,18 @@ 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());
@@ -809,7 +831,6 @@ 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 d2545f6..8ed9bf8 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, target_profile, items,
+ coordinator->StartImportSettings(source_profile, items,
new ProfileWriter(target_profile),
first_run);
}