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

Side by Side Diff: chrome/browser/sync/glue/autofill_profile_model_associator.cc

Issue 5159001: Rest of the autofill work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Autofill code after fixing the lint errors. Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 4
5 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" 5 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h"
9 #include "chrome/browser/sync/glue/do_optimistic_refresh_Task.h"
10 #include "chrome/browser/sync/syncable/syncable.h"
8 #include "chrome/browser/sync/profile_sync_service.h" 11 #include "chrome/browser/sync/profile_sync_service.h"
9 #include "chrome/browser/webdata/web_database.h" 12 #include "chrome/browser/webdata/web_database.h"
10 13
11 using sync_api::ReadNode; 14 using sync_api::ReadNode;
12 namespace browser_sync { 15 namespace browser_sync {
13 16
14 const char kAutofillProfileTag[] = "google_chrome_autofill_profile"; 17 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
15 18
16 AutofillProfileModelAssociator::AutofillProfileModelAssociator( 19 AutofillProfileModelAssociator::AutofillProfileModelAssociator(
17 ProfileSyncService* sync_service, 20 ProfileSyncService* sync_service,
18 WebDatabase* web_database, 21 WebDatabase* web_database,
19 PersonalDataManager* personal_data) 22 PersonalDataManager* personal_data)
20 : sync_service_(sync_service), 23 : sync_service_(sync_service),
21 web_database_(web_database), 24 web_database_(web_database),
22 personal_data_(personal_data), 25 personal_data_(personal_data),
23 autofill_node_id_(sync_api::kInvalidId), 26 autofill_node_id_(sync_api::kInvalidId),
24 abort_association_pending_(false) { 27 abort_association_pending_(false),
28 number_of_profiles_created_(0) {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
26 DCHECK(sync_service_); 30 DCHECK(sync_service_);
27 DCHECK(web_database_); 31 DCHECK(web_database_);
28 DCHECK(personal_data_); 32 DCHECK(personal_data_);
29 } 33 }
30 34
31 AutofillProfileModelAssociator::~AutofillProfileModelAssociator() { 35 AutofillProfileModelAssociator::~AutofillProfileModelAssociator() {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
33 } 37 }
34 38
(...skipping 24 matching lines...) Expand all
59 current_profiles->insert(guid); 63 current_profiles->insert(guid);
60 } else { 64 } else {
61 MakeNewAutofillProfileSyncNodeIfNeeded(write_trans, 65 MakeNewAutofillProfileSyncNodeIfNeeded(write_trans,
62 autofill_root, 66 autofill_root,
63 (**ix), 67 (**ix),
64 new_profiles, 68 new_profiles,
65 current_profiles, 69 current_profiles,
66 profiles_to_delete); 70 profiles_to_delete);
67 } 71 }
68 } 72 }
69 73 return true;
74 }
75
76 bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode(
77 const std::string& tag,
78 int64* sync_id) {
79 sync_api::ReadTransaction trans(
80 sync_service_->backend()->GetUserShareHandle());
81 sync_api::ReadNode sync_node(&trans);
82 if (!sync_node.InitByTagLookup(tag.c_str()))
83 return false;
84 *sync_id = sync_node.GetId();
70 return true; 85 return true;
71 } 86 }
72 87
73 bool AutofillProfileModelAssociator::LoadAutofillData( 88 bool AutofillProfileModelAssociator::LoadAutofillData(
74 std::vector<AutoFillProfile*>* profiles) { 89 std::vector<AutoFillProfile*>* profiles) {
75 if (IsAbortPending()) 90 if (IsAbortPending())
76 return false; 91 return false;
77 92
78 if (!web_database_->GetAutoFillProfiles(profiles)) 93 if (!web_database_->GetAutoFillProfiles(profiles))
79 return false; 94 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { 133 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) {
119 return false; 134 return false;
120 } 135 }
121 } 136 }
122 137
123 if (!SaveChangesToWebData(bundle)) { 138 if (!SaveChangesToWebData(bundle)) {
124 LOG(ERROR) << "Failed to update autofill entries."; 139 LOG(ERROR) << "Failed to update autofill entries.";
125 return false; 140 return false;
126 } 141 }
127 142
128 // TODO(lipalani) Bug 64111- split out the OptimisticRefreshTask 143 if (sync_service_->backend()->GetAutofillMigrationState() !=
129 // into its own class 144 syncable::Directory::PersistedKernelInfo::MIGRATED) {
130 // from autofill_model_associator 145 syncable::AutofillMigrationDebugInfo debug_info;
131 // Will be done as part of the autofill_model_associator work. 146 debug_info.autofill_profile_added_during_migration =
132 // BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 147 number_of_profiles_created_;
133 // new DoOptimisticRefreshTask(personal_data_)); 148 sync_service_->backend()->SetAutofillMigrationDebugInfo(
149 syncable::AutofillMigrationDebugInfo::PROFILES_ADDED,
150 debug_info);
151 }
152
lipalani 2010/12/09 19:45:25 move this code above.
lipalani 2010/12/11 00:12:36 Done.
153 sync_service()->backend()->SetAutofillMigrationState(
154 syncable::Directory::PersistedKernelInfo::MIGRATED);
155
156 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
157 new DoOptimisticRefreshForAutofill(personal_data_));
134 return true; 158 return true;
135 } 159 }
136 160
137 bool AutofillProfileModelAssociator::DisassociateModels() { 161 bool AutofillProfileModelAssociator::DisassociateModels() {
138 id_map_.clear(); 162 id_map_.clear();
139 id_map_inverse_.clear(); 163 id_map_inverse_.clear();
140 return true; 164 return true;
141 } 165 }
142 166
143 // Helper to compare the local value and cloud value of a field, merge into 167 // Helper to compare the local value and cloud value of a field, merge into
144 // the local value if they differ, and return whether the merge happened. 168 // the local value if they differ, and return whether the merge happened.
145 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, 169 bool AutofillProfileModelAssociator::MergeField(FormGroup* f,
146 AutoFillFieldType t, 170 AutoFillFieldType t,
147 const std::string& specifics_field) { 171 const std::string& specifics_field) {
148 if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field) 172 if (UTF16ToUTF8(f->GetFieldText(AutoFillType(t))) == specifics_field)
149 return false; 173 return false;
150 f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field)); 174 f->SetInfo(AutoFillType(t), UTF8ToUTF16(specifics_field));
151 return true; 175 return true;
152 } 176 }
153 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes( 177 bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes(
154 bool *has_nodes) { 178 bool *has_nodes) {
155 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL)); 179 CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL));
156 sync_api::ReadTransaction trans( 180 sync_api::ReadTransaction trans(
157 sync_service_->backend()->GetUserShareHandle()); 181 sync_service_->backend()->GetUserShareHandle());
158 182
159 sync_api::ReadNode node(&trans); 183 sync_api::ReadNode node(&trans);
160 184
161 if (!node.InitByClientTagLookup( 185 if (!node.InitByTagLookup(kAutofillProfileTag)) {
162 syncable::AUTOFILL_PROFILE,
163 kAutofillProfileTag)) {
164 LOG(ERROR) << "Sever did not create a top level node" 186 LOG(ERROR) << "Sever did not create a top level node"
165 << "Out of data server or autofill type not enabled"; 187 << "Out of data server or autofill type not enabled";
166 return false; 188 return false;
167 } 189 }
168 190
169 *has_nodes = sync_api::kInvalidId != node.GetFirstChildId(); 191 *has_nodes = sync_api::kInvalidId != node.GetFirstChildId();
170 return true; 192 return true;
171 } 193 }
172 // static 194 // static
173 bool AutofillProfileModelAssociator::OverwriteProfileWithServerData( 195 bool AutofillProfileModelAssociator::OverwriteProfileWithServerData(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 current_profiles->insert(autofill_specifics.guid()); 269 current_profiles->insert(autofill_specifics.guid());
248 } else { 270 } else {
249 sync_api::WriteNode node(trans); 271 sync_api::WriteNode node(trans);
250 if (!node.InitUniqueByCreation( 272 if (!node.InitUniqueByCreation(
251 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) { 273 syncable::AUTOFILL_PROFILE, autofill_root, profile.guid())) {
252 LOG(ERROR) << "Failed to create autofill sync node."; 274 LOG(ERROR) << "Failed to create autofill sync node.";
253 return false; 275 return false;
254 } 276 }
255 node.SetTitle(UTF8ToWide(profile.guid())); 277 node.SetTitle(UTF8ToWide(profile.guid()));
256 278
257 // TODO(lipalani) -Bug 64111 This needs rewriting. This will be tackled 279 AutofillProfileChangeProcessor::WriteAutofillProfile(profile, &node);
258 // when rewriting autofill change processor. 280 current_profiles->insert(profile.guid());
259 // AutofillChangeProcessor::WriteAutofillProfile(profile, &node); 281 number_of_profiles_created_++;
260 } 282 }
261 return true; 283 return true;
262 } 284 }
263 285
264 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes( 286 bool AutofillProfileModelAssociator::TraverseAndAssociateAllSyncNodes(
265 sync_api::WriteTransaction* write_trans, 287 sync_api::WriteTransaction* write_trans,
266 const sync_api::ReadNode& autofill_root, 288 const sync_api::ReadNode& autofill_root,
267 DataBundle* bundle) { 289 DataBundle* bundle) {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
269 291
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill); 377 AutofillToSyncIdMap::const_iterator iter = id_map_.find(autofill);
356 return iter == id_map_.end() ? sync_api::kInvalidId : iter->second; 378 return iter == id_map_.end() ? sync_api::kInvalidId : iter->second;
357 } 379 }
358 380
359 void AutofillProfileModelAssociator::AbortAssociation() { 381 void AutofillProfileModelAssociator::AbortAssociation() {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361 AutoLock lock(abort_association_pending_lock_); 383 AutoLock lock(abort_association_pending_lock_);
362 abort_association_pending_ = true; 384 abort_association_pending_ = true;
363 } 385 }
364 386
387 const std::string* AutofillProfileModelAssociator::GetChromeNodeFromSyncId(
388 int64 sync_id) {
389 SyncIdToAutofillMap::const_iterator iter = id_map_inverse_.find(sync_id);
390 return iter == id_map_inverse_.end() ? NULL : &(iter->second);
391 }
392
365 bool AutofillProfileModelAssociator::IsAbortPending() { 393 bool AutofillProfileModelAssociator::IsAbortPending() {
366 AutoLock lock(abort_association_pending_lock_); 394 AutoLock lock(abort_association_pending_lock_);
367 return abort_association_pending_; 395 return abort_association_pending_;
368 } 396 }
369 397
370 } // namespace browser_sync 398 } // namespace browser_sync
371 399
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698