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/environment.h" | 10 #include "base/environment.h" |
10 #include "base/guid.h" | 11 #include "base/guid.h" |
11 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
15 #include "base/string_split.h" | 16 #include "base/string_split.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 // Index any visits that occurred before we finished loading. | 788 // Index any visits that occurred before we finished loading. |
788 for (size_t i = 0; i < visits_to_add_.size(); ++i) | 789 for (size_t i = 0; i < visits_to_add_.size(); ++i) |
789 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); | 790 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); |
790 visits_to_add_.clear(); | 791 visits_to_add_.clear(); |
791 | 792 |
792 if (new_resource_keyword_version) | 793 if (new_resource_keyword_version) |
793 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); | 794 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
794 | 795 |
795 bool check_if_default_search_valid = !is_default_search_managed_; | 796 bool check_if_default_search_valid = !is_default_search_managed_; |
796 | 797 |
797 #if defined(ENABLE_PROTECTOR_SERVICE) | |
798 // Don't do anything if the default search provider has been changed since the | 798 // Don't do anything if the default search provider has been changed since the |
799 // check at the beginning (overridden by Sync). | 799 // check at the beginning (overridden by Sync). |
800 if (is_default_search_hijacked && | 800 if (is_default_search_hijacked && |
801 default_search_provider_ == hijacked_default_search_provider) { | 801 default_search_provider_ == hijacked_default_search_provider) { |
| 802 // Put the #if defined(ENABLE_PROTECTOR_SERVICE) inside the 'if' block to |
| 803 // avoid 'unused-but-set-variable' error. |
| 804 #if defined(ENABLE_PROTECTOR_SERVICE) |
802 // The histograms should be reported even when Protector is disabled. | 805 // The histograms should be reported even when Protector is disabled. |
803 scoped_ptr<protector::BaseSettingChange> change( | 806 scoped_ptr<protector::BaseSettingChange> change( |
804 protector::CreateDefaultSearchProviderChange( | 807 protector::CreateDefaultSearchProviderChange( |
805 hijacked_default_search_provider, | 808 hijacked_default_search_provider, |
806 backup_default_search_provider.release())); | 809 backup_default_search_provider.release())); |
807 if (protector::IsEnabled()) { | 810 if (protector::IsEnabled()) { |
808 protector::ProtectorService* protector_service = | 811 protector::ProtectorService* protector_service = |
809 protector::ProtectorServiceFactory::GetForProfile(profile()); | 812 protector::ProtectorServiceFactory::GetForProfile(profile()); |
810 DCHECK(protector_service); | 813 DCHECK(protector_service); |
811 protector_service->ShowChange(change.release()); | 814 protector_service->ShowChange(change.release()); |
812 } else { | 815 } else { |
813 // Protector is turned off: set the current default search to itself | 816 // Protector is turned off: set the current default search to itself |
814 // to update the backup and sign it. Otherwise, change will be reported | 817 // to update the backup and sign it. Otherwise, change will be reported |
815 // every time when keywords are loaded until a search provider is added. | 818 // every time when keywords are loaded until a search provider is added. |
816 service_->SetDefaultSearchProvider(default_search_provider_); | 819 service_->SetDefaultSearchProvider(default_search_provider_); |
817 } | 820 } |
818 // The default search provider sanity check makes no sense in this case | 821 // The default search provider sanity check makes no sense in this case |
819 // because ProtectorService is going to change default search eventually. | 822 // because ProtectorService is going to change default search eventually. |
820 check_if_default_search_valid = false; | 823 check_if_default_search_valid = false; |
| 824 #endif |
821 } | 825 } |
822 #endif | |
823 | 826 |
824 if (check_if_default_search_valid) { | 827 if (check_if_default_search_valid) { |
825 bool has_default_search_provider = default_search_provider_ != NULL && | 828 bool has_default_search_provider = default_search_provider_ != NULL && |
826 default_search_provider_->SupportsReplacement(); | 829 default_search_provider_->SupportsReplacement(); |
827 UMA_HISTOGRAM_BOOLEAN("Search.HasDefaultSearchProvider", | 830 UMA_HISTOGRAM_BOOLEAN("Search.HasDefaultSearchProvider", |
828 has_default_search_provider); | 831 has_default_search_provider); |
829 // Ensure that default search provider exists. See http://crbug.com/116952. | 832 // Ensure that default search provider exists. See http://crbug.com/116952. |
830 if (!has_default_search_provider) { | 833 if (!has_default_search_provider) { |
831 bool success = | 834 bool success = |
832 SetDefaultSearchProviderNoNotify(FindNewDefaultSearchProvider()); | 835 SetDefaultSearchProviderNoNotify(FindNewDefaultSearchProvider()); |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2485 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2488 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2486 // should be persisted to disk and synced. | 2489 // should be persisted to disk and synced. |
2487 if (template_url->sync_guid().empty() && | 2490 if (template_url->sync_guid().empty() && |
2488 !template_url->IsExtensionKeyword()) { | 2491 !template_url->IsExtensionKeyword()) { |
2489 template_url->data_.sync_guid = base::GenerateGUID(); | 2492 template_url->data_.sync_guid = base::GenerateGUID(); |
2490 if (service_.get()) | 2493 if (service_.get()) |
2491 service_->UpdateKeyword(template_url->data()); | 2494 service_->UpdateKeyword(template_url->data()); |
2492 } | 2495 } |
2493 } | 2496 } |
2494 } | 2497 } |
OLD | NEW |