Index: components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h |
diff --git a/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h b/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..85986d8f45434d41339d134f8a5fddddeec29838 |
--- /dev/null |
+++ b/components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h |
@@ -0,0 +1,98 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_METADATA_SYNCABLE_SERVICE_H_ |
+#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_METADATA_SYNCABLE_SERVICE_H_ |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/scoped_observer.h" |
+#include "base/supports_user_data.h" |
+#include "base/threading/thread_checker.h" |
+#include "components/autofill/core/browser/webdata/autofill_webdata_service_observer.h" |
+#include "sync/api/syncable_service.h" |
+ |
+namespace autofill { |
+ |
+class AutofillProfile; |
+class AutofillWebDataBackend; |
+class AutofillWebDataService; |
+class CreditCard; |
+ |
+// Syncs usage counts and last use dates for Wallet cards and addresses. |
+class AutofillWalletMetadataSyncableService |
+ : public base::SupportsUserData::Data, |
+ public syncer::SyncableService, |
+ public AutofillWebDataServiceObserverOnDBThread { |
+ public: |
+ ~AutofillWalletMetadataSyncableService() override; |
+ |
+ // syncer::SyncableService implementation. |
+ syncer::SyncMergeResult MergeDataAndStartSyncing( |
+ syncer::ModelType type, |
+ const syncer::SyncDataList& initial_sync_data, |
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
+ scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) override; |
+ void StopSyncing(syncer::ModelType type) override; |
+ syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; |
+ syncer::SyncError ProcessSyncChanges( |
+ const tracked_objects::Location& from_here, |
+ const syncer::SyncChangeList& change_list) override; |
+ |
+ // AutofillWebDataServiceObserverOnDBThread implementation. |
+ void AutofillProfileChanged(const AutofillProfileChange& change) override; |
+ void CreditCardChanged(const CreditCardChange& change) override; |
+ void AutofillMultipleChanged() override; |
+ |
+ // Creates a new AutofillWalletMetadataSyncableService and hangs it off of |
+ // |web_data_service|, which takes ownership. This method should only be |
+ // called on |web_data_service|'s DB thread. |
+ static void CreateForWebDataServiceAndBackend( |
+ AutofillWebDataService* web_data_service, |
+ AutofillWebDataBackend* webdata_backend, |
+ const std::string& app_locale); |
+ |
+ // Retrieves the AutofillWalletMetadataSyncableService stored on |
+ // |web_data_service|. |
+ static AutofillWalletMetadataSyncableService* FromWebDataService( |
+ AutofillWebDataService* web_data_service); |
+ |
+ protected: |
+ AutofillWalletMetadataSyncableService(AutofillWebDataBackend* webdata_backend, |
+ const std::string& app_locale); |
+ |
+ // Overridden in tests. |
+ virtual bool GetServerProfiles(std::vector<AutofillProfile*>* profiles) const; |
+ virtual bool GetServerCreditCards( |
+ std::vector<CreditCard*>* credit_cards) const; |
+ virtual bool UpdateServerAddressUsageStats(const AutofillProfile& profile); |
+ virtual bool UpdateServerCardUsageStats(const CreditCard& credit_card); |
+ |
+ private: |
+ // Updates local and remote metadata. |
+ // Deletes remote metadata for which there's no local Wallet data. |
+ // Adds missing remote metadata. |
+ syncer::SyncError Reconcile(const syncer::SyncDataList& sync_data); |
+ |
+ // Populates the provided |profiles| and |cards| with mappings from server ID |
+ // to unowned server profiles and server cards. Returns true on success. |
+ bool GetServerData(std::map<std::string, AutofillProfile*>* profiles, |
+ std::map<std::string, CreditCard*>* cards); |
+ |
+ base::ThreadChecker thread_checker_; |
+ AutofillWebDataBackend* webdata_backend_; // Weak ref. |
+ ScopedObserver<AutofillWebDataBackend, AutofillWalletMetadataSyncableService> |
+ scoped_observer_; |
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
+ scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AutofillWalletMetadataSyncableService); |
+}; |
+ |
+} // namespace autofill |
+ |
+#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_METADATA_SYNCABLE_SERVICE_H_ |