| Index: chrome/browser/webdata/autofill_web_data_service.cc
 | 
| diff --git a/chrome/browser/webdata/autofill_web_data_service.cc b/chrome/browser/webdata/autofill_web_data_service.cc
 | 
| index 2f7e630897b375b211a2f0e592b10a39f96422be..efe5d16fef9c61acffa3fbbe40915b79920b7c4d 100644
 | 
| --- a/chrome/browser/webdata/autofill_web_data_service.cc
 | 
| +++ b/chrome/browser/webdata/autofill_web_data_service.cc
 | 
| @@ -9,35 +9,17 @@
 | 
|  #include "chrome/browser/webdata/autofill_change.h"
 | 
|  #include "chrome/browser/webdata/autofill_entry.h"
 | 
|  #include "chrome/browser/webdata/autofill_table.h"
 | 
| +#include "chrome/browser/webdata/autofill_web_data_service_observer.h"
 | 
|  #include "chrome/browser/webdata/web_database_service.h"
 | 
| -#include "chrome/common/chrome_notification_types.h"
 | 
|  #include "components/autofill/browser/autofill_country.h"
 | 
|  #include "components/autofill/browser/autofill_profile.h"
 | 
|  #include "components/autofill/browser/credit_card.h"
 | 
|  #include "components/autofill/common/form_field_data.h"
 | 
| -#include "content/public/browser/notification_details.h"
 | 
| -#include "content/public/browser/notification_service.h"
 | 
| -#include "content/public/browser/notification_source.h"
 | 
|  
 | 
|  using base::Bind;
 | 
|  using base::Time;
 | 
|  using content::BrowserThread;
 | 
|  
 | 
| -namespace {
 | 
| -
 | 
| -// A task used by AutofillWebDataService (for Sync mainly) to inform the
 | 
| -// PersonalDataManager living on the UI thread that it needs to refresh.
 | 
| -void NotifyOfMultipleAutofillChangesTask(
 | 
| -    const scoped_refptr<AutofillWebDataService>& web_data_service) {
 | 
| -  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 | 
| -
 | 
| -  content::NotificationService::current()->Notify(
 | 
| -      chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
 | 
| -      content::Source<AutofillWebDataService>(web_data_service.get()),
 | 
| -      content::NotificationService::NoDetails());
 | 
| -}
 | 
| -}
 | 
| -
 | 
|  // static
 | 
|  void AutofillWebDataService::NotifyOfMultipleAutofillChanges(
 | 
|      AutofillWebDataService* web_data_service) {
 | 
| @@ -48,7 +30,7 @@ void AutofillWebDataService::NotifyOfMultipleAutofillChanges(
 | 
|  
 | 
|    BrowserThread::PostTask(
 | 
|        BrowserThread::UI, FROM_HERE,
 | 
| -      Bind(&NotifyOfMultipleAutofillChangesTask,
 | 
| +      Bind(&AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread,
 | 
|             make_scoped_refptr(web_data_service)));
 | 
|  }
 | 
|  
 | 
| @@ -63,10 +45,6 @@ AutofillWebDataService::AutofillWebDataService()
 | 
|                           WebDataServiceBase::ProfileErrorCallback()) {
 | 
|  }
 | 
|  
 | 
| -content::NotificationSource AutofillWebDataService::GetNotificationSource() {
 | 
| -  return content::Source<AutofillWebDataService>(this);
 | 
| -}
 | 
| -
 | 
|  void AutofillWebDataService::AddFormFields(
 | 
|      const std::vector<FormFieldData>& fields) {
 | 
|    wdbs_->ScheduleDBTask(FROM_HERE,
 | 
| @@ -127,19 +105,21 @@ WebDataServiceBase::Handle AutofillWebDataService::GetAutofillProfiles(
 | 
|  }
 | 
|  
 | 
|  void AutofillWebDataService::AddCreditCard(const CreditCard& credit_card) {
 | 
| -  wdbs_->ScheduleDBTask(FROM_HERE,
 | 
| +  wdbs_->ScheduleDBTask(
 | 
| +      FROM_HERE,
 | 
|        Bind(&AutofillWebDataService::AddCreditCardImpl, this, credit_card));
 | 
|  }
 | 
|  
 | 
|  void AutofillWebDataService::UpdateCreditCard(
 | 
|      const CreditCard& credit_card) {
 | 
| -  wdbs_->ScheduleDBTask(FROM_HERE,
 | 
| -      Bind(&AutofillWebDataService::UpdateCreditCardImpl, this,
 | 
| -           credit_card));
 | 
| +  wdbs_->ScheduleDBTask(
 | 
| +      FROM_HERE,
 | 
| +      Bind(&AutofillWebDataService::UpdateCreditCardImpl, this, credit_card));
 | 
|  }
 | 
|  
 | 
|  void AutofillWebDataService::RemoveCreditCard(const std::string& guid) {
 | 
| -  wdbs_->ScheduleDBTask(FROM_HERE,
 | 
| +  wdbs_->ScheduleDBTask(
 | 
| +      FROM_HERE,
 | 
|        Bind(&AutofillWebDataService::RemoveCreditCardImpl, this, guid));
 | 
|  }
 | 
|  
 | 
| @@ -150,13 +130,45 @@ WebDataServiceBase::Handle AutofillWebDataService::GetCreditCards(
 | 
|  }
 | 
|  
 | 
|  void AutofillWebDataService::RemoveAutofillDataModifiedBetween(
 | 
| -    const Time& delete_begin, const Time& delete_end) {
 | 
| -  wdbs_->ScheduleDBTask(FROM_HERE, Bind(
 | 
| -&AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl,
 | 
| -      this, delete_begin, delete_end));
 | 
| +    const Time& delete_begin,
 | 
| +    const Time& delete_end) {
 | 
| +  wdbs_->ScheduleDBTask(
 | 
| +      FROM_HERE,
 | 
| +      Bind(&AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl,
 | 
| +           this, delete_begin, delete_end));
 | 
| +}
 | 
| +
 | 
| +void AutofillWebDataService::AddObserver(
 | 
| +    AutofillWebDataServiceObserverOnDBThread* observer) {
 | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
 | 
| +  db_observer_list_.AddObserver(observer);
 | 
| +}
 | 
| +
 | 
| +void AutofillWebDataService::RemoveObserver(
 | 
| +    AutofillWebDataServiceObserverOnDBThread* observer) {
 | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
 | 
| +  db_observer_list_.RemoveObserver(observer);
 | 
|  }
 | 
|  
 | 
| -AutofillWebDataService::~AutofillWebDataService() {
 | 
| +void AutofillWebDataService::AddObserver(
 | 
| +    AutofillWebDataServiceObserverOnUIThread* observer) {
 | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 | 
| +  ui_observer_list_.AddObserver(observer);
 | 
| +}
 | 
| +
 | 
| +void AutofillWebDataService::RemoveObserver(
 | 
| +    AutofillWebDataServiceObserverOnUIThread* observer) {
 | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 | 
| +  ui_observer_list_.RemoveObserver(observer);
 | 
| +}
 | 
| +
 | 
| +AutofillWebDataService::~AutofillWebDataService() {}
 | 
| +
 | 
| +void AutofillWebDataService::NotifyDatabaseLoadedOnUIThread() {
 | 
| +  // Notify that the database has been initialized.
 | 
| +  FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread,
 | 
| +                    ui_observer_list_,
 | 
| +                    WebDatabaseLoaded());
 | 
|  }
 | 
|  
 | 
|  ////////////////////////////////////////////////////////////////////////////////
 | 
| @@ -178,10 +190,9 @@ WebDatabase::State AutofillWebDataService::AddFormElementsImpl(
 | 
|    // Post the notifications including the list of affected keys.
 | 
|    // This is sent here so that work resulting from this notification will be
 | 
|    // done on the DB thread, and not the UI thread.
 | 
| -  content::NotificationService::current()->Notify(
 | 
| -      chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
 | 
| -      content::Source<AutofillWebDataService>(this),
 | 
| -      content::Details<AutofillChangeList>(&changes));
 | 
| +  FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                    db_observer_list_,
 | 
| +                    AutofillEntriesChanged(changes));
 | 
|  
 | 
|    return WebDatabase::COMMIT_NEEDED;
 | 
|  }
 | 
| @@ -209,10 +220,9 @@ WebDatabase::State AutofillWebDataService::RemoveFormElementsAddedBetweenImpl(
 | 
|        // Post the notifications including the list of affected keys.
 | 
|        // This is sent here so that work resulting from this notification
 | 
|        // will be done on the DB thread, and not the UI thread.
 | 
| -      content::NotificationService::current()->Notify(
 | 
| -          chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
 | 
| -          content::Source<AutofillWebDataService>(this),
 | 
| -          content::Details<AutofillChangeList>(&changes));
 | 
| +      FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                        db_observer_list_,
 | 
| +                        AutofillEntriesChanged(changes));
 | 
|      }
 | 
|      return WebDatabase::COMMIT_NEEDED;
 | 
|    }
 | 
| @@ -229,10 +239,9 @@ WebDatabase::State AutofillWebDataService::RemoveExpiredFormElementsImpl(
 | 
|        // Post the notifications including the list of affected keys.
 | 
|        // This is sent here so that work resulting from this notification
 | 
|        // will be done on the DB thread, and not the UI thread.
 | 
| -      content::NotificationService::current()->Notify(
 | 
| -          chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
 | 
| -          content::Source<AutofillWebDataService>(this),
 | 
| -          content::Details<AutofillChangeList>(&changes));
 | 
| +      FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                        db_observer_list_,
 | 
| +                        AutofillEntriesChanged(changes));
 | 
|      }
 | 
|      return WebDatabase::COMMIT_NEEDED;
 | 
|    }
 | 
| @@ -245,14 +254,13 @@ WebDatabase::State AutofillWebDataService::RemoveFormValueForElementNameImpl(
 | 
|  
 | 
|    if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
 | 
|      AutofillChangeList changes;
 | 
| -    changes.push_back(AutofillChange(AutofillChange::REMOVE,
 | 
| -                                     AutofillKey(name, value)));
 | 
| +    changes.push_back(
 | 
| +        AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value)));
 | 
|  
 | 
|      // Post the notifications including the list of affected keys.
 | 
| -    content::NotificationService::current()->Notify(
 | 
| -        chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
 | 
| -        content::Source<AutofillWebDataService>(this),
 | 
| -        content::Details<AutofillChangeList>(&changes));
 | 
| +    FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                      db_observer_list_,
 | 
| +                      AutofillEntriesChanged(changes));
 | 
|  
 | 
|      return WebDatabase::COMMIT_NEEDED;
 | 
|    }
 | 
| @@ -268,12 +276,11 @@ WebDatabase::State AutofillWebDataService::AddAutofillProfileImpl(
 | 
|    }
 | 
|  
 | 
|    // Send GUID-based notification.
 | 
| -  AutofillProfileChange change(AutofillProfileChange::ADD,
 | 
| -                               profile.guid(), &profile);
 | 
| -  content::NotificationService::current()->Notify(
 | 
| -      chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
 | 
| -      content::Source<AutofillWebDataService>(this),
 | 
| -      content::Details<AutofillProfileChange>(&change));
 | 
| +  AutofillProfileChange change(
 | 
| +      AutofillProfileChange::ADD, profile.guid(), &profile);
 | 
| +  FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                    db_observer_list_,
 | 
| +                    AutofillProfileChanged(change));
 | 
|  
 | 
|    return WebDatabase::COMMIT_NEEDED;
 | 
|  }
 | 
| @@ -298,12 +305,11 @@ WebDatabase::State AutofillWebDataService::UpdateAutofillProfileImpl(
 | 
|    }
 | 
|  
 | 
|    // Send GUID-based notification.
 | 
| -  AutofillProfileChange change(AutofillProfileChange::UPDATE,
 | 
| -                               profile.guid(), &profile);
 | 
| -  content::NotificationService::current()->Notify(
 | 
| -      chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
 | 
| -      content::Source<AutofillWebDataService>(this),
 | 
| -      content::Details<AutofillProfileChange>(&change));
 | 
| +  AutofillProfileChange change(
 | 
| +      AutofillProfileChange::UPDATE, profile.guid(), &profile);
 | 
| +  FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                    db_observer_list_,
 | 
| +                    AutofillProfileChanged(change));
 | 
|  
 | 
|    return WebDatabase::COMMIT_NEEDED;
 | 
|  }
 | 
| @@ -325,10 +331,9 @@ WebDatabase::State AutofillWebDataService::RemoveAutofillProfileImpl(
 | 
|  
 | 
|    // Send GUID-based notification.
 | 
|    AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL);
 | 
| -  content::NotificationService::current()->Notify(
 | 
| -      chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
 | 
| -      content::Source<AutofillWebDataService>(this),
 | 
| -      content::Details<AutofillProfileChange>(&change));
 | 
| +  FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                    db_observer_list_,
 | 
| +                    AutofillProfileChanged(change));
 | 
|  
 | 
|    return WebDatabase::COMMIT_NEEDED;
 | 
|  }
 | 
| @@ -400,25 +405,24 @@ scoped_ptr<WDTypedResult> AutofillWebDataService::GetCreditCardsImpl(
 | 
|  }
 | 
|  
 | 
|  WebDatabase::State
 | 
| -AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl(
 | 
| -        const base::Time& delete_begin, const base::Time& delete_end,
 | 
| +    AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl(
 | 
| +        const base::Time& delete_begin,
 | 
| +        const base::Time& delete_end,
 | 
|          WebDatabase* db) {
 | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
 | 
|    std::vector<std::string> profile_guids;
 | 
|    std::vector<std::string> credit_card_guids;
 | 
| -  if (AutofillTable::FromWebDatabase(db)->
 | 
| -      RemoveAutofillDataModifiedBetween(
 | 
| +  if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween(
 | 
|            delete_begin,
 | 
|            delete_end,
 | 
|            &profile_guids,
 | 
|            &credit_card_guids)) {
 | 
|      for (std::vector<std::string>::iterator iter = profile_guids.begin();
 | 
|           iter != profile_guids.end(); ++iter) {
 | 
| -      AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter,
 | 
| -                                   NULL);
 | 
| -      content::NotificationService::current()->Notify(
 | 
| -          chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
 | 
| -          content::Source<AutofillWebDataService>(this),
 | 
| -          content::Details<AutofillProfileChange>(&change));
 | 
| +      AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL);
 | 
| +      FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
 | 
| +                        db_observer_list_,
 | 
| +                        AutofillProfileChanged(change));
 | 
|      }
 | 
|      // Note: It is the caller's responsibility to post notifications for any
 | 
|      // changes, e.g. by calling the Refresh() method of PersonalDataManager.
 | 
| @@ -445,3 +449,10 @@ void AutofillWebDataService::DestroyAutofillCreditCardResult(
 | 
|    std::vector<CreditCard*> credit_cards = r->GetValue();
 | 
|    STLDeleteElements(&credit_cards);
 | 
|  }
 | 
| +
 | 
| +void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() {
 | 
| +  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 | 
| +  FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread,
 | 
| +                    ui_observer_list_,
 | 
| +                    AutofillMultipleChanged());
 | 
| +}
 | 
| 
 |