Chromium Code Reviews| Index: chrome/browser/sync/glue/autofill_profile_data_type_controller.cc |
| diff --git a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc |
| index e387ea49cc27b5913ef002db3ed3b16efb3e252f..729add7986f23b7cd247ad7fe3afb70452a55f74 100644 |
| --- a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc |
| +++ b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc |
| @@ -5,31 +5,122 @@ |
| #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/task.h" |
| +#include "chrome/browser/autofill/personal_data_manager.h" |
| +#include "chrome/browser/autofill/personal_data_manager_factory.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/sync/api/sync_error.h" |
| +#include "chrome/browser/sync/api/syncable_service.h" |
| #include "chrome/browser/sync/profile_sync_factory.h" |
| +#include "chrome/browser/sync/profile_sync_service.h" |
| #include "chrome/browser/webdata/web_data_service.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "content/browser/browser_thread.h" |
| +#include "content/common/notification_service.h" |
| +#include "content/common/notification_source.h" |
| namespace browser_sync { |
| AutofillProfileDataTypeController::AutofillProfileDataTypeController( |
| ProfileSyncFactory* profile_sync_factory, |
| Profile* profile) |
| - : AutofillDataTypeController(profile_sync_factory, profile) {} |
| + : NewNonFrontendDataTypeController(profile_sync_factory, profile), |
| + personal_data_(NULL) { |
| +} |
| AutofillProfileDataTypeController::~AutofillProfileDataTypeController() {} |
| +bool AutofillProfileDataTypeController::StartModels() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK_EQ(state(), MODEL_STARTING); |
| + // Waiting for the personal data is subtle: we do this as the PDM resets |
| + // its cache of unique IDs once it gets loaded. If we were to proceed with |
| + // association, the local ids in the mappings would wind up colliding. |
| + personal_data_ = PersonalDataManagerFactory::GetForProfile(profile()); |
| + if (!personal_data_->IsDataLoaded()) { |
| + personal_data_->SetObserver(this); |
| + return false; |
| + } |
| + |
| + web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS); |
| + if (web_data_service_.get() && web_data_service_->IsDatabaseLoaded()) { |
| + return true; |
| + } else { |
| + notification_registrar_.Add(this, chrome::NOTIFICATION_WEB_DATABASE_LOADED, |
| + NotificationService::AllSources()); |
| + return false; |
| + } |
| +} |
| + |
| +void AutofillProfileDataTypeController::OnPersonalDataChanged() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK_EQ(state(), MODEL_STARTING); |
| + personal_data_->RemoveObserver(this); |
| + web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS); |
| + if (web_data_service_.get() && web_data_service_->IsDatabaseLoaded()) { |
| + DoStartAssociationAsync(); |
| + } else { |
| + notification_registrar_.Add(this, chrome::NOTIFICATION_WEB_DATABASE_LOADED, |
| + NotificationService::AllSources()); |
| + } |
| +} |
| + |
| +void AutofillProfileDataTypeController::Observe( |
| + int notification_type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + notification_registrar_.RemoveAll(); |
| + DoStartAssociationAsync(); |
| +} |
| + |
| +void AutofillProfileDataTypeController::DoStartAssociationAsync() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK_EQ(state(), MODEL_STARTING); |
| + set_state(ASSOCIATING); |
| + if (!StartAssociationAsync()) { |
| + SyncError error(FROM_HERE, |
| + "Failed to post association task.", |
| + type()); |
| + StartDoneImpl(ASSOCIATION_FAILED, NOT_RUNNING, error); |
| + } |
| +} |
| + |
| +bool AutofillProfileDataTypeController::StartAssociationAsync() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK_EQ(state(), ASSOCIATING); |
| + return BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| + base::Bind(&AutofillProfileDataTypeController::StartAssociation, |
| + this)); |
| +} |
| + |
| +base::WeakPtr<SyncableService> |
| + AutofillProfileDataTypeController::GetWeakPtrToSyncableService() const { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| + // TODO(isherman): This shouldn't create anything, but just get a weakptr to |
|
akalin
2011/10/12 19:54:21
this TODO is now obsolete, isn't it? Or do you ne
Nicolas Zea
2011/10/12 23:47:43
Done.
|
| + // the AutofillProfileSyncableService. See crbug.com/96922. |
| + return profile_sync_factory()->GetAutofillProfileSyncableService( |
| + web_data_service_.get()); |
| +} |
| + |
| +void AutofillProfileDataTypeController::StopModels() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(state() == STOPPING || state() == NOT_RUNNING); |
| + notification_registrar_.RemoveAll(); |
| + personal_data_->RemoveObserver(this); |
| +} |
| + |
| +void AutofillProfileDataTypeController::StopLocalServiceAsync() { |
| + BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| + base::Bind(&AutofillProfileDataTypeController::StopLocalService, |
| + this)); |
| +} |
| syncable::ModelType AutofillProfileDataTypeController::type() const { |
| return syncable::AUTOFILL_PROFILE; |
| } |
| -void AutofillProfileDataTypeController::CreateSyncComponents() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| - ProfileSyncFactory::SyncComponents sync_components = |
| - profile_sync_factory()-> |
| - CreateAutofillProfileSyncComponents(profile_sync_service(), |
| - web_data_service(), |
| - this); |
| - set_model_associator(sync_components.model_associator); |
| - set_change_processor(sync_components.change_processor); |
| +browser_sync::ModelSafeGroup |
| + AutofillProfileDataTypeController::model_safe_group() const { |
| + return browser_sync::GROUP_DB; |
| } |
| void AutofillProfileDataTypeController::RecordUnrecoverableError( |