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 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 se_specifics->set_url(turl.url() ? turl.url()->url() : std::string()); | 860 se_specifics->set_url(turl.url() ? turl.url()->url() : std::string()); |
861 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); | 861 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); |
862 se_specifics->set_originating_url(turl.originating_url().spec()); | 862 se_specifics->set_originating_url(turl.originating_url().spec()); |
863 se_specifics->set_date_created(turl.date_created().ToInternalValue()); | 863 se_specifics->set_date_created(turl.date_created().ToInternalValue()); |
864 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); | 864 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); |
865 se_specifics->set_show_in_default_list(turl.show_in_default_list()); | 865 se_specifics->set_show_in_default_list(turl.show_in_default_list()); |
866 se_specifics->set_suggestions_url(turl.suggestions_url() ? | 866 se_specifics->set_suggestions_url(turl.suggestions_url() ? |
867 turl.suggestions_url()->url() : std::string()); | 867 turl.suggestions_url()->url() : std::string()); |
868 se_specifics->set_prepopulate_id(turl.prepopulate_id()); | 868 se_specifics->set_prepopulate_id(turl.prepopulate_id()); |
869 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword()); | 869 se_specifics->set_autogenerate_keyword(turl.autogenerate_keyword()); |
870 se_specifics->set_logo_id(turl.logo_id()); | |
871 se_specifics->set_created_by_policy(turl.created_by_policy()); | 870 se_specifics->set_created_by_policy(turl.created_by_policy()); |
872 se_specifics->set_instant_url(turl.instant_url() ? | 871 se_specifics->set_instant_url(turl.instant_url() ? |
873 turl.instant_url()->url() : std::string()); | 872 turl.instant_url()->url() : std::string()); |
874 se_specifics->set_id(turl.id()); | |
875 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); | 873 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); |
876 se_specifics->set_sync_guid(turl.sync_guid()); | 874 se_specifics->set_sync_guid(turl.sync_guid()); |
877 return SyncData::CreateLocalData(se_specifics->sync_guid(), | 875 return SyncData::CreateLocalData(se_specifics->sync_guid(), |
878 se_specifics->keyword(), | 876 se_specifics->keyword(), |
879 specifics); | 877 specifics); |
880 } | 878 } |
881 | 879 |
882 // static | 880 // static |
883 TemplateURL* TemplateURLService::CreateTemplateURLFromSyncData( | 881 TemplateURL* TemplateURLService::CreateTemplateURLFromSyncData( |
884 const SyncData& sync_data) { | 882 const SyncData& sync_data) { |
885 sync_pb::SearchEngineSpecifics specifics = | 883 sync_pb::SearchEngineSpecifics specifics = |
886 sync_data.GetSpecifics().GetExtension(sync_pb::search_engine); | 884 sync_data.GetSpecifics().GetExtension(sync_pb::search_engine); |
887 TemplateURL* turl = new TemplateURL(); | 885 TemplateURL* turl = new TemplateURL(); |
888 turl->set_short_name(UTF8ToUTF16(specifics.short_name())); | 886 turl->set_short_name(UTF8ToUTF16(specifics.short_name())); |
889 turl->set_keyword(UTF8ToUTF16(specifics.keyword())); | 887 turl->set_keyword(UTF8ToUTF16(specifics.keyword())); |
890 turl->SetFaviconURL(GURL(specifics.favicon_url())); | 888 turl->SetFaviconURL(GURL(specifics.favicon_url())); |
891 turl->SetURL(specifics.url(), 0, 0); | 889 turl->SetURL(specifics.url(), 0, 0); |
892 turl->set_safe_for_autoreplace(specifics.safe_for_autoreplace()); | 890 turl->set_safe_for_autoreplace(specifics.safe_for_autoreplace()); |
893 turl->set_originating_url(GURL(specifics.originating_url())); | 891 turl->set_originating_url(GURL(specifics.originating_url())); |
894 turl->set_date_created( | 892 turl->set_date_created( |
895 base::Time::FromInternalValue(specifics.date_created())); | 893 base::Time::FromInternalValue(specifics.date_created())); |
896 std::vector<std::string> input_encodings; | 894 std::vector<std::string> input_encodings; |
897 base::SplitString(specifics.input_encodings(), ';', &input_encodings); | 895 base::SplitString(specifics.input_encodings(), ';', &input_encodings); |
898 turl->set_input_encodings(input_encodings); | 896 turl->set_input_encodings(input_encodings); |
899 turl->set_show_in_default_list(specifics.show_in_default_list()); | 897 turl->set_show_in_default_list(specifics.show_in_default_list()); |
900 turl->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); | 898 turl->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); |
901 turl->SetPrepopulateId(specifics.prepopulate_id()); | 899 turl->SetPrepopulateId(specifics.prepopulate_id()); |
902 turl->set_autogenerate_keyword(specifics.autogenerate_keyword()); | 900 turl->set_autogenerate_keyword(specifics.autogenerate_keyword()); |
903 turl->set_logo_id(specifics.logo_id()); | |
904 turl->set_created_by_policy(specifics.created_by_policy()); | 901 turl->set_created_by_policy(specifics.created_by_policy()); |
905 turl->SetInstantURL(specifics.instant_url(), 0, 0); | 902 turl->SetInstantURL(specifics.instant_url(), 0, 0); |
906 turl->set_id(specifics.id()); | |
907 turl->set_last_modified( | 903 turl->set_last_modified( |
908 base::Time::FromInternalValue(specifics.last_modified())); | 904 base::Time::FromInternalValue(specifics.last_modified())); |
909 turl->set_sync_guid(specifics.sync_guid()); | 905 turl->set_sync_guid(specifics.sync_guid()); |
910 return turl; | 906 return turl; |
911 } | 907 } |
912 | 908 |
913 // static | 909 // static |
914 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( | 910 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( |
915 const SyncDataList& sync_data) { | 911 const SyncDataList& sync_data) { |
916 SyncDataMap data_map; | 912 SyncDataMap data_map; |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 rlz_lib::SET_TO_GOOGLE); | 1511 rlz_lib::SET_TO_GOOGLE); |
1516 #endif | 1512 #endif |
1517 } | 1513 } |
1518 } | 1514 } |
1519 | 1515 |
1520 if (!is_default_search_managed_) | 1516 if (!is_default_search_managed_) |
1521 SaveDefaultSearchProviderToPrefs(url); | 1517 SaveDefaultSearchProviderToPrefs(url); |
1522 | 1518 |
1523 if (service_.get()) | 1519 if (service_.get()) |
1524 service_->SetDefaultSearchProvider(url); | 1520 service_->SetDefaultSearchProvider(url); |
| 1521 |
| 1522 // Inform sync the change to the show_in_default_list flag. |
| 1523 if (url) |
| 1524 ProcessTemplateURLChange(url, SyncChange::ACTION_UPDATE); |
1525 } | 1525 } |
1526 | 1526 |
1527 void TemplateURLService::AddNoNotify(TemplateURL* template_url) { | 1527 void TemplateURLService::AddNoNotify(TemplateURL* template_url) { |
1528 DCHECK(template_url); | 1528 DCHECK(template_url); |
1529 DCHECK(template_url->id() == 0); | 1529 DCHECK(template_url->id() == 0); |
1530 DCHECK(find(template_urls_.begin(), template_urls_.end(), template_url) == | 1530 DCHECK(find(template_urls_.begin(), template_urls_.end(), template_url) == |
1531 template_urls_.end()); | 1531 template_urls_.end()); |
1532 template_url->set_id(++next_id_); | 1532 template_url->set_id(++next_id_); |
1533 template_urls_.push_back(template_url); | 1533 template_urls_.push_back(template_url); |
1534 AddToMaps(template_url); | 1534 AddToMaps(template_url); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 } else { | 1728 } else { |
1729 // Change the local TURL's GUID to the server's GUID and push an update to | 1729 // 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 | 1730 // 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 | 1731 // the server, and the next time local_url is synced, it is recognized by |
1732 // having the same GUID. | 1732 // having the same GUID. |
1733 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); | 1733 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); |
1734 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); | 1734 SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); |
1735 change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 1735 change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
1736 } | 1736 } |
1737 } | 1737 } |
OLD | NEW |