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/search_engines/template_url_service.h" | 5 #include "chrome/browser/search_engines/template_url_service.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 } | 490 } |
491 | 491 |
492 // initial_default_search_provider_ is only needed before we've finished | 492 // initial_default_search_provider_ is only needed before we've finished |
493 // loading. Now that we've loaded we can nuke it. | 493 // loading. Now that we've loaded we can nuke it. |
494 initial_default_search_provider_.reset(); | 494 initial_default_search_provider_.reset(); |
495 is_default_search_managed_ = false; | 495 is_default_search_managed_ = false; |
496 | 496 |
497 std::vector<TemplateURL*> template_urls; | 497 std::vector<TemplateURL*> template_urls; |
498 const TemplateURL* default_search_provider = NULL; | 498 const TemplateURL* default_search_provider = NULL; |
499 int new_resource_keyword_version = 0; | 499 int new_resource_keyword_version = 0; |
500 GetSearchProvidersUsingKeywordResult(*result, | 500 GetSearchProvidersUsingKeywordResult(*result, |
SteveT
2011/09/01 14:21:54
sky 2011/08/17 23:22:29
This may end up modifying
| |
501 service_.get(), | 501 service_.get(), |
502 GetPrefs(), | 502 GetPrefs(), |
503 &template_urls, | 503 &template_urls, |
504 &default_search_provider, | 504 &default_search_provider, |
505 &new_resource_keyword_version); | 505 &new_resource_keyword_version); |
506 | 506 |
507 bool database_specified_a_default = NULL != default_search_provider; | 507 bool database_specified_a_default = NULL != default_search_provider; |
508 | 508 |
509 // Check if default search provider is now managed. | 509 // Check if default search provider is now managed. |
510 scoped_ptr<TemplateURL> default_from_prefs; | 510 scoped_ptr<TemplateURL> default_from_prefs; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 const SyncChangeList& change_list) { | 642 const SyncChangeList& change_list) { |
643 if (!models_associated_) { | 643 if (!models_associated_) { |
644 SyncError error(FROM_HERE, "Models not yet associated.", | 644 SyncError error(FROM_HERE, "Models not yet associated.", |
645 syncable::SEARCH_ENGINES); | 645 syncable::SEARCH_ENGINES); |
646 return error; | 646 return error; |
647 } | 647 } |
648 | 648 |
649 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); | 649 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); |
650 | 650 |
651 SyncChangeList new_changes; | 651 SyncChangeList new_changes; |
652 SyncError error; | |
652 for (SyncChangeList::const_iterator iter = change_list.begin(); | 653 for (SyncChangeList::const_iterator iter = change_list.begin(); |
653 iter != change_list.end(); ++iter) { | 654 iter != change_list.end(); ++iter) { |
654 DCHECK_EQ(syncable::SEARCH_ENGINES, iter->sync_data().GetDataType()); | 655 DCHECK_EQ(syncable::SEARCH_ENGINES, iter->sync_data().GetDataType()); |
655 | 656 |
656 scoped_ptr<TemplateURL> turl( | 657 scoped_ptr<TemplateURL> turl( |
657 CreateTemplateURLFromSyncData(iter->sync_data())); | 658 CreateTemplateURLFromSyncData(iter->sync_data())); |
658 if (!turl.get()) { | 659 if (!turl.get()) { |
659 NOTREACHED() << "Failed to read search engine."; | 660 NOTREACHED() << "Failed to read search engine."; |
660 continue; | 661 continue; |
661 } | 662 } |
662 | 663 |
663 const TemplateURL* existing_turl = GetTemplateURLForGUID(turl->sync_guid()); | 664 const TemplateURL* existing_turl = GetTemplateURLForGUID(turl->sync_guid()); |
664 const TemplateURL* existing_keyword_turl = | 665 const TemplateURL* existing_keyword_turl = |
665 GetTemplateURLForKeyword(turl->keyword()); | 666 GetTemplateURLForKeyword(turl->keyword()); |
666 | 667 |
667 if (iter->change_type() == SyncChange::ACTION_DELETE && existing_turl) { | 668 if (iter->change_type() == SyncChange::ACTION_DELETE && existing_turl) { |
668 Remove(existing_turl); | 669 Remove(existing_turl); |
669 } else if (iter->change_type() == SyncChange::ACTION_ADD && | 670 } else if (iter->change_type() == SyncChange::ACTION_ADD && |
670 !existing_turl) { | 671 !existing_turl) { |
671 if (existing_keyword_turl) | 672 if (existing_keyword_turl) |
672 ResolveSyncKeywordConflict(turl.get(), new_changes); | 673 ResolveSyncKeywordConflict(turl.get(), &new_changes); |
673 // Force the local ID to 0 so we can add it. | 674 // Force the local ID to 0 so we can add it. |
674 turl->set_id(0); | 675 turl->set_id(0); |
675 Add(turl.release()); | 676 Add(turl.release()); |
676 } else if (iter->change_type() == SyncChange::ACTION_UPDATE && | 677 } else if (iter->change_type() == SyncChange::ACTION_UPDATE && |
677 existing_turl) { | 678 existing_turl) { |
678 if (existing_keyword_turl) | 679 if (existing_keyword_turl) |
679 ResolveSyncKeywordConflict(turl.get(), new_changes); | 680 ResolveSyncKeywordConflict(turl.get(), &new_changes); |
680 ResetTemplateURL(existing_turl, turl->short_name(), turl->keyword(), | 681 ResetTemplateURL(existing_turl, turl->short_name(), turl->keyword(), |
681 turl->url() ? turl->url()->url() : std::string()); | 682 turl->url() ? turl->url()->url() : std::string()); |
682 } else { | 683 } else { |
683 // Something really unexpected happened. Either we received an | 684 // Something really unexpected happened. Either we received an |
684 // ACTION_INVALID, or Sync is in a crazy state: | 685 // ACTION_INVALID, or Sync is in a crazy state: |
685 // . Trying to DELETE or UPDATE a non-existent search engine. | 686 // . Trying to DELETE or UPDATE a non-existent search engine. |
686 // . Trying to ADD a search engine that already exists. | 687 // . Trying to ADD a search engine that already exists. |
687 NOTREACHED() << "Unexpected sync change state."; | 688 NOTREACHED() << "Unexpected sync change state."; |
688 SyncError error(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + | 689 error = SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + |
689 SyncChange::ChangeTypeToString(iter->change_type()), | 690 SyncChange::ChangeTypeToString(iter->change_type()), |
690 syncable::SEARCH_ENGINES); | 691 syncable::SEARCH_ENGINES); |
691 return error; | |
SteveT
2011/09/01 14:21:54
sky 2011/08/17 23:22:29
Are you sure we want to re
| |
692 } | 692 } |
693 } | 693 } |
694 | 694 |
695 SyncError sync_error = | 695 // If something went wrong, we want to prematurely exit to avoid pushing |
696 sync_processor_->ProcessSyncChanges(from_here, new_changes); | 696 // inconsistent data to Sync. We return the last error we received. |
697 if (error.IsSet()) | |
698 return error; | |
697 | 699 |
698 return sync_error; | 700 error = sync_processor_->ProcessSyncChanges(from_here, new_changes); |
701 | |
702 return error; | |
699 } | 703 } |
700 | 704 |
701 SyncError TemplateURLService::MergeDataAndStartSyncing( | 705 SyncError TemplateURLService::MergeDataAndStartSyncing( |
SteveT
2011/09/01 14:21:54
sky 2011/08/17 23:22:29
Is it guaranteed these met
| |
702 syncable::ModelType type, | 706 syncable::ModelType type, |
703 const SyncDataList& initial_sync_data, | 707 const SyncDataList& initial_sync_data, |
704 SyncChangeProcessor* sync_processor) { | 708 SyncChangeProcessor* sync_processor) { |
709 DCHECK(loaded()); | |
705 DCHECK_EQ(type, syncable::SEARCH_ENGINES); | 710 DCHECK_EQ(type, syncable::SEARCH_ENGINES); |
706 DCHECK(!sync_processor_); | 711 DCHECK(!sync_processor_); |
707 sync_processor_ = sync_processor; | 712 sync_processor_ = sync_processor; |
708 | 713 |
709 // We do a lot of calls to Add/Remove/ResetTemplateURL here, so ensure we | 714 // We do a lot of calls to Add/Remove/ResetTemplateURL here, so ensure we |
710 // don't step on our own toes. | 715 // don't step on our own toes. |
711 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); | 716 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); |
712 | 717 |
713 SyncChangeList new_changes; | 718 SyncChangeList new_changes; |
714 | 719 |
715 // Build maps of our sync GUIDs to SyncData. | 720 // Build maps of our sync GUIDs to SyncData. |
716 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( | 721 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( |
717 GetAllSyncData(syncable::SEARCH_ENGINES)); | 722 GetAllSyncData(syncable::SEARCH_ENGINES)); |
718 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); | 723 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); |
719 | 724 |
720 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); | 725 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); |
721 iter != sync_data_map.end(); ++iter) { | 726 iter != sync_data_map.end(); ++iter) { |
722 scoped_ptr<TemplateURL> sync_turl( | 727 scoped_ptr<TemplateURL> sync_turl( |
723 CreateTemplateURLFromSyncData(iter->second)); | 728 CreateTemplateURLFromSyncData(iter->second)); |
724 DCHECK(sync_turl.get()); | 729 DCHECK(sync_turl.get()); |
725 const TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); | 730 const TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); |
726 | 731 |
727 if (local_turl) { | 732 if (local_turl) { |
728 // This local search engine is already synced. If the timestamp differs | 733 // This local search engine is already synced. If the timestamp differs |
729 // from Sync, we need to update locally or to the cloud. Note that if the | 734 // from Sync, we need to update locally or to the cloud. Note that if the |
730 // timestamps are equal, we touch neither. | 735 // timestamps are equal, we touch neither. |
731 if (sync_turl->last_modified() > local_turl->last_modified()) { | 736 if (sync_turl->last_modified() > local_turl->last_modified()) { |
732 // TODO(stevet): For now we just reset the local TemplateURL with the | 737 // We've received an update from Sync. We should replace all existing |
733 // more important Sync data fields. We may want to transfer over | 738 // values with the ones from sync except the local TemplateURLID. Note |
734 // additional fields. | 739 // that this means that the TemplateURL may have to be reparsed. This |
735 ResetTemplateURL( | 740 // also makes the local data's last_modified timestamp equal to Sync's, |
736 local_turl, | 741 // avoiding an Update on the next MergeData call. |
737 sync_turl->short_name(), | 742 sync_turl->set_id(local_turl->id()); |
738 sync_turl->keyword(), | 743 UpdateNoNotify(local_turl, *sync_turl); |
739 sync_turl->url() ? sync_turl->url()->url() : std::string()); | 744 NotifyObservers(); |
SteveT
2011/09/01 14:21:54
sky 2011/08/17 23:22:29
I believe you'll also want
| |
740 } else if (sync_turl->last_modified() < local_turl->last_modified()) { | 745 } else if (sync_turl->last_modified() < local_turl->last_modified()) { |
746 // Otherwise, we know we have newer data, so update Sync with our | |
747 // data fields. | |
741 new_changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, | 748 new_changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, |
742 local_data_map[local_turl->sync_guid()])); | 749 local_data_map[local_turl->sync_guid()])); |
743 } | 750 } |
744 local_data_map.erase(iter->first); | 751 local_data_map.erase(iter->first); |
745 } else { | 752 } else { |
746 // The search engine from the cloud has not been synced locally, but there | 753 // The search engine from the cloud has not been synced locally, but there |
747 // might be a local search engine that is a duplicate that needs to be | 754 // might be a local search engine that is a duplicate that needs to be |
748 // merged. | 755 // merged. |
749 const TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); | 756 const TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); |
750 if (dupe_turl) { | 757 if (dupe_turl) { |
751 // Merge duplicates and remove the processed local TURL from the map. | 758 // Merge duplicates and remove the processed local TURL from the map. |
752 TemplateURL* modifiable_dupe_turl = | 759 TemplateURL* modifiable_dupe_turl = |
753 const_cast<TemplateURL*>(dupe_turl); | 760 const_cast<TemplateURL*>(dupe_turl); |
754 std::string old_guid = dupe_turl->sync_guid(); | 761 std::string old_guid = dupe_turl->sync_guid(); |
755 MergeSyncAndLocalURLDuplicates(sync_turl.release(), | 762 MergeSyncAndLocalURLDuplicates(sync_turl.release(), |
756 modifiable_dupe_turl, | 763 modifiable_dupe_turl, |
757 new_changes); | 764 &new_changes); |
758 local_data_map.erase(old_guid); | 765 local_data_map.erase(old_guid); |
759 } else { | 766 } else { |
760 // Keyword conflict is possible in this case. Resolve it first before | 767 // Keyword conflict is possible in this case. Resolve it first before |
761 // adding the new TemplateURL. Note that we don't remove the local TURL | 768 // adding the new TemplateURL. Note that we don't remove the local TURL |
762 // from local_data_map in this case as it may still need to be pushed to | 769 // from local_data_map in this case as it may still need to be pushed to |
763 // the cloud. | 770 // the cloud. |
764 ResolveSyncKeywordConflict(sync_turl.get(), new_changes); | 771 ResolveSyncKeywordConflict(sync_turl.get(), &new_changes); |
765 // Force the local ID to 0 so we can add it. | 772 // Force the local ID to 0 so we can add it. |
766 sync_turl->set_id(0); | 773 sync_turl->set_id(0); |
767 Add(sync_turl.release()); | 774 Add(sync_turl.release()); |
768 } | 775 } |
769 } | 776 } |
770 } // for | 777 } // for |
771 | 778 |
772 // The remaining SyncData in local_data_map should be everything that needs to | 779 // The remaining SyncData in local_data_map should be everything that needs to |
773 // be pushed as ADDs to sync. | 780 // be pushed as ADDs to sync. |
774 for (SyncDataMap::const_iterator iter = local_data_map.begin(); | 781 for (SyncDataMap::const_iterator iter = local_data_map.begin(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 turl.suggestions_url()->url() : std::string()); | 874 turl.suggestions_url()->url() : std::string()); |
868 se_specifics->set_prepopulate_id(turl.prepopulate_id()); | 875 se_specifics->set_prepopulate_id(turl.prepopulate_id()); |
869 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword()); | 876 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword()); |
870 se_specifics->set_created_by_policy(turl.created_by_policy()); | 877 se_specifics->set_created_by_policy(turl.created_by_policy()); |
871 se_specifics->set_instant_url(turl.instant_url() ? | 878 se_specifics->set_instant_url(turl.instant_url() ? |
872 turl.instant_url()->url() : std::string()); | 879 turl.instant_url()->url() : std::string()); |
873 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); | 880 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); |
874 se_specifics->set_sync_guid(turl.sync_guid()); | 881 se_specifics->set_sync_guid(turl.sync_guid()); |
875 return SyncData::CreateLocalData(se_specifics->sync_guid(), | 882 return SyncData::CreateLocalData(se_specifics->sync_guid(), |
876 se_specifics->keyword(), | 883 se_specifics->keyword(), |
877 specifics); | 884 specifics); |
SteveT
2011/09/01 14:21:54
sky 2011/08/17 23:22:29
Is there any protection to
| |
878 } | 885 } |
879 | 886 |
880 // static | 887 // static |
881 TemplateURL* TemplateURLService::CreateTemplateURLFromSyncData( | 888 TemplateURL* TemplateURLService::CreateTemplateURLFromSyncData( |
882 const SyncData& sync_data) { | 889 const SyncData& sync_data) { |
883 sync_pb::SearchEngineSpecifics specifics = | 890 sync_pb::SearchEngineSpecifics specifics = |
884 sync_data.GetSpecifics().GetExtension(sync_pb::search_engine); | 891 sync_data.GetSpecifics().GetExtension(sync_pb::search_engine); |
885 TemplateURL* turl = new TemplateURL(); | 892 TemplateURL* turl = new TemplateURL(); |
886 turl->set_short_name(UTF8ToUTF16(specifics.short_name())); | 893 turl->set_short_name(UTF8ToUTF16(specifics.short_name())); |
887 turl->set_keyword(UTF8ToUTF16(specifics.keyword())); | 894 turl->set_keyword(UTF8ToUTF16(specifics.keyword())); |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1661 keyword_candidate = turl.keyword(); | 1668 keyword_candidate = turl.keyword(); |
1662 do { | 1669 do { |
1663 keyword_candidate.append(UTF8ToUTF16("_")); | 1670 keyword_candidate.append(UTF8ToUTF16("_")); |
1664 } while (GetTemplateURLForKeyword(keyword_candidate)); | 1671 } while (GetTemplateURLForKeyword(keyword_candidate)); |
1665 | 1672 |
1666 return keyword_candidate; | 1673 return keyword_candidate; |
1667 } | 1674 } |
1668 | 1675 |
1669 bool TemplateURLService::ResolveSyncKeywordConflict( | 1676 bool TemplateURLService::ResolveSyncKeywordConflict( |
1670 TemplateURL* sync_turl, | 1677 TemplateURL* sync_turl, |
1671 SyncChangeList& change_list) { | 1678 SyncChangeList* change_list) { |
1672 DCHECK(sync_turl); | 1679 DCHECK(sync_turl); |
1680 DCHECK(change_list); | |
1673 | 1681 |
1674 const TemplateURL* existing_turl = | 1682 const TemplateURL* existing_turl = |
1675 GetTemplateURLForKeyword(sync_turl->keyword()); | 1683 GetTemplateURLForKeyword(sync_turl->keyword()); |
1676 if (!existing_turl) | 1684 if (!existing_turl) |
1677 return false; | 1685 return false; |
1678 | 1686 |
1679 string16 new_keyword; | |
SteveT
2011/09/01 14:21:54
sky 2011/08/17 23:22:29
nit: pull into if as you d
| |
1680 if (existing_turl->last_modified() > sync_turl->last_modified()) { | 1687 if (existing_turl->last_modified() > sync_turl->last_modified()) { |
1681 new_keyword = UniquifyKeyword(*sync_turl); | 1688 string16 new_keyword = UniquifyKeyword(*sync_turl); |
1682 DCHECK(!GetTemplateURLForKeyword(new_keyword)); | 1689 DCHECK(!GetTemplateURLForKeyword(new_keyword)); |
1683 sync_turl->set_keyword(new_keyword); | 1690 sync_turl->set_keyword(new_keyword); |
1684 // If we update the cloud TURL, we need to push an update back to sync | 1691 // If we update the cloud TURL, we need to push an update back to sync |
1685 // informing it that something has changed. | 1692 // informing it that something has changed. |
1686 SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl); | 1693 SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl); |
1687 change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 1694 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
1688 } else { | 1695 } else { |
1689 new_keyword = UniquifyKeyword(*existing_turl); | 1696 string16 new_keyword = UniquifyKeyword(*existing_turl); |
1690 ResetTemplateURL(existing_turl, existing_turl->short_name(), new_keyword, | 1697 ResetTemplateURL(existing_turl, existing_turl->short_name(), new_keyword, |
1691 existing_turl->url() ? existing_turl->url()->url() : std::string()); | 1698 existing_turl->url() ? existing_turl->url()->url() : std::string()); |
1692 } | 1699 } |
1693 return true; | 1700 return true; |
1694 } | 1701 } |
1695 | 1702 |
1696 const TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( | 1703 const TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( |
1697 const TemplateURL& sync_turl) { | 1704 const TemplateURL& sync_turl) { |
1698 const TemplateURL* existing_turl = | 1705 const TemplateURL* existing_turl = |
1699 GetTemplateURLForKeyword(sync_turl.keyword()); | 1706 GetTemplateURLForKeyword(sync_turl.keyword()); |
1700 if (!existing_turl) | 1707 if (!existing_turl) |
1701 return NULL; | 1708 return NULL; |
1702 | 1709 |
1703 if (existing_turl->url() && sync_turl.url() && | 1710 if (existing_turl->url() && sync_turl.url() && |
1704 existing_turl->url()->url() == sync_turl.url()->url()) { | 1711 existing_turl->url()->url() == sync_turl.url()->url()) { |
1705 return existing_turl; | 1712 return existing_turl; |
1706 } | 1713 } |
1707 return NULL; | 1714 return NULL; |
1708 } | 1715 } |
1709 | 1716 |
1710 void TemplateURLService::MergeSyncAndLocalURLDuplicates( | 1717 void TemplateURLService::MergeSyncAndLocalURLDuplicates( |
1711 TemplateURL* sync_turl, | 1718 TemplateURL* sync_turl, |
1712 TemplateURL* local_turl, | 1719 TemplateURL* local_turl, |
1713 SyncChangeList& change_list) { | 1720 SyncChangeList* change_list) { |
1714 DCHECK(sync_turl); | 1721 DCHECK(sync_turl); |
1715 DCHECK(local_turl); | 1722 DCHECK(local_turl); |
1723 DCHECK(change_list); | |
1716 | 1724 |
1717 scoped_ptr<TemplateURL> scoped_sync_turl(sync_turl); | 1725 scoped_ptr<TemplateURL> scoped_sync_turl(sync_turl); |
1718 | 1726 |
1719 if (scoped_sync_turl->last_modified() > local_turl->last_modified()) { | 1727 if (scoped_sync_turl->last_modified() > local_turl->last_modified()) { |
1720 // Fully replace local_url with Sync's copy. Note that because use Add | 1728 // Fully replace local_url with Sync's copy. Note that because use Add |
1721 // rather than ResetTemplateURL, |sync_url| is added with a fresh | 1729 // rather than ResetTemplateURL, |sync_url| is added with a fresh |
1722 // TemplateURLID. We don't need to sync the new ID back to the server since | 1730 // TemplateURLID. We don't need to sync the new ID back to the server since |
1723 // it's only relevant locally. | 1731 // it's only relevant locally. |
1724 Remove(local_turl); | 1732 Remove(local_turl); |
1725 // Force the local ID to 0 so we can add it. | 1733 // Force the local ID to 0 so we can add it. |
1726 scoped_sync_turl->set_id(0); | 1734 scoped_sync_turl->set_id(0); |
1727 Add(scoped_sync_turl.release()); | 1735 Add(scoped_sync_turl.release()); |
1728 } else { | 1736 } else { |
1729 // Change the local TURL's GUID to the server's GUID and push an update to | 1737 // Change the local TURL's GUID to the server's GUID and push an update to |
1730 // Sync. This ensures that the rest of local_url's fields are sync'd up to | 1738 // Sync. This ensures that the rest of local_url's fields are sync'd up to |
1731 // the server, and the next time local_url is synced, it is recognized by | 1739 // the server, and the next time local_url is synced, it is recognized by |
1732 // having the same GUID. | 1740 // having the same GUID. |
1733 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); | 1741 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); |
1734 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); | 1742 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); |
1735 change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 1743 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
1736 } | 1744 } |
1737 } | 1745 } |
OLD | NEW |