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