Chromium Code Reviews| 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 // See |UserDataKey| below. | |
| 83 int user_data_key = 0; | |
|
dhollowa
2013/03/20 21:47:37
nit: this could be pulled into the body of UserDat
Jói
2013/03/20 22:03:16
Done. I've also added it to my TODO list to update
| |
| 84 | |
| 85 void* UserDataKey() { | |
| 86 // Use the address of a static that COMDAT folding won't ever fold | |
| 87 // with something else. | |
| 88 return reinterpret_cast<void*>(&user_data_key); | |
| 89 } | |
| 90 | |
| 82 } // namespace | 91 } // namespace |
| 83 | 92 |
| 84 AutocompleteSyncableService::AutocompleteSyncableService( | 93 AutocompleteSyncableService::AutocompleteSyncableService( |
| 85 WebDataService* web_data_service) | 94 WebDataService* web_data_service) |
| 86 : web_data_service_(web_data_service), | 95 : web_data_service_(web_data_service), |
| 87 cull_expired_entries_(false) { | 96 cull_expired_entries_(false) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 89 DCHECK(web_data_service_); | 98 DCHECK(web_data_service_); |
| 90 notification_registrar_.Add( | 99 notification_registrar_.Add( |
| 91 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 100 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 92 content::Source<WebDataService>(web_data_service)); | 101 content::Source<WebDataService>(web_data_service)); |
| 93 } | 102 } |
| 94 | 103 |
| 95 AutocompleteSyncableService::~AutocompleteSyncableService() { | 104 AutocompleteSyncableService::~AutocompleteSyncableService() { |
| 96 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 97 } | 106 } |
| 98 | 107 |
| 108 // static | |
| 109 void AutocompleteSyncableService::CreateForWebDataService( | |
| 110 WebDataService* web_data) { | |
| 111 web_data->GetDBUserData()->SetUserData( | |
| 112 UserDataKey(), new AutocompleteSyncableService(web_data)); | |
| 113 } | |
| 114 | |
| 115 // static | |
| 116 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService( | |
| 117 WebDataService* web_data) { | |
| 118 return static_cast<AutocompleteSyncableService*>( | |
| 119 web_data->GetDBUserData()->GetUserData(UserDataKey())); | |
| 120 } | |
| 121 | |
| 99 AutocompleteSyncableService::AutocompleteSyncableService() | 122 AutocompleteSyncableService::AutocompleteSyncableService() |
| 100 : web_data_service_(NULL), | 123 : web_data_service_(NULL), |
| 101 cull_expired_entries_(false) { | 124 cull_expired_entries_(false) { |
| 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 103 } | 126 } |
| 104 | 127 |
| 105 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( | 128 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( |
| 106 syncer::ModelType type, | 129 syncer::ModelType type, |
| 107 const syncer::SyncDataList& initial_sync_data, | 130 const syncer::SyncDataList& initial_sync_data, |
| 108 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 131 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 UTF16ToUTF8(entry.key().value()))); | 480 UTF16ToUTF8(entry.key().value()))); |
| 458 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); | 481 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); |
| 459 } | 482 } |
| 460 | 483 |
| 461 // static | 484 // static |
| 462 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, | 485 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, |
| 463 const std::string& value) { | 486 const std::string& value) { |
| 464 std::string ns(kAutofillEntryNamespaceTag); | 487 std::string ns(kAutofillEntryNamespaceTag); |
| 465 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); | 488 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); |
| 466 } | 489 } |
| OLD | NEW |