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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 void* UserDataKey() { | 82 void* UserDataKey() { |
83 return reinterpret_cast<void*>( | 83 return reinterpret_cast<void*>( |
84 &AutocompleteSyncableService::CreateForWebDataService); | 84 &AutocompleteSyncableService::CreateForWebDataService); |
85 } | 85 } |
86 | 86 |
87 } // namespace | 87 } // namespace |
88 | 88 |
89 AutocompleteSyncableService::AutocompleteSyncableService( | 89 AutocompleteSyncableService::AutocompleteSyncableService( |
90 WebDataService* web_data_service) | 90 AutofillWebDataService* web_data_service) |
91 : web_data_service_(web_data_service), | 91 : web_data_service_(web_data_service), |
92 cull_expired_entries_(false) { | 92 cull_expired_entries_(false) { |
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
94 DCHECK(web_data_service_); | 94 DCHECK(web_data_service_); |
95 notification_registrar_.Add( | 95 notification_registrar_.Add( |
96 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 96 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
97 content::Source<WebDataService>(web_data_service)); | 97 content::Source<AutofillWebDataService>(web_data_service)); |
98 } | 98 } |
99 | 99 |
100 AutocompleteSyncableService::~AutocompleteSyncableService() { | 100 AutocompleteSyncableService::~AutocompleteSyncableService() { |
101 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
102 } | 102 } |
103 | 103 |
104 // static | 104 // static |
105 void AutocompleteSyncableService::CreateForWebDataService( | 105 void AutocompleteSyncableService::CreateForWebDataService( |
106 WebDataService* web_data) { | 106 AutofillWebDataService* web_data) { |
107 web_data->GetDBUserData()->SetUserData( | 107 web_data->GetDBUserData()->SetUserData( |
108 UserDataKey(), new AutocompleteSyncableService(web_data)); | 108 UserDataKey(), new AutocompleteSyncableService(web_data)); |
109 } | 109 } |
110 | 110 |
111 // static | 111 // static |
112 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService( | 112 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService( |
113 WebDataService* web_data) { | 113 AutofillWebDataService* web_data) { |
114 return static_cast<AutocompleteSyncableService*>( | 114 return static_cast<AutocompleteSyncableService*>( |
115 web_data->GetDBUserData()->GetUserData(UserDataKey())); | 115 web_data->GetDBUserData()->GetUserData(UserDataKey())); |
116 } | 116 } |
117 | 117 |
118 AutocompleteSyncableService::AutocompleteSyncableService() | 118 AutocompleteSyncableService::AutocompleteSyncableService() |
119 : web_data_service_(NULL), | 119 : web_data_service_(NULL), |
120 cull_expired_entries_(false) { | 120 cull_expired_entries_(false) { |
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
122 } | 122 } |
123 | 123 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); | 161 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); |
162 } | 162 } |
163 | 163 |
164 if (!SaveChangesToWebData(new_synced_entries)) { | 164 if (!SaveChangesToWebData(new_synced_entries)) { |
165 merge_result.set_error(error_handler_->CreateAndUploadError( | 165 merge_result.set_error(error_handler_->CreateAndUploadError( |
166 FROM_HERE, | 166 FROM_HERE, |
167 "Failed to update webdata.")); | 167 "Failed to update webdata.")); |
168 return merge_result; | 168 return merge_result; |
169 } | 169 } |
170 | 170 |
171 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 171 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
172 | 172 |
173 syncer::SyncChangeList new_changes; | 173 syncer::SyncChangeList new_changes; |
174 for (AutocompleteEntryMap::iterator i = new_db_entries.begin(); | 174 for (AutocompleteEntryMap::iterator i = new_db_entries.begin(); |
175 i != new_db_entries.end(); ++i) { | 175 i != new_db_entries.end(); ++i) { |
176 new_changes.push_back( | 176 new_changes.push_back( |
177 syncer::SyncChange(FROM_HERE, | 177 syncer::SyncChange(FROM_HERE, |
178 i->second.first, | 178 i->second.first, |
179 CreateSyncData(*(i->second.second)))); | 179 CreateSyncData(*(i->second.second)))); |
180 } | 180 } |
181 | 181 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 syncer::SyncChange::ChangeTypeToString(i->change_type())); | 278 syncer::SyncChange::ChangeTypeToString(i->change_type())); |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 if (!SaveChangesToWebData(new_entries)) { | 282 if (!SaveChangesToWebData(new_entries)) { |
283 return error_handler_->CreateAndUploadError( | 283 return error_handler_->CreateAndUploadError( |
284 FROM_HERE, | 284 FROM_HERE, |
285 "Failed to update webdata."); | 285 "Failed to update webdata."); |
286 } | 286 } |
287 | 287 |
288 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 288 AutofillWebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
289 | 289 |
290 if (cull_expired_entries_) { | 290 if (cull_expired_entries_) { |
291 // This will schedule a deletion operation on the DB thread, which will | 291 // This will schedule a deletion operation on the DB thread, which will |
292 // trigger a notification to propagate the deletion to Sync. | 292 // trigger a notification to propagate the deletion to Sync. |
293 web_data_service_->RemoveExpiredFormElements(); | 293 web_data_service_->RemoveExpiredFormElements(); |
294 } | 294 } |
295 | 295 |
296 return list_processing_error; | 296 return list_processing_error; |
297 } | 297 } |
298 | 298 |
299 void AutocompleteSyncableService::Observe(int type, | 299 void AutocompleteSyncableService::Observe(int type, |
300 const content::NotificationSource& source, | 300 const content::NotificationSource& source, |
301 const content::NotificationDetails& details) { | 301 const content::NotificationDetails& details) { |
302 DCHECK_EQ(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, type); | 302 DCHECK_EQ(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, type); |
303 | 303 |
304 // Check if sync is on. If we receive notification prior to the sync being set | 304 // Check if sync is on. If we receive notification prior to the sync being set |
305 // up we are going to process all when MergeData..() is called. If we receive | 305 // up we are going to process all when MergeData..() is called. If we receive |
306 // notification after the sync exited, it will be sinced next time Chrome | 306 // notification after the sync exited, it will be sinced next time Chrome |
307 // starts. | 307 // starts. |
308 if (!sync_processor_.get()) | 308 if (!sync_processor_.get()) |
309 return; | 309 return; |
310 WebDataService* wds = content::Source<WebDataService>(source).ptr(); | 310 AutofillWebDataService* wds = |
| 311 content::Source<AutofillWebDataService>(source).ptr(); |
311 | 312 |
312 DCHECK_EQ(web_data_service_, wds); | 313 DCHECK_EQ(web_data_service_, wds); |
313 | 314 |
314 AutofillChangeList* changes = | 315 AutofillChangeList* changes = |
315 content::Details<AutofillChangeList>(details).ptr(); | 316 content::Details<AutofillChangeList>(details).ptr(); |
316 ActOnChanges(*changes); | 317 ActOnChanges(*changes); |
317 } | 318 } |
318 | 319 |
319 bool AutocompleteSyncableService::LoadAutofillData( | 320 bool AutocompleteSyncableService::LoadAutofillData( |
320 std::vector<AutofillEntry>* entries) const { | 321 std::vector<AutofillEntry>* entries) const { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 UTF16ToUTF8(entry.key().value()))); | 477 UTF16ToUTF8(entry.key().value()))); |
477 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); | 478 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); |
478 } | 479 } |
479 | 480 |
480 // static | 481 // static |
481 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, | 482 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, |
482 const std::string& value) { | 483 const std::string& value) { |
483 std::string ns(kAutofillEntryNamespaceTag); | 484 std::string ns(kAutofillEntryNamespaceTag); |
484 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); | 485 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); |
485 } | 486 } |
OLD | NEW |