OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "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 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/protector/protector_service.h" | 27 #include "chrome/browser/protector/protector_service.h" |
28 #include "chrome/browser/rlz/rlz.h" | 28 #include "chrome/browser/rlz/rlz.h" |
29 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 29 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
30 #include "chrome/browser/search_engines/search_terms_data.h" | 30 #include "chrome/browser/search_engines/search_terms_data.h" |
31 #include "chrome/browser/search_engines/template_url.h" | 31 #include "chrome/browser/search_engines/template_url.h" |
32 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 32 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
33 #include "chrome/browser/search_engines/template_url_service_observer.h" | 33 #include "chrome/browser/search_engines/template_url_service_observer.h" |
34 #include "chrome/browser/search_engines/util.h" | 34 #include "chrome/browser/search_engines/util.h" |
35 #include "chrome/browser/sync/api/sync_change.h" | 35 #include "chrome/browser/sync/api/sync_change.h" |
36 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" |
| 37 #include "chrome/browser/sync/protocol/sync.pb.h" |
37 #include "chrome/common/chrome_notification_types.h" | 38 #include "chrome/common/chrome_notification_types.h" |
38 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/env_vars.h" | 40 #include "chrome/common/env_vars.h" |
40 #include "chrome/common/extensions/extension.h" | 41 #include "chrome/common/extensions/extension.h" |
41 #include "chrome/common/guid.h" | 42 #include "chrome/common/guid.h" |
42 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
43 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
44 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
45 #include "net/base/net_util.h" | 46 #include "net/base/net_util.h" |
46 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 959 SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
959 changes.push_back(SyncChange(type, sync_data)); | 960 changes.push_back(SyncChange(type, sync_data)); |
960 | 961 |
961 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 962 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
962 } | 963 } |
963 | 964 |
964 // static | 965 // static |
965 SyncData TemplateURLService::CreateSyncDataFromTemplateURL( | 966 SyncData TemplateURLService::CreateSyncDataFromTemplateURL( |
966 const TemplateURL& turl) { | 967 const TemplateURL& turl) { |
967 sync_pb::EntitySpecifics specifics; | 968 sync_pb::EntitySpecifics specifics; |
968 sync_pb::SearchEngineSpecifics* se_specifics = specifics.MutableExtension( | 969 sync_pb::SearchEngineSpecifics* se_specifics = |
969 sync_pb::search_engine); | 970 specifics.mutable_search_engine(); |
970 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name())); | 971 se_specifics->set_short_name(UTF16ToUTF8(turl.short_name())); |
971 se_specifics->set_keyword(UTF16ToUTF8(turl.keyword())); | 972 se_specifics->set_keyword(UTF16ToUTF8(turl.keyword())); |
972 se_specifics->set_favicon_url(turl.GetFaviconURL().spec()); | 973 se_specifics->set_favicon_url(turl.GetFaviconURL().spec()); |
973 se_specifics->set_url(turl.url() ? turl.url()->url() : std::string()); | 974 se_specifics->set_url(turl.url() ? turl.url()->url() : std::string()); |
974 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); | 975 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); |
975 se_specifics->set_originating_url(turl.originating_url().spec()); | 976 se_specifics->set_originating_url(turl.originating_url().spec()); |
976 se_specifics->set_date_created(turl.date_created().ToInternalValue()); | 977 se_specifics->set_date_created(turl.date_created().ToInternalValue()); |
977 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); | 978 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); |
978 se_specifics->set_show_in_default_list(turl.show_in_default_list()); | 979 se_specifics->set_show_in_default_list(turl.show_in_default_list()); |
979 se_specifics->set_suggestions_url(turl.suggestions_url() ? | 980 se_specifics->set_suggestions_url(turl.suggestions_url() ? |
(...skipping 16 matching lines...) Expand all Loading... |
996 UpdateTemplateURLWithSyncData(turl, sync_data); | 997 UpdateTemplateURLWithSyncData(turl, sync_data); |
997 return turl; | 998 return turl; |
998 } | 999 } |
999 | 1000 |
1000 // static | 1001 // static |
1001 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( | 1002 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( |
1002 const SyncDataList& sync_data) { | 1003 const SyncDataList& sync_data) { |
1003 SyncDataMap data_map; | 1004 SyncDataMap data_map; |
1004 SyncDataList::const_iterator iter; | 1005 SyncDataList::const_iterator iter; |
1005 for (iter = sync_data.begin(); iter != sync_data.end(); ++iter) { | 1006 for (iter = sync_data.begin(); iter != sync_data.end(); ++iter) { |
1006 data_map[iter->GetSpecifics().GetExtension( | 1007 data_map[iter->GetSpecifics().search_engine().sync_guid()] = *iter; |
1007 sync_pb::search_engine).sync_guid()] = *iter; | |
1008 } | 1008 } |
1009 return data_map; | 1009 return data_map; |
1010 } | 1010 } |
1011 | 1011 |
1012 void TemplateURLService::SetKeywordSearchTermsForURL(const TemplateURL* t_url, | 1012 void TemplateURLService::SetKeywordSearchTermsForURL(const TemplateURL* t_url, |
1013 const GURL& url, | 1013 const GURL& url, |
1014 const string16& term) { | 1014 const string16& term) { |
1015 HistoryService* history = profile_ ? | 1015 HistoryService* history = profile_ ? |
1016 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; | 1016 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; |
1017 if (!history) | 1017 if (!history) |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 service_->UpdateKeyword(*template_url); | 1882 service_->UpdateKeyword(*template_url); |
1883 } | 1883 } |
1884 } | 1884 } |
1885 } | 1885 } |
1886 | 1886 |
1887 // static | 1887 // static |
1888 void TemplateURLService::UpdateTemplateURLWithSyncData( | 1888 void TemplateURLService::UpdateTemplateURLWithSyncData( |
1889 TemplateURL* dst, | 1889 TemplateURL* dst, |
1890 const SyncData& sync_data) { | 1890 const SyncData& sync_data) { |
1891 sync_pb::SearchEngineSpecifics specifics = | 1891 sync_pb::SearchEngineSpecifics specifics = |
1892 sync_data.GetSpecifics().GetExtension(sync_pb::search_engine); | 1892 sync_data.GetSpecifics().search_engine(); |
1893 dst->set_short_name(UTF8ToUTF16(specifics.short_name())); | 1893 dst->set_short_name(UTF8ToUTF16(specifics.short_name())); |
1894 dst->set_keyword(UTF8ToUTF16(specifics.keyword())); | 1894 dst->set_keyword(UTF8ToUTF16(specifics.keyword())); |
1895 dst->SetFaviconURL(GURL(specifics.favicon_url())); | 1895 dst->SetFaviconURL(GURL(specifics.favicon_url())); |
1896 dst->SetURL(specifics.url(), 0, 0); | 1896 dst->SetURL(specifics.url(), 0, 0); |
1897 dst->set_safe_for_autoreplace(specifics.safe_for_autoreplace()); | 1897 dst->set_safe_for_autoreplace(specifics.safe_for_autoreplace()); |
1898 dst->set_originating_url(GURL(specifics.originating_url())); | 1898 dst->set_originating_url(GURL(specifics.originating_url())); |
1899 dst->set_date_created( | 1899 dst->set_date_created( |
1900 base::Time::FromInternalValue(specifics.date_created())); | 1900 base::Time::FromInternalValue(specifics.date_created())); |
1901 std::vector<std::string> input_encodings; | 1901 std::vector<std::string> input_encodings; |
1902 base::SplitString(specifics.input_encodings(), ';', &input_encodings); | 1902 base::SplitString(specifics.input_encodings(), ';', &input_encodings); |
1903 dst->set_input_encodings(input_encodings); | 1903 dst->set_input_encodings(input_encodings); |
1904 dst->set_show_in_default_list(specifics.show_in_default_list()); | 1904 dst->set_show_in_default_list(specifics.show_in_default_list()); |
1905 dst->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); | 1905 dst->SetSuggestionsURL(specifics.suggestions_url(), 0, 0); |
1906 dst->SetPrepopulateId(specifics.prepopulate_id()); | 1906 dst->SetPrepopulateId(specifics.prepopulate_id()); |
1907 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); | 1907 dst->set_autogenerate_keyword(specifics.autogenerate_keyword()); |
1908 dst->SetInstantURL(specifics.instant_url(), 0, 0); | 1908 dst->SetInstantURL(specifics.instant_url(), 0, 0); |
1909 dst->set_last_modified( | 1909 dst->set_last_modified( |
1910 base::Time::FromInternalValue(specifics.last_modified())); | 1910 base::Time::FromInternalValue(specifics.last_modified())); |
1911 dst->set_sync_guid(specifics.sync_guid()); | 1911 dst->set_sync_guid(specifics.sync_guid()); |
1912 } | 1912 } |
OLD | NEW |