Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/scoped_vector.h" | |
| 18 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 18 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/time/default_clock.h" | 22 #include "base/time/default_clock.h" |
| 24 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 25 #include "components/omnibox/browser/omnibox_field_trial.h" | 24 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 26 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 27 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 | 657 |
| 659 if ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || | 658 if ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || |
| 660 (default_search_provider_source_ == | 659 (default_search_provider_source_ == |
| 661 DefaultSearchManager::FROM_FALLBACK)) { | 660 DefaultSearchManager::FROM_FALLBACK)) { |
| 662 // Clear |default_search_provider_| in case we want to remove the engine it | 661 // Clear |default_search_provider_| in case we want to remove the engine it |
| 663 // points to. This will get reset at the end of the function anyway. | 662 // points to. This will get reset at the end of the function anyway. |
| 664 default_search_provider_ = nullptr; | 663 default_search_provider_ = nullptr; |
| 665 } | 664 } |
| 666 | 665 |
| 667 size_t default_search_provider_index = 0; | 666 size_t default_search_provider_index = 0; |
| 668 ScopedVector<TemplateURLData> prepopulated_urls = | 667 std::vector<std::unique_ptr<TemplateURLData>> prepopulated_urls = |
| 669 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 668 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 670 prefs_, &default_search_provider_index); | 669 prefs_, &default_search_provider_index); |
| 671 DCHECK(!prepopulated_urls.empty()); | 670 DCHECK(!prepopulated_urls.empty()); |
| 672 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( | 671 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
| 673 &prepopulated_urls, template_urls_, default_search_provider_)); | 672 &prepopulated_urls, template_urls_, default_search_provider_)); |
| 674 | 673 |
| 675 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); | 674 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 676 | 675 |
| 677 // Remove items. | 676 // Remove items. |
| 678 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); | 677 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 | 1729 |
| 1731 // static | 1730 // static |
| 1732 void TemplateURLService::UpdateTemplateURLIfPrepopulated( | 1731 void TemplateURLService::UpdateTemplateURLIfPrepopulated( |
| 1733 TemplateURL* template_url, | 1732 TemplateURL* template_url, |
| 1734 PrefService* prefs) { | 1733 PrefService* prefs) { |
| 1735 int prepopulate_id = template_url->prepopulate_id(); | 1734 int prepopulate_id = template_url->prepopulate_id(); |
| 1736 if (template_url->prepopulate_id() == 0) | 1735 if (template_url->prepopulate_id() == 0) |
| 1737 return; | 1736 return; |
| 1738 | 1737 |
| 1739 size_t default_search_index; | 1738 size_t default_search_index; |
| 1740 ScopedVector<TemplateURLData> prepopulated_urls = | 1739 std::vector<std::unique_ptr<TemplateURLData>> prepopulated_urls = |
| 1741 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 1740 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, |
| 1742 prefs, &default_search_index); | 1741 &default_search_index); |
| 1743 | 1742 |
| 1744 for (size_t i = 0; i < prepopulated_urls.size(); ++i) { | 1743 for (auto& url : prepopulated_urls) { |
|
Peter Kasting
2016/09/01 23:17:32
Nit: const auto&?
Avi (use Gerrit)
2016/09/01 23:26:43
Done.
| |
| 1745 if (prepopulated_urls[i]->prepopulate_id == prepopulate_id) { | 1744 if (url->prepopulate_id == prepopulate_id) { |
| 1746 MergeIntoPrepopulatedEngineData(template_url, prepopulated_urls[i]); | 1745 MergeIntoPrepopulatedEngineData(template_url, url.get()); |
| 1747 template_url->CopyFrom(TemplateURL(*prepopulated_urls[i])); | 1746 template_url->CopyFrom(TemplateURL(*url)); |
| 1748 } | 1747 } |
| 1749 } | 1748 } |
| 1750 } | 1749 } |
| 1751 | 1750 |
| 1752 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) { | 1751 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) { |
| 1753 if (prefs_ && | 1752 if (prefs_ && |
| 1754 (synced_turl->sync_guid() == | 1753 (synced_turl->sync_guid() == |
| 1755 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID))) { | 1754 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID))) { |
| 1756 default_search_manager_.SetUserSelectedDefaultSearchEngine( | 1755 default_search_manager_.SetUserSelectedDefaultSearchEngine( |
| 1757 synced_turl->data()); | 1756 synced_turl->data()); |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2466 | 2465 |
| 2467 if (most_recently_intalled_default) { | 2466 if (most_recently_intalled_default) { |
| 2468 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2467 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2469 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2468 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2470 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2469 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2471 most_recently_intalled_default->data()); | 2470 most_recently_intalled_default->data()); |
| 2472 } else { | 2471 } else { |
| 2473 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2472 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2474 } | 2473 } |
| 2475 } | 2474 } |
| OLD | NEW |