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

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

Issue 12494020: Remove knowledge of Chrome-specific SyncableService classes from WebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a unit test bug, use safer keys for SupportsUserData. 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"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 28
29 std::string LimitData(const std::string& data) { 29 std::string LimitData(const std::string& data) {
30 std::string sanitized_value(data); 30 std::string sanitized_value(data);
31 if (sanitized_value.length() > AutofillTable::kMaxDataLength) 31 if (sanitized_value.length() > AutofillTable::kMaxDataLength)
32 sanitized_value.resize(AutofillTable::kMaxDataLength); 32 sanitized_value.resize(AutofillTable::kMaxDataLength);
33 return sanitized_value; 33 return sanitized_value;
34 } 34 }
35 35
36 // See |UserDataKey| below.
37 int user_data_key = 0;
dhollowa 2013/03/20 21:47:37 nit: Pull inside UserDataKey() as static.
Jói 2013/03/20 22:03:16 Done.
38
39 void* UserDataKey() {
40 // Use the address of a static that COMDAT folding won't ever fold
41 // with something else.
42 return reinterpret_cast<void*>(&user_data_key);
43 }
44
36 } // namespace 45 } // namespace
37 46
38 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 47 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
39 48
40 AutofillProfileSyncableService::AutofillProfileSyncableService( 49 AutofillProfileSyncableService::AutofillProfileSyncableService(
41 WebDataService* web_data_service) 50 WebDataService* web_data_service)
42 : web_data_service_(web_data_service) { 51 : web_data_service_(web_data_service) {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
44 DCHECK(web_data_service_); 53 DCHECK(web_data_service_);
45 notification_registrar_.Add( 54 notification_registrar_.Add(
46 this, 55 this,
47 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 56 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
48 content::Source<WebDataService>(web_data_service_)); 57 content::Source<WebDataService>(web_data_service_));
49 } 58 }
50 59
51 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 60 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
52 DCHECK(CalledOnValidThread()); 61 DCHECK(CalledOnValidThread());
53 } 62 }
54 63
64 // static
65 void AutofillProfileSyncableService::CreateForWebDataService(
66 WebDataService* web_data) {
67 web_data->GetDBUserData()->SetUserData(
68 UserDataKey(), new AutofillProfileSyncableService(web_data));
69 }
70
71 // static
72 AutofillProfileSyncableService*
73 AutofillProfileSyncableService::FromWebDataService(
74 WebDataService* service) {
75 return static_cast<AutofillProfileSyncableService*>(
76 service->GetDBUserData()->GetUserData(UserDataKey()));
77 }
78
55 AutofillProfileSyncableService::AutofillProfileSyncableService() 79 AutofillProfileSyncableService::AutofillProfileSyncableService()
56 : web_data_service_(NULL) { 80 : web_data_service_(NULL) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
58 } 82 }
59 83
60 syncer::SyncMergeResult 84 syncer::SyncMergeResult
61 AutofillProfileSyncableService::MergeDataAndStartSyncing( 85 AutofillProfileSyncableService::MergeDataAndStartSyncing(
62 syncer::ModelType type, 86 syncer::ModelType type,
63 const syncer::SyncDataList& initial_sync_data, 87 const syncer::SyncDataList& initial_sync_data,
64 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 88 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 570 }
547 571
548 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { 572 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {
549 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); 573 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase());
550 } 574 }
551 575
552 AutofillProfileSyncableService::DataBundle::DataBundle() {} 576 AutofillProfileSyncableService::DataBundle::DataBundle() {}
553 577
554 AutofillProfileSyncableService::DataBundle::~DataBundle() { 578 AutofillProfileSyncableService::DataBundle::~DataBundle() {
555 } 579 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698