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 } | 72 } |
73 | 73 |
74 AutocompleteSyncableService::AutocompleteSyncableService() | 74 AutocompleteSyncableService::AutocompleteSyncableService() |
75 : web_data_service_(NULL) { | 75 : web_data_service_(NULL) { |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
77 } | 77 } |
78 | 78 |
79 SyncError AutocompleteSyncableService::MergeDataAndStartSyncing( | 79 SyncError AutocompleteSyncableService::MergeDataAndStartSyncing( |
80 syncable::ModelType type, | 80 syncable::ModelType type, |
81 const SyncDataList& initial_sync_data, | 81 const SyncDataList& initial_sync_data, |
82 SyncChangeProcessor* sync_processor) { | 82 scoped_ptr<SyncChangeProcessor> sync_processor) { |
83 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
84 DCHECK(!sync_processor_.get()); | 84 DCHECK(!sync_processor_.get()); |
| 85 DCHECK(sync_processor.get()); |
85 VLOG(1) << "Associating Autocomplete: MergeDataAndStartSyncing"; | 86 VLOG(1) << "Associating Autocomplete: MergeDataAndStartSyncing"; |
86 | 87 |
87 std::vector<AutofillEntry> entries; | 88 std::vector<AutofillEntry> entries; |
88 if (!LoadAutofillData(&entries)) { | 89 if (!LoadAutofillData(&entries)) { |
89 return SyncError( | 90 return SyncError( |
90 FROM_HERE, "Could not get the autocomplete data from WebDatabase.", | 91 FROM_HERE, "Could not get the autocomplete data from WebDatabase.", |
91 model_type()); | 92 model_type()); |
92 } | 93 } |
93 | 94 |
94 AutocompleteEntryMap new_db_entries; | 95 AutocompleteEntryMap new_db_entries; |
95 for (std::vector<AutofillEntry>::iterator it = entries.begin(); | 96 for (std::vector<AutofillEntry>::iterator it = entries.begin(); |
96 it != entries.end(); ++it) { | 97 it != entries.end(); ++it) { |
97 new_db_entries[it->key()] = std::make_pair(SyncChange::ACTION_ADD, it); | 98 new_db_entries[it->key()] = std::make_pair(SyncChange::ACTION_ADD, it); |
98 } | 99 } |
99 | 100 |
100 sync_processor_.reset(sync_processor); | 101 sync_processor_ = sync_processor.Pass(); |
101 | 102 |
102 std::vector<AutofillEntry> new_synced_entries; | 103 std::vector<AutofillEntry> new_synced_entries; |
103 // Go through and check for all the entries that sync already knows about. | 104 // Go through and check for all the entries that sync already knows about. |
104 // CreateOrUpdateEntry() will remove entries that are same with the synced | 105 // CreateOrUpdateEntry() will remove entries that are same with the synced |
105 // ones from |new_db_entries|. | 106 // ones from |new_db_entries|. |
106 for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin(); | 107 for (SyncDataList::const_iterator sync_iter = initial_sync_data.begin(); |
107 sync_iter != initial_sync_data.end(); ++sync_iter) { | 108 sync_iter != initial_sync_data.end(); ++sync_iter) { |
108 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); | 109 CreateOrUpdateEntry(*sync_iter, &new_db_entries, &new_synced_entries); |
109 } | 110 } |
110 | 111 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 UTF16ToUTF8(entry.key().value()))); | 385 UTF16ToUTF8(entry.key().value()))); |
385 return SyncData::CreateLocalData(tag, tag, autofill_specifics); | 386 return SyncData::CreateLocalData(tag, tag, autofill_specifics); |
386 } | 387 } |
387 | 388 |
388 // static | 389 // static |
389 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, | 390 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, |
390 const std::string& value) { | 391 const std::string& value) { |
391 std::string ns(kAutofillEntryNamespaceTag); | 392 std::string ns(kAutofillEntryNamespaceTag); |
392 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); | 393 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); |
393 } | 394 } |
OLD | NEW |