Chromium Code Reviews| 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 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 class AutofillProfileSyncableService | 40 class AutofillProfileSyncableService |
| 41 : public base::SupportsUserData::Data, | 41 : public base::SupportsUserData::Data, |
| 42 public syncer::SyncableService, | 42 public syncer::SyncableService, |
| 43 public AutofillWebDataServiceObserverOnDBThread, | 43 public AutofillWebDataServiceObserverOnDBThread, |
| 44 public base::NonThreadSafe { | 44 public base::NonThreadSafe { |
| 45 public: | 45 public: |
| 46 virtual ~AutofillProfileSyncableService(); | 46 virtual ~AutofillProfileSyncableService(); |
| 47 | 47 |
| 48 // Creates a new AutofillProfileSyncableService and hangs it off of | 48 // Creates a new AutofillProfileSyncableService and hangs it off of |
| 49 // |web_data_service|, which takes ownership. | 49 // |web_data_service|, which takes ownership. |
| 50 static void CreateForWebDataService(AutofillWebDataService* web_data_service); | 50 static void CreateForWebDataService(AutofillWebDataService* web_data_service, |
| 51 const std::string& app_locale); | |
| 51 // Retrieves the AutofillProfileSyncableService stored on |web_data_service|. | 52 // Retrieves the AutofillProfileSyncableService stored on |web_data_service|. |
| 52 static AutofillProfileSyncableService* FromWebDataService( | 53 static AutofillProfileSyncableService* FromWebDataService( |
| 53 AutofillWebDataService* web_data_service); | 54 AutofillWebDataService* web_data_service); |
| 54 | 55 |
| 55 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } | 56 static syncer::ModelType model_type() { return syncer::AUTOFILL_PROFILE; } |
| 56 | 57 |
| 57 // syncer::SyncableService implementation. | 58 // syncer::SyncableService implementation. |
| 58 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 59 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 59 syncer::ModelType type, | 60 syncer::ModelType type, |
| 60 const syncer::SyncDataList& initial_sync_data, | 61 const syncer::SyncDataList& initial_sync_data, |
| 61 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 62 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 62 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; | 63 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; |
| 63 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 64 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 64 virtual syncer::SyncDataList GetAllSyncData( | 65 virtual syncer::SyncDataList GetAllSyncData( |
| 65 syncer::ModelType type) const OVERRIDE; | 66 syncer::ModelType type) const OVERRIDE; |
| 66 virtual syncer::SyncError ProcessSyncChanges( | 67 virtual syncer::SyncError ProcessSyncChanges( |
| 67 const tracked_objects::Location& from_here, | 68 const tracked_objects::Location& from_here, |
| 68 const syncer::SyncChangeList& change_list) OVERRIDE; | 69 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 69 | 70 |
| 70 // AutofillWebDataServiceObserverOnDBThread implementation. | 71 // AutofillWebDataServiceObserverOnDBThread implementation. |
| 71 virtual void AutofillProfileChanged( | 72 virtual void AutofillProfileChanged( |
| 72 const AutofillProfileChange& change) OVERRIDE; | 73 const AutofillProfileChange& change) OVERRIDE; |
| 73 | 74 |
| 74 protected: | 75 protected: |
| 75 explicit AutofillProfileSyncableService( | 76 explicit AutofillProfileSyncableService( |
| 76 AutofillWebDataService* web_data_service); | 77 AutofillWebDataService* web_data_service, |
| 78 const std::string& app_locale); | |
| 77 | 79 |
| 78 // 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 |
| 79 // associating models, and send to the WebDatabase for persistence. | 81 // associating models, and send to the WebDatabase for persistence. |
| 80 // 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. |
| 81 // 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. |
| 82 struct DataBundle; | 84 struct DataBundle; |
| 83 | 85 |
| 84 // Helper to query WebDatabase for the current autofill state. | 86 // Helper to query WebDatabase for the current autofill state. |
| 85 // Made virtual for ease of mocking in the unit-test. | 87 // Made virtual for ease of mocking in the unit-test. |
| 86 // Caller owns returned |profiles|. | 88 // Caller owns returned |profiles|. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 108 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 110 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
| 109 MergeProfile); | 111 MergeProfile); |
| 110 | 112 |
| 111 // The map of the guid to profiles owned by the |profiles_| vector. | 113 // The map of the guid to profiles owned by the |profiles_| vector. |
| 112 typedef std::map<std::string, AutofillProfile*> GUIDToProfileMap; | 114 typedef std::map<std::string, AutofillProfile*> GUIDToProfileMap; |
| 113 | 115 |
| 114 // Helper function that overwrites |profile| with data from proto-buffer | 116 // Helper function that overwrites |profile| with data from proto-buffer |
| 115 // |specifics|. | 117 // |specifics|. |
| 116 static bool OverwriteProfileWithServerData( | 118 static bool OverwriteProfileWithServerData( |
| 117 const sync_pb::AutofillProfileSpecifics& specifics, | 119 const sync_pb::AutofillProfileSpecifics& specifics, |
| 118 AutofillProfile* profile); | 120 AutofillProfile* profile, |
| 121 const std::string& app_locale); | |
| 119 | 122 |
| 120 // Writes |profile| data into supplied |profile_specifics|. | 123 // Writes |profile| data into supplied |profile_specifics|. |
| 121 static void WriteAutofillProfile(const AutofillProfile& profile, | 124 static void WriteAutofillProfile(const AutofillProfile& profile, |
| 122 sync_pb::EntitySpecifics* profile_specifics); | 125 sync_pb::EntitySpecifics* profile_specifics); |
| 123 | 126 |
| 124 // Creates |profile_map| from the supplied |profiles| vector. Necessary for | 127 // Creates |profile_map| from the supplied |profiles| vector. Necessary for |
| 125 // fast processing of the changes. | 128 // fast processing of the changes. |
| 126 void CreateGUIDToProfileMap(const std::vector<AutofillProfile*>& profiles, | 129 void CreateGUIDToProfileMap(const std::vector<AutofillProfile*>& profiles, |
| 127 GUIDToProfileMap* profile_map); | 130 GUIDToProfileMap* profile_map); |
| 128 | 131 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 static bool MergeProfile(const AutofillProfile& merge_from, | 164 static bool MergeProfile(const AutofillProfile& merge_from, |
| 162 AutofillProfile* merge_into); | 165 AutofillProfile* merge_into); |
| 163 | 166 |
| 164 // For unit-tests. | 167 // For unit-tests. |
| 165 AutofillProfileSyncableService(); | 168 AutofillProfileSyncableService(); |
| 166 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | 169 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { |
| 167 sync_processor_.reset(sync_processor); | 170 sync_processor_.reset(sync_processor); |
| 168 } | 171 } |
| 169 | 172 |
| 170 AutofillWebDataService* web_data_service_; // WEAK | 173 AutofillWebDataService* web_data_service_; // WEAK |
| 174 std::string app_locale_; | |
|
Ilya Sherman
2013/04/05 07:18:41
nit: Can this be const?
jam
2013/04/05 07:35:35
yes it can, but i'm personally not a fan of consti
| |
| 171 ScopedObserver<AutofillWebDataService, AutofillProfileSyncableService> | 175 ScopedObserver<AutofillWebDataService, AutofillProfileSyncableService> |
| 172 scoped_observer_; | 176 scoped_observer_; |
| 173 | 177 |
| 174 // Cached Autofill profiles. *Warning* deleted profiles are still in the | 178 // Cached Autofill profiles. *Warning* deleted profiles are still in the |
| 175 // vector - use the |profiles_map_| to iterate through actual profiles. | 179 // vector - use the |profiles_map_| to iterate through actual profiles. |
| 176 ScopedVector<AutofillProfile> profiles_; | 180 ScopedVector<AutofillProfile> profiles_; |
| 177 GUIDToProfileMap profiles_map_; | 181 GUIDToProfileMap profiles_map_; |
| 178 | 182 |
| 179 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 183 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 180 | 184 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 193 std::vector<AutofillProfile*> profiles_to_add; | 197 std::vector<AutofillProfile*> profiles_to_add; |
| 194 | 198 |
| 195 // When we go through sync we find profiles that are similar but unmatched. | 199 // When we go through sync we find profiles that are similar but unmatched. |
| 196 // Merge such profiles. | 200 // Merge such profiles. |
| 197 GUIDToProfileMap candidates_to_merge; | 201 GUIDToProfileMap candidates_to_merge; |
| 198 // Profiles that have multi-valued fields that are not in sync. | 202 // Profiles that have multi-valued fields that are not in sync. |
| 199 std::vector<AutofillProfile*> profiles_to_sync_back; | 203 std::vector<AutofillProfile*> profiles_to_sync_back; |
| 200 }; | 204 }; |
| 201 | 205 |
| 202 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 206 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
| OLD | NEW |