diff options
author | georgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 22:52:34 +0000 |
---|---|---|
committer | georgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 22:52:34 +0000 |
commit | d857d72eb2795bb1a386878cf1a53e8e7ef6827a (patch) | |
tree | 0ddf3163521820abefde2ebeec10ea80c65a3fb9 /chrome/browser/autofill | |
parent | 2db27be7dbb16f02587b90f150a843d8ad234563 (diff) | |
download | chromium_src-d857d72eb2795bb1a386878cf1a53e8e7ef6827a.zip chromium_src-d857d72eb2795bb1a386878cf1a53e8e7ef6827a.tar.gz chromium_src-d857d72eb2795bb1a386878cf1a53e8e7ef6827a.tar.bz2 |
Dialog showed now only if profiles are loaded - if not it waits until they are.
Added capability of multiple observers for profile loading.
BUG=33026
TEST=If loading of profiles takes time (slow connection, for example), dialog does not appear until they are loaded.
Review URL: http://codereview.chromium.org/601010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38688 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.cc | 38 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.h | 4 |
2 files changed, 32 insertions, 10 deletions
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc index 7f9a581..87cb5b6 100644 --- a/chrome/browser/autofill/personal_data_manager.cc +++ b/chrome/browser/autofill/personal_data_manager.cc @@ -54,8 +54,16 @@ void PersonalDataManager::OnWebDataServiceRequestDone( // If both requests have responded, then all personal data is loaded. if (pending_profiles_query_ == 0 && pending_creditcards_query_ == 0) { is_data_loaded_ = true; - if (observer_) - observer_->OnPersonalDataLoaded(); + // Copy is needed as observer can unsubsribe itself when notified. + std::vector<PersonalDataManager::Observer*> temporary_copy; + temporary_copy.resize(observers_.size()); + std::copy(observers_.begin(), observers_.end(), temporary_copy.begin()); + for (std::vector<PersonalDataManager::Observer*>::iterator + iter = temporary_copy.begin(); + iter != temporary_copy.end(); + ++iter) { + (*iter)->OnPersonalDataLoaded(); + } } } @@ -74,14 +82,29 @@ void PersonalDataManager::OnAutoFillDialogApply( } void PersonalDataManager::SetObserver(PersonalDataManager::Observer* observer) { - DCHECK(observer_ == NULL); - observer_ = observer; + for (std::vector<PersonalDataManager::Observer*>::iterator + iter = observers_.begin(); + iter != observers_.end(); + ++iter) { + if (*iter == observer) { + // Already have this observer. + return; + } + } + observers_.push_back(observer); } void PersonalDataManager::RemoveObserver( PersonalDataManager::Observer* observer) { - if (observer_ == observer) - observer_ = NULL; + for (std::vector<PersonalDataManager::Observer*>::iterator + iter = observers_.begin(); + iter != observers_.end(); + ++iter) { + if (*iter == observer) { + observers_.erase(iter); + return; + } + } } bool PersonalDataManager::ImportFormData( @@ -329,8 +352,7 @@ PersonalDataManager::PersonalDataManager(Profile* profile) is_initialized_(false), is_data_loaded_(false), pending_profiles_query_(0), - pending_creditcards_query_(0), - observer_(NULL) { + pending_creditcards_query_(0) { LoadProfiles(); LoadCreditCards(); } diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index 7f4bb38..1dfbd1f 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -180,8 +180,8 @@ class PersonalDataManager : public WebDataServiceConsumer, WebDataService::Handle pending_profiles_query_; WebDataService::Handle pending_creditcards_query_; - // The observer. This can be NULL. - Observer* observer_; + // The observers. This can be empty. + std::vector<PersonalDataManager::Observer*> observers_; DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); }; |