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

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

Issue 7967024: Profile shouldn't own PersonalDataManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addresses isherman #11 Created 9 years, 3 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) 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/guid.h" 28 #include "chrome/common/guid.h"
29 #include "content/browser/browser_thread.h" 29 #include "content/browser/browser_thread.h"
(...skipping 11 matching lines...) Expand all
41 std::vector<AutofillEntry> new_entries; 41 std::vector<AutofillEntry> new_entries;
42 std::set<string16> current_profiles; 42 std::set<string16> current_profiles;
43 std::vector<AutofillProfile*> updated_profiles; 43 std::vector<AutofillProfile*> updated_profiles;
44 std::vector<AutofillProfile*> new_profiles; // We own these pointers. 44 std::vector<AutofillProfile*> new_profiles; // We own these pointers.
45 ~DataBundle() { STLDeleteElements(&new_profiles); } 45 ~DataBundle() { STLDeleteElements(&new_profiles); }
46 }; 46 };
47 47
48 AutofillModelAssociator::AutofillModelAssociator( 48 AutofillModelAssociator::AutofillModelAssociator(
49 ProfileSyncService* sync_service, 49 ProfileSyncService* sync_service,
50 WebDatabase* web_database, 50 WebDatabase* web_database,
51 PersonalDataManager* personal_data) 51 Profile* profile)
52 : sync_service_(sync_service), 52 : sync_service_(sync_service),
53 web_database_(web_database), 53 web_database_(web_database),
54 personal_data_(personal_data), 54 profile_(profile),
55 autofill_node_id_(sync_api::kInvalidId), 55 autofill_node_id_(sync_api::kInvalidId),
56 abort_association_pending_(false) { 56 abort_association_pending_(false) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
58 DCHECK(sync_service_); 58 DCHECK(sync_service_);
59 DCHECK(web_database_); 59 DCHECK(web_database_);
60 DCHECK(personal_data_); 60 DCHECK(profile_);
61 } 61 }
62 62
63 AutofillModelAssociator::~AutofillModelAssociator() { 63 AutofillModelAssociator::~AutofillModelAssociator() {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
65 } 65 }
66 66
67 bool AutofillModelAssociator::TraverseAndAssociateChromeAutofillEntries( 67 bool AutofillModelAssociator::TraverseAndAssociateChromeAutofillEntries(
68 sync_api::WriteTransaction* write_trans, 68 sync_api::WriteTransaction* write_trans,
69 const sync_api::ReadNode& autofill_root, 69 const sync_api::ReadNode& autofill_root,
70 const std::vector<AutofillEntry>& all_entries_from_db, 70 const std::vector<AutofillEntry>& all_entries_from_db,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Since we're on the DB thread, we don't have to worry about updating 191 // 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 192 // 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 193 // 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 194 // to worry about the sync model getting out of sync, because changes are
195 // propagated to the ChangeProcessor on this thread. 195 // propagated to the ChangeProcessor on this thread.
196 if (!SaveChangesToWebData(bundle)) { 196 if (!SaveChangesToWebData(bundle)) {
197 error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); 197 error->Reset(FROM_HERE, "Failed to update webdata.", model_type());
198 return false; 198 return false;
199 } 199 }
200 200
201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 201 WebDataService::NotifyOfMultipleAutofillChanges(profile_);
202 new DoOptimisticRefreshForAutofill(personal_data_)); 202
203 return true; 203 return true;
204 } 204 }
205 205
206 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) { 206 bool AutofillModelAssociator::SaveChangesToWebData(const DataBundle& bundle) {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
208 208
209 if (IsAbortPending()) 209 if (IsAbortPending())
210 return false; 210 return false;
211 211
212 if (bundle.new_entries.size() && 212 if (bundle.new_entries.size() &&
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 bool AutofillModelAssociator::CryptoReadyIfNecessary() { 514 bool AutofillModelAssociator::CryptoReadyIfNecessary() {
515 // We only access the cryptographer while holding a transaction. 515 // We only access the cryptographer while holding a transaction.
516 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 516 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
517 syncable::ModelTypeSet encrypted_types; 517 syncable::ModelTypeSet encrypted_types;
518 encrypted_types = sync_api::GetEncryptedTypes(&trans); 518 encrypted_types = sync_api::GetEncryptedTypes(&trans);
519 return encrypted_types.count(syncable::AUTOFILL) == 0 || 519 return encrypted_types.count(syncable::AUTOFILL) == 0 ||
520 sync_service_->IsCryptographerReady(&trans); 520 sync_service_->IsCryptographerReady(&trans);
521 } 521 }
522 522
523 } // namespace browser_sync 523 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698