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

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

Issue 12805007: wd5-syncableServices for try only (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wd5-syncableServices with debug test fix 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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void* UserDataKey() {
83 // Use the address of a static that COMDAT folding won't ever fold
84 // with something else.
85 static int user_data_key = 0;
86 return reinterpret_cast<void*>(&user_data_key);
87 }
88
82 } // namespace 89 } // namespace
83 90
84 AutocompleteSyncableService::AutocompleteSyncableService( 91 AutocompleteSyncableService::AutocompleteSyncableService(
85 WebDataService* web_data_service) 92 WebDataService* web_data_service)
86 : web_data_service_(web_data_service), 93 : web_data_service_(web_data_service),
87 cull_expired_entries_(false) { 94 cull_expired_entries_(false) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
89 DCHECK(web_data_service_); 96 DCHECK(web_data_service_);
90 notification_registrar_.Add( 97 notification_registrar_.Add(
91 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 98 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
92 content::Source<WebDataService>(web_data_service)); 99 content::Source<WebDataService>(web_data_service));
93 } 100 }
94 101
95 AutocompleteSyncableService::~AutocompleteSyncableService() { 102 AutocompleteSyncableService::~AutocompleteSyncableService() {
96 DCHECK(CalledOnValidThread()); 103 DCHECK(CalledOnValidThread());
97 } 104 }
98 105
106 // static
107 void AutocompleteSyncableService::CreateForWebDataService(
108 WebDataService* web_data) {
109 web_data->GetDBUserData()->SetUserData(
110 UserDataKey(), new AutocompleteSyncableService(web_data));
111 }
112
113 // static
114 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService(
115 WebDataService* web_data) {
116 return static_cast<AutocompleteSyncableService*>(
117 web_data->GetDBUserData()->GetUserData(UserDataKey()));
118 }
119
99 AutocompleteSyncableService::AutocompleteSyncableService() 120 AutocompleteSyncableService::AutocompleteSyncableService()
100 : web_data_service_(NULL), 121 : web_data_service_(NULL),
101 cull_expired_entries_(false) { 122 cull_expired_entries_(false) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
103 } 124 }
104 125
105 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( 126 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing(
106 syncer::ModelType type, 127 syncer::ModelType type,
107 const syncer::SyncDataList& initial_sync_data, 128 const syncer::SyncDataList& initial_sync_data,
108 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 129 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 313
293 DCHECK_EQ(web_data_service_, wds); 314 DCHECK_EQ(web_data_service_, wds);
294 315
295 AutofillChangeList* changes = 316 AutofillChangeList* changes =
296 content::Details<AutofillChangeList>(details).ptr(); 317 content::Details<AutofillChangeList>(details).ptr();
297 ActOnChanges(*changes); 318 ActOnChanges(*changes);
298 } 319 }
299 320
300 bool AutocompleteSyncableService::LoadAutofillData( 321 bool AutocompleteSyncableService::LoadAutofillData(
301 std::vector<AutofillEntry>* entries) const { 322 std::vector<AutofillEntry>* entries) const {
302 return web_data_service_->GetDatabase()-> 323 return AutofillTable::FromWebDatabase(
303 GetAutofillTable()->GetAllAutofillEntries(entries); 324 web_data_service_->GetDatabase())->GetAllAutofillEntries(entries);
304 } 325 }
305 326
306 bool AutocompleteSyncableService::SaveChangesToWebData( 327 bool AutocompleteSyncableService::SaveChangesToWebData(
307 const std::vector<AutofillEntry>& new_entries) { 328 const std::vector<AutofillEntry>& new_entries) {
308 DCHECK(CalledOnValidThread()); 329 DCHECK(CalledOnValidThread());
309 330
310 if (!new_entries.empty() && 331 if (!new_entries.empty() &&
311 !web_data_service_->GetDatabase()-> 332 !AutofillTable::FromWebDatabase(
312 GetAutofillTable()->UpdateAutofillEntries(new_entries)) { 333 web_data_service_->GetDatabase())->UpdateAutofillEntries(
334 new_entries)) {
313 return false; 335 return false;
314 } 336 }
315 return true; 337 return true;
316 } 338 }
317 339
318 // Creates or updates an autocomplete entry based on |data|. 340 // Creates or updates an autocomplete entry based on |data|.
319 void AutocompleteSyncableService::CreateOrUpdateEntry( 341 void AutocompleteSyncableService::CreateOrUpdateEntry(
320 const syncer::SyncData& data, 342 const syncer::SyncData& data,
321 AutocompleteEntryMap* loaded_data, 343 AutocompleteEntryMap* loaded_data,
322 std::vector<AutofillEntry>* new_entries) { 344 std::vector<AutofillEntry>* new_entries) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 autofill->set_value(UTF16ToUTF8(entry.key().value())); 396 autofill->set_value(UTF16ToUTF8(entry.key().value()));
375 const std::vector<base::Time>& ts(entry.timestamps()); 397 const std::vector<base::Time>& ts(entry.timestamps());
376 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); 398 for (std::vector<base::Time>::const_iterator timestamp = ts.begin();
377 timestamp != ts.end(); ++timestamp) { 399 timestamp != ts.end(); ++timestamp) {
378 autofill->add_usage_timestamp(timestamp->ToInternalValue()); 400 autofill->add_usage_timestamp(timestamp->ToInternalValue());
379 } 401 }
380 } 402 }
381 403
382 syncer::SyncError AutocompleteSyncableService::AutofillEntryDelete( 404 syncer::SyncError AutocompleteSyncableService::AutofillEntryDelete(
383 const sync_pb::AutofillSpecifics& autofill) { 405 const sync_pb::AutofillSpecifics& autofill) {
384 if (!web_data_service_->GetDatabase()->GetAutofillTable()->RemoveFormElement( 406 if (!AutofillTable::FromWebDatabase(
385 UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) { 407 web_data_service_->GetDatabase())->RemoveFormElement(
408 UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) {
386 return error_handler_->CreateAndUploadError( 409 return error_handler_->CreateAndUploadError(
387 FROM_HERE, 410 FROM_HERE,
388 "Could not remove autocomplete entry from WebDatabase."); 411 "Could not remove autocomplete entry from WebDatabase.");
389 } 412 }
390 return syncer::SyncError(); 413 return syncer::SyncError();
391 } 414 }
392 415
393 void AutocompleteSyncableService::ActOnChanges( 416 void AutocompleteSyncableService::ActOnChanges(
394 const AutofillChangeList& changes) { 417 const AutofillChangeList& changes) {
395 DCHECK(sync_processor_.get()); 418 DCHECK(sync_processor_.get());
396 syncer::SyncChangeList new_changes; 419 syncer::SyncChangeList new_changes;
397 for (AutofillChangeList::const_iterator change = changes.begin(); 420 for (AutofillChangeList::const_iterator change = changes.begin();
398 change != changes.end(); ++change) { 421 change != changes.end(); ++change) {
399 switch (change->type()) { 422 switch (change->type()) {
400 case AutofillChange::ADD: 423 case AutofillChange::ADD:
401 case AutofillChange::UPDATE: { 424 case AutofillChange::UPDATE: {
402 std::vector<base::Time> timestamps; 425 std::vector<base::Time> timestamps;
403 if (!web_data_service_->GetDatabase()-> 426 if (!AutofillTable::FromWebDatabase(
404 GetAutofillTable()->GetAutofillTimestamps( 427 web_data_service_->GetDatabase())->GetAutofillTimestamps(
405 change->key().name(), 428 change->key().name(),
406 change->key().value(), 429 change->key().value(),
407 &timestamps)) { 430 &timestamps)) {
408 NOTREACHED(); 431 NOTREACHED();
409 return; 432 return;
410 } 433 }
411 AutofillEntry entry(change->key(), timestamps); 434 AutofillEntry entry(change->key(), timestamps);
412 syncer::SyncChange::SyncChangeType change_type = 435 syncer::SyncChange::SyncChangeType change_type =
413 (change->type() == AutofillChange::ADD) ? 436 (change->type() == AutofillChange::ADD) ?
414 syncer::SyncChange::ACTION_ADD : 437 syncer::SyncChange::ACTION_ADD :
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 UTF16ToUTF8(entry.key().value()))); 478 UTF16ToUTF8(entry.key().value())));
456 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); 479 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics);
457 } 480 }
458 481
459 // static 482 // static
460 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, 483 std::string AutocompleteSyncableService::KeyToTag(const std::string& name,
461 const std::string& value) { 484 const std::string& value) {
462 std::string ns(kAutofillEntryNamespaceTag); 485 std::string ns(kAutofillEntryNamespaceTag);
463 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); 486 return ns + net::EscapePath(name) + "|" + net::EscapePath(value);
464 } 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