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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_split.h" | 16 #include "base/string_split.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
22 #include "chrome/browser/google/google_url_tracker.h" | 22 #include "chrome/browser/google/google_url_tracker.h" |
23 #include "chrome/browser/history/history.h" | 23 #include "chrome/browser/history/history.h" |
24 #include "chrome/browser/history/history_notifications.h" | 24 #include "chrome/browser/history/history_notifications.h" |
25 #include "chrome/browser/history/history_service_factory.h" | 25 #include "chrome/browser/history/history_service_factory.h" |
26 #include "chrome/browser/net/url_fixer_upper.h" | 26 #include "chrome/browser/net/url_fixer_upper.h" |
27 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/protector/base_setting_change.h" | |
30 #include "chrome/browser/protector/protector_service.h" | |
31 #include "chrome/browser/protector/protector_service_factory.h" | |
32 #include "chrome/browser/protector/protector_utils.h" | |
33 #include "chrome/browser/rlz/rlz.h" | 29 #include "chrome/browser/rlz/rlz.h" |
34 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 30 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
35 #include "chrome/browser/search_engines/search_terms_data.h" | 31 #include "chrome/browser/search_engines/search_terms_data.h" |
36 #include "chrome/browser/search_engines/template_url.h" | 32 #include "chrome/browser/search_engines/template_url.h" |
37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 33 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
38 #include "chrome/browser/search_engines/template_url_service_observer.h" | 34 #include "chrome/browser/search_engines/template_url_service_observer.h" |
39 #include "chrome/browser/search_engines/util.h" | 35 #include "chrome/browser/search_engines/util.h" |
40 #include "chrome/browser/webdata/web_data_service_factory.h" | 36 #include "chrome/browser/webdata/web_data_service_factory.h" |
41 #include "chrome/common/chrome_notification_types.h" | 37 #include "chrome/common/chrome_notification_types.h" |
42 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 &template_urls, &default_search_provider, &new_resource_keyword_version, | 732 &template_urls, &default_search_provider, &new_resource_keyword_version, |
737 &pre_sync_deletes_); | 733 &pre_sync_deletes_); |
738 | 734 |
739 bool database_specified_a_default = (default_search_provider != NULL); | 735 bool database_specified_a_default = (default_search_provider != NULL); |
740 | 736 |
741 // Check if default search provider is now managed. | 737 // Check if default search provider is now managed. |
742 scoped_ptr<TemplateURL> default_from_prefs; | 738 scoped_ptr<TemplateURL> default_from_prefs; |
743 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, | 739 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, |
744 &is_default_search_managed_); | 740 &is_default_search_managed_); |
745 | 741 |
746 // Check if the default search provider has been changed in Web Data by | |
747 // another program. No immediate action is performed because the default | |
748 // search may be changed below by Sync which effectively undoes the hijacking. | |
749 bool is_default_search_hijacked = false; | |
750 TemplateURL* hijacked_default_search_provider = NULL; | |
751 scoped_ptr<TemplateURL> backup_default_search_provider; | |
752 // No check is required if the default search is managed. | |
753 // |DidDefaultSearchProviderChange| must always be called because it will | |
754 // take care of the unowned backup default search provider instance. | |
755 if (DidDefaultSearchProviderChange(*result, profile_, | |
756 &backup_default_search_provider) && | |
757 !is_default_search_managed_) { | |
758 hijacked_default_search_provider = default_search_provider; | |
759 is_default_search_hijacked = true; | |
760 } | |
761 | |
762 // Remove entries that were created because of policy as they may have | 742 // Remove entries that were created because of policy as they may have |
763 // changed since the database was saved. | 743 // changed since the database was saved. |
764 RemoveProvidersCreatedByPolicy(&template_urls, | 744 RemoveProvidersCreatedByPolicy(&template_urls, |
765 &default_search_provider, | 745 &default_search_provider, |
766 default_from_prefs.get()); | 746 default_from_prefs.get()); |
767 | 747 |
768 PatchMissingSyncGUIDs(&template_urls); | 748 PatchMissingSyncGUIDs(&template_urls); |
769 | 749 |
770 if (is_default_search_managed_) { | 750 if (is_default_search_managed_) { |
771 SetTemplateURLs(template_urls); | 751 SetTemplateURLs(template_urls); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 ChangeToLoadedState(); | 813 ChangeToLoadedState(); |
834 | 814 |
835 // Index any visits that occurred before we finished loading. | 815 // Index any visits that occurred before we finished loading. |
836 for (size_t i = 0; i < visits_to_add_.size(); ++i) | 816 for (size_t i = 0; i < visits_to_add_.size(); ++i) |
837 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); | 817 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); |
838 visits_to_add_.clear(); | 818 visits_to_add_.clear(); |
839 | 819 |
840 if (new_resource_keyword_version) | 820 if (new_resource_keyword_version) |
841 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); | 821 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
842 | 822 |
843 bool check_if_default_search_valid = !is_default_search_managed_; | 823 if (!is_default_search_managed_) { |
844 | |
845 // Don't do anything if the default search provider has been changed since the | |
846 // check at the beginning (overridden by Sync). | |
847 if (is_default_search_hijacked && | |
848 default_search_provider_ == hijacked_default_search_provider) { | |
849 // Put the #if defined(ENABLE_PROTECTOR_SERVICE) inside the 'if' block to | |
850 // avoid 'unused-but-set-variable' error. | |
851 #if defined(ENABLE_PROTECTOR_SERVICE) | |
852 // The histograms should be reported even when Protector is disabled. | |
853 scoped_ptr<protector::BaseSettingChange> change( | |
854 protector::CreateDefaultSearchProviderChange( | |
855 hijacked_default_search_provider, | |
856 backup_default_search_provider.release())); | |
857 if (protector::IsEnabled()) { | |
858 protector::ProtectorService* protector_service = | |
859 protector::ProtectorServiceFactory::GetForProfile(profile()); | |
860 DCHECK(protector_service); | |
861 protector_service->ShowChange(change.release()); | |
862 } else { | |
863 // Protector is turned off: set the current default search to itself | |
864 // to update the backup and sign it. Otherwise, change will be reported | |
865 // every time when keywords are loaded until a search provider is added. | |
866 service_->SetDefaultSearchProvider(default_search_provider_); | |
867 } | |
868 // The default search provider sanity check makes no sense in this case | |
869 // because ProtectorService is going to change default search eventually. | |
870 check_if_default_search_valid = false; | |
871 #endif | |
872 } | |
873 | |
874 if (check_if_default_search_valid) { | |
875 bool has_default_search_provider = default_search_provider_ != NULL && | 824 bool has_default_search_provider = default_search_provider_ != NULL && |
876 default_search_provider_->SupportsReplacement(); | 825 default_search_provider_->SupportsReplacement(); |
877 UMA_HISTOGRAM_BOOLEAN("Search.HasDefaultSearchProvider", | 826 UMA_HISTOGRAM_BOOLEAN("Search.HasDefaultSearchProvider", |
878 has_default_search_provider); | 827 has_default_search_provider); |
879 // Ensure that default search provider exists. See http://crbug.com/116952. | 828 // Ensure that default search provider exists. See http://crbug.com/116952. |
880 if (!has_default_search_provider) { | 829 if (!has_default_search_provider) { |
881 bool success = | 830 bool success = |
882 SetDefaultSearchProviderNoNotify(FindNewDefaultSearchProvider()); | 831 SetDefaultSearchProviderNoNotify(FindNewDefaultSearchProvider()); |
883 DCHECK(success); | 832 DCHECK(success); |
884 } | 833 } |
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2563 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2512 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2564 // should be persisted to disk and synced. | 2513 // should be persisted to disk and synced. |
2565 if (template_url->sync_guid().empty() && | 2514 if (template_url->sync_guid().empty() && |
2566 !template_url->IsExtensionKeyword()) { | 2515 !template_url->IsExtensionKeyword()) { |
2567 template_url->data_.sync_guid = base::GenerateGUID(); | 2516 template_url->data_.sync_guid = base::GenerateGUID(); |
2568 if (service_.get()) | 2517 if (service_.get()) |
2569 service_->UpdateKeyword(template_url->data()); | 2518 service_->UpdateKeyword(template_url->data()); |
2570 } | 2519 } |
2571 } | 2520 } |
2572 } | 2521 } |
OLD | NEW |