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

Side by Side Diff: chrome/browser/search_engines/template_url_service.cc

Issue 367863005: No chrome dependencies in TemplateURLService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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 <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/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/i18n/case_conversion.h" 14 #include "base/i18n/case_conversion.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/google/google_url_tracker_factory.h"
26 #include "chrome/browser/history/history_service.h"
27 #include "chrome/browser/history/history_service_factory.h"
28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 24 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
30 #include "chrome/browser/search_engines/template_url_service_observer.h" 25 #include "chrome/browser/search_engines/template_url_service_observer.h"
31 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
32 #include "chrome/browser/search_engines/util.h" 26 #include "chrome/browser/search_engines/util.h"
33 #include "chrome/browser/webdata/web_data_service_factory.h"
34 #include "components/rappor/rappor_service.h" 27 #include "components/rappor/rappor_service.h"
35 #include "components/search_engines/search_engines_pref_names.h" 28 #include "components/search_engines/search_engines_pref_names.h"
29 #include "components/search_engines/search_terms_data.h"
36 #include "components/search_engines/template_url.h" 30 #include "components/search_engines/template_url.h"
37 #include "components/search_engines/template_url_prepopulate_data.h" 31 #include "components/search_engines/template_url_prepopulate_data.h"
38 #include "components/url_fixer/url_fixer.h" 32 #include "components/url_fixer/url_fixer.h"
39 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_source.h"
41 #include "net/base/net_util.h" 33 #include "net/base/net_util.h"
42 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 34 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
43 #include "sync/api/sync_change.h" 35 #include "sync/api/sync_change.h"
44 #include "sync/api/sync_error_factory.h" 36 #include "sync/api/sync_error_factory.h"
45 #include "sync/protocol/search_engine_specifics.pb.h" 37 #include "sync/protocol/search_engine_specifics.pb.h"
46 #include "sync/protocol/sync.pb.h" 38 #include "sync/protocol/sync.pb.h"
47 #include "ui/base/l10n/l10n_util.h"
48 #include "url/gurl.h" 39 #include "url/gurl.h"
49 40
50 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet; 41 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
51 typedef TemplateURLService::SyncDataMap SyncDataMap; 42 typedef TemplateURLService::SyncDataMap SyncDataMap;
52 43
53 namespace { 44 namespace {
54 45
55 bool IdenticalSyncGUIDs(const TemplateURLData* data, const TemplateURL* turl) { 46 bool IdenticalSyncGUIDs(const TemplateURLData* data, const TemplateURL* turl) {
56 if (!data || !turl) 47 if (!data || !turl)
57 return !data && !turl; 48 return !data && !turl;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const KeywordToTemplateMap::value_type& elem2) const { 169 const KeywordToTemplateMap::value_type& elem2) const {
179 return (elem1.second == NULL) ? 170 return (elem1.second == NULL) ?
180 (elem2.first.compare(0, elem1.first.length(), elem1.first) > 0) : 171 (elem2.first.compare(0, elem1.first.length(), elem1.first) > 0) :
181 (elem1.first < elem2.first); 172 (elem1.first < elem2.first);
182 } 173 }
183 }; 174 };
184 175
185 176
186 // TemplateURLService --------------------------------------------------------- 177 // TemplateURLService ---------------------------------------------------------
187 178
188 TemplateURLService::TemplateURLService(Profile* profile, 179 TemplateURLService::TemplateURLService(
189 rappor::RapporService* rappor_service, 180 PrefService* prefs,
190 const base::Closure& dsp_change_callback) 181 scoped_ptr<SearchTermsData> search_terms_data,
182 KeywordWebDataService* web_data_service,
183 scoped_ptr<KeywordHistoryServiceInterface> history_service,
184 GoogleURLTracker* google_url_tracker,
185 rappor::RapporService* rappor_service,
186 const base::Closure& dsp_change_callback)
191 : provider_map_(new SearchHostToURLsMap), 187 : provider_map_(new SearchHostToURLsMap),
192 profile_(profile), 188 prefs_(prefs),
193 prefs_(profile ? profile->GetPrefs() : NULL), 189 search_terms_data_(search_terms_data.Pass()),
190 web_data_service_(web_data_service),
191 history_service_(history_service.Pass()),
192 google_url_tracker_(google_url_tracker),
194 rappor_service_(rappor_service), 193 rappor_service_(rappor_service),
195 search_terms_data_(new UIThreadSearchTermsData(profile)),
196 dsp_change_callback_(dsp_change_callback), 194 dsp_change_callback_(dsp_change_callback),
197 loaded_(false), 195 loaded_(false),
198 load_failed_(false), 196 load_failed_(false),
199 load_handle_(0), 197 load_handle_(0),
200 default_search_provider_(NULL), 198 default_search_provider_(NULL),
201 next_id_(kInvalidTemplateURLID + 1), 199 next_id_(kInvalidTemplateURLID + 1),
202 time_provider_(&base::Time::Now), 200 time_provider_(&base::Time::Now),
203 models_associated_(false), 201 models_associated_(false),
204 processing_syncer_changes_(false), 202 processing_syncer_changes_(false),
205 dsp_change_origin_(DSP_CHANGE_OTHER), 203 dsp_change_origin_(DSP_CHANGE_OTHER),
206 default_search_manager_( 204 default_search_manager_(
207 prefs_, 205 prefs_,
208 base::Bind(&TemplateURLService::OnDefaultSearchChange, 206 base::Bind(&TemplateURLService::OnDefaultSearchChange,
209 base::Unretained(this))) { 207 base::Unretained(this))) {
210 DCHECK(profile_); 208 DCHECK(search_terms_data_);
211 Init(NULL, 0); 209 Init(NULL, 0);
212 } 210 }
213 211
214 TemplateURLService::TemplateURLService(const Initializer* initializers, 212 TemplateURLService::TemplateURLService(const Initializer* initializers,
215 const int count) 213 const int count)
216 : provider_map_(new SearchHostToURLsMap), 214 : provider_map_(new SearchHostToURLsMap),
217 profile_(NULL),
218 prefs_(NULL), 215 prefs_(NULL),
216 search_terms_data_(new SearchTermsData),
217 web_data_service_(NULL),
218 google_url_tracker_(NULL),
219 rappor_service_(NULL), 219 rappor_service_(NULL),
220 search_terms_data_(new UIThreadSearchTermsData(NULL)),
221 loaded_(false), 220 loaded_(false),
222 load_failed_(false), 221 load_failed_(false),
223 load_handle_(0), 222 load_handle_(0),
224 default_search_provider_(NULL), 223 default_search_provider_(NULL),
225 next_id_(kInvalidTemplateURLID + 1), 224 next_id_(kInvalidTemplateURLID + 1),
226 time_provider_(&base::Time::Now), 225 time_provider_(&base::Time::Now),
227 models_associated_(false), 226 models_associated_(false),
228 processing_syncer_changes_(false), 227 processing_syncer_changes_(false),
229 dsp_change_origin_(DSP_CHANGE_OTHER), 228 dsp_change_origin_(DSP_CHANGE_OTHER),
230 default_search_manager_( 229 default_search_manager_(
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 800 }
802 801
803 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { 802 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) {
804 model_observers_.RemoveObserver(observer); 803 model_observers_.RemoveObserver(observer);
805 } 804 }
806 805
807 void TemplateURLService::Load() { 806 void TemplateURLService::Load() {
808 if (loaded_ || load_handle_) 807 if (loaded_ || load_handle_)
809 return; 808 return;
810 809
811 if (!web_data_service_) {
812 web_data_service_ = WebDataServiceFactory::GetKeywordWebDataForProfile(
813 profile_, Profile::EXPLICIT_ACCESS);
814 }
815
816 if (web_data_service_) 810 if (web_data_service_)
817 load_handle_ = web_data_service_->GetKeywords(this); 811 load_handle_ = web_data_service_->GetKeywords(this);
818 else 812 else
819 ChangeToLoadedState(); 813 ChangeToLoadedState();
820 } 814 }
821 815
822 scoped_ptr<TemplateURLService::Subscription> 816 scoped_ptr<TemplateURLService::Subscription>
823 TemplateURLService::RegisterOnLoadedCallback( 817 TemplateURLService::RegisterOnLoadedCallback(
824 const base::Closure& callback) { 818 const base::Closure& callback) {
825 return loaded_ ? 819 return loaded_ ?
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // to track changes to the model, this should become a DCHECK. 895 // to track changes to the model, this should become a DCHECK.
902 if (template_url) { 896 if (template_url) {
903 *is_omnibox_api_extension_keyword = 897 *is_omnibox_api_extension_keyword =
904 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; 898 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
905 return template_url->AdjustedShortNameForLocaleDirection(); 899 return template_url->AdjustedShortNameForLocaleDirection();
906 } 900 }
907 *is_omnibox_api_extension_keyword = false; 901 *is_omnibox_api_extension_keyword = false;
908 return base::string16(); 902 return base::string16();
909 } 903 }
910 904
911 void TemplateURLService::Observe(int type, 905 void TemplateURLService::OnHistoryURLVisited(const URLVisitedDetails& details) {
912 const content::NotificationSource& source,
913 const content::NotificationDetails& details) {
914 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED);
915 content::Details<history::URLVisitedDetails> visit_details(details);
916 if (!loaded_) 906 if (!loaded_)
917 visits_to_add_.push_back(*visit_details.ptr()); 907 visits_to_add_.push_back(details);
918 else 908 else
919 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); 909 UpdateKeywordSearchTermsForURL(details);
920 } 910 }
921 911
922 void TemplateURLService::Shutdown() { 912 void TemplateURLService::Shutdown() {
923 // This check has to be done at Shutdown() instead of in the dtor to ensure 913 // This check has to be done at Shutdown() instead of in the dtor to ensure
924 // that no clients of KeywordWebDataService are holding ptrs to it after the 914 // that no clients of KeywordWebDataService are holding ptrs to it after the
925 // first phase of the KeyedService Shutdown() process. 915 // first phase of the KeyedService Shutdown() process.
926 if (load_handle_) { 916 if (load_handle_) {
927 DCHECK(web_data_service_.get()); 917 DCHECK(web_data_service_.get());
928 web_data_service_->CancelRequest(load_handle_); 918 web_data_service_->CancelRequest(load_handle_);
929 } 919 }
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 i != sync_data.end(); 1396 i != sync_data.end();
1407 ++i) 1397 ++i)
1408 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i; 1398 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i;
1409 return data_map; 1399 return data_map;
1410 } 1400 }
1411 1401
1412 void TemplateURLService::SetKeywordSearchTermsForURL( 1402 void TemplateURLService::SetKeywordSearchTermsForURL(
1413 const TemplateURL* t_url, 1403 const TemplateURL* t_url,
1414 const GURL& url, 1404 const GURL& url,
1415 const base::string16& term) { 1405 const base::string16& term) {
1416 HistoryService* history = profile_ ? 1406 if (!history_service_)
1417 HistoryServiceFactory::GetForProfile(profile_,
1418 Profile::EXPLICIT_ACCESS) :
1419 NULL;
1420 if (!history)
1421 return; 1407 return;
Peter Kasting 2014/07/02 20:45:57 Nit: Can be shortened to two lines by reversing th
hashimoto 2014/07/03 00:05:07 Done.
1422 history->SetKeywordSearchTermsForURL(url, t_url->id(), term); 1408 history_service_->SetKeywordSearchTermsForURL(url, t_url->id(), term);
1423 } 1409 }
1424 1410
1425 void TemplateURLService::Init(const Initializer* initializers, 1411 void TemplateURLService::Init(const Initializer* initializers,
1426 int num_initializers) { 1412 int num_initializers) {
1427 // Register for notifications. 1413 if (history_service_)
1428 if (profile_) { 1414 history_service_->SetOwner(this);
1429 // TODO(sky): bug 1166191. The keywords should be moved into the history
1430 // db, which will mean we no longer need this notification and the history
1431 // backend can handle automatically adding the search terms as the user
1432 // navigates.
1433 content::Source<Profile> profile_source(profile_->GetOriginalProfile());
1434 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
1435 profile_source);
1436 GoogleURLTracker* google_url_tracker =
1437 GoogleURLTrackerFactory::GetForProfile(profile_);
1438 1415
1439 // GoogleURLTracker is not created in tests. 1416 // GoogleURLTracker is not created in tests.
1440 if (google_url_tracker) { 1417 if (google_url_tracker_) {
1441 google_url_updated_subscription_ = 1418 google_url_updated_subscription_ =
1442 google_url_tracker->RegisterCallback(base::Bind( 1419 google_url_tracker_->RegisterCallback(base::Bind(
1443 &TemplateURLService::OnGoogleURLUpdated, base::Unretained(this))); 1420 &TemplateURLService::OnGoogleURLUpdated, base::Unretained(this)));
1444 } 1421 }
1422
1423 if (prefs_) {
1445 pref_change_registrar_.Init(prefs_); 1424 pref_change_registrar_.Init(prefs_);
1446 pref_change_registrar_.Add( 1425 pref_change_registrar_.Add(
1447 prefs::kSyncedDefaultSearchProviderGUID, 1426 prefs::kSyncedDefaultSearchProviderGUID,
1448 base::Bind( 1427 base::Bind(
1449 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged, 1428 &TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged,
1450 base::Unretained(this))); 1429 base::Unretained(this)));
1451 } 1430 }
1452 1431
1453 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER; 1432 DefaultSearchManager::Source source = DefaultSearchManager::FROM_USER;
1454 TemplateURLData* dse = 1433 TemplateURLData* dse =
(...skipping 23 matching lines...) Expand all
1478 1457
1479 // Set the first provided identifier to be the default. 1458 // Set the first provided identifier to be the default.
1480 if (i == 0) 1459 if (i == 0)
1481 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); 1460 default_search_manager_.SetUserSelectedDefaultSearchEngine(data);
1482 } 1461 }
1483 } 1462 }
1484 1463
1485 // Request a server check for the correct Google URL if Google is the 1464 // Request a server check for the correct Google URL if Google is the
1486 // default search engine. 1465 // default search engine.
1487 TemplateURL* default_search_provider = GetDefaultSearchProvider(); 1466 TemplateURL* default_search_provider = GetDefaultSearchProvider();
1488 if (profile_ && default_search_provider && 1467 if (default_search_provider &&
1489 default_search_provider->HasGoogleBaseURLs(search_terms_data())) { 1468 default_search_provider->HasGoogleBaseURLs(search_terms_data()) &&
1490 GoogleURLTracker* tracker = 1469 google_url_tracker_)
1491 GoogleURLTrackerFactory::GetForProfile(profile_); 1470 google_url_tracker_->RequestServerCheck(false);
1492 if (tracker)
1493 tracker->RequestServerCheck(false);
1494 }
1495 } 1471 }
1496 1472
1497 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { 1473 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
1498 const base::string16& keyword = template_url->keyword(); 1474 const base::string16& keyword = template_url->keyword();
1499 DCHECK_NE(0U, keyword_to_template_map_.count(keyword)); 1475 DCHECK_NE(0U, keyword_to_template_map_.count(keyword));
1500 if (keyword_to_template_map_[keyword] == template_url) { 1476 if (keyword_to_template_map_[keyword] == template_url) {
1501 // We need to check whether the keyword can now be provided by another 1477 // We need to check whether the keyword can now be provided by another
1502 // TemplateURL. See the comments in AddToMaps() for more information on 1478 // TemplateURL. See the comments in AddToMaps() for more information on
1503 // extension keywords and how they can coexist with non-extension keywords. 1479 // extension keywords and how they can coexist with non-extension keywords.
1504 // In the case of more than one extension, we use the most recently 1480 // In the case of more than one extension, we use the most recently
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) { 1715 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) {
1740 if (prefs_ && 1716 if (prefs_ &&
1741 (synced_turl->sync_guid() == 1717 (synced_turl->sync_guid() ==
1742 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID))) { 1718 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID))) {
1743 default_search_manager_.SetUserSelectedDefaultSearchEngine( 1719 default_search_manager_.SetUserSelectedDefaultSearchEngine(
1744 synced_turl->data()); 1720 synced_turl->data());
1745 } 1721 }
1746 } 1722 }
1747 1723
1748 void TemplateURLService::UpdateKeywordSearchTermsForURL( 1724 void TemplateURLService::UpdateKeywordSearchTermsForURL(
1749 const history::URLVisitedDetails& details) { 1725 const URLVisitedDetails& details) {
1750 const history::URLRow& row = details.row; 1726 if (!details.url.is_valid())
1751 if (!row.url().is_valid())
1752 return; 1727 return;
1753 1728
1754 const TemplateURLSet* urls_for_host = 1729 const TemplateURLSet* urls_for_host =
1755 provider_map_->GetURLsForHost(row.url().host()); 1730 provider_map_->GetURLsForHost(details.url.host());
1756 if (!urls_for_host) 1731 if (!urls_for_host)
1757 return; 1732 return;
1758 1733
1759 for (TemplateURLSet::const_iterator i = urls_for_host->begin(); 1734 for (TemplateURLSet::const_iterator i = urls_for_host->begin();
1760 i != urls_for_host->end(); ++i) { 1735 i != urls_for_host->end(); ++i) {
1761 base::string16 search_terms; 1736 base::string16 search_terms;
1762 if ((*i)->ExtractSearchTermsFromURL(row.url(), search_terms_data(), 1737 if ((*i)->ExtractSearchTermsFromURL(details.url, search_terms_data(),
1763 &search_terms) && 1738 &search_terms) &&
1764 !search_terms.empty()) { 1739 !search_terms.empty()) {
1765 if (content::PageTransitionStripQualifier(details.transition) == 1740 if (details.is_keyword_transition) {
1766 content::PAGE_TRANSITION_KEYWORD) {
1767 // The visit is the result of the user entering a keyword, generate a 1741 // The visit is the result of the user entering a keyword, generate a
1768 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed 1742 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed
1769 // count is boosted. 1743 // count is boosted.
1770 AddTabToSearchVisit(**i); 1744 AddTabToSearchVisit(**i);
1771 } 1745 }
1772 SetKeywordSearchTermsForURL(*i, row.url(), search_terms); 1746 SetKeywordSearchTermsForURL(*i, details.url, search_terms);
1773 } 1747 }
1774 } 1748 }
1775 } 1749 }
1776 1750
1777 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { 1751 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) {
1778 // Only add visits for entries the user hasn't modified. If the user modified 1752 // Only add visits for entries the user hasn't modified. If the user modified
1779 // the entry the keyword may no longer correspond to the host name. It may be 1753 // the entry the keyword may no longer correspond to the host name. It may be
1780 // possible to do something more sophisticated here, but it's so rare as to 1754 // possible to do something more sophisticated here, but it's so rare as to
1781 // not be worth it. 1755 // not be worth it.
1782 if (!t_url.safe_for_autoreplace()) 1756 if (!t_url.safe_for_autoreplace())
1783 return; 1757 return;
1784 1758
1785 if (!profile_) 1759 if (!history_service_)
1786 return;
1787
1788 HistoryService* history =
1789 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
1790 if (!history)
1791 return; 1760 return;
1792 1761
1793 GURL url( 1762 GURL url(
1794 url_fixer::FixupURL(base::UTF16ToUTF8(t_url.keyword()), std::string())); 1763 url_fixer::FixupURL(base::UTF16ToUTF8(t_url.keyword()), std::string()));
1795 if (!url.is_valid()) 1764 if (!url.is_valid())
1796 return; 1765 return;
1797 1766
1798 // Synthesize a visit for the keyword. This ensures the url for the keyword is 1767 // Synthesize a visit for the keyword. This ensures the url for the keyword is
1799 // autocompleted even if the user doesn't type the url in directly. 1768 // autocompleted even if the user doesn't type the url in directly.
1800 history->AddPage(url, base::Time::Now(), NULL, 0, GURL(), 1769 history_service_->AddKeywordGeneratedVisit(url);
1801 history::RedirectList(),
1802 content::PAGE_TRANSITION_KEYWORD_GENERATED,
1803 history::SOURCE_BROWSED, false);
1804 } 1770 }
1805 1771
1806 void TemplateURLService::GoogleBaseURLChanged() { 1772 void TemplateURLService::GoogleBaseURLChanged() {
1807 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 1773 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
1808 bool something_changed = false; 1774 bool something_changed = false;
1809 for (TemplateURLVector::iterator i(template_urls_.begin()); 1775 for (TemplateURLVector::iterator i(template_urls_.begin());
1810 i != template_urls_.end(); ++i) { 1776 i != template_urls_.end(); ++i) {
1811 TemplateURL* t_url = *i; 1777 TemplateURL* t_url = *i;
1812 if (t_url->HasGoogleBaseURLs(search_terms_data())) { 1778 if (t_url->HasGoogleBaseURLs(search_terms_data())) {
1813 TemplateURL updated_turl(t_url->data()); 1779 TemplateURL updated_turl(t_url->data());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID, 1921 prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID,
1956 default_search_provider_->sync_guid()); 1922 default_search_provider_->sync_guid());
1957 } 1923 }
1958 1924
1959 } 1925 }
1960 1926
1961 default_search_provider_source_ = source; 1927 default_search_provider_source_ = source;
1962 1928
1963 bool changed = default_search_provider_ != previous_default_search_engine; 1929 bool changed = default_search_provider_ != previous_default_search_engine;
1964 1930
1965 if (profile_ && changed && default_search_provider_ && 1931 if (changed && default_search_provider_ &&
1966 default_search_provider_->HasGoogleBaseURLs(search_terms_data())) { 1932 default_search_provider_->HasGoogleBaseURLs(search_terms_data()) &&
1967 GoogleURLTracker* tracker = 1933 google_url_tracker_)
1968 GoogleURLTrackerFactory::GetForProfile(profile_); 1934 google_url_tracker_->RequestServerCheck(false);
Peter Kasting 2014/07/02 20:45:57 Nit: This is the second place we've done something
hashimoto 2014/07/03 00:05:07 Done.
1969 if (tracker)
1970 tracker->RequestServerCheck(false);
1971 }
1972 1935
1973 NotifyObservers(); 1936 NotifyObservers();
1974 1937
1975 return changed; 1938 return changed;
1976 } 1939 }
1977 1940
1978 bool TemplateURLService::AddNoNotify(TemplateURL* template_url, 1941 bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
1979 bool newly_adding) { 1942 bool newly_adding) {
1980 DCHECK(template_url); 1943 DCHECK(template_url);
1981 1944
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 2023
2061 // Inform sync of the deletion. 2024 // Inform sync of the deletion.
2062 ProcessTemplateURLChange(FROM_HERE, 2025 ProcessTemplateURLChange(FROM_HERE,
2063 template_url, 2026 template_url,
2064 syncer::SyncChange::ACTION_DELETE); 2027 syncer::SyncChange::ACTION_DELETE);
2065 2028
2066 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, 2029 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName,
2067 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); 2030 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX);
2068 } 2031 }
2069 2032
2070 if (loaded_ && profile_) { 2033 if (loaded_ && history_service_)
2071 HistoryService* history = HistoryServiceFactory::GetForProfile( 2034 history_service_->DeleteAllSearchTermsForKeyword(template_url->id());
2072 profile_, Profile::EXPLICIT_ACCESS);
2073 if (history)
2074 history->DeleteAllSearchTermsForKeyword(template_url->id());
2075 }
2076 2035
2077 // We own the TemplateURL and need to delete it. 2036 // We own the TemplateURL and need to delete it.
2078 delete template_url; 2037 delete template_url;
2079 } 2038 }
2080 2039
2081 bool TemplateURLService::ResetTemplateURLNoNotify( 2040 bool TemplateURLService::ResetTemplateURLNoNotify(
2082 TemplateURL* url, 2041 TemplateURL* url,
2083 const base::string16& title, 2042 const base::string16& title,
2084 const base::string16& keyword, 2043 const base::string16& keyword,
2085 const std::string& search_url) { 2044 const std::string& search_url) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 2363
2405 if (most_recently_intalled_default) { 2364 if (most_recently_intalled_default) {
2406 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2365 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2407 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2366 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2408 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2367 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2409 most_recently_intalled_default->data()); 2368 most_recently_intalled_default->data());
2410 } else { 2369 } else {
2411 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2370 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2412 } 2371 }
2413 } 2372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698