Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/webdata/autofill_profile_syncable_service.h

Issue 16024018: [Autofill] Sync Autofill profiles' origins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Hyphens? We don't need no stinkin' hyphens. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 autofill::AutofillWebDataBackend* webdata_backend, 89 autofill::AutofillWebDataBackend* webdata_backend,
90 const std::string& app_locale); 90 const std::string& app_locale);
91 91
92 // A convenience wrapper of a bunch of state we pass around while 92 // A convenience wrapper of a bunch of state we pass around while
93 // associating models, and send to the WebDatabase for persistence. 93 // associating models, and send to the WebDatabase for persistence.
94 // We do this so we hold the write lock for only a small period. 94 // We do this so we hold the write lock for only a small period.
95 // When storing the web db we are out of the write lock. 95 // When storing the web db we are out of the write lock.
96 struct DataBundle; 96 struct DataBundle;
97 97
98 // Helper to query WebDatabase for the current autofill state. 98 // Helper to query WebDatabase for the current autofill state.
99 // Made virtual for ease of mocking in the unit-test. 99 // Made virtual for ease of mocking in unit tests.
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 unit tests.
107 virtual bool SaveChangesToWebData(const DataBundle& bundle); 107 virtual bool SaveChangesToWebData(const DataBundle& bundle);
108 108
109 // For unit tests.
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
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
198 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 194 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
199 195
200 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; 196 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_;
201 197
202 syncer::SyncableService::StartSyncFlare flare_; 198 syncer::SyncableService::StartSyncFlare flare_;
203 199
204 DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncableService); 200 DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncableService);
205 }; 201 };
206 202
207 // This object is used in unit-tests as well, so it defined here. 203 // This object is used in unit tests as well, so it defined here.
208 struct AutofillProfileSyncableService::DataBundle { 204 struct AutofillProfileSyncableService::DataBundle {
209 DataBundle(); 205 DataBundle();
210 ~DataBundle(); 206 ~DataBundle();
211 207
212 std::vector<std::string> profiles_to_delete; 208 std::vector<std::string> profiles_to_delete;
213 std::vector<autofill::AutofillProfile*> profiles_to_update; 209 std::vector<autofill::AutofillProfile*> profiles_to_update;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698