| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 617 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 618 syncer::ReadNode autofill_root(&trans); | 618 syncer::ReadNode autofill_root(&trans); |
| 619 if (autofill_root.InitByTagLookup( | 619 if (autofill_root.InitByTagLookup( |
| 620 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) != | 620 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) != |
| 621 BaseNode::INIT_OK) { | 621 BaseNode::INIT_OK) { |
| 622 return false; | 622 return false; |
| 623 } | 623 } |
| 624 | 624 |
| 625 syncer::WriteNode node(&trans); | 625 syncer::WriteNode node(&trans); |
| 626 std::string tag = AutocompleteSyncableService::KeyToTag( | 626 std::string tag = AutocompleteSyncableService::KeyToTag( |
| 627 UTF16ToUTF8(entry.key().name()), UTF16ToUTF8(entry.key().value())); | 627 base::UTF16ToUTF8(entry.key().name()), |
| 628 base::UTF16ToUTF8(entry.key().value())); |
| 628 syncer::WriteNode::InitUniqueByCreationResult result = | 629 syncer::WriteNode::InitUniqueByCreationResult result = |
| 629 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); | 630 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); |
| 630 if (result != syncer::WriteNode::INIT_SUCCESS) | 631 if (result != syncer::WriteNode::INIT_SUCCESS) |
| 631 return false; | 632 return false; |
| 632 | 633 |
| 633 sync_pb::EntitySpecifics specifics; | 634 sync_pb::EntitySpecifics specifics; |
| 634 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); | 635 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); |
| 635 sync_pb::AutofillSpecifics* autofill_specifics = | 636 sync_pb::AutofillSpecifics* autofill_specifics = |
| 636 specifics.mutable_autofill(); | 637 specifics.mutable_autofill(); |
| 637 node.SetAutofillSpecifics(*autofill_specifics); | 638 node.SetAutofillSpecifics(*autofill_specifics); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 674 |
| 674 int64 child_id = autofill_root.GetFirstChildId(); | 675 int64 child_id = autofill_root.GetFirstChildId(); |
| 675 while (child_id != syncer::kInvalidId) { | 676 while (child_id != syncer::kInvalidId) { |
| 676 syncer::ReadNode child_node(&trans); | 677 syncer::ReadNode child_node(&trans); |
| 677 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 678 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
| 678 return false; | 679 return false; |
| 679 | 680 |
| 680 const sync_pb::AutofillSpecifics& autofill( | 681 const sync_pb::AutofillSpecifics& autofill( |
| 681 child_node.GetAutofillSpecifics()); | 682 child_node.GetAutofillSpecifics()); |
| 682 if (autofill.has_value()) { | 683 if (autofill.has_value()) { |
| 683 AutofillKey key(UTF8ToUTF16(autofill.name()), | 684 AutofillKey key(base::UTF8ToUTF16(autofill.name()), |
| 684 UTF8ToUTF16(autofill.value())); | 685 base::UTF8ToUTF16(autofill.value())); |
| 685 std::vector<base::Time> timestamps; | 686 std::vector<base::Time> timestamps; |
| 686 int timestamps_count = autofill.usage_timestamp_size(); | 687 int timestamps_count = autofill.usage_timestamp_size(); |
| 687 for (int i = 0; i < timestamps_count; ++i) { | 688 for (int i = 0; i < timestamps_count; ++i) { |
| 688 timestamps.push_back(Time::FromInternalValue( | 689 timestamps.push_back(Time::FromInternalValue( |
| 689 autofill.usage_timestamp(i))); | 690 autofill.usage_timestamp(i))); |
| 690 } | 691 } |
| 691 entries->push_back(AutofillEntry(key, timestamps)); | 692 entries->push_back(AutofillEntry(key, timestamps)); |
| 692 } else if (autofill.has_profile()) { | 693 } else if (autofill.has_profile()) { |
| 693 AutofillProfile p; | 694 AutofillProfile p; |
| 694 p.set_guid(autofill.profile().guid()); | 695 p.set_guid(autofill.profile().guid()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 // Time deep in the past would cause Autocomplete sync to discard the | 742 // Time deep in the past would cause Autocomplete sync to discard the |
| 742 // entries. | 743 // entries. |
| 743 static Time base_time = Time::Now().LocalMidnight(); | 744 static Time base_time = Time::Now().LocalMidnight(); |
| 744 | 745 |
| 745 std::vector<Time> timestamps; | 746 std::vector<Time> timestamps; |
| 746 if (time_shift0 > 0) | 747 if (time_shift0 > 0) |
| 747 timestamps.push_back(base_time + TimeDelta::FromSeconds(time_shift0)); | 748 timestamps.push_back(base_time + TimeDelta::FromSeconds(time_shift0)); |
| 748 if (time_shift1 > 0) | 749 if (time_shift1 > 0) |
| 749 timestamps.push_back(base_time + TimeDelta::FromSeconds(time_shift1)); | 750 timestamps.push_back(base_time + TimeDelta::FromSeconds(time_shift1)); |
| 750 return AutofillEntry( | 751 return AutofillEntry( |
| 751 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); | 752 AutofillKey(base::ASCIIToUTF16(name), base::ASCIIToUTF16(value)), |
| 753 timestamps); |
| 752 } | 754 } |
| 753 | 755 |
| 754 static AutofillEntry MakeAutofillEntry(const char* name, | 756 static AutofillEntry MakeAutofillEntry(const char* name, |
| 755 const char* value, | 757 const char* value, |
| 756 int time_shift) { | 758 int time_shift) { |
| 757 return MakeAutofillEntry(name, value, time_shift, -1); | 759 return MakeAutofillEntry(name, value, time_shift, -1); |
| 758 } | 760 } |
| 759 | 761 |
| 760 friend class AddAutofillHelper<AutofillEntry>; | 762 friend class AddAutofillHelper<AutofillEntry>; |
| 761 friend class AddAutofillHelper<AutofillProfile>; | 763 friend class AddAutofillHelper<AutofillProfile>; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 840 |
| 839 void Update() { | 841 void Update() { |
| 840 // This gets called in a modelsafeworker thread. | 842 // This gets called in a modelsafeworker thread. |
| 841 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 843 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 842 | 844 |
| 843 syncer::UserShare* user_share = service_->GetUserShare(); | 845 syncer::UserShare* user_share = service_->GetUserShare(); |
| 844 syncer::syncable::Directory* directory = user_share->directory.get(); | 846 syncer::syncable::Directory* directory = user_share->directory.get(); |
| 845 | 847 |
| 846 // Create autofill protobuf. | 848 // Create autofill protobuf. |
| 847 std::string tag = AutocompleteSyncableService::KeyToTag( | 849 std::string tag = AutocompleteSyncableService::KeyToTag( |
| 848 UTF16ToUTF8(entry_.key().name()), UTF16ToUTF8(entry_.key().value())); | 850 base::UTF16ToUTF8(entry_.key().name()), |
| 851 base::UTF16ToUTF8(entry_.key().value())); |
| 849 sync_pb::AutofillSpecifics new_autofill; | 852 sync_pb::AutofillSpecifics new_autofill; |
| 850 new_autofill.set_name(UTF16ToUTF8(entry_.key().name())); | 853 new_autofill.set_name(base::UTF16ToUTF8(entry_.key().name())); |
| 851 new_autofill.set_value(UTF16ToUTF8(entry_.key().value())); | 854 new_autofill.set_value(base::UTF16ToUTF8(entry_.key().value())); |
| 852 const std::vector<base::Time>& ts(entry_.timestamps()); | 855 const std::vector<base::Time>& ts(entry_.timestamps()); |
| 853 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); | 856 for (std::vector<base::Time>::const_iterator timestamp = ts.begin(); |
| 854 timestamp != ts.end(); ++timestamp) { | 857 timestamp != ts.end(); ++timestamp) { |
| 855 new_autofill.add_usage_timestamp(timestamp->ToInternalValue()); | 858 new_autofill.add_usage_timestamp(timestamp->ToInternalValue()); |
| 856 } | 859 } |
| 857 | 860 |
| 858 sync_pb::EntitySpecifics entity_specifics; | 861 sync_pb::EntitySpecifics entity_specifics; |
| 859 entity_specifics.mutable_autofill()->CopyFrom(new_autofill); | 862 entity_specifics.mutable_autofill()->CopyFrom(new_autofill); |
| 860 | 863 |
| 861 { | 864 { |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 std::vector<AutofillEntry> sync_entries; | 1411 std::vector<AutofillEntry> sync_entries; |
| 1409 std::vector<AutofillProfile> sync_profiles; | 1412 std::vector<AutofillProfile> sync_profiles; |
| 1410 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1413 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1411 EXPECT_EQ(3U, sync_entries.size()); | 1414 EXPECT_EQ(3U, sync_entries.size()); |
| 1412 EXPECT_EQ(0U, sync_profiles.size()); | 1415 EXPECT_EQ(0U, sync_profiles.size()); |
| 1413 for (size_t i = 0; i < sync_entries.size(); i++) { | 1416 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1414 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1417 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1415 << ", " << sync_entries[i].key().value(); | 1418 << ", " << sync_entries[i].key().value(); |
| 1416 } | 1419 } |
| 1417 } | 1420 } |
| OLD | NEW |