Chromium Code Reviews| 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_model_associator.h" | 5 #include "chrome/browser/sync/glue/autofill_model_associator.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "base/task.h" | 13 #include "base/task.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/sync/api/sync_error.h" | 18 #include "chrome/browser/sync/api/sync_error.h" |
| 18 #include "chrome/browser/sync/glue/autofill_change_processor.h" | 19 #include "chrome/browser/sync/glue/autofill_change_processor.h" |
| 19 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | |
| 20 #include "chrome/browser/sync/internal_api/read_node.h" | 20 #include "chrome/browser/sync/internal_api/read_node.h" |
| 21 #include "chrome/browser/sync/internal_api/read_transaction.h" | 21 #include "chrome/browser/sync/internal_api/read_transaction.h" |
| 22 #include "chrome/browser/sync/internal_api/write_node.h" | 22 #include "chrome/browser/sync/internal_api/write_node.h" |
| 23 #include "chrome/browser/sync/internal_api/write_transaction.h" | 23 #include "chrome/browser/sync/internal_api/write_transaction.h" |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
| 25 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 25 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 26 #include "chrome/browser/webdata/autofill_table.h" | 26 #include "chrome/browser/webdata/autofill_table.h" |
| 27 #include "chrome/browser/webdata/web_database.h" | 27 #include "chrome/browser/webdata/web_database.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | |
| 28 #include "chrome/common/guid.h" | 29 #include "chrome/common/guid.h" |
| 29 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
| 31 #include "content/common/notification_service.h" | |
| 32 #include "content/common/notification_source.h" | |
|
Ilya Sherman
2011/09/23 03:56:34
nit: I'm not seeing why these header additions are
dhollowa
2011/09/23 16:30:03
Vestigial. Removed.
| |
| 30 #include "net/base/escape.h" | 33 #include "net/base/escape.h" |
| 31 | 34 |
| 32 using base::TimeTicks; | 35 using base::TimeTicks; |
| 33 | 36 |
| 34 namespace browser_sync { | 37 namespace browser_sync { |
| 35 | 38 |
| 36 const char kAutofillTag[] = "google_chrome_autofill"; | 39 const char kAutofillTag[] = "google_chrome_autofill"; |
| 37 const char kAutofillEntryNamespaceTag[] = "autofill_entry|"; | 40 const char kAutofillEntryNamespaceTag[] = "autofill_entry|"; |
| 38 | 41 |
| 39 struct AutofillModelAssociator::DataBundle { | 42 struct AutofillModelAssociator::DataBundle { |
| 40 std::set<AutofillKey> current_entries; | 43 std::set<AutofillKey> current_entries; |
| 41 std::vector<AutofillEntry> new_entries; | 44 std::vector<AutofillEntry> new_entries; |
| 42 std::set<string16> current_profiles; | 45 std::set<string16> current_profiles; |
| 43 std::vector<AutofillProfile*> updated_profiles; | 46 std::vector<AutofillProfile*> updated_profiles; |
| 44 std::vector<AutofillProfile*> new_profiles; // We own these pointers. | 47 std::vector<AutofillProfile*> new_profiles; // We own these pointers. |
| 45 ~DataBundle() { STLDeleteElements(&new_profiles); } | 48 ~DataBundle() { STLDeleteElements(&new_profiles); } |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 AutofillModelAssociator::AutofillModelAssociator( | 51 AutofillModelAssociator::AutofillModelAssociator( |
| 49 ProfileSyncService* sync_service, | 52 ProfileSyncService* sync_service, |
| 50 WebDatabase* web_database, | 53 WebDatabase* web_database, |
| 51 PersonalDataManager* personal_data) | 54 Profile* profile) |
| 52 : sync_service_(sync_service), | 55 : sync_service_(sync_service), |
| 53 web_database_(web_database), | 56 web_database_(web_database), |
| 54 personal_data_(personal_data), | 57 profile_(profile), |
| 55 autofill_node_id_(sync_api::kInvalidId), | 58 autofill_node_id_(sync_api::kInvalidId), |
| 56 abort_association_pending_(false) { | 59 abort_association_pending_(false) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 58 DCHECK(sync_service_); | 61 DCHECK(sync_service_); |
| 59 DCHECK(web_database_); | 62 DCHECK(web_database_); |
| 60 DCHECK(personal_data_); | 63 DCHECK(profile_); |
| 61 } | 64 } |
| 62 | 65 |
| 63 AutofillModelAssociator::~AutofillModelAssociator() { | 66 AutofillModelAssociator::~AutofillModelAssociator() { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 65 } | 68 } |
| 66 | 69 |
| 67 bool AutofillModelAssociator::TraverseAndAssociateChromeAutofillEntries( | 70 bool AutofillModelAssociator::TraverseAndAssociateChromeAutofillEntries( |
| 68 sync_api::WriteTransaction* write_trans, | 71 sync_api::WriteTransaction* write_trans, |
| 69 const sync_api::ReadNode& autofill_root, | 72 const sync_api::ReadNode& autofill_root, |
| 70 const std::vector<AutofillEntry>& all_entries_from_db, | 73 const std::vector<AutofillEntry>& all_entries_from_db, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 // Since we're on the DB thread, we don't have to worry about updating | 194 // Since we're on the DB thread, we don't have to worry about updating |
| 192 // the autofill database after closing the write transaction, since | 195 // the autofill database after closing the write transaction, since |
| 193 // this is the only thread that writes to the database. We also don't have | 196 // this is the only thread that writes to the database. We also don't have |
| 194 // to worry about the sync model getting out of sync, because changes are | 197 // to worry about the sync model getting out of sync, because changes are |
| 195 // propagated to the ChangeProcessor on this thread. | 198 // propagated to the ChangeProcessor on this thread. |
| 196 if (!SaveChangesToWebData(bundle)) { | 199 if (!SaveChangesToWebData(bundle)) { |
| 197 error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); | 200 error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); |
| 198 return false; | 201 return false; |
| 199 } | 202 } |
| 200 | 203 |
| 201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 204 WebDataService* web_data_service = |
| 202 new DoOptimisticRefreshForAutofill(personal_data_)); | 205 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 206 if (web_data_service) | |
| 207 web_data_service->NotifyOfMultipleAutofillChanges(); | |
| 208 | |
| 203 return true; | 209 return true; |
| 204 } | 210 } |
| 205 | 211 |
| 206 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) { | 212 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 208 | 214 |
| 209 if (IsAbortPending()) | 215 if (IsAbortPending()) |
| 210 return false; | 216 return false; |
| 211 | 217 |
| 212 if (bundle.new_entries.size() && | 218 if (bundle.new_entries.size() && |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 bool AutofillModelAssociator::CryptoReadyIfNecessary() { | 520 bool AutofillModelAssociator::CryptoReadyIfNecessary() { |
| 515 // We only access the cryptographer while holding a transaction. | 521 // We only access the cryptographer while holding a transaction. |
| 516 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 522 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 517 syncable::ModelTypeSet encrypted_types; | 523 syncable::ModelTypeSet encrypted_types; |
| 518 encrypted_types = sync_api::GetEncryptedTypes(&trans); | 524 encrypted_types = sync_api::GetEncryptedTypes(&trans); |
| 519 return encrypted_types.count(syncable::AUTOFILL) == 0 || | 525 return encrypted_types.count(syncable::AUTOFILL) == 0 || |
| 520 sync_service_->IsCryptographerReady(&trans); | 526 sync_service_->IsCryptographerReady(&trans); |
| 521 } | 527 } |
| 522 | 528 |
| 523 } // namespace browser_sync | 529 } // namespace browser_sync |
| OLD | NEW |