| 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/autocomplete_syncable_service.h" | 5 #include "chrome/browser/webdata/autocomplete_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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return true; | 72 return true; |
| 73 } else { | 73 } else { |
| 74 new_timestamps->insert(new_timestamps->begin(), | 74 new_timestamps->insert(new_timestamps->begin(), |
| 75 timestamps.begin(), | 75 timestamps.begin(), |
| 76 timestamps.end()); | 76 timestamps.end()); |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 class DataObject : public base::SupportsUserData::Data { |
| 83 public: |
| 84 explicit DataObject(scoped_ptr<AutocompleteSyncableService> service) |
| 85 : service_(service.Pass()) { |
| 86 } |
| 87 |
| 88 AutocompleteSyncableService* service() { |
| 89 return service_.get(); |
| 90 } |
| 91 |
| 92 private: |
| 93 scoped_ptr<AutocompleteSyncableService> service_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(DataObject); |
| 96 }; |
| 97 |
| 98 void* DataKey() { |
| 99 return reinterpret_cast<void*>(&AutocompleteSyncableService::AttachToWebData); |
| 100 } |
| 101 |
| 82 } // namespace | 102 } // namespace |
| 83 | 103 |
| 84 AutocompleteSyncableService::AutocompleteSyncableService( | 104 AutocompleteSyncableService::AutocompleteSyncableService( |
| 85 WebDataService* web_data_service) | 105 WebDataService* web_data_service) |
| 86 : web_data_service_(web_data_service), | 106 : web_data_service_(web_data_service), |
| 87 cull_expired_entries_(false) { | 107 cull_expired_entries_(false) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 89 DCHECK(web_data_service_); | 109 DCHECK(web_data_service_); |
| 90 notification_registrar_.Add( | 110 notification_registrar_.Add( |
| 91 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 111 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 92 content::Source<WebDataService>(web_data_service)); | 112 content::Source<WebDataService>(web_data_service)); |
| 93 } | 113 } |
| 94 | 114 |
| 95 AutocompleteSyncableService::~AutocompleteSyncableService() { | 115 AutocompleteSyncableService::~AutocompleteSyncableService() { |
| 96 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
| 97 } | 117 } |
| 98 | 118 |
| 119 // static |
| 120 AutocompleteSyncableService* AutocompleteSyncableService::FromWebData( |
| 121 WebDataServiceBase* service) { |
| 122 return static_cast<DataObject*>( |
| 123 service->GetDBUserData()->GetUserData(DataKey()))->service(); |
| 124 } |
| 125 |
| 126 // static |
| 127 void AutocompleteSyncableService::AttachToWebData( |
| 128 scoped_ptr<AutocompleteSyncableService> service, |
| 129 WebDataServiceBase* web_data) { |
| 130 web_data->GetDBUserData()->SetUserData(DataKey(), |
| 131 new DataObject(service.Pass())); |
| 132 } |
| 133 |
| 99 AutocompleteSyncableService::AutocompleteSyncableService() | 134 AutocompleteSyncableService::AutocompleteSyncableService() |
| 100 : web_data_service_(NULL), | 135 : web_data_service_(NULL), |
| 101 cull_expired_entries_(false) { | 136 cull_expired_entries_(false) { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 103 } | 138 } |
| 104 | 139 |
| 105 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( | 140 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( |
| 106 syncer::ModelType type, | 141 syncer::ModelType type, |
| 107 const syncer::SyncDataList& initial_sync_data, | 142 const syncer::SyncDataList& initial_sync_data, |
| 108 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 143 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 UTF16ToUTF8(entry.key().value()))); | 492 UTF16ToUTF8(entry.key().value()))); |
| 458 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); | 493 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); |
| 459 } | 494 } |
| 460 | 495 |
| 461 // static | 496 // static |
| 462 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, | 497 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, |
| 463 const std::string& value) { | 498 const std::string& value) { |
| 464 std::string ns(kAutofillEntryNamespaceTag); | 499 std::string ns(kAutofillEntryNamespaceTag); |
| 465 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); | 500 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); |
| 466 } | 501 } |
| OLD | NEW |