Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: components/search_engines/template_url_service.cc

Issue 2367373003: [Android] Allow setting recently visited search engines as default search engine (Closed)
Patch Set: update based on ian's comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 if (!urls) 1635 if (!urls)
1636 return true; 1636 return true;
1637 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { 1637 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
1638 if (!(*i)->safe_for_autoreplace()) 1638 if (!(*i)->safe_for_autoreplace())
1639 return false; 1639 return false;
1640 } 1640 }
1641 return true; 1641 return true;
1642 } 1642 }
1643 1643
1644 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { 1644 bool TemplateURLService::CanReplace(const TemplateURL* t_url) {
1645 return (t_url != default_search_provider_ && !t_url->show_in_default_list() && 1645 return (t_url != default_search_provider_ && t_url->prepopulate_id() <= 0 &&
1646 t_url->safe_for_autoreplace()); 1646 !t_url->created_by_policy() && t_url->safe_for_autoreplace());
1647 } 1647 }
1648 1648
1649 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( 1649 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
1650 const base::string16& keyword) { 1650 const base::string16& keyword) {
1651 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); 1651 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword);
1652 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) 1652 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL))
1653 return keyword_turl; 1653 return keyword_turl;
1654 // The extension keyword in the model may be hiding a replaceable 1654 // The extension keyword in the model may be hiding a replaceable
1655 // non-extension keyword. Look for it. 1655 // non-extension keyword. Look for it.
1656 for (const auto& turl : template_urls_) { 1656 for (const auto& turl : template_urls_) {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 data.favicon_url = GURL(); 2107 data.favicon_url = GURL();
2108 } 2108 }
2109 data.safe_for_autoreplace = false; 2109 data.safe_for_autoreplace = false;
2110 data.last_modified = clock_->Now(); 2110 data.last_modified = clock_->Now();
2111 return UpdateNoNotify(url, TemplateURL(data)); 2111 return UpdateNoNotify(url, TemplateURL(data));
2112 } 2112 }
2113 2113
2114 void TemplateURLService::NotifyObservers() { 2114 void TemplateURLService::NotifyObservers() {
2115 if (!loaded_) 2115 if (!loaded_)
2116 return; 2116 return;
2117
2118 FOR_EACH_OBSERVER(TemplateURLServiceObserver, model_observers_, 2117 FOR_EACH_OBSERVER(TemplateURLServiceObserver, model_observers_,
2119 OnTemplateURLServiceChanged()); 2118 OnTemplateURLServiceChanged());
2120 } 2119 }
2121 2120
2122 // |template_urls| are the TemplateURLs loaded from the database. 2121 // |template_urls| are the TemplateURLs loaded from the database.
2123 // |default_from_prefs| is the default search provider from the preferences, or 2122 // |default_from_prefs| is the default search provider from the preferences, or
2124 // NULL if the DSE is not policy-defined. 2123 // NULL if the DSE is not policy-defined.
2125 // 2124 //
2126 // This function removes from the vector and the database all the TemplateURLs 2125 // This function removes from the vector and the database all the TemplateURLs
2127 // that were set by policy, unless it is the current default search provider, in 2126 // that were set by policy, unless it is the current default search provider, in
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 2473
2475 if (most_recently_intalled_default) { 2474 if (most_recently_intalled_default) {
2476 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2475 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2477 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2476 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2478 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2477 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2479 most_recently_intalled_default->data()); 2478 most_recently_intalled_default->data());
2480 } else { 2479 } else {
2481 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2480 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2482 } 2481 }
2483 } 2482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698