OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tracked.h" | 7 #include "base/tracked.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/sync/api/sync_error.h" |
9 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" | 10 #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" |
10 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | 11 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" |
11 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
12 #include "chrome/browser/webdata/web_database.h" | 13 #include "chrome/browser/webdata/web_database.h" |
13 #include "chrome/common/guid.h" | 14 #include "chrome/common/guid.h" |
14 | 15 |
15 using sync_api::ReadNode; | 16 using sync_api::ReadNode; |
16 namespace browser_sync { | 17 namespace browser_sync { |
17 | 18 |
18 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; | 19 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::vector<AutofillProfile*>* profiles) { | 130 std::vector<AutofillProfile*>* profiles) { |
130 if (IsAbortPending()) | 131 if (IsAbortPending()) |
131 return false; | 132 return false; |
132 | 133 |
133 if (!web_database_->GetAutofillTable()->GetAutofillProfiles(profiles)) | 134 if (!web_database_->GetAutofillTable()->GetAutofillProfiles(profiles)) |
134 return false; | 135 return false; |
135 | 136 |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 bool AutofillProfileModelAssociator::AssociateModels() { | 140 bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { |
140 VLOG(1) << "Associating Autofill Models"; | 141 VLOG(1) << "Associating Autofill Models"; |
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
142 { | 143 { |
143 base::AutoLock lock(abort_association_pending_lock_); | 144 base::AutoLock lock(abort_association_pending_lock_); |
144 abort_association_pending_ = false; | 145 abort_association_pending_ = false; |
145 } | 146 } |
146 | 147 |
147 ScopedVector<AutofillProfile> profiles; | 148 ScopedVector<AutofillProfile> profiles; |
148 | 149 |
149 if (!LoadAutofillData(&profiles.get())) { | 150 if (!LoadAutofillData(&profiles.get())) { |
150 LOG(ERROR) << "Could not get the autofill data from WebDatabase."; | 151 error->Reset(FROM_HERE, |
| 152 "Could not get the autofill data from WebDatabase.", |
| 153 model_type()); |
151 return false; | 154 return false; |
152 } | 155 } |
153 | 156 |
154 VLOG(1) << "[AUTOFILL MIGRATION]" | 157 VLOG(1) << "[AUTOFILL MIGRATION]" |
155 << " Now associating to the new autofill profile model associator" | 158 << " Now associating to the new autofill profile model associator" |
156 << " root node"; | 159 << " root node"; |
157 DataBundle bundle; | 160 DataBundle bundle; |
158 { | 161 { |
159 // The write transaction lock is held inside this block. | 162 // The write transaction lock is held inside this block. |
160 // We do all the web db operations outside this block. | 163 // We do all the web db operations outside this block. |
161 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 164 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
162 | 165 |
163 sync_api::ReadNode autofill_root(&trans); | 166 sync_api::ReadNode autofill_root(&trans); |
164 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { | 167 if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { |
165 LOG(ERROR) << "Server did not create the top-level autofill node. We " | 168 error->Reset(FROM_HERE, |
166 << "might be running against an out-of-date server."; | 169 "Server did not create the top-level autofill node. We " |
| 170 "might be running against an out-of-date server.", |
| 171 model_type()); |
167 return false; | 172 return false; |
168 } | 173 } |
169 | 174 |
170 if (!TraverseAndAssociateChromeAutofillProfiles(&trans, autofill_root, | 175 if (!TraverseAndAssociateChromeAutofillProfiles(&trans, autofill_root, |
171 profiles.get(), &bundle.current_profiles, | 176 profiles.get(), &bundle.current_profiles, |
172 &bundle.updated_profiles, | 177 &bundle.updated_profiles, |
173 &bundle.new_profiles, | 178 &bundle.new_profiles, |
174 &bundle.profiles_to_delete) || | 179 &bundle.profiles_to_delete) || |
175 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { | 180 !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { |
| 181 error->Reset(FROM_HERE, |
| 182 "Failed to associate all sync nodes.", |
| 183 model_type()); |
176 return false; | 184 return false; |
177 } | 185 } |
178 } | 186 } |
179 | 187 |
180 if (!SaveChangesToWebData(bundle)) { | 188 if (!SaveChangesToWebData(bundle)) { |
181 LOG(ERROR) << "Failed to update autofill entries."; | 189 error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); |
182 return false; | 190 return false; |
183 } | 191 } |
184 | 192 |
185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 193 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
186 new DoOptimisticRefreshForAutofill(personal_data_)); | 194 new DoOptimisticRefreshForAutofill(personal_data_)); |
187 return true; | 195 return true; |
188 } | 196 } |
189 | 197 |
190 bool AutofillProfileModelAssociator::DisassociateModels() { | 198 bool AutofillProfileModelAssociator::DisassociateModels(SyncError* error) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
192 id_map_.clear(); | 200 id_map_.clear(); |
193 id_map_inverse_.clear(); | 201 id_map_inverse_.clear(); |
194 return true; | 202 return true; |
195 } | 203 } |
196 | 204 |
197 // Helper to compare the local value and cloud value of a field, merge into | 205 // Helper to compare the local value and cloud value of a field, merge into |
198 // the local value if they differ, and return whether the merge happened. | 206 // the local value if they differ, and return whether the merge happened. |
199 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, | 207 bool AutofillProfileModelAssociator::MergeField(FormGroup* f, |
200 AutofillFieldType t, | 208 AutofillFieldType t, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 bool AutofillProfileModelAssociator::CryptoReadyIfNecessary() { | 504 bool AutofillProfileModelAssociator::CryptoReadyIfNecessary() { |
497 // We only access the cryptographer while holding a transaction. | 505 // We only access the cryptographer while holding a transaction. |
498 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 506 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
499 syncable::ModelTypeSet encrypted_types; | 507 syncable::ModelTypeSet encrypted_types; |
500 encrypted_types = sync_api::GetEncryptedTypes(&trans); | 508 encrypted_types = sync_api::GetEncryptedTypes(&trans); |
501 return encrypted_types.count(syncable::AUTOFILL_PROFILE) == 0 || | 509 return encrypted_types.count(syncable::AUTOFILL_PROFILE) == 0 || |
502 sync_service_->IsCryptographerReady(&trans); | 510 sync_service_->IsCryptographerReady(&trans); |
503 } | 511 } |
504 | 512 |
505 } // namespace browser_sync | 513 } // namespace browser_sync |
OLD | NEW |