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/api/webdata/autofill_web_data_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/webdata/autofill_table.h" | 12 #include "chrome/browser/webdata/autofill_table.h" |
12 #include "chrome/browser/webdata/web_data_service.h" | |
13 #include "chrome/browser/webdata/web_database.h" | 13 #include "chrome/browser/webdata/web_database.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
18 #include "sync/api/sync_error.h" | 18 #include "sync/api/sync_error.h" |
19 #include "sync/api/sync_error_factory.h" | 19 #include "sync/api/sync_error_factory.h" |
20 #include "sync/protocol/autofill_specifics.pb.h" | 20 #include "sync/protocol/autofill_specifics.pb.h" |
21 #include "sync/protocol/sync.pb.h" | 21 #include "sync/protocol/sync.pb.h" |
22 | 22 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 void* UserDataKey() { | 82 void* UserDataKey() { |
83 // Use the address of a static that COMDAT folding won't ever fold | 83 // Use the address of a static that COMDAT folding won't ever fold |
84 // with something else. | 84 // with something else. |
85 static int user_data_key = 0; | 85 static int user_data_key = 0; |
86 return reinterpret_cast<void*>(&user_data_key); | 86 return reinterpret_cast<void*>(&user_data_key); |
87 } | 87 } |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 | 90 |
91 AutocompleteSyncableService::AutocompleteSyncableService( | 91 AutocompleteSyncableService::AutocompleteSyncableService( |
92 WebDataService* web_data_service) | 92 AutofillWebDataService* web_data_service) |
93 : web_data_service_(web_data_service), | 93 : web_data_service_(web_data_service), |
94 cull_expired_entries_(false) { | 94 cull_expired_entries_(false) { |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
96 DCHECK(web_data_service_); | 96 DCHECK(web_data_service_); |
97 notification_registrar_.Add( | 97 notification_registrar_.Add( |
98 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 98 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
99 content::Source<WebDataService>(web_data_service)); | 99 content::Source<AutofillWebDataService>(web_data_service)); |
100 } | 100 } |
101 | 101 |
102 AutocompleteSyncableService::~AutocompleteSyncableService() { | 102 AutocompleteSyncableService::~AutocompleteSyncableService() { |
103 DCHECK(CalledOnValidThread()); | 103 DCHECK(CalledOnValidThread()); |
104 } | 104 } |
105 | 105 |
106 // static | 106 // static |
107 void AutocompleteSyncableService::CreateForWebDataService( | 107 void AutocompleteSyncableService::CreateForWebDataService( |
108 WebDataService* web_data) { | 108 AutofillWebDataService* web_data_service) { |
109 web_data->GetDBUserData()->SetUserData( | 109 web_data_service->GetDBUserData()->SetUserData( |
110 UserDataKey(), new AutocompleteSyncableService(web_data)); | 110 UserDataKey(), new AutocompleteSyncableService(web_data_service)); |
111 } | 111 } |
112 | 112 |
113 // static | 113 // static |
114 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService( | 114 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService( |
115 WebDataService* web_data) { | 115 AutofillWebDataService* web_data_service) { |
116 return static_cast<AutocompleteSyncableService*>( | 116 return static_cast<AutocompleteSyncableService*>( |
117 web_data->GetDBUserData()->GetUserData(UserDataKey())); | 117 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); |
118 } | 118 } |
119 | 119 |
120 AutocompleteSyncableService::AutocompleteSyncableService() | 120 AutocompleteSyncableService::AutocompleteSyncableService() |
121 : web_data_service_(NULL), | 121 : web_data_service_(NULL), |
122 cull_expired_entries_(false) { | 122 cull_expired_entries_(false) { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
124 } | 124 } |
125 | 125 |
126 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( | 126 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( |
127 syncer::ModelType type, | 127 syncer::ModelType type, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); | 163 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); |
164 } | 164 } |
165 | 165 |
166 if (!SaveChangesToWebData(new_synced_entries)) { | 166 if (!SaveChangesToWebData(new_synced_entries)) { |
167 merge_result.set_error(error_handler_->CreateAndUploadError( | 167 merge_result.set_error(error_handler_->CreateAndUploadError( |
168 FROM_HERE, | 168 FROM_HERE, |
169 "Failed to update webdata.")); | 169 "Failed to update webdata.")); |
170 return merge_result; | 170 return merge_result; |
171 } | 171 } |
172 | 172 |
173 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 173 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
174 | 174 |
175 syncer::SyncChangeList new_changes; | 175 syncer::SyncChangeList new_changes; |
176 for (AutocompleteEntryMap::iterator i = new_db_entries.begin(); | 176 for (AutocompleteEntryMap::iterator i = new_db_entries.begin(); |
177 i != new_db_entries.end(); ++i) { | 177 i != new_db_entries.end(); ++i) { |
178 new_changes.push_back( | 178 new_changes.push_back( |
179 syncer::SyncChange(FROM_HERE, | 179 syncer::SyncChange(FROM_HERE, |
180 i->second.first, | 180 i->second.first, |
181 CreateSyncData(*(i->second.second)))); | 181 CreateSyncData(*(i->second.second)))); |
182 } | 182 } |
183 | 183 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 syncer::SyncChange::ChangeTypeToString(i->change_type())); | 280 syncer::SyncChange::ChangeTypeToString(i->change_type())); |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 if (!SaveChangesToWebData(new_entries)) { | 284 if (!SaveChangesToWebData(new_entries)) { |
285 return error_handler_->CreateAndUploadError( | 285 return error_handler_->CreateAndUploadError( |
286 FROM_HERE, | 286 FROM_HERE, |
287 "Failed to update webdata."); | 287 "Failed to update webdata."); |
288 } | 288 } |
289 | 289 |
290 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 290 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
291 | 291 |
292 if (cull_expired_entries_) { | 292 if (cull_expired_entries_) { |
293 // This will schedule a deletion operation on the DB thread, which will | 293 // This will schedule a deletion operation on the DB thread, which will |
294 // trigger a notification to propagate the deletion to Sync. | 294 // trigger a notification to propagate the deletion to Sync. |
295 web_data_service_->RemoveExpiredFormElements(); | 295 web_data_service_->RemoveExpiredFormElements(); |
296 } | 296 } |
297 | 297 |
298 return list_processing_error; | 298 return list_processing_error; |
299 } | 299 } |
300 | 300 |
301 void AutocompleteSyncableService::Observe(int type, | 301 void AutocompleteSyncableService::Observe(int type, |
302 const content::NotificationSource& source, | 302 const content::NotificationSource& source, |
303 const content::NotificationDetails& details) { | 303 const content::NotificationDetails& details) { |
304 DCHECK_EQ(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, type); | 304 DCHECK_EQ(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, type); |
305 | 305 |
306 // Check if sync is on. If we receive notification prior to the sync being set | 306 // Check if sync is on. If we receive notification prior to the sync being set |
307 // up we are going to process all when MergeData..() is called. If we receive | 307 // up we are going to process all when MergeData..() is called. If we receive |
308 // notification after the sync exited, it will be sinced next time Chrome | 308 // notification after the sync exited, it will be sinced next time Chrome |
309 // starts. | 309 // starts. |
310 if (!sync_processor_.get()) | 310 if (!sync_processor_.get()) |
311 return; | 311 return; |
312 WebDataService* wds = content::Source<WebDataService>(source).ptr(); | 312 AutofillWebDataService* web_data_service = |
| 313 content::Source<AutofillWebDataService>(source).ptr(); |
313 | 314 |
314 DCHECK_EQ(web_data_service_, wds); | 315 DCHECK_EQ(web_data_service_, web_data_service); |
315 | 316 |
316 AutofillChangeList* changes = | 317 AutofillChangeList* changes = |
317 content::Details<AutofillChangeList>(details).ptr(); | 318 content::Details<AutofillChangeList>(details).ptr(); |
318 ActOnChanges(*changes); | 319 ActOnChanges(*changes); |
319 } | 320 } |
320 | 321 |
321 bool AutocompleteSyncableService::LoadAutofillData( | 322 bool AutocompleteSyncableService::LoadAutofillData( |
322 std::vector<AutofillEntry>* entries) const { | 323 std::vector<AutofillEntry>* entries) const { |
323 return AutofillTable::FromWebDatabase( | 324 return AutofillTable::FromWebDatabase( |
324 web_data_service_->GetDatabase())->GetAllAutofillEntries(entries); | 325 web_data_service_->GetDatabase())->GetAllAutofillEntries(entries); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 UTF16ToUTF8(entry.key().value()))); | 479 UTF16ToUTF8(entry.key().value()))); |
479 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); | 480 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); |
480 } | 481 } |
481 | 482 |
482 // static | 483 // static |
483 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, | 484 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, |
484 const std::string& value) { | 485 const std::string& value) { |
485 std::string ns(kAutofillEntryNamespaceTag); | 486 std::string ns(kAutofillEntryNamespaceTag); |
486 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); | 487 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); |
487 } | 488 } |
OLD | NEW |