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

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

Issue 14081043: Hook up Autofill Backend interface to SyncableServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 "components/autofill/browser/autofill_country.h" 11 #include "components/autofill/browser/autofill_country.h"
12 #include "components/autofill/browser/autofill_profile.h" 12 #include "components/autofill/browser/autofill_profile.h"
13 #include "components/autofill/browser/form_group.h" 13 #include "components/autofill/browser/form_group.h"
14 #include "components/autofill/browser/webdata/autofill_backend_delegate.h"
14 #include "components/autofill/browser/webdata/autofill_table.h" 15 #include "components/autofill/browser/webdata/autofill_table.h"
15 #include "components/autofill/browser/webdata/autofill_webdata_service.h" 16 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
16 #include "components/webdata/common/web_database.h" 17 #include "components/webdata/common/web_database.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "sync/api/sync_error.h" 19 #include "sync/api/sync_error.h"
19 #include "sync/api/sync_error_factory.h" 20 #include "sync/api/sync_error_factory.h"
20 #include "sync/protocol/sync.pb.h" 21 #include "sync/protocol/sync.pb.h"
21 22
22 using autofill::AutofillCountry; 23 using autofill::AutofillCountry;
23 using autofill::AutofillFieldType; 24 using autofill::AutofillFieldType;
24 using autofill::AutofillProfile; 25 using autofill::AutofillProfile;
25 using autofill::AutofillProfileChange; 26 using autofill::AutofillProfileChange;
26 using autofill::AutofillTable; 27 using autofill::AutofillTable;
27 using autofill::AutofillWebDataService; 28 using autofill::AutofillWebDataService;
29 using autofill::AutofillBackendDelegate;
28 using content::BrowserThread; 30 using content::BrowserThread;
29 31
30 namespace { 32 namespace {
31 33
32 std::string LimitData(const std::string& data) { 34 std::string LimitData(const std::string& data) {
33 std::string sanitized_value(data); 35 std::string sanitized_value(data);
34 if (sanitized_value.length() > AutofillTable::kMaxDataLength) 36 if (sanitized_value.length() > AutofillTable::kMaxDataLength)
35 sanitized_value.resize(AutofillTable::kMaxDataLength); 37 sanitized_value.resize(AutofillTable::kMaxDataLength);
36 return sanitized_value; 38 return sanitized_value;
37 } 39 }
38 40
39 void* UserDataKey() { 41 void* UserDataKey() {
40 // Use the address of a static that COMDAT folding won't ever fold 42 // Use the address of a static that COMDAT folding won't ever fold
41 // with something else. 43 // with something else.
42 static int user_data_key = 0; 44 static int user_data_key = 0;
43 return reinterpret_cast<void*>(&user_data_key); 45 return reinterpret_cast<void*>(&user_data_key);
44 } 46 }
45 47
46 } // namespace 48 } // namespace
47 49
48 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 50 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
49 51
50 AutofillProfileSyncableService::AutofillProfileSyncableService( 52 AutofillProfileSyncableService::AutofillProfileSyncableService(
51 AutofillWebDataService* web_data_service, 53 AutofillWebDataService* web_data_service,
54 AutofillBackendDelegate* web_data_delegate,
52 const std::string& app_locale) 55 const std::string& app_locale)
53 : web_data_service_(web_data_service), 56 : web_data_service_(web_data_service),
57 web_data_delegate_(web_data_delegate),
54 app_locale_(app_locale), 58 app_locale_(app_locale),
55 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_observer_(this)) { 59 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_observer_(this)) {
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
57 DCHECK(web_data_service_); 61 DCHECK(web_data_delegate_);
58 62
59 scoped_observer_.Add(web_data_service_); 63 scoped_observer_.Add(web_data_delegate_);
60 } 64 }
61 65
62 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 66 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
63 DCHECK(CalledOnValidThread()); 67 DCHECK(CalledOnValidThread());
64 } 68 }
65 69
66 // static 70 // static
67 void AutofillProfileSyncableService::CreateForWebDataService( 71 void AutofillProfileSyncableService::CreateForWebDataService(
68 AutofillWebDataService* web_data_service, 72 AutofillWebDataService* web_data_service,
73 AutofillBackendDelegate* delegate,
69 const std::string& app_locale) { 74 const std::string& app_locale) {
70 web_data_service->GetDBUserData()->SetUserData( 75 web_data_service->GetDBUserData()->SetUserData(
71 UserDataKey(), 76 UserDataKey(),
72 new AutofillProfileSyncableService(web_data_service, app_locale)); 77 new AutofillProfileSyncableService(
78 web_data_service, delegate, app_locale));
73 } 79 }
74 80
75 // static 81 // static
76 AutofillProfileSyncableService* 82 AutofillProfileSyncableService*
77 AutofillProfileSyncableService::FromWebDataService( 83 AutofillProfileSyncableService::FromWebDataService(
78 AutofillWebDataService* web_data_service) { 84 AutofillWebDataService* web_data_service) {
79 return static_cast<AutofillProfileSyncableService*>( 85 return static_cast<AutofillProfileSyncableService*>(
80 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); 86 web_data_service->GetDBUserData()->GetUserData(UserDataKey()));
81 } 87 }
82 88
83 AutofillProfileSyncableService::AutofillProfileSyncableService() 89 AutofillProfileSyncableService::AutofillProfileSyncableService()
84 : web_data_service_(NULL), 90 : web_data_service_(NULL),
91 web_data_delegate_(NULL),
85 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_observer_(this)) { 92 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_observer_(this)) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
87 } 94 }
88 95
89 syncer::SyncMergeResult 96 syncer::SyncMergeResult
90 AutofillProfileSyncableService::MergeDataAndStartSyncing( 97 AutofillProfileSyncableService::MergeDataAndStartSyncing(
91 syncer::ModelType type, 98 syncer::ModelType type,
92 const syncer::SyncDataList& initial_sync_data, 99 const syncer::SyncDataList& initial_sync_data,
93 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 100 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
94 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { 101 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 syncer::SyncChange(FROM_HERE, 191 syncer::SyncChange(FROM_HERE,
185 syncer::SyncChange::ACTION_UPDATE, 192 syncer::SyncChange::ACTION_UPDATE,
186 CreateData(*(bundle.profiles_to_sync_back[i])))); 193 CreateData(*(bundle.profiles_to_sync_back[i]))));
187 } 194 }
188 195
189 if (!new_changes.empty()) { 196 if (!new_changes.empty()) {
190 merge_result.set_error( 197 merge_result.set_error(
191 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes)); 198 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes));
192 } 199 }
193 200
194 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 201 if (web_data_delegate_)
202 web_data_delegate_->NotifyOfMultipleAutofillChanges(web_data_service_);
195 203
196 return merge_result; 204 return merge_result;
197 } 205 }
198 206
199 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) { 207 void AutofillProfileSyncableService::StopSyncing(syncer::ModelType type) {
200 DCHECK(CalledOnValidThread()); 208 DCHECK(CalledOnValidThread());
201 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE); 209 DCHECK_EQ(type, syncer::AUTOFILL_PROFILE);
202 210
203 sync_processor_.reset(); 211 sync_processor_.reset();
204 sync_error_factory_.reset(); 212 sync_error_factory_.reset();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 syncer::SyncChange::ChangeTypeToString(i->change_type())); 263 syncer::SyncChange::ChangeTypeToString(i->change_type()));
256 } 264 }
257 } 265 }
258 266
259 if (!SaveChangesToWebData(bundle)) { 267 if (!SaveChangesToWebData(bundle)) {
260 return sync_error_factory_->CreateAndUploadError( 268 return sync_error_factory_->CreateAndUploadError(
261 FROM_HERE, 269 FROM_HERE,
262 "Failed to update webdata."); 270 "Failed to update webdata.");
263 } 271 }
264 272
265 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 273 if (web_data_delegate_)
274 web_data_delegate_->NotifyOfMultipleAutofillChanges(web_data_service_);
266 275
267 return syncer::SyncError(); 276 return syncer::SyncError();
268 } 277 }
269 278
270 void AutofillProfileSyncableService::AutofillProfileChanged( 279 void AutofillProfileSyncableService::AutofillProfileChanged(
271 const AutofillProfileChange& change) { 280 const AutofillProfileChange& change) {
272 // Check if sync is on. If we receive notification prior to the sync being set 281 // Check if sync is on. If we receive notification prior to the sync being set
273 // up we are going to process all when MergeData..() is called. If we receive 282 // up we are going to process all when MergeData..() is called. If we receive
274 // notification after the sync exited, it will be sinced next time Chrome 283 // notification after the sync exited, it will be sinced next time Chrome
275 // starts. 284 // starts.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 581
573 bool AutofillProfileSyncableService::MergeProfile( 582 bool AutofillProfileSyncableService::MergeProfile(
574 const AutofillProfile& merge_from, 583 const AutofillProfile& merge_from,
575 AutofillProfile* merge_into, 584 AutofillProfile* merge_into,
576 const std::string& app_locale) { 585 const std::string& app_locale) {
577 merge_into->OverwriteWithOrAddTo(merge_from, app_locale); 586 merge_into->OverwriteWithOrAddTo(merge_from, app_locale);
578 return (merge_into->Compare(merge_from) != 0); 587 return (merge_into->Compare(merge_from) != 0);
579 } 588 }
580 589
581 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { 590 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {
582 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); 591 return AutofillTable::FromWebDatabase(web_data_delegate_->GetDatabase());
583 } 592 }
584 593
585 AutofillProfileSyncableService::DataBundle::DataBundle() {} 594 AutofillProfileSyncableService::DataBundle::DataBundle() {}
586 595
587 AutofillProfileSyncableService::DataBundle::~DataBundle() {} 596 AutofillProfileSyncableService::DataBundle::~DataBundle() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698