| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 4 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
| 5 #define CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 5 #define CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/scoped_observer.h" |
| 13 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 16 #include "chrome/browser/webdata/autofill_change.h" | 17 #include "chrome/browser/webdata/autofill_change.h" |
| 17 #include "chrome/browser/webdata/autofill_entry.h" | 18 #include "chrome/browser/webdata/autofill_entry.h" |
| 19 #include "chrome/browser/webdata/autofill_web_data_service_observer.h" |
| 18 #include "components/autofill/browser/autofill_type.h" | 20 #include "components/autofill/browser/autofill_type.h" |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 #include "content/public/browser/notification_types.h" | |
| 22 #include "sync/api/sync_change.h" | 21 #include "sync/api/sync_change.h" |
| 23 #include "sync/api/sync_data.h" | 22 #include "sync/api/sync_data.h" |
| 24 #include "sync/api/sync_error.h" | 23 #include "sync/api/sync_error.h" |
| 25 #include "sync/api/syncable_service.h" | 24 #include "sync/api/syncable_service.h" |
| 26 #include "sync/protocol/autofill_specifics.pb.h" | 25 #include "sync/protocol/autofill_specifics.pb.h" |
| 27 | 26 |
| 28 class AutofillProfile; | 27 class AutofillProfile; |
| 29 class AutofillTable; | 28 class AutofillTable; |
| 30 class AutofillWebDataService; | 29 class AutofillWebDataService; |
| 31 class FormGroup; | 30 class FormGroup; |
| 32 class ProfileSyncServiceAutofillTest; | 31 class ProfileSyncServiceAutofillTest; |
| 33 class WebDataServiceBase; | 32 class WebDataServiceBase; |
| 34 | 33 |
| 35 extern const char kAutofillProfileTag[]; | 34 extern const char kAutofillProfileTag[]; |
| 36 | 35 |
| 37 // The sync implementation for AutofillProfiles. | 36 // The sync implementation for AutofillProfiles. |
| 38 // MergeDataAndStartSyncing() called first, it does cloud->local and | 37 // MergeDataAndStartSyncing() called first, it does cloud->local and |
| 39 // local->cloud syncs. Then for each cloud change we receive | 38 // local->cloud syncs. Then for each cloud change we receive |
| 40 // ProcessSyncChanges() and for each local change Observe() is called. | 39 // ProcessSyncChanges() and for each local change Observe() is called. |
| 41 class AutofillProfileSyncableService | 40 class AutofillProfileSyncableService |
| 42 : public base::SupportsUserData::Data, | 41 : public base::SupportsUserData::Data, |
| 43 public syncer::SyncableService, | 42 public syncer::SyncableService, |
| 44 public content::NotificationObserver, | 43 public AutofillWebDataServiceObserverOnDBThread, |
| 45 public base::NonThreadSafe { | 44 public base::NonThreadSafe { |
| 46 public: | 45 public: |
| 47 virtual ~AutofillProfileSyncableService(); | 46 virtual ~AutofillProfileSyncableService(); |
| 48 | 47 |
| 49 // Creates a new AutofillProfileSyncableService and hangs it off of | 48 // Creates a new AutofillProfileSyncableService and hangs it off of |
| 50 // |web_data_service|, which takes ownership. | 49 // |web_data_service|, which takes ownership. |
| 51 static void CreateForWebDataService(AutofillWebDataService* web_data_service); | 50 static void CreateForWebDataService(AutofillWebDataService* web_data_service); |
| 52 // Retrieves the AutofillProfileSyncableService stored on |web_data_service|. | 51 // Retrieves the AutofillProfileSyncableService stored on |web_data_service|. |
| 53 static AutofillProfileSyncableService* FromWebDataService( | 52 static AutofillProfileSyncableService* FromWebDataService( |
| 54 AutofillWebDataService* web_data_service); | 53 AutofillWebDataService* web_data_service); |
| 55 | 54 |
| 56 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } | 55 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } |
| 57 | 56 |
| 58 // syncer::SyncableService implementation. | 57 // syncer::SyncableService implementation. |
| 59 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 58 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 60 syncer::ModelType type, | 59 syncer::ModelType type, |
| 61 const syncer::SyncDataList& initial_sync_data, | 60 const syncer::SyncDataList& initial_sync_data, |
| 62 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 61 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 63 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; | 62 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; |
| 64 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 63 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 65 virtual syncer::SyncDataList GetAllSyncData( | 64 virtual syncer::SyncDataList GetAllSyncData( |
| 66 syncer::ModelType type) const OVERRIDE; | 65 syncer::ModelType type) const OVERRIDE; |
| 67 virtual syncer::SyncError ProcessSyncChanges( | 66 virtual syncer::SyncError ProcessSyncChanges( |
| 68 const tracked_objects::Location& from_here, | 67 const tracked_objects::Location& from_here, |
| 69 const syncer::SyncChangeList& change_list) OVERRIDE; | 68 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 70 | 69 |
| 71 // content::NotificationObserver implementation. | 70 // AutofillWebDataServiceObserverOnDBThread implementation. |
| 72 virtual void Observe(int type, | 71 virtual void AutofillProfileChanged( |
| 73 const content::NotificationSource& source, | 72 const AutofillProfileChange& change) OVERRIDE; |
| 74 const content::NotificationDetails& details) OVERRIDE; | |
| 75 | 73 |
| 76 protected: | 74 protected: |
| 77 explicit AutofillProfileSyncableService( | 75 explicit AutofillProfileSyncableService( |
| 78 AutofillWebDataService* web_data_service); | 76 AutofillWebDataService* web_data_service); |
| 79 | 77 |
| 80 // A convenience wrapper of a bunch of state we pass around while | 78 // A convenience wrapper of a bunch of state we pass around while |
| 81 // associating models, and send to the WebDatabase for persistence. | 79 // associating models, and send to the WebDatabase for persistence. |
| 82 // We do this so we hold the write lock for only a small period. | 80 // We do this so we hold the write lock for only a small period. |
| 83 // When storing the web db we are out of the write lock. | 81 // When storing the web db we are out of the write lock. |
| 84 struct DataBundle; | 82 struct DataBundle; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 static bool MergeProfile(const AutofillProfile& merge_from, | 161 static bool MergeProfile(const AutofillProfile& merge_from, |
| 164 AutofillProfile* merge_into); | 162 AutofillProfile* merge_into); |
| 165 | 163 |
| 166 // For unit-tests. | 164 // For unit-tests. |
| 167 AutofillProfileSyncableService(); | 165 AutofillProfileSyncableService(); |
| 168 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 166 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |
| 169 sync_processor_.reset(sync_processor); | 167 sync_processor_.reset(sync_processor); |
| 170 } | 168 } |
| 171 | 169 |
| 172 AutofillWebDataService* web_data_service_; // WEAK | 170 AutofillWebDataService* web_data_service_; // WEAK |
| 173 content::NotificationRegistrar notification_registrar_; | 171 ScopedObserver<AutofillWebDataService, AutofillProfileSyncableService> |
| 172 scoped_observer_; |
| 174 | 173 |
| 175 // Cached Autofill profiles. *Warning* deleted profiles are still in the | 174 // Cached Autofill profiles. *Warning* deleted profiles are still in the |
| 176 // vector - use the |profiles_map_| to iterate through actual profiles. | 175 // vector - use the |profiles_map_| to iterate through actual profiles. |
| 177 ScopedVector<AutofillProfile> profiles_; | 176 ScopedVector<AutofillProfile> profiles_; |
| 178 GUIDToProfileMap profiles_map_; | 177 GUIDToProfileMap profiles_map_; |
| 179 | 178 |
| 180 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 179 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 181 | 180 |
| 182 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | 181 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; |
| 183 | 182 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 194 std::vector<AutofillProfile*> profiles_to_add; | 193 std::vector<AutofillProfile*> profiles_to_add; |
| 195 | 194 |
| 196 // When we go through sync we find profiles that are similar but unmatched. | 195 // When we go through sync we find profiles that are similar but unmatched. |
| 197 // Merge such profiles. | 196 // Merge such profiles. |
| 198 GUIDToProfileMap candidates_to_merge; | 197 GUIDToProfileMap candidates_to_merge; |
| 199 // Profiles that have multi-valued fields that are not in sync. | 198 // Profiles that have multi-valued fields that are not in sync. |
| 200 std::vector<AutofillProfile*> profiles_to_sync_back; | 199 std::vector<AutofillProfile*> profiles_to_sync_back; |
| 201 }; | 200 }; |
| 202 | 201 |
| 203 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 202 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
| OLD | NEW |