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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 // Made virtual for ease of mocking in the unit-test. | 99 // Made virtual for ease of mocking in the unit-test. |
100 // Caller owns returned |profiles|. | 100 // Caller owns returned |profiles|. |
101 virtual bool LoadAutofillData( | 101 virtual bool LoadAutofillData( |
102 std::vector<autofill::AutofillProfile*>* profiles); | 102 std::vector<autofill::AutofillProfile*>* profiles); |
103 | 103 |
104 // Helper to persist any changes that occured during model association to | 104 // Helper to persist any changes that occured during model association to |
105 // the WebDatabase. | 105 // the WebDatabase. |
106 // Made virtual for ease of mocking in the unit-test. | 106 // Made virtual for ease of mocking in the unit-test. |
107 virtual bool SaveChangesToWebData(const DataBundle& bundle); | 107 virtual bool SaveChangesToWebData(const DataBundle& bundle); |
108 | 108 |
109 // For unit-tests. | |
Evan Stade
2013/06/11 21:38:44
nit: why the hyphen
Ilya Sherman
2013/06/11 21:53:42
Done.
| |
110 AutofillProfileSyncableService(); | |
111 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | |
112 sync_processor_.reset(sync_processor); | |
113 } | |
114 | |
115 // Creates syncer::SyncData based on supplied |profile|. | |
116 // Exposed for unit tests. | |
117 static syncer::SyncData CreateData(const autofill::AutofillProfile& profile); | |
118 | |
109 private: | 119 private: |
110 friend class ProfileSyncServiceAutofillTest; | 120 friend class ProfileSyncServiceAutofillTest; |
111 friend class MockAutofillProfileSyncableService; | |
112 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | |
113 MergeDataAndStartSyncing); | |
114 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, GetAllSyncData); | |
115 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | |
116 ProcessSyncChanges); | |
117 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | |
118 ActOnChange); | |
119 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 121 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
120 UpdateField); | 122 UpdateField); |
121 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 123 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
122 UpdateMultivaluedField); | 124 UpdateMultivaluedField); |
123 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, | 125 FRIEND_TEST_ALL_PREFIXES(AutofillProfileSyncableServiceTest, |
124 MergeProfile); | 126 MergeProfile); |
125 | 127 |
126 // The map of the guid to profiles owned by the |profiles_| vector. | 128 // The map of the guid to profiles owned by the |profiles_| vector. |
127 typedef std::map<std::string, autofill::AutofillProfile*> GUIDToProfileMap; | 129 typedef std::map<std::string, autofill::AutofillProfile*> GUIDToProfileMap; |
128 | 130 |
(...skipping 20 matching lines...) Expand all Loading... | |
149 // found substitutes it for the new one, otherwise adds a new profile. Returns | 151 // found substitutes it for the new one, otherwise adds a new profile. Returns |
150 // iterator pointing to added/updated profile. | 152 // iterator pointing to added/updated profile. |
151 GUIDToProfileMap::iterator CreateOrUpdateProfile( | 153 GUIDToProfileMap::iterator CreateOrUpdateProfile( |
152 const syncer::SyncData& data, | 154 const syncer::SyncData& data, |
153 GUIDToProfileMap* profile_map, | 155 GUIDToProfileMap* profile_map, |
154 DataBundle* bundle); | 156 DataBundle* bundle); |
155 | 157 |
156 // Syncs |change| to the cloud. | 158 // Syncs |change| to the cloud. |
157 void ActOnChange(const autofill::AutofillProfileChange& change); | 159 void ActOnChange(const autofill::AutofillProfileChange& change); |
158 | 160 |
159 // Creates syncer::SyncData based on supplied |profile|. | |
160 static syncer::SyncData CreateData(const autofill::AutofillProfile& profile); | |
161 | |
162 autofill::AutofillTable* GetAutofillTable() const; | 161 autofill::AutofillTable* GetAutofillTable() const; |
163 | 162 |
164 // Helper to compare the local value and cloud value of a field, copy into | 163 // Helper to compare the local value and cloud value of a field, copy into |
165 // the local value if they differ, and return whether the change happened. | 164 // the local value if they differ, and return whether the change happened. |
166 static bool UpdateField(autofill::AutofillFieldType field_type, | 165 static bool UpdateField(autofill::AutofillFieldType field_type, |
167 const std::string& new_value, | 166 const std::string& new_value, |
168 autofill::AutofillProfile* autofill_profile); | 167 autofill::AutofillProfile* autofill_profile); |
169 // The same as |UpdateField|, but for multi-valued fields. | 168 // The same as |UpdateField|, but for multi-valued fields. |
170 static bool UpdateMultivaluedField( | 169 static bool UpdateMultivaluedField( |
171 autofill::AutofillFieldType field_type, | 170 autofill::AutofillFieldType field_type, |
172 const ::google::protobuf::RepeatedPtrField<std::string>& new_value, | 171 const ::google::protobuf::RepeatedPtrField<std::string>& new_value, |
173 autofill::AutofillProfile* autofill_profile); | 172 autofill::AutofillProfile* autofill_profile); |
174 | 173 |
175 // Calls merge_into->OverwriteWithOrAddTo() and then checks if the | 174 // Calls merge_into->OverwriteWithOrAddTo() and then checks if the |
176 // |merge_into| has extra data. Returns |true| if |merge_into| posseses some | 175 // |merge_into| has extra data. Returns |true| if |merge_into| posseses some |
177 // multi-valued field values that are not in |merge_from|, false otherwise. | 176 // multi-valued field values that are not in |merge_from| or if the origins |
177 // of the two profiles differ, false otherwise. | |
178 // TODO(isherman): Seems like this should return |true| if |merge_into| was | |
179 // modified at all: http://crbug.com/248440 | |
178 static bool MergeProfile(const autofill::AutofillProfile& merge_from, | 180 static bool MergeProfile(const autofill::AutofillProfile& merge_from, |
179 autofill::AutofillProfile* merge_into, | 181 autofill::AutofillProfile* merge_into, |
180 const std::string& app_locale); | 182 const std::string& app_locale); |
181 | 183 |
182 // For unit-tests. | |
183 AutofillProfileSyncableService(); | |
184 void set_sync_processor(syncer::SyncChangeProcessor* sync_processor) { | |
185 sync_processor_.reset(sync_processor); | |
186 } | |
187 | |
188 autofill::AutofillWebDataBackend* webdata_backend_; // WEAK | 184 autofill::AutofillWebDataBackend* webdata_backend_; // WEAK |
189 std::string app_locale_; | 185 std::string app_locale_; |
190 ScopedObserver<autofill::AutofillWebDataBackend, | 186 ScopedObserver<autofill::AutofillWebDataBackend, |
191 AutofillProfileSyncableService> scoped_observer_; | 187 AutofillProfileSyncableService> scoped_observer_; |
192 | 188 |
193 // Cached Autofill profiles. *Warning* deleted profiles are still in the | 189 // Cached Autofill profiles. *Warning* deleted profiles are still in the |
194 // vector - use the |profiles_map_| to iterate through actual profiles. | 190 // vector - use the |profiles_map_| to iterate through actual profiles. |
195 ScopedVector<autofill::AutofillProfile> profiles_; | 191 ScopedVector<autofill::AutofillProfile> profiles_; |
196 GUIDToProfileMap profiles_map_; | 192 GUIDToProfileMap profiles_map_; |
197 | 193 |
(...skipping 16 matching lines...) Expand all Loading... | |
214 std::vector<autofill::AutofillProfile*> profiles_to_add; | 210 std::vector<autofill::AutofillProfile*> profiles_to_add; |
215 | 211 |
216 // When we go through sync we find profiles that are similar but unmatched. | 212 // When we go through sync we find profiles that are similar but unmatched. |
217 // Merge such profiles. | 213 // Merge such profiles. |
218 GUIDToProfileMap candidates_to_merge; | 214 GUIDToProfileMap candidates_to_merge; |
219 // Profiles that have multi-valued fields that are not in sync. | 215 // Profiles that have multi-valued fields that are not in sync. |
220 std::vector<autofill::AutofillProfile*> profiles_to_sync_back; | 216 std::vector<autofill::AutofillProfile*> profiles_to_sync_back; |
221 }; | 217 }; |
222 | 218 |
223 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ | 219 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_PROFILE_SYNCABLE_SERVICE_H_ |
OLD | NEW |