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/sync/glue/autofill_change_processor.h" | 5 #include "chrome/browser/sync/glue/autofill_change_processor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/tracked.h" | 11 #include "base/tracked.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/personal_data_manager.h" | 13 #include "chrome/browser/autofill/personal_data_manager.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/sync/glue/autofill_model_associator.h" | 15 #include "chrome/browser/sync/glue/autofill_model_associator.h" |
16 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | 16 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" |
17 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" | 17 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
19 #include "chrome/browser/webdata/autofill_change.h" | 19 #include "chrome/browser/webdata/autofill_change.h" |
20 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
21 #include "chrome/browser/webdata/web_database.h" | 21 #include "chrome/browser/webdata/web_database.h" |
| 22 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/guid.h" | 23 #include "chrome/common/guid.h" |
23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
24 | 25 |
25 namespace browser_sync { | 26 namespace browser_sync { |
26 | 27 |
27 struct AutofillChangeProcessor::AutofillChangeRecord { | 28 struct AutofillChangeProcessor::AutofillChangeRecord { |
28 sync_api::SyncManager::ChangeRecord::Action action_; | 29 sync_api::SyncManager::ChangeRecord::Action action_; |
29 int64 id_; | 30 int64 id_; |
30 sync_pb::AutofillSpecifics autofill_; | 31 sync_pb::AutofillSpecifics autofill_; |
31 AutofillChangeRecord(sync_api::SyncManager::ChangeRecord::Action action, | 32 AutofillChangeRecord(sync_api::SyncManager::ChangeRecord::Action action, |
(...skipping 16 matching lines...) Expand all Loading... |
48 DCHECK(model_associator); | 49 DCHECK(model_associator); |
49 DCHECK(web_database); | 50 DCHECK(web_database); |
50 DCHECK(error_handler); | 51 DCHECK(error_handler); |
51 DCHECK(personal_data); | 52 DCHECK(personal_data); |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
53 StartObserving(); | 54 StartObserving(); |
54 } | 55 } |
55 | 56 |
56 AutofillChangeProcessor::~AutofillChangeProcessor() {} | 57 AutofillChangeProcessor::~AutofillChangeProcessor() {} |
57 | 58 |
58 void AutofillChangeProcessor::Observe(NotificationType type, | 59 void AutofillChangeProcessor::Observe(int type, |
59 const NotificationSource& source, | 60 const NotificationSource& source, |
60 const NotificationDetails& details) { | 61 const NotificationDetails& details) { |
61 // Ensure this notification came from our web database. | 62 // Ensure this notification came from our web database. |
62 WebDataService* wds = Source<WebDataService>(source).ptr(); | 63 WebDataService* wds = Source<WebDataService>(source).ptr(); |
63 if (!wds || wds->GetDatabase() != web_database_) | 64 if (!wds || wds->GetDatabase() != web_database_) |
64 return; | 65 return; |
65 | 66 |
66 DCHECK(running()); | 67 DCHECK(running()); |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
68 if (!observing_) | 69 if (!observing_) |
69 return; | 70 return; |
70 | 71 |
71 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); | 72 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); |
72 sync_api::ReadNode autofill_root(&trans); | 73 sync_api::ReadNode autofill_root(&trans); |
73 if (!autofill_root.InitByTagLookup(kAutofillTag)) { | 74 if (!autofill_root.InitByTagLookup(kAutofillTag)) { |
74 error_handler()->OnUnrecoverableError(FROM_HERE, | 75 error_handler()->OnUnrecoverableError(FROM_HERE, |
75 "Server did not create the top-level autofill node. " | 76 "Server did not create the top-level autofill node. " |
76 "We might be running against an out-of-date server."); | 77 "We might be running against an out-of-date server."); |
77 return; | 78 return; |
78 } | 79 } |
79 | 80 |
80 DCHECK(type.value == NotificationType::AUTOFILL_ENTRIES_CHANGED); | 81 DCHECK(type == chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED); |
81 | 82 |
82 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); | 83 AutofillChangeList* changes = Details<AutofillChangeList>(details).ptr(); |
83 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); | 84 ObserveAutofillEntriesChanged(changes, &trans, autofill_root); |
84 } | 85 } |
85 | 86 |
86 void AutofillChangeProcessor::PostOptimisticRefreshTask() { | 87 void AutofillChangeProcessor::PostOptimisticRefreshTask() { |
87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
88 new DoOptimisticRefreshForAutofill( | 89 new DoOptimisticRefreshForAutofill( |
89 personal_data_)); | 90 personal_data_)); |
90 } | 91 } |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 } | 413 } |
413 | 414 |
414 void AutofillChangeProcessor::StopImpl() { | 415 void AutofillChangeProcessor::StopImpl() { |
415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
416 observing_ = false; | 417 observing_ = false; |
417 } | 418 } |
418 | 419 |
419 | 420 |
420 void AutofillChangeProcessor::StartObserving() { | 421 void AutofillChangeProcessor::StartObserving() { |
421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
422 notification_registrar_.Add(this, NotificationType::AUTOFILL_ENTRIES_CHANGED, | 423 notification_registrar_.Add(this, |
| 424 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
423 NotificationService::AllSources()); | 425 NotificationService::AllSources()); |
424 } | 426 } |
425 | 427 |
426 void AutofillChangeProcessor::StopObserving() { | 428 void AutofillChangeProcessor::StopObserving() { |
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
428 notification_registrar_.RemoveAll(); | 430 notification_registrar_.RemoveAll(); |
429 } | 431 } |
430 | 432 |
431 // static | 433 // static |
432 void AutofillChangeProcessor::WriteAutofillEntry( | 434 void AutofillChangeProcessor::WriteAutofillEntry( |
433 const AutofillEntry& entry, | 435 const AutofillEntry& entry, |
434 sync_api::WriteNode* node) { | 436 sync_api::WriteNode* node) { |
435 sync_pb::AutofillSpecifics autofill; | 437 sync_pb::AutofillSpecifics autofill; |
436 autofill.set_name(UTF16ToUTF8(entry.key().name())); | 438 autofill.set_name(UTF16ToUTF8(entry.key().name())); |
437 autofill.set_value(UTF16ToUTF8(entry.key().value())); | 439 autofill.set_value(UTF16ToUTF8(entry.key().value())); |
438 const std::vector<base::Time>& ts(entry.timestamps()); | 440 const std::vector<base::Time>& ts(entry.timestamps()); |
439 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 441 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
440 timestamp != ts.end(); ++timestamp) { | 442 timestamp != ts.end(); ++timestamp) { |
441 autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 443 autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
442 } | 444 } |
443 node->SetAutofillSpecifics(autofill); | 445 node->SetAutofillSpecifics(autofill); |
444 } | 446 } |
445 | 447 |
446 } // namespace browser_sync | 448 } // namespace browser_sync |
OLD | NEW |