| 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/google/google_url_tracker.h" | 20 #include "chrome/browser/google/google_url_tracker.h" |
| 21 #include "chrome/browser/history/history.h" | 21 #include "chrome/browser/history/history.h" |
| 22 #include "chrome/browser/history/history_notifications.h" | 22 #include "chrome/browser/history/history_notifications.h" |
| 23 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
| 24 #include "chrome/browser/net/url_fixer_upper.h" | 24 #include "chrome/browser/net/url_fixer_upper.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/protector/base_setting_change.h" | |
| 28 #include "chrome/browser/protector/protector_service.h" | |
| 29 #include "chrome/browser/protector/protector_service_factory.h" | |
| 30 #include "chrome/browser/protector/protector_utils.h" | |
| 31 #include "chrome/browser/rlz/rlz.h" | 27 #include "chrome/browser/rlz/rlz.h" |
| 32 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 28 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
| 33 #include "chrome/browser/search_engines/search_terms_data.h" | 29 #include "chrome/browser/search_engines/search_terms_data.h" |
| 34 #include "chrome/browser/search_engines/template_url.h" | 30 #include "chrome/browser/search_engines/template_url.h" |
| 35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 31 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 36 #include "chrome/browser/search_engines/template_url_service_observer.h" | 32 #include "chrome/browser/search_engines/template_url_service_observer.h" |
| 37 #include "chrome/browser/search_engines/util.h" | 33 #include "chrome/browser/search_engines/util.h" |
| 38 #include "chrome/browser/webdata/web_data_service_factory.h" | 34 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 39 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 40 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 &template_urls, &default_search_provider, &new_resource_keyword_version, | 717 &template_urls, &default_search_provider, &new_resource_keyword_version, |
| 722 &pre_sync_deletes_); | 718 &pre_sync_deletes_); |
| 723 | 719 |
| 724 bool database_specified_a_default = (default_search_provider != NULL); | 720 bool database_specified_a_default = (default_search_provider != NULL); |
| 725 | 721 |
| 726 // Check if default search provider is now managed. | 722 // Check if default search provider is now managed. |
| 727 scoped_ptr<TemplateURL> default_from_prefs; | 723 scoped_ptr<TemplateURL> default_from_prefs; |
| 728 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, | 724 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, |
| 729 &is_default_search_managed_); | 725 &is_default_search_managed_); |
| 730 | 726 |
| 731 // Check if the default search provider has been changed in Web Data by | |
| 732 // another program. No immediate action is performed because the default | |
| 733 // search may be changed below by Sync which effectively undoes the hijacking. | |
| 734 bool is_default_search_hijacked = false; | |
| 735 TemplateURL* hijacked_default_search_provider = NULL; | |
| 736 scoped_ptr<TemplateURL> backup_default_search_provider; | |
| 737 // No check is required if the default search is managed. | |
| 738 // |DidDefaultSearchProviderChange| must always be called because it will | |
| 739 // take care of the unowned backup default search provider instance. | |
| 740 if (DidDefaultSearchProviderChange(*result, profile_, | |
| 741 &backup_default_search_provider) && | |
| 742 !is_default_search_managed_) { | |
| 743 hijacked_default_search_provider = default_search_provider; | |
| 744 is_default_search_hijacked = true; | |
| 745 } | |
| 746 | |
| 747 // Remove entries that were created because of policy as they may have | 727 // Remove entries that were created because of policy as they may have |
| 748 // changed since the database was saved. | 728 // changed since the database was saved. |
| 749 RemoveProvidersCreatedByPolicy(&template_urls, | 729 RemoveProvidersCreatedByPolicy(&template_urls, |
| 750 &default_search_provider, | 730 &default_search_provider, |
| 751 default_from_prefs.get()); | 731 default_from_prefs.get()); |
| 752 | 732 |
| 753 PatchMissingSyncGUIDs(&template_urls); | 733 PatchMissingSyncGUIDs(&template_urls); |
| 754 | 734 |
| 755 if (is_default_search_managed_) { | 735 if (is_default_search_managed_) { |
| 756 SetTemplateURLs(template_urls); | 736 SetTemplateURLs(template_urls); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 ChangeToLoadedState(); | 798 ChangeToLoadedState(); |
| 819 | 799 |
| 820 // Index any visits that occurred before we finished loading. | 800 // Index any visits that occurred before we finished loading. |
| 821 for (size_t i = 0; i < visits_to_add_.size(); ++i) | 801 for (size_t i = 0; i < visits_to_add_.size(); ++i) |
| 822 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); | 802 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); |
| 823 visits_to_add_.clear(); | 803 visits_to_add_.clear(); |
| 824 | 804 |
| 825 if (new_resource_keyword_version) | 805 if (new_resource_keyword_version) |
| 826 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); | 806 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
| 827 | 807 |
| 828 bool check_if_default_search_valid = !is_default_search_managed_; | 808 if (!is_default_search_managed_) { |
| 829 | |
| 830 // Don't do anything if the default search provider has been changed since the | |
| 831 // check at the beginning (overridden by Sync). | |
| 832 if (is_default_search_hijacked && | |
| 833 default_search_provider_ == hijacked_default_search_provider) { | |
| 834 // Put the #if defined(ENABLE_PROTECTOR_SERVICE) inside the 'if' block to | |
| 835 // avoid 'unused-but-set-variable' error. | |
| 836 #if defined(ENABLE_PROTECTOR_SERVICE) | |
| 837 // The histograms should be reported even when Protector is disabled. | |
| 838 scoped_ptr<protector::BaseSettingChange> change( | |
| 839 protector::CreateDefaultSearchProviderChange( | |
| 840 hijacked_default_search_provider, | |
| 841 backup_default_search_provider.release())); | |
| 842 if (protector::IsEnabled()) { | |
| 843 protector::ProtectorService* protector_service = | |
| 844 protector::ProtectorServiceFactory::GetForProfile(profile()); | |
| 845 DCHECK(protector_service); | |
| 846 protector_service->ShowChange(change.release()); | |
| 847 } else { | |
| 848 // Protector is turned off: set the current default search to itself | |
| 849 // to update the backup and sign it. Otherwise, change will be reported | |
| 850 // every time when keywords are loaded until a search provider is added. | |
| 851 service_->SetDefaultSearchProvider(default_search_provider_); | |
| 852 } | |
| 853 // The default search provider sanity check makes no sense in this case | |
| 854 // because ProtectorService is going to change default search eventually. | |
| 855 check_if_default_search_valid = false; | |
| 856 #endif | |
| 857 } | |
| 858 | |
| 859 if (check_if_default_search_valid) { | |
| 860 bool has_default_search_provider = default_search_provider_ != NULL && | 809 bool has_default_search_provider = default_search_provider_ != NULL && |
| 861 default_search_provider_->SupportsReplacement(); | 810 default_search_provider_->SupportsReplacement(); |
| 862 UMA_HISTOGRAM_BOOLEAN("Search.HasDefaultSearchProvider", | 811 UMA_HISTOGRAM_BOOLEAN("Search.HasDefaultSearchProvider", |
| 863 has_default_search_provider); | 812 has_default_search_provider); |
| 864 // Ensure that default search provider exists. See http://crbug.com/116952. | 813 // Ensure that default search provider exists. See http://crbug.com/116952. |
| 865 if (!has_default_search_provider) { | 814 if (!has_default_search_provider) { |
| 866 bool success = | 815 bool success = |
| 867 SetDefaultSearchProviderNoNotify(FindNewDefaultSearchProvider()); | 816 SetDefaultSearchProviderNoNotify(FindNewDefaultSearchProvider()); |
| 868 DCHECK(success); | 817 DCHECK(success); |
| 869 } | 818 } |
| (...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2487 // TODO(mpcomplete): If we allow editing extension keywords, then those |
| 2539 // should be persisted to disk and synced. | 2488 // should be persisted to disk and synced. |
| 2540 if (template_url->sync_guid().empty() && | 2489 if (template_url->sync_guid().empty() && |
| 2541 !template_url->IsExtensionKeyword()) { | 2490 !template_url->IsExtensionKeyword()) { |
| 2542 template_url->data_.sync_guid = base::GenerateGUID(); | 2491 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2543 if (service_.get()) | 2492 if (service_.get()) |
| 2544 service_->UpdateKeyword(template_url->data()); | 2493 service_->UpdateKeyword(template_url->data()); |
| 2545 } | 2494 } |
| 2546 } | 2495 } |
| 2547 } | 2496 } |
| OLD | NEW |