OLD | NEW |
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 Loading... |
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 class DataObject : public base::SupportsUserData::Data { |
| 37 public: |
| 38 explicit DataObject(scoped_ptr<AutofillProfileSyncableService> service) |
| 39 : service_(service.Pass()) { |
| 40 } |
| 41 |
| 42 AutofillProfileSyncableService* service() { |
| 43 return service_.get(); |
| 44 } |
| 45 |
| 46 private: |
| 47 scoped_ptr<AutofillProfileSyncableService> service_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(DataObject); |
| 50 }; |
| 51 |
| 52 void* DataKey() { |
| 53 return reinterpret_cast<void*>( |
| 54 &AutofillProfileSyncableService::AttachToWebData); |
| 55 } |
| 56 |
36 } // namespace | 57 } // namespace |
37 | 58 |
38 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; | 59 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; |
39 | 60 |
40 AutofillProfileSyncableService::AutofillProfileSyncableService( | 61 AutofillProfileSyncableService::AutofillProfileSyncableService( |
41 WebDataService* web_data_service) | 62 WebDataService* web_data_service) |
42 : web_data_service_(web_data_service) { | 63 : web_data_service_(web_data_service) { |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
44 DCHECK(web_data_service_); | 65 DCHECK(web_data_service_); |
45 notification_registrar_.Add( | 66 notification_registrar_.Add( |
46 this, | 67 this, |
47 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 68 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
48 content::Source<WebDataService>(web_data_service_)); | 69 content::Source<WebDataService>(web_data_service_)); |
49 } | 70 } |
50 | 71 |
51 AutofillProfileSyncableService::~AutofillProfileSyncableService() { | 72 AutofillProfileSyncableService::~AutofillProfileSyncableService() { |
52 DCHECK(CalledOnValidThread()); | 73 DCHECK(CalledOnValidThread()); |
53 } | 74 } |
54 | 75 |
| 76 // static |
| 77 AutofillProfileSyncableService* AutofillProfileSyncableService::FromWebData( |
| 78 WebDataServiceBase* service) { |
| 79 return static_cast<DataObject*>( |
| 80 service->GetDBUserData()->GetUserData(DataKey()))->service(); |
| 81 } |
| 82 |
| 83 // static |
| 84 void AutofillProfileSyncableService::AttachToWebData( |
| 85 scoped_ptr<AutofillProfileSyncableService> service, |
| 86 WebDataServiceBase* web_data) { |
| 87 web_data->GetDBUserData()->SetUserData(DataKey(), |
| 88 new DataObject(service.Pass())); |
| 89 } |
| 90 |
55 AutofillProfileSyncableService::AutofillProfileSyncableService() | 91 AutofillProfileSyncableService::AutofillProfileSyncableService() |
56 : web_data_service_(NULL) { | 92 : web_data_service_(NULL) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
58 } | 94 } |
59 | 95 |
60 syncer::SyncMergeResult | 96 syncer::SyncMergeResult |
61 AutofillProfileSyncableService::MergeDataAndStartSyncing( | 97 AutofillProfileSyncableService::MergeDataAndStartSyncing( |
62 syncer::ModelType type, | 98 syncer::ModelType type, |
63 const syncer::SyncDataList& initial_sync_data, | 99 const syncer::SyncDataList& initial_sync_data, |
64 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 100 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 } | 582 } |
547 | 583 |
548 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { | 584 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { |
549 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); | 585 return AutofillTable::FromWebDatabase(web_data_service_->GetDatabase()); |
550 } | 586 } |
551 | 587 |
552 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 588 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
553 | 589 |
554 AutofillProfileSyncableService::DataBundle::~DataBundle() { | 590 AutofillProfileSyncableService::DataBundle::~DataBundle() { |
555 } | 591 } |
OLD | NEW |