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" |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 for (std::vector<TemplateURLData>::const_iterator i = | 671 for (std::vector<TemplateURLData>::const_iterator i = |
672 actions.added_engines.begin(); | 672 actions.added_engines.begin(); |
673 i < actions.added_engines.end(); | 673 i < actions.added_engines.end(); |
674 ++i) { | 674 ++i) { |
675 AddNoNotify(base::MakeUnique<TemplateURL>(*i), true); | 675 AddNoNotify(base::MakeUnique<TemplateURL>(*i), true); |
676 } | 676 } |
677 | 677 |
678 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 678 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
679 &dsp_change_origin_, DSP_CHANGE_PROFILE_RESET); | 679 &dsp_change_origin_, DSP_CHANGE_PROFILE_RESET); |
680 | 680 |
681 DefaultSearchManager::Source old_source = default_search_provider_source_; | |
681 default_search_manager_.ClearUserSelectedDefaultSearchEngine(); | 682 default_search_manager_.ClearUserSelectedDefaultSearchEngine(); |
682 | 683 |
683 if (!default_search_provider_) { | 684 if (!default_search_provider_) { |
684 // If the default search provider came from a user pref we would have been | 685 // If the default search provider came from a user pref we would have been |
vasilii
2017/02/07 14:45:37
If the reproduction steps are:
- set the DSE to Bl
Alexander Yashkin
2017/02/07 16:26:23
We can land here only if previous DSE was fallback
| |
685 // notified of the new (fallback-provided) value in | 686 // notified of the new (fallback-provided) value in |
686 // ClearUserSelectedDefaultSearchEngine() above. Since we are here, the | 687 // ClearUserSelectedDefaultSearchEngine() above. Since we are here, the |
687 // value was presumably originally a fallback value (which may have been | 688 // value was presumably originally a fallback value (which may have been |
688 // repaired). | 689 // repaired). |
689 DefaultSearchManager::Source source; | 690 DefaultSearchManager::Source source; |
690 const TemplateURLData* new_dse = | 691 const TemplateURLData* new_dse = |
691 default_search_manager_.GetDefaultSearchEngine(&source); | 692 default_search_manager_.GetDefaultSearchEngine(&source); |
692 // ApplyDefaultSearchChange will notify observers once it is done. | 693 // ApplyDefaultSearchChange will notify observers once it is done. |
693 ApplyDefaultSearchChange(new_dse, source); | 694 ApplyDefaultSearchChange(new_dse, source); |
695 } else if (old_source == DefaultSearchManager::FROM_USER) { | |
vasilii
2017/02/07 17:12:56
Your reasoning sounds good. It seems that we shoul
| |
696 // We expect that if old default source was FROM_USER we could only get to | |
697 // fallback engine source after ClearUserSelectedDefaultSearchEngine. | |
698 DCHECK(default_search_provider_source_ == | |
699 DefaultSearchManager::FROM_FALLBACK); | |
700 // Set fallback engine as user selected, because repair is considered a user | |
701 // action and the new engine is expected to sync to other devices. | |
702 default_search_manager_.SetUserSelectedDefaultSearchEngine( | |
703 default_search_provider_->data()); | |
694 } else { | 704 } else { |
695 NotifyObservers(); | 705 NotifyObservers(); |
696 } | 706 } |
697 } | 707 } |
698 | 708 |
699 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { | 709 void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { |
700 model_observers_.AddObserver(observer); | 710 model_observers_.AddObserver(observer); |
701 } | 711 } |
702 | 712 |
703 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { | 713 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1930 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); | 1940 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
1931 if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || | 1941 if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || |
1932 source == DefaultSearchManager::FROM_POLICY) { | 1942 source == DefaultSearchManager::FROM_POLICY) { |
1933 // We do this both to remove any no-longer-applicable policy-defined DSE as | 1943 // We do this both to remove any no-longer-applicable policy-defined DSE as |
1934 // well as to add the new one, if appropriate. | 1944 // well as to add the new one, if appropriate. |
1935 UpdateProvidersCreatedByPolicy( | 1945 UpdateProvidersCreatedByPolicy( |
1936 &template_urls_, | 1946 &template_urls_, |
1937 source == DefaultSearchManager::FROM_POLICY ? data : nullptr); | 1947 source == DefaultSearchManager::FROM_POLICY ? data : nullptr); |
1938 } | 1948 } |
1939 | 1949 |
1950 // |default_search_provider_source_| must be set before calling | |
1951 // UpdateNoNotify(), since that function needs to know the source of the | |
1952 // update in question. | |
1953 default_search_provider_source_ = source; | |
1954 | |
1940 if (!data) { | 1955 if (!data) { |
1941 default_search_provider_ = nullptr; | 1956 default_search_provider_ = nullptr; |
1942 } else if (source == DefaultSearchManager::FROM_EXTENSION) { | 1957 } else if (source == DefaultSearchManager::FROM_EXTENSION) { |
1943 default_search_provider_ = FindMatchingExtensionTemplateURL( | 1958 default_search_provider_ = FindMatchingExtensionTemplateURL( |
1944 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | 1959 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); |
1945 } else if (source == DefaultSearchManager::FROM_FALLBACK) { | 1960 } else if (source == DefaultSearchManager::FROM_FALLBACK) { |
1946 default_search_provider_ = | 1961 default_search_provider_ = |
1947 FindPrepopulatedTemplateURL(data->prepopulate_id); | 1962 FindPrepopulatedTemplateURL(data->prepopulate_id); |
1948 if (default_search_provider_) { | 1963 if (default_search_provider_) { |
1949 TemplateURLData update_data(*data); | 1964 TemplateURLData update_data(*data); |
(...skipping 30 matching lines...) Expand all Loading... | |
1980 std::unique_ptr<TemplateURL> new_dse_ptr = | 1995 std::unique_ptr<TemplateURL> new_dse_ptr = |
1981 base::MakeUnique<TemplateURL>(new_data); | 1996 base::MakeUnique<TemplateURL>(new_data); |
1982 TemplateURL* new_dse = new_dse_ptr.get(); | 1997 TemplateURL* new_dse = new_dse_ptr.get(); |
1983 if (AddNoNotify(std::move(new_dse_ptr), true)) | 1998 if (AddNoNotify(std::move(new_dse_ptr), true)) |
1984 default_search_provider_ = new_dse; | 1999 default_search_provider_ = new_dse; |
1985 } | 2000 } |
1986 if (default_search_provider_ && prefs_) { | 2001 if (default_search_provider_ && prefs_) { |
1987 prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID, | 2002 prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID, |
1988 default_search_provider_->sync_guid()); | 2003 default_search_provider_->sync_guid()); |
1989 } | 2004 } |
1990 | |
1991 } | 2005 } |
1992 | 2006 |
1993 default_search_provider_source_ = source; | |
1994 | |
1995 bool changed = default_search_provider_ != previous_default_search_engine; | 2007 bool changed = default_search_provider_ != previous_default_search_engine; |
1996 if (changed) | 2008 if (changed) |
1997 RequestGoogleURLTrackerServerCheckIfNecessary(); | 2009 RequestGoogleURLTrackerServerCheckIfNecessary(); |
1998 | 2010 |
1999 NotifyObservers(); | 2011 NotifyObservers(); |
2000 | 2012 |
2001 return changed; | 2013 return changed; |
2002 } | 2014 } |
2003 | 2015 |
2004 TemplateURL* TemplateURLService::AddNoNotify( | 2016 TemplateURL* TemplateURLService::AddNoNotify( |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2477 | 2489 |
2478 if (most_recently_intalled_default) { | 2490 if (most_recently_intalled_default) { |
2479 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2491 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
2480 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2492 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
2481 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2493 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
2482 most_recently_intalled_default->data()); | 2494 most_recently_intalled_default->data()); |
2483 } else { | 2495 } else { |
2484 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2496 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
2485 } | 2497 } |
2486 } | 2498 } |
OLD | NEW |