Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Side by Side Diff: chrome/browser/webdata/autocomplete_syncable_service.cc

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

Powered by Google App Engine
This is Rietveld 408576698