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

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

Issue 8065016: [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reffffactor Created 9 years, 2 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_profile_syncable_service.h" 5 #include "chrome/browser/sync/glue/autofill_profile_syncable_service.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autofill/autofill_profile.h" 10 #include "chrome/browser/autofill/autofill_profile.h"
(...skipping 24 matching lines...) Expand all
35 } // namespace 35 } // namespace
36 36
37 namespace browser_sync { 37 namespace browser_sync {
38 38
39 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 39 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
40 40
41 AutofillProfileSyncableService::AutofillProfileSyncableService( 41 AutofillProfileSyncableService::AutofillProfileSyncableService(
42 WebDatabase* web_database, 42 WebDatabase* web_database,
43 Profile* profile) 43 Profile* profile)
44 : web_database_(web_database), 44 : web_database_(web_database),
45 profile_(profile), 45 profile_(profile) {
46 sync_processor_(NULL) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
48 DCHECK(web_database_); 47 DCHECK(web_database_);
49 DCHECK(profile); 48 DCHECK(profile);
50 notification_registrar_.Add(this, 49 notification_registrar_.Add(this,
51 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 50 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
52 Source<WebDataService>( 51 Source<WebDataService>(
53 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS))); 52 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)));
54 } 53 }
55 54
56 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 55 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
57 DCHECK(CalledOnValidThread()); 56 DCHECK(CalledOnValidThread());
58 } 57 }
59 58
60 AutofillProfileSyncableService::AutofillProfileSyncableService() 59 AutofillProfileSyncableService::AutofillProfileSyncableService()
61 : web_database_(NULL), 60 : web_database_(NULL),
62 profile_(NULL), 61 profile_(NULL) {
63 sync_processor_(NULL) {
64 } 62 }
65 63
66 SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( 64 SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing(
67 syncable::ModelType type, 65 syncable::ModelType type,
68 const SyncDataList& initial_sync_data, 66 const SyncDataList& initial_sync_data,
69 SyncChangeProcessor* sync_processor) { 67 SyncChangeProcessor* sync_processor) {
70 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
71 DCHECK(sync_processor_ == NULL); 69 DCHECK(!sync_processor_.get());
72 VLOG(1) << "Associating Autofill: MergeDataAndStartSyncing"; 70 VLOG(1) << "Associating Autofill: MergeDataAndStartSyncing";
73 71
74 if (!LoadAutofillData(&profiles_.get())) { 72 if (!LoadAutofillData(&profiles_.get())) {
75 return SyncError( 73 return SyncError(
76 FROM_HERE, "Could not get the autofill data from WebDatabase.", 74 FROM_HERE, "Could not get the autofill data from WebDatabase.",
77 model_type()); 75 model_type());
78 } 76 }
79 77
80 if (VLOG_IS_ON(2)) { 78 if (VLOG_IS_ON(2)) {
81 VLOG(2) << "[AUTOFILL MIGRATION]" 79 VLOG(2) << "[AUTOFILL MIGRATION]"
82 << "Printing profiles from web db"; 80 << "Printing profiles from web db";
83 81
84 for (ScopedVector<AutofillProfile>::const_iterator ix = 82 for (ScopedVector<AutofillProfile>::const_iterator ix =
85 profiles_.begin(); ix != profiles_.end(); ++ix) { 83 profiles_.begin(); ix != profiles_.end(); ++ix) {
86 AutofillProfile* p = *ix; 84 AutofillProfile* p = *ix;
87 VLOG(2) << "[AUTOFILL MIGRATION] " 85 VLOG(2) << "[AUTOFILL MIGRATION] "
88 << p->GetInfo(NAME_FIRST) 86 << p->GetInfo(NAME_FIRST)
89 << p->GetInfo(NAME_LAST) 87 << p->GetInfo(NAME_LAST)
90 << p->guid(); 88 << p->guid();
91 } 89 }
92 } 90 }
93 91
94 sync_processor_ = sync_processor; 92 sync_processor_.reset(sync_processor);
95 93
96 GUIDToProfileMap remaining_profiles; 94 GUIDToProfileMap remaining_profiles;
97 CreateGUIDToProfileMap(profiles_.get(), &remaining_profiles); 95 CreateGUIDToProfileMap(profiles_.get(), &remaining_profiles);
98 96
99 DataBundle bundle; 97 DataBundle bundle;
100 // Go through and check for all the profiles that sync already knows about. 98 // Go through and check for all the profiles that sync already knows about.
101 for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin(); 99 for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin();
102 sync_iter != initial_sync_data.end(); 100 sync_iter != initial_sync_data.end();
103 ++sync_iter) { 101 ++sync_iter) {
104 GUIDToProfileMap::iterator it = 102 GUIDToProfileMap::iterator it =
(...skipping 15 matching lines...) Expand all
120 118
121 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 119 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
122 120
123 WebDataService::NotifyOfMultipleAutofillChanges(profile_); 121 WebDataService::NotifyOfMultipleAutofillChanges(profile_);
124 122
125 return error; 123 return error;
126 } 124 }
127 125
128 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) { 126 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) {
129 DCHECK(CalledOnValidThread()); 127 DCHECK(CalledOnValidThread());
130 DCHECK(sync_processor_ != NULL);
131 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); 128 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE);
132 129
133 sync_processor_ = NULL; 130 sync_processor_.reset();
134 profiles_.reset(); 131 profiles_.reset();
135 profiles_map_.clear(); 132 profiles_map_.clear();
136 } 133 }
137 134
138 SyncDataList AutofillProfileSyncableService::GetAllSyncData( 135 SyncDataList AutofillProfileSyncableService::GetAllSyncData(
139 syncable::ModelType type) const { 136 syncable::ModelType type) const {
140 DCHECK(CalledOnValidThread()); 137 DCHECK(CalledOnValidThread());
141 DCHECK(sync_processor_ != NULL); 138 DCHECK(sync_processor_.get());
142 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); 139 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE);
143 140
144 SyncDataList current_data; 141 SyncDataList current_data;
145 142
146 for (GUIDToProfileMap::const_iterator i = profiles_map_.begin(); 143 for (GUIDToProfileMap::const_iterator i = profiles_map_.begin();
147 i != profiles_map_.end(); ++i) { 144 i != profiles_map_.end(); ++i) {
148 current_data.push_back(CreateData(*(i->second))); 145 current_data.push_back(CreateData(*(i->second)));
149 } 146 }
150 return current_data; 147 return current_data;
151 } 148 }
152 149
153 SyncError AutofillProfileSyncableService::ProcessSyncChanges( 150 SyncError AutofillProfileSyncableService::ProcessSyncChanges(
154 const tracked_objects::Location& from_here, 151 const tracked_objects::Location& from_here,
155 const SyncChangeList& change_list) { 152 const SyncChangeList& change_list) {
156 DCHECK(CalledOnValidThread()); 153 DCHECK(CalledOnValidThread());
157 DCHECK(sync_processor_ != NULL); 154 if (!sync_processor_.get()) {
158 if (sync_processor_ == NULL) {
159 SyncError error(FROM_HERE, "Models not yet associated.", 155 SyncError error(FROM_HERE, "Models not yet associated.",
160 syncable::AUTOFILL_PROFILE); 156 syncable::AUTOFILL_PROFILE);
161 return error; 157 return error;
162 } 158 }
163 159
164 DataBundle bundle; 160 DataBundle bundle;
165 161
166 for (SyncChangeList::const_iterator i = change_list.begin(); 162 for (SyncChangeList::const_iterator i = change_list.begin();
167 i != change_list.end(); ++i) { 163 i != change_list.end(); ++i) {
168 DCHECK(i->IsValid()); 164 DCHECK(i->IsValid());
(...skipping 25 matching lines...) Expand all
194 } 190 }
195 191
196 void AutofillProfileSyncableService::Observe(int type, 192 void AutofillProfileSyncableService::Observe(int type,
197 const NotificationSource& source, 193 const NotificationSource& source,
198 const NotificationDetails& details) { 194 const NotificationDetails& details) {
199 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); 195 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED);
200 // Check if sync is on. If we receive notification prior to the sync being set 196 // Check if sync is on. If we receive notification prior to the sync being set
201 // up we are going to process all when MergeData..() is called. If we receive 197 // up we are going to process all when MergeData..() is called. If we receive
202 // notification after the sync exited, it will be sinced next time Chrome 198 // notification after the sync exited, it will be sinced next time Chrome
203 // starts. 199 // starts.
204 if (!sync_processor_) 200 if (!sync_processor_.get())
205 return; 201 return;
206 WebDataService* wds = Source<WebDataService>(source).ptr(); 202 WebDataService* wds = Source<WebDataService>(source).ptr();
207 203
208 DCHECK(wds && wds->GetDatabase() == web_database_); 204 DCHECK(wds && wds->GetDatabase() == web_database_);
209 205
210 AutofillProfileChange* change = Details<AutofillProfileChange>(details).ptr(); 206 AutofillProfileChange* change = Details<AutofillProfileChange>(details).ptr();
211 207
212 ActOnChange(*change); 208 ActOnChange(*change);
213 } 209 }
214 210
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 bundle->profiles_to_add.push_back(new_profile); 349 bundle->profiles_to_add.push_back(new_profile);
354 } 350 }
355 return it; 351 return it;
356 } 352 }
357 353
358 void AutofillProfileSyncableService::ActOnChange( 354 void AutofillProfileSyncableService::ActOnChange(
359 const AutofillProfileChange& change) { 355 const AutofillProfileChange& change) {
360 DCHECK((change.type() == AutofillProfileChange::REMOVE && 356 DCHECK((change.type() == AutofillProfileChange::REMOVE &&
361 !change.profile()) || 357 !change.profile()) ||
362 (change.type() != AutofillProfileChange::REMOVE && change.profile())); 358 (change.type() != AutofillProfileChange::REMOVE && change.profile()));
363 DCHECK(sync_processor_); 359 DCHECK(sync_processor_.get());
364 SyncChangeList new_changes; 360 SyncChangeList new_changes;
365 DataBundle bundle; 361 DataBundle bundle;
366 switch (change.type()) { 362 switch (change.type()) {
367 case AutofillProfileChange::ADD: 363 case AutofillProfileChange::ADD:
368 new_changes.push_back( 364 new_changes.push_back(
369 SyncChange(SyncChange::ACTION_ADD, CreateData(*(change.profile())))); 365 SyncChange(SyncChange::ACTION_ADD, CreateData(*(change.profile()))));
370 DCHECK(profiles_map_.find(change.profile()->guid()) == 366 DCHECK(profiles_map_.find(change.profile()->guid()) ==
371 profiles_map_.end()); 367 profiles_map_.end());
372 profiles_.push_back(new AutofillProfile(*(change.profile()))); 368 profiles_.push_back(new AutofillProfile(*(change.profile())));
373 profiles_map_[change.profile()->guid()] = profiles_.get().back(); 369 profiles_map_[change.profile()->guid()] = profiles_.get().back();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 WriteAutofillProfile(profile, &specifics); 403 WriteAutofillProfile(profile, &specifics);
408 return SyncData::CreateLocalData(profile.guid(), profile.guid(), specifics); 404 return SyncData::CreateLocalData(profile.guid(), profile.guid(), specifics);
409 } 405 }
410 406
411 AutofillProfileSyncableService::DataBundle::DataBundle() {} 407 AutofillProfileSyncableService::DataBundle::DataBundle() {}
412 408
413 AutofillProfileSyncableService::DataBundle::~DataBundle() { 409 AutofillProfileSyncableService::DataBundle::~DataBundle() {
414 } 410 }
415 411
416 } // namespace browser_sync 412 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698