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

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: Rename to TemplateURLServiceClient 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"
25 #include "chrome/browser/search_engines/template_url_service_client.h"
30 #include "chrome/browser/search_engines/template_url_service_observer.h" 26 #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" 27 #include "chrome/browser/search_engines/util.h"
33 #include "chrome/browser/webdata/web_data_service_factory.h"
34 #include "components/rappor/rappor_service.h" 28 #include "components/rappor/rappor_service.h"
35 #include "components/search_engines/search_engines_pref_names.h" 29 #include "components/search_engines/search_engines_pref_names.h"
30 #include "components/search_engines/search_terms_data.h"
36 #include "components/search_engines/template_url.h" 31 #include "components/search_engines/template_url.h"
37 #include "components/search_engines/template_url_prepopulate_data.h" 32 #include "components/search_engines/template_url_prepopulate_data.h"
38 #include "components/url_fixer/url_fixer.h" 33 #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" 34 #include "net/base/net_util.h"
42 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 35 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
43 #include "sync/api/sync_change.h" 36 #include "sync/api/sync_change.h"
44 #include "sync/api/sync_error_factory.h" 37 #include "sync/api/sync_error_factory.h"
45 #include "sync/protocol/search_engine_specifics.pb.h" 38 #include "sync/protocol/search_engine_specifics.pb.h"
46 #include "sync/protocol/sync.pb.h" 39 #include "sync/protocol/sync.pb.h"
47 #include "ui/base/l10n/l10n_util.h"
48 #include "url/gurl.h" 40 #include "url/gurl.h"
49 41
50 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet; 42 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
51 typedef TemplateURLService::SyncDataMap SyncDataMap; 43 typedef TemplateURLService::SyncDataMap SyncDataMap;
52 44
53 namespace { 45 namespace {
54 46
55 bool IdenticalSyncGUIDs(const TemplateURLData* data, const TemplateURL* turl) { 47 bool IdenticalSyncGUIDs(const TemplateURLData* data, const TemplateURL* turl) {
56 if (!data || !turl) 48 if (!data || !turl)
57 return !data && !turl; 49 return !data && !turl;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const KeywordToTemplateMap::value_type& elem2) const { 170 const KeywordToTemplateMap::value_type& elem2) const {
179 return (elem1.second == NULL) ? 171 return (elem1.second == NULL) ?
180 (elem2.first.compare(0, elem1.first.length(), elem1.first) > 0) : 172 (elem2.first.compare(0, elem1.first.length(), elem1.first) > 0) :
181 (elem1.first < elem2.first); 173 (elem1.first < elem2.first);
182 } 174 }
183 }; 175 };
184 176
185 177
186 // TemplateURLService --------------------------------------------------------- 178 // TemplateURLService ---------------------------------------------------------
187 179
188 TemplateURLService::TemplateURLService(Profile* profile, 180 TemplateURLService::TemplateURLService(
189 rappor::RapporService* rappor_service, 181 PrefService* prefs,
190 const base::Closure& dsp_change_callback) 182 scoped_ptr<SearchTermsData> search_terms_data,
191 : provider_map_(new SearchHostToURLsMap), 183 KeywordWebDataService* web_data_service,
192 profile_(profile), 184 scoped_ptr<TemplateURLServiceClient> client,
193 prefs_(profile ? profile->GetPrefs() : NULL), 185 GoogleURLTracker* google_url_tracker,
186 rappor::RapporService* rappor_service,
187 const base::Closure& dsp_change_callback)
188 : prefs_(prefs),
189 search_terms_data_(search_terms_data.Pass()),
190 web_data_service_(web_data_service),
191 client_(client.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),
195 provider_map_(new SearchHostToURLsMap),
197 loaded_(false), 196 loaded_(false),
198 load_failed_(false), 197 load_failed_(false),
199 load_handle_(0), 198 load_handle_(0),
200 default_search_provider_(NULL), 199 default_search_provider_(NULL),
201 next_id_(kInvalidTemplateURLID + 1), 200 next_id_(kInvalidTemplateURLID + 1),
202 time_provider_(&base::Time::Now), 201 time_provider_(&base::Time::Now),
203 models_associated_(false), 202 models_associated_(false),
204 processing_syncer_changes_(false), 203 processing_syncer_changes_(false),
205 dsp_change_origin_(DSP_CHANGE_OTHER), 204 dsp_change_origin_(DSP_CHANGE_OTHER),
206 default_search_manager_( 205 default_search_manager_(
207 prefs_, 206 prefs_,
208 base::Bind(&TemplateURLService::OnDefaultSearchChange, 207 base::Bind(&TemplateURLService::OnDefaultSearchChange,
209 base::Unretained(this))) { 208 base::Unretained(this))) {
210 DCHECK(profile_); 209 DCHECK(search_terms_data_);
211 Init(NULL, 0); 210 Init(NULL, 0);
212 } 211 }
213 212
214 TemplateURLService::TemplateURLService(const Initializer* initializers, 213 TemplateURLService::TemplateURLService(const Initializer* initializers,
215 const int count) 214 const int count)
216 : provider_map_(new SearchHostToURLsMap), 215 : prefs_(NULL),
217 profile_(NULL), 216 search_terms_data_(new SearchTermsData),
218 prefs_(NULL), 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)), 220 provider_map_(new SearchHostToURLsMap),
221 loaded_(false), 221 loaded_(false),
222 load_failed_(false), 222 load_failed_(false),
223 load_handle_(0), 223 load_handle_(0),
224 default_search_provider_(NULL), 224 default_search_provider_(NULL),
225 next_id_(kInvalidTemplateURLID + 1), 225 next_id_(kInvalidTemplateURLID + 1),
226 time_provider_(&base::Time::Now), 226 time_provider_(&base::Time::Now),
227 models_associated_(false), 227 models_associated_(false),
228 processing_syncer_changes_(false), 228 processing_syncer_changes_(false),
229 dsp_change_origin_(DSP_CHANGE_OTHER), 229 dsp_change_origin_(DSP_CHANGE_OTHER),
230 default_search_manager_( 230 default_search_manager_(
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 801 }
802 802
803 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { 803 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) {
804 model_observers_.RemoveObserver(observer); 804 model_observers_.RemoveObserver(observer);
805 } 805 }
806 806
807 void TemplateURLService::Load() { 807 void TemplateURLService::Load() {
808 if (loaded_ || load_handle_) 808 if (loaded_ || load_handle_)
809 return; 809 return;
810 810
811 if (!web_data_service_) {
812 web_data_service_ = WebDataServiceFactory::GetKeywordWebDataForProfile(
813 profile_, Profile::EXPLICIT_ACCESS);
814 }
815
816 if (web_data_service_) 811 if (web_data_service_)
817 load_handle_ = web_data_service_->GetKeywords(this); 812 load_handle_ = web_data_service_->GetKeywords(this);
818 else 813 else
819 ChangeToLoadedState(); 814 ChangeToLoadedState();
820 } 815 }
821 816
822 scoped_ptr<TemplateURLService::Subscription> 817 scoped_ptr<TemplateURLService::Subscription>
823 TemplateURLService::RegisterOnLoadedCallback( 818 TemplateURLService::RegisterOnLoadedCallback(
824 const base::Closure& callback) { 819 const base::Closure& callback) {
825 return loaded_ ? 820 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. 896 // to track changes to the model, this should become a DCHECK.
902 if (template_url) { 897 if (template_url) {
903 *is_omnibox_api_extension_keyword = 898 *is_omnibox_api_extension_keyword =
904 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; 899 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
905 return template_url->AdjustedShortNameForLocaleDirection(); 900 return template_url->AdjustedShortNameForLocaleDirection();
906 } 901 }
907 *is_omnibox_api_extension_keyword = false; 902 *is_omnibox_api_extension_keyword = false;
908 return base::string16(); 903 return base::string16();
909 } 904 }
910 905
911 void TemplateURLService::Observe(int type, 906 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_) 907 if (!loaded_)
917 visits_to_add_.push_back(*visit_details.ptr()); 908 visits_to_add_.push_back(details);
918 else 909 else
919 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); 910 UpdateKeywordSearchTermsForURL(details);
920 } 911 }
921 912
922 void TemplateURLService::Shutdown() { 913 void TemplateURLService::Shutdown() {
923 // This check has to be done at Shutdown() instead of in the dtor to ensure 914 // 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 915 // that no clients of KeywordWebDataService are holding ptrs to it after the
925 // first phase of the KeyedService Shutdown() process. 916 // first phase of the KeyedService Shutdown() process.
926 if (load_handle_) { 917 if (load_handle_) {
927 DCHECK(web_data_service_.get()); 918 DCHECK(web_data_service_.get());
928 web_data_service_->CancelRequest(load_handle_); 919 web_data_service_->CancelRequest(load_handle_);
929 } 920 }
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 i != sync_data.end(); 1397 i != sync_data.end();
1407 ++i) 1398 ++i)
1408 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i; 1399 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i;
1409 return data_map; 1400 return data_map;
1410 } 1401 }
1411 1402
1412 void TemplateURLService::SetKeywordSearchTermsForURL( 1403 void TemplateURLService::SetKeywordSearchTermsForURL(
1413 const TemplateURL* t_url, 1404 const TemplateURL* t_url,
1414 const GURL& url, 1405 const GURL& url,
1415 const base::string16& term) { 1406 const base::string16& term) {
1416 HistoryService* history = profile_ ? 1407 if (client_)
1417 HistoryServiceFactory::GetForProfile(profile_, 1408 client_->SetKeywordSearchTermsForURL(url, t_url->id(), term);
1418 Profile::EXPLICIT_ACCESS) :
1419 NULL;
1420 if (!history)
1421 return;
1422 history->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 (client_)
1428 if (profile_) { 1414 client_->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 22 matching lines...) Expand all
1477 AddNoNotify(template_url, true); 1456 AddNoNotify(template_url, true);
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 RequestGoogleURLTrackerServerCheckIfNecessary();
1488 if (profile_ && default_search_provider &&
1489 default_search_provider->HasGoogleBaseURLs(search_terms_data())) {
1490 GoogleURLTracker* tracker =
1491 GoogleURLTrackerFactory::GetForProfile(profile_);
1492 if (tracker)
1493 tracker->RequestServerCheck(false);
1494 }
1495 } 1467 }
1496 1468
1497 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { 1469 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
1498 const base::string16& keyword = template_url->keyword(); 1470 const base::string16& keyword = template_url->keyword();
1499 DCHECK_NE(0U, keyword_to_template_map_.count(keyword)); 1471 DCHECK_NE(0U, keyword_to_template_map_.count(keyword));
1500 if (keyword_to_template_map_[keyword] == template_url) { 1472 if (keyword_to_template_map_[keyword] == template_url) {
1501 // We need to check whether the keyword can now be provided by another 1473 // We need to check whether the keyword can now be provided by another
1502 // TemplateURL. See the comments in AddToMaps() for more information on 1474 // TemplateURL. See the comments in AddToMaps() for more information on
1503 // extension keywords and how they can coexist with non-extension keywords. 1475 // 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 1476 // 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) { 1711 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) {
1740 if (prefs_ && 1712 if (prefs_ &&
1741 (synced_turl->sync_guid() == 1713 (synced_turl->sync_guid() ==
1742 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID))) { 1714 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID))) {
1743 default_search_manager_.SetUserSelectedDefaultSearchEngine( 1715 default_search_manager_.SetUserSelectedDefaultSearchEngine(
1744 synced_turl->data()); 1716 synced_turl->data());
1745 } 1717 }
1746 } 1718 }
1747 1719
1748 void TemplateURLService::UpdateKeywordSearchTermsForURL( 1720 void TemplateURLService::UpdateKeywordSearchTermsForURL(
1749 const history::URLVisitedDetails& details) { 1721 const URLVisitedDetails& details) {
1750 const history::URLRow& row = details.row; 1722 if (!details.url.is_valid())
1751 if (!row.url().is_valid())
1752 return; 1723 return;
1753 1724
1754 const TemplateURLSet* urls_for_host = 1725 const TemplateURLSet* urls_for_host =
1755 provider_map_->GetURLsForHost(row.url().host()); 1726 provider_map_->GetURLsForHost(details.url.host());
1756 if (!urls_for_host) 1727 if (!urls_for_host)
1757 return; 1728 return;
1758 1729
1759 for (TemplateURLSet::const_iterator i = urls_for_host->begin(); 1730 for (TemplateURLSet::const_iterator i = urls_for_host->begin();
1760 i != urls_for_host->end(); ++i) { 1731 i != urls_for_host->end(); ++i) {
1761 base::string16 search_terms; 1732 base::string16 search_terms;
1762 if ((*i)->ExtractSearchTermsFromURL(row.url(), search_terms_data(), 1733 if ((*i)->ExtractSearchTermsFromURL(details.url, search_terms_data(),
1763 &search_terms) && 1734 &search_terms) &&
1764 !search_terms.empty()) { 1735 !search_terms.empty()) {
1765 if (content::PageTransitionStripQualifier(details.transition) == 1736 if (details.is_keyword_transition) {
1766 content::PAGE_TRANSITION_KEYWORD) {
1767 // The visit is the result of the user entering a keyword, generate a 1737 // 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 1738 // KEYWORD_GENERATED visit for the KEYWORD so that the keyword typed
1769 // count is boosted. 1739 // count is boosted.
1770 AddTabToSearchVisit(**i); 1740 AddTabToSearchVisit(**i);
1771 } 1741 }
1772 SetKeywordSearchTermsForURL(*i, row.url(), search_terms); 1742 SetKeywordSearchTermsForURL(*i, details.url, search_terms);
1773 } 1743 }
1774 } 1744 }
1775 } 1745 }
1776 1746
1777 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { 1747 void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) {
1778 // Only add visits for entries the user hasn't modified. If the user modified 1748 // 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 1749 // 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 1750 // possible to do something more sophisticated here, but it's so rare as to
1781 // not be worth it. 1751 // not be worth it.
1782 if (!t_url.safe_for_autoreplace()) 1752 if (!t_url.safe_for_autoreplace())
1783 return; 1753 return;
1784 1754
1785 if (!profile_) 1755 if (!client_)
1786 return;
1787
1788 HistoryService* history =
1789 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
1790 if (!history)
1791 return; 1756 return;
1792 1757
1793 GURL url( 1758 GURL url(
1794 url_fixer::FixupURL(base::UTF16ToUTF8(t_url.keyword()), std::string())); 1759 url_fixer::FixupURL(base::UTF16ToUTF8(t_url.keyword()), std::string()));
1795 if (!url.is_valid()) 1760 if (!url.is_valid())
1796 return; 1761 return;
1797 1762
1798 // Synthesize a visit for the keyword. This ensures the url for the keyword is 1763 // 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. 1764 // autocompleted even if the user doesn't type the url in directly.
1800 history->AddPage(url, base::Time::Now(), NULL, 0, GURL(), 1765 client_->AddKeywordGeneratedVisit(url);
1801 history::RedirectList(), 1766 }
1802 content::PAGE_TRANSITION_KEYWORD_GENERATED, 1767
1803 history::SOURCE_BROWSED, false); 1768 void TemplateURLService::RequestGoogleURLTrackerServerCheckIfNecessary() {
1769 if (default_search_provider_ &&
1770 default_search_provider_->HasGoogleBaseURLs(search_terms_data()) &&
1771 google_url_tracker_)
1772 google_url_tracker_->RequestServerCheck(false);
1804 } 1773 }
1805 1774
1806 void TemplateURLService::GoogleBaseURLChanged() { 1775 void TemplateURLService::GoogleBaseURLChanged() {
1807 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 1776 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
1808 bool something_changed = false; 1777 bool something_changed = false;
1809 for (TemplateURLVector::iterator i(template_urls_.begin()); 1778 for (TemplateURLVector::iterator i(template_urls_.begin());
1810 i != template_urls_.end(); ++i) { 1779 i != template_urls_.end(); ++i) {
1811 TemplateURL* t_url = *i; 1780 TemplateURL* t_url = *i;
1812 if (t_url->HasGoogleBaseURLs(search_terms_data())) { 1781 if (t_url->HasGoogleBaseURLs(search_terms_data())) {
1813 TemplateURL updated_turl(t_url->data()); 1782 TemplateURL updated_turl(t_url->data());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 if (default_search_provider_ && prefs_) { 1923 if (default_search_provider_ && prefs_) {
1955 prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID, 1924 prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID,
1956 default_search_provider_->sync_guid()); 1925 default_search_provider_->sync_guid());
1957 } 1926 }
1958 1927
1959 } 1928 }
1960 1929
1961 default_search_provider_source_ = source; 1930 default_search_provider_source_ = source;
1962 1931
1963 bool changed = default_search_provider_ != previous_default_search_engine; 1932 bool changed = default_search_provider_ != previous_default_search_engine;
1964 1933 if (changed)
1965 if (profile_ && changed && default_search_provider_ && 1934 RequestGoogleURLTrackerServerCheckIfNecessary();
1966 default_search_provider_->HasGoogleBaseURLs(search_terms_data())) {
1967 GoogleURLTracker* tracker =
1968 GoogleURLTrackerFactory::GetForProfile(profile_);
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_ && client_)
2071 HistoryService* history = HistoryServiceFactory::GetForProfile( 2034 client_->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
« no previous file with comments | « chrome/browser/search_engines/template_url_service.h ('k') | chrome/browser/search_engines/template_url_service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698