OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "chrome/browser/sync/api/sync_error.h" | 11 #include "chrome/browser/sync/api/sync_error.h" |
12 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 13 #include "chrome/browser/sync/protocol/sync.pb.h" |
13 #include "chrome/browser/webdata/autofill_table.h" | 14 #include "chrome/browser/webdata/autofill_table.h" |
14 #include "chrome/browser/webdata/web_data_service.h" | 15 #include "chrome/browser/webdata/web_data_service.h" |
15 #include "chrome/browser/webdata/web_database.h" | 16 #include "chrome/browser/webdata/web_database.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/guid.h" | 18 #include "chrome/common/guid.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
21 | 22 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 db_entries.reset(new AutocompleteEntryMap); | 187 db_entries.reset(new AutocompleteEntryMap); |
187 for (std::vector<AutofillEntry>::iterator it = entries.begin(); | 188 for (std::vector<AutofillEntry>::iterator it = entries.begin(); |
188 it != entries.end(); ++it) { | 189 it != entries.end(); ++it) { |
189 (*db_entries)[it->key()] = | 190 (*db_entries)[it->key()] = |
190 std::make_pair(SyncChange::ACTION_ADD, it); | 191 std::make_pair(SyncChange::ACTION_ADD, it); |
191 } | 192 } |
192 } | 193 } |
193 CreateOrUpdateEntry(i->sync_data(), db_entries.get(), &new_entries); | 194 CreateOrUpdateEntry(i->sync_data(), db_entries.get(), &new_entries); |
194 break; | 195 break; |
195 case SyncChange::ACTION_DELETE: { | 196 case SyncChange::ACTION_DELETE: { |
196 DCHECK(i->sync_data().GetSpecifics().HasExtension(sync_pb::autofill)) | 197 DCHECK(i->sync_data().GetSpecifics().has_autofill()) |
197 << "Autofill specifics data not present on delete!"; | 198 << "Autofill specifics data not present on delete!"; |
198 const sync_pb::AutofillSpecifics& autofill = | 199 const sync_pb::AutofillSpecifics& autofill = |
199 i->sync_data().GetSpecifics().GetExtension(sync_pb::autofill); | 200 i->sync_data().GetSpecifics().autofill(); |
200 if (autofill.has_value()) { | 201 if (autofill.has_value()) { |
201 list_processing_error = AutofillEntryDelete(autofill); | 202 list_processing_error = AutofillEntryDelete(autofill); |
202 } else { | 203 } else { |
203 DLOG(WARNING) | 204 DLOG(WARNING) |
204 << "Delete for old-style autofill profile being dropped!"; | 205 << "Delete for old-style autofill profile being dropped!"; |
205 } | 206 } |
206 } break; | 207 } break; |
207 default: | 208 default: |
208 NOTREACHED() << "Unexpected sync change state."; | 209 NOTREACHED() << "Unexpected sync change state."; |
209 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + | 210 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 return true; | 259 return true; |
259 } | 260 } |
260 | 261 |
261 // Creates or updates an autocomplete entry based on |data|. | 262 // Creates or updates an autocomplete entry based on |data|. |
262 void AutocompleteSyncableService::CreateOrUpdateEntry( | 263 void AutocompleteSyncableService::CreateOrUpdateEntry( |
263 const SyncData& data, | 264 const SyncData& data, |
264 AutocompleteEntryMap* loaded_data, | 265 AutocompleteEntryMap* loaded_data, |
265 std::vector<AutofillEntry>* new_entries) { | 266 std::vector<AutofillEntry>* new_entries) { |
266 const sync_pb::EntitySpecifics& specifics = data.GetSpecifics(); | 267 const sync_pb::EntitySpecifics& specifics = data.GetSpecifics(); |
267 const sync_pb::AutofillSpecifics& autofill_specifics( | 268 const sync_pb::AutofillSpecifics& autofill_specifics( |
268 specifics.GetExtension(sync_pb::autofill)); | 269 specifics.autofill()); |
269 | 270 |
270 if (!autofill_specifics.has_value()) { | 271 if (!autofill_specifics.has_value()) { |
271 DLOG(WARNING) | 272 DLOG(WARNING) |
272 << "Add/Update for old-style autofill profile being dropped!"; | 273 << "Add/Update for old-style autofill profile being dropped!"; |
273 return; | 274 return; |
274 } | 275 } |
275 | 276 |
276 AutofillKey key(autofill_specifics.name().c_str(), | 277 AutofillKey key(autofill_specifics.name().c_str(), |
277 autofill_specifics.value().c_str()); | 278 autofill_specifics.value().c_str()); |
278 AutocompleteEntryMap::iterator it = loaded_data->find(key); | 279 AutocompleteEntryMap::iterator it = loaded_data->find(key); |
(...skipping 22 matching lines...) Expand all Loading... |
301 } else { | 302 } else { |
302 loaded_data->erase(it); | 303 loaded_data->erase(it); |
303 } | 304 } |
304 } | 305 } |
305 } | 306 } |
306 | 307 |
307 // static | 308 // static |
308 void AutocompleteSyncableService::WriteAutofillEntry( | 309 void AutocompleteSyncableService::WriteAutofillEntry( |
309 const AutofillEntry& entry, sync_pb::EntitySpecifics* autofill_specifics) { | 310 const AutofillEntry& entry, sync_pb::EntitySpecifics* autofill_specifics) { |
310 sync_pb::AutofillSpecifics* autofill = | 311 sync_pb::AutofillSpecifics* autofill = |
311 autofill_specifics->MutableExtension(sync_pb::autofill); | 312 autofill_specifics->mutable_autofill(); |
312 autofill->set_name(UTF16ToUTF8(entry.key().name())); | 313 autofill->set_name(UTF16ToUTF8(entry.key().name())); |
313 autofill->set_value(UTF16ToUTF8(entry.key().value())); | 314 autofill->set_value(UTF16ToUTF8(entry.key().value())); |
314 const std::vector<base::Time>& ts(entry.timestamps()); | 315 const std::vector<base::Time>& ts(entry.timestamps()); |
315 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 316 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
316 timestamp != ts.end(); ++timestamp) { | 317 timestamp != ts.end(); ++timestamp) { |
317 autofill->add_usage_timestamp(timestamp->ToInternalValue()); | 318 autofill->add_usage_timestamp(timestamp->ToInternalValue()); |
318 } | 319 } |
319 } | 320 } |
320 | 321 |
321 SyncError AutocompleteSyncableService::AutofillEntryDelete( | 322 SyncError AutocompleteSyncableService::AutofillEntryDelete( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 UTF16ToUTF8(entry.key().value()))); | 384 UTF16ToUTF8(entry.key().value()))); |
384 return SyncData::CreateLocalData(tag, tag, autofill_specifics); | 385 return SyncData::CreateLocalData(tag, tag, autofill_specifics); |
385 } | 386 } |
386 | 387 |
387 // static | 388 // static |
388 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, | 389 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, |
389 const std::string& value) { | 390 const std::string& value) { |
390 std::string ns(kAutofillEntryNamespaceTag); | 391 std::string ns(kAutofillEntryNamespaceTag); |
391 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); | 392 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); |
392 } | 393 } |
OLD | NEW |