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

Side by Side Diff: chrome/browser/webdata/autofill_profile_syncable_service.cc

Issue 12695015: Split Autofill webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Convert all Autofill/Sync clients of WDS to using AutofillWDS Created 7 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/webdata/autofill_profile_syncable_service.h" 5 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/api/webdata/autofill_web_data_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/webdata/autofill_table.h" 13 #include "chrome/browser/webdata/autofill_table.h"
13 #include "chrome/browser/webdata/web_data_service.h"
14 #include "chrome/browser/webdata/web_database.h" 14 #include "chrome/browser/webdata/web_database.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "components/autofill/browser/autofill_profile.h" 16 #include "components/autofill/browser/autofill_profile.h"
17 #include "components/autofill/browser/form_group.h" 17 #include "components/autofill/browser/form_group.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "sync/api/sync_error.h" 21 #include "sync/api/sync_error.h"
22 #include "sync/api/sync_error_factory.h" 22 #include "sync/api/sync_error_factory.h"
23 #include "sync/protocol/sync.pb.h" 23 #include "sync/protocol/sync.pb.h"
(...skipping 12 matching lines...) Expand all
36 void* UserDataKey() { 36 void* UserDataKey() {
37 return reinterpret_cast<void*>( 37 return reinterpret_cast<void*>(
38 &AutofillProfileSyncableService::CreateForWebDataService); 38 &AutofillProfileSyncableService::CreateForWebDataService);
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 43 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
44 44
45 AutofillProfileSyncableService::AutofillProfileSyncableService( 45 AutofillProfileSyncableService::AutofillProfileSyncableService(
46 WebDataService* web_data_service) 46 AutofillWebDataService* web_data_service)
47 : web_data_service_(web_data_service) { 47 : web_data_service_(web_data_service) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
49 DCHECK(web_data_service_); 49 DCHECK(web_data_service_);
50 notification_registrar_.Add( 50 notification_registrar_.Add(
51 this, 51 this,
52 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 52 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
53 content::Source<WebDataService>(web_data_service_)); 53 content::Source<AutofillWebDataService>(web_data_service_));
54 } 54 }
55 55
56 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 56 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
57 DCHECK(CalledOnValidThread()); 57 DCHECK(CalledOnValidThread());
58 } 58 }
59 59
60 // static 60 // static
61 void AutofillProfileSyncableService::CreateForWebDataService( 61 void AutofillProfileSyncableService::CreateForWebDataService(
62 WebDataService* web_data) { 62 AutofillWebDataService* web_data) {
63 web_data->GetDBUserData()->SetUserData( 63 web_data->GetDBUserData()->SetUserData(
64 UserDataKey(), new AutofillProfileSyncableService(web_data)); 64 UserDataKey(), new AutofillProfileSyncableService(web_data));
65 } 65 }
66 66
67 // static 67 // static
68 AutofillProfileSyncableService* 68 AutofillProfileSyncableService*
69 AutofillProfileSyncableService::FromWebDataService( 69 AutofillProfileSyncableService::FromWebDataService(
70 WebDataService* service) { 70 AutofillWebDataService* service) {
71 return static_cast<AutofillProfileSyncableService*>( 71 return static_cast<AutofillProfileSyncableService*>(
72 service->GetDBUserData()->GetUserData(UserDataKey())); 72 service->GetDBUserData()->GetUserData(UserDataKey()));
73 } 73 }
74 74
75 AutofillProfileSyncableService::AutofillProfileSyncableService() 75 AutofillProfileSyncableService::AutofillProfileSyncableService()
76 : web_data_service_(NULL) { 76 : web_data_service_(NULL) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
78 } 78 }
79 79
80 syncer::SyncMergeResult 80 syncer::SyncMergeResult
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 syncer::SyncChange(FROM_HERE, 175 syncer::SyncChange(FROM_HERE,
176 syncer::SyncChange::ACTION_UPDATE, 176 syncer::SyncChange::ACTION_UPDATE,
177 CreateData(*(bundle.profiles_to_sync_back[i])))); 177 CreateData(*(bundle.profiles_to_sync_back[i]))));
178 } 178 }
179 179
180 if (!new_changes.empty()) { 180 if (!new_changes.empty()) {
181 merge_result.set_error( 181 merge_result.set_error(
182 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); 182 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes));
183 } 183 }
184 184
185 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 185 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
186 186
187 return merge_result; 187 return merge_result;
188 } 188 }
189 189
190 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) { 190 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) {
191 DCHECK(CalledOnValidThread()); 191 DCHECK(CalledOnValidThread());
192 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE); 192 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE);
193 193
194 sync_processor_.reset(); 194 sync_processor_.reset();
195 sync_error_factory_.reset(); 195 sync_error_factory_.reset();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 syncer::SyncChange::ChangeTypeToString(i->change_type())); 246 syncer::SyncChange::ChangeTypeToString(i->change_type()));
247 } 247 }
248 } 248 }
249 249
250 if (!SaveChangesToWebData(bundle)) { 250 if (!SaveChangesToWebData(bundle)) {
251 return sync_error_factory_->CreateAndUploadError( 251 return sync_error_factory_->CreateAndUploadError(
252 FROM_HERE, 252 FROM_HERE,
253 "Failed to update webdata."); 253 "Failed to update webdata.");
254 } 254 }
255 255
256 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 256 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
257 257
258 return syncer::SyncError(); 258 return syncer::SyncError();
259 } 259 }
260 260
261 void AutofillProfileSyncableService::Observe(int type, 261 void AutofillProfileSyncableService::Observe(int type,
262 const content::NotificationSource& source, 262 const content::NotificationSource& source,
263 const content::NotificationDetails& details) { 263 const content::NotificationDetails& details) {
264 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); 264 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED);
265 DCHECK_EQ(web_data_service_, content::Source<WebDataService>(source).ptr()); 265 DCHECK_EQ(web_data_service_,
266 content::Source<AutofillWebDataService>(source).ptr());
266 // Check if sync is on. If we receive notification prior to the sync being set 267 // Check if sync is on. If we receive notification prior to the sync being set
267 // up we are going to process all when MergeData..() is called. If we receive 268 // up we are going to process all when MergeData..() is called. If we receive
268 // notification after the sync exited, it will be sinced next time Chrome 269 // notification after the sync exited, it will be sinced next time Chrome
269 // starts. 270 // starts.
270 if (!sync_processor_.get()) 271 if (!sync_processor_.get())
271 return; 272 return;
272 273
273 AutofillProfileChange* change = 274 AutofillProfileChange* change =
274 content::Details<AutofillProfileChange>(details).ptr(); 275 content::Details<AutofillProfileChange>(details).ptr();
275 ActOnChange(*change); 276 ActOnChange(*change);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 567 }
567 568
568 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { 569 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {
569 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); 570 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase());
570 } 571 }
571 572
572 AutofillProfileSyncableService::DataBundle::DataBundle() {} 573 AutofillProfileSyncableService::DataBundle::DataBundle() {}
573 574
574 AutofillProfileSyncableService::DataBundle::~DataBundle() { 575 AutofillProfileSyncableService::DataBundle::~DataBundle() {
575 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698