| OLD | NEW |
| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 25 #include "chrome/browser/google/google_url_tracker_factory.h" | 25 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 26 #include "chrome/browser/history/history_service.h" | 26 #include "chrome/browser/history/history_service.h" |
| 27 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/rlz/rlz.h" | 29 #include "chrome/browser/rlz/rlz.h" |
| 30 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 30 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
| 31 #include "chrome/browser/search_engines/template_url_service_observer.h" | 31 #include "chrome/browser/search_engines/template_url_service_observer.h" |
| 32 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 32 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 33 #include "chrome/browser/search_engines/util.h" | 33 #include "chrome/browser/search_engines/util.h" |
| 34 #include "chrome/browser/webdata/web_data_service.h" | 34 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 35 #include "components/rappor/rappor_service.h" | 35 #include "components/rappor/rappor_service.h" |
| 36 #include "components/search_engines/search_engines_pref_names.h" | 36 #include "components/search_engines/search_engines_pref_names.h" |
| 37 #include "components/search_engines/template_url.h" | 37 #include "components/search_engines/template_url.h" |
| 38 #include "components/search_engines/template_url_prepopulate_data.h" | 38 #include "components/search_engines/template_url_prepopulate_data.h" |
| 39 #include "components/url_fixer/url_fixer.h" | 39 #include "components/url_fixer/url_fixer.h" |
| 40 #include "content/public/browser/notification_details.h" | 40 #include "content/public/browser/notification_details.h" |
| 41 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
| 42 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
| 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 44 #include "sync/api/sync_change.h" | 44 #include "sync/api/sync_change.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 TemplateURLService::TemplateURLService(const Initializer* initializers, | 213 TemplateURLService::TemplateURLService(const Initializer* initializers, |
| 214 const int count) | 214 const int count) |
| 215 : provider_map_(new SearchHostToURLsMap), | 215 : provider_map_(new SearchHostToURLsMap), |
| 216 profile_(NULL), | 216 profile_(NULL), |
| 217 prefs_(NULL), | 217 prefs_(NULL), |
| 218 rappor_service_(NULL), | 218 rappor_service_(NULL), |
| 219 search_terms_data_(new UIThreadSearchTermsData(NULL)), | 219 search_terms_data_(new UIThreadSearchTermsData(NULL)), |
| 220 loaded_(false), | 220 loaded_(false), |
| 221 load_failed_(false), | 221 load_failed_(false), |
| 222 load_handle_(0), | 222 load_handle_(0), |
| 223 service_(NULL), | |
| 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_( |
| 231 prefs_, | 230 prefs_, |
| 232 base::Bind(&TemplateURLService::OnDefaultSearchChange, | 231 base::Bind(&TemplateURLService::OnDefaultSearchChange, |
| 233 base::Unretained(this))) { | 232 base::Unretained(this))) { |
| 234 Init(initializers, count); | 233 Init(initializers, count); |
| 235 } | 234 } |
| 236 | 235 |
| 237 TemplateURLService::~TemplateURLService() { | 236 TemplateURLService::~TemplateURLService() { |
| 238 // |service_| should be deleted during Shutdown(). | 237 // |web_data_service_| should be deleted during Shutdown(). |
| 239 DCHECK(!service_); | 238 DCHECK(!web_data_service_); |
| 240 STLDeleteElements(&template_urls_); | 239 STLDeleteElements(&template_urls_); |
| 241 } | 240 } |
| 242 | 241 |
| 243 // static | 242 // static |
| 244 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( | 243 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( |
| 245 PrefService* prefs, | 244 PrefService* prefs, |
| 246 scoped_ptr<TemplateURLData>* default_provider_data, | 245 scoped_ptr<TemplateURLData>* default_provider_data, |
| 247 bool* is_managed) { | 246 bool* is_managed) { |
| 248 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL) || | 247 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL) || |
| 249 !prefs->HasPrefPath(prefs::kDefaultSearchProviderKeyword)) | 248 !prefs->HasPrefPath(prefs::kDefaultSearchProviderKeyword)) |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 if (loaded_) | 530 if (loaded_) |
| 532 return provider_map_->GetTemplateURLForHost(host); | 531 return provider_map_->GetTemplateURLForHost(host); |
| 533 TemplateURL* initial_dsp = initial_default_search_provider_.get(); | 532 TemplateURL* initial_dsp = initial_default_search_provider_.get(); |
| 534 if (!initial_dsp) | 533 if (!initial_dsp) |
| 535 return NULL; | 534 return NULL; |
| 536 return (initial_dsp->GenerateSearchURL(search_terms_data()).host() == host) ? | 535 return (initial_dsp->GenerateSearchURL(search_terms_data()).host() == host) ? |
| 537 initial_dsp : NULL; | 536 initial_dsp : NULL; |
| 538 } | 537 } |
| 539 | 538 |
| 540 bool TemplateURLService::Add(TemplateURL* template_url) { | 539 bool TemplateURLService::Add(TemplateURL* template_url) { |
| 541 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 540 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 542 if (!AddNoNotify(template_url, true)) | 541 if (!AddNoNotify(template_url, true)) |
| 543 return false; | 542 return false; |
| 544 NotifyObservers(); | 543 NotifyObservers(); |
| 545 return true; | 544 return true; |
| 546 } | 545 } |
| 547 | 546 |
| 548 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, | 547 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, |
| 549 const base::string16& short_name, | 548 const base::string16& short_name, |
| 550 const base::string16& keyword, | 549 const base::string16& keyword, |
| 551 const std::string& url) { | 550 const std::string& url) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 563 DCHECK(loaded_); | 562 DCHECK(loaded_); |
| 564 DCHECK(template_url); | 563 DCHECK(template_url); |
| 565 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); | 564 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); |
| 566 DCHECK(info); | 565 DCHECK(info); |
| 567 DCHECK_NE(TemplateURL::NORMAL, info->type); | 566 DCHECK_NE(TemplateURL::NORMAL, info->type); |
| 568 DCHECK_EQ(info->wants_to_be_default_engine, | 567 DCHECK_EQ(info->wants_to_be_default_engine, |
| 569 template_url->show_in_default_list()); | 568 template_url->show_in_default_list()); |
| 570 DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); | 569 DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); |
| 571 template_url->extension_info_.swap(info); | 570 template_url->extension_info_.swap(info); |
| 572 | 571 |
| 573 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 572 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 574 if (AddNoNotify(template_url, true)) { | 573 if (AddNoNotify(template_url, true)) { |
| 575 if (template_url->extension_info_->wants_to_be_default_engine) | 574 if (template_url->extension_info_->wants_to_be_default_engine) |
| 576 UpdateExtensionDefaultSearchEngine(); | 575 UpdateExtensionDefaultSearchEngine(); |
| 577 NotifyObservers(); | 576 NotifyObservers(); |
| 578 } | 577 } |
| 579 } | 578 } |
| 580 | 579 |
| 581 void TemplateURLService::Remove(TemplateURL* template_url) { | 580 void TemplateURLService::Remove(TemplateURL* template_url) { |
| 582 RemoveNoNotify(template_url); | 581 RemoveNoNotify(template_url); |
| 583 NotifyObservers(); | 582 NotifyObservers(); |
| 584 } | 583 } |
| 585 | 584 |
| 586 void TemplateURLService::RemoveExtensionControlledTURL( | 585 void TemplateURLService::RemoveExtensionControlledTURL( |
| 587 const std::string& extension_id, | 586 const std::string& extension_id, |
| 588 TemplateURL::Type type) { | 587 TemplateURL::Type type) { |
| 589 DCHECK(loaded_); | 588 DCHECK(loaded_); |
| 590 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); | 589 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); |
| 591 if (!url) | 590 if (!url) |
| 592 return; | 591 return; |
| 593 // NULL this out so that we can call RemoveNoNotify. | 592 // NULL this out so that we can call RemoveNoNotify. |
| 594 // UpdateExtensionDefaultSearchEngine will cause it to be reset. | 593 // UpdateExtensionDefaultSearchEngine will cause it to be reset. |
| 595 if (default_search_provider_ == url) | 594 if (default_search_provider_ == url) |
| 596 default_search_provider_ = NULL; | 595 default_search_provider_ = NULL; |
| 597 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 596 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 598 RemoveNoNotify(url); | 597 RemoveNoNotify(url); |
| 599 UpdateExtensionDefaultSearchEngine(); | 598 UpdateExtensionDefaultSearchEngine(); |
| 600 NotifyObservers(); | 599 NotifyObservers(); |
| 601 } | 600 } |
| 602 | 601 |
| 603 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { | 602 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { |
| 604 RemoveAutoGeneratedBetween(created_after, base::Time()); | 603 RemoveAutoGeneratedBetween(created_after, base::Time()); |
| 605 } | 604 } |
| 606 | 605 |
| 607 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, | 606 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, |
| 608 base::Time created_before) { | 607 base::Time created_before) { |
| 609 RemoveAutoGeneratedForOriginBetween(GURL(), created_after, created_before); | 608 RemoveAutoGeneratedForOriginBetween(GURL(), created_after, created_before); |
| 610 } | 609 } |
| 611 | 610 |
| 612 void TemplateURLService::RemoveAutoGeneratedForOriginBetween( | 611 void TemplateURLService::RemoveAutoGeneratedForOriginBetween( |
| 613 const GURL& origin, | 612 const GURL& origin, |
| 614 base::Time created_after, | 613 base::Time created_after, |
| 615 base::Time created_before) { | 614 base::Time created_before) { |
| 616 GURL o(origin.GetOrigin()); | 615 GURL o(origin.GetOrigin()); |
| 617 bool should_notify = false; | 616 bool should_notify = false; |
| 618 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 617 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 619 for (size_t i = 0; i < template_urls_.size();) { | 618 for (size_t i = 0; i < template_urls_.size();) { |
| 620 if (template_urls_[i]->date_created() >= created_after && | 619 if (template_urls_[i]->date_created() >= created_after && |
| 621 (created_before.is_null() || | 620 (created_before.is_null() || |
| 622 template_urls_[i]->date_created() < created_before) && | 621 template_urls_[i]->date_created() < created_before) && |
| 623 CanReplace(template_urls_[i]) && | 622 CanReplace(template_urls_[i]) && |
| 624 (o.is_empty() || | 623 (o.is_empty() || |
| 625 template_urls_[i]->GenerateSearchURL( | 624 template_urls_[i]->GenerateSearchURL( |
| 626 search_terms_data()).GetOrigin() == o)) { | 625 search_terms_data()).GetOrigin() == o)) { |
| 627 RemoveNoNotify(template_urls_[i]); | 626 RemoveNoNotify(template_urls_[i]); |
| 628 should_notify = true; | 627 should_notify = true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { | 662 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { |
| 664 DCHECK(url); | 663 DCHECK(url); |
| 665 // Extension-controlled search engines are not persisted. | 664 // Extension-controlled search engines are not persisted. |
| 666 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) | 665 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) |
| 667 return; | 666 return; |
| 668 if (std::find(template_urls_.begin(), template_urls_.end(), url) == | 667 if (std::find(template_urls_.begin(), template_urls_.end(), url) == |
| 669 template_urls_.end()) | 668 template_urls_.end()) |
| 670 return; | 669 return; |
| 671 ++url->data_.usage_count; | 670 ++url->data_.usage_count; |
| 672 | 671 |
| 673 if (service_) | 672 if (web_data_service_) |
| 674 service_->UpdateKeyword(url->data()); | 673 web_data_service_->UpdateKeyword(url->data()); |
| 675 } | 674 } |
| 676 | 675 |
| 677 void TemplateURLService::ResetTemplateURL(TemplateURL* url, | 676 void TemplateURLService::ResetTemplateURL(TemplateURL* url, |
| 678 const base::string16& title, | 677 const base::string16& title, |
| 679 const base::string16& keyword, | 678 const base::string16& keyword, |
| 680 const std::string& search_url) { | 679 const std::string& search_url) { |
| 681 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) | 680 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) |
| 682 NotifyObservers(); | 681 NotifyObservers(); |
| 683 } | 682 } |
| 684 | 683 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 } | 745 } |
| 747 | 746 |
| 748 size_t default_search_provider_index = 0; | 747 size_t default_search_provider_index = 0; |
| 749 ScopedVector<TemplateURLData> prepopulated_urls = | 748 ScopedVector<TemplateURLData> prepopulated_urls = |
| 750 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 749 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 751 prefs_, &default_search_provider_index); | 750 prefs_, &default_search_provider_index); |
| 752 DCHECK(!prepopulated_urls.empty()); | 751 DCHECK(!prepopulated_urls.empty()); |
| 753 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( | 752 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
| 754 &prepopulated_urls, template_urls_, default_search_provider_)); | 753 &prepopulated_urls, template_urls_, default_search_provider_)); |
| 755 | 754 |
| 756 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 755 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 757 | 756 |
| 758 // Remove items. | 757 // Remove items. |
| 759 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); | 758 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); |
| 760 i < actions.removed_engines.end(); ++i) | 759 i < actions.removed_engines.end(); ++i) |
| 761 RemoveNoNotify(*i); | 760 RemoveNoNotify(*i); |
| 762 | 761 |
| 763 // Edit items. | 762 // Edit items. |
| 764 for (EditedEngines::iterator i(actions.edited_engines.begin()); | 763 for (EditedEngines::iterator i(actions.edited_engines.begin()); |
| 765 i < actions.edited_engines.end(); ++i) { | 764 i < actions.edited_engines.end(); ++i) { |
| 766 TemplateURL new_values(i->second); | 765 TemplateURL new_values(i->second); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (!service_) | 810 if (!web_data_service_) { |
| 812 service_ = WebDataService::FromBrowserContext(profile_); | 811 web_data_service_ = WebDataServiceFactory::GetKeywordWebDataForProfile( |
| 812 profile_, Profile::EXPLICIT_ACCESS); |
| 813 } |
| 813 | 814 |
| 814 if (service_) | 815 if (web_data_service_) |
| 815 load_handle_ = service_->GetKeywords(this); | 816 load_handle_ = web_data_service_->GetKeywords(this); |
| 816 else | 817 else |
| 817 ChangeToLoadedState(); | 818 ChangeToLoadedState(); |
| 818 } | 819 } |
| 819 | 820 |
| 820 scoped_ptr<TemplateURLService::Subscription> | 821 scoped_ptr<TemplateURLService::Subscription> |
| 821 TemplateURLService::RegisterOnLoadedCallback( | 822 TemplateURLService::RegisterOnLoadedCallback( |
| 822 const base::Closure& callback) { | 823 const base::Closure& callback) { |
| 823 return loaded_ ? | 824 return loaded_ ? |
| 824 scoped_ptr<TemplateURLService::Subscription>() : | 825 scoped_ptr<TemplateURLService::Subscription>() : |
| 825 on_loaded_callbacks_.Add(callback); | 826 on_loaded_callbacks_.Add(callback); |
| 826 } | 827 } |
| 827 | 828 |
| 828 void TemplateURLService::OnWebDataServiceRequestDone( | 829 void TemplateURLService::OnWebDataServiceRequestDone( |
| 829 WebDataService::Handle h, | 830 KeywordWebDataService::Handle h, |
| 830 const WDTypedResult* result) { | 831 const WDTypedResult* result) { |
| 831 // Reset the load_handle so that we don't try and cancel the load in | 832 // Reset the load_handle so that we don't try and cancel the load in |
| 832 // the destructor. | 833 // the destructor. |
| 833 load_handle_ = 0; | 834 load_handle_ = 0; |
| 834 | 835 |
| 835 if (!result) { | 836 if (!result) { |
| 836 // Results are null if the database went away or (most likely) wasn't | 837 // Results are null if the database went away or (most likely) wasn't |
| 837 // loaded. | 838 // loaded. |
| 838 load_failed_ = true; | 839 load_failed_ = true; |
| 839 service_ = NULL; | 840 web_data_service_ = NULL; |
| 840 ChangeToLoadedState(); | 841 ChangeToLoadedState(); |
| 841 return; | 842 return; |
| 842 } | 843 } |
| 843 | 844 |
| 844 TemplateURLVector template_urls; | 845 TemplateURLVector template_urls; |
| 845 int new_resource_keyword_version = 0; | 846 int new_resource_keyword_version = 0; |
| 846 GetSearchProvidersUsingKeywordResult( | 847 GetSearchProvidersUsingKeywordResult( |
| 847 *result, | 848 *result, |
| 848 service_.get(), | 849 web_data_service_.get(), |
| 849 prefs_, | 850 prefs_, |
| 850 &template_urls, | 851 &template_urls, |
| 851 (default_search_provider_source_ == DefaultSearchManager::FROM_USER) ? | 852 (default_search_provider_source_ == DefaultSearchManager::FROM_USER) ? |
| 852 initial_default_search_provider_.get() : NULL, | 853 initial_default_search_provider_.get() : NULL, |
| 853 search_terms_data(), | 854 search_terms_data(), |
| 854 &new_resource_keyword_version, | 855 &new_resource_keyword_version, |
| 855 &pre_sync_deletes_); | 856 &pre_sync_deletes_); |
| 856 | 857 |
| 857 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 858 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 858 | 859 |
| 859 PatchMissingSyncGUIDs(&template_urls); | 860 PatchMissingSyncGUIDs(&template_urls); |
| 860 SetTemplateURLs(&template_urls); | 861 SetTemplateURLs(&template_urls); |
| 861 | 862 |
| 862 // This initializes provider_map_ which should be done before | 863 // This initializes provider_map_ which should be done before |
| 863 // calling UpdateKeywordSearchTermsForURL. | 864 // calling UpdateKeywordSearchTermsForURL. |
| 864 // This also calls NotifyObservers. | 865 // This also calls NotifyObservers. |
| 865 ChangeToLoadedState(); | 866 ChangeToLoadedState(); |
| 866 | 867 |
| 867 // Index any visits that occurred before we finished loading. | 868 // Index any visits that occurred before we finished loading. |
| 868 for (size_t i = 0; i < visits_to_add_.size(); ++i) | 869 for (size_t i = 0; i < visits_to_add_.size(); ++i) |
| 869 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); | 870 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); |
| 870 visits_to_add_.clear(); | 871 visits_to_add_.clear(); |
| 871 | 872 |
| 872 if (new_resource_keyword_version) | 873 if (new_resource_keyword_version) |
| 873 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); | 874 web_data_service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
| 874 | 875 |
| 875 if (default_search_provider_) { | 876 if (default_search_provider_) { |
| 876 UMA_HISTOGRAM_ENUMERATION( | 877 UMA_HISTOGRAM_ENUMERATION( |
| 877 "Search.DefaultSearchProviderType", | 878 "Search.DefaultSearchProviderType", |
| 878 TemplateURLPrepopulateData::GetEngineType( | 879 TemplateURLPrepopulateData::GetEngineType( |
| 879 *default_search_provider_, search_terms_data()), | 880 *default_search_provider_, search_terms_data()), |
| 880 SEARCH_ENGINE_MAX); | 881 SEARCH_ENGINE_MAX); |
| 881 | 882 |
| 882 if (rappor_service_) { | 883 if (rappor_service_) { |
| 883 rappor_service_->RecordSample( | 884 rappor_service_->RecordSample( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 912 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED); | 913 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED); |
| 913 content::Details<history::URLVisitedDetails> visit_details(details); | 914 content::Details<history::URLVisitedDetails> visit_details(details); |
| 914 if (!loaded_) | 915 if (!loaded_) |
| 915 visits_to_add_.push_back(*visit_details.ptr()); | 916 visits_to_add_.push_back(*visit_details.ptr()); |
| 916 else | 917 else |
| 917 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); | 918 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); |
| 918 } | 919 } |
| 919 | 920 |
| 920 void TemplateURLService::Shutdown() { | 921 void TemplateURLService::Shutdown() { |
| 921 // This check has to be done at Shutdown() instead of in the dtor to ensure | 922 // This check has to be done at Shutdown() instead of in the dtor to ensure |
| 922 // that no clients of WebDataService are holding ptrs to it after the first | 923 // that no clients of KeywordWebDataService are holding ptrs to it after the |
| 923 // phase of the KeyedService Shutdown() process. | 924 // first phase of the KeyedService Shutdown() process. |
| 924 if (load_handle_) { | 925 if (load_handle_) { |
| 925 DCHECK(service_.get()); | 926 DCHECK(web_data_service_.get()); |
| 926 service_->CancelRequest(load_handle_); | 927 web_data_service_->CancelRequest(load_handle_); |
| 927 } | 928 } |
| 928 service_ = NULL; | 929 web_data_service_ = NULL; |
| 929 } | 930 } |
| 930 | 931 |
| 931 syncer::SyncDataList TemplateURLService::GetAllSyncData( | 932 syncer::SyncDataList TemplateURLService::GetAllSyncData( |
| 932 syncer::ModelType type) const { | 933 syncer::ModelType type) const { |
| 933 DCHECK_EQ(syncer::SEARCH_ENGINES, type); | 934 DCHECK_EQ(syncer::SEARCH_ENGINES, type); |
| 934 | 935 |
| 935 syncer::SyncDataList current_data; | 936 syncer::SyncDataList current_data; |
| 936 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); | 937 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); |
| 937 iter != template_urls_.end(); ++iter) { | 938 iter != template_urls_.end(); ++iter) { |
| 938 // We don't sync keywords managed by policy. | 939 // We don't sync keywords managed by policy. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 960 DCHECK(loaded_); | 961 DCHECK(loaded_); |
| 961 | 962 |
| 962 base::AutoReset<bool> processing_changes(&processing_syncer_changes_, true); | 963 base::AutoReset<bool> processing_changes(&processing_syncer_changes_, true); |
| 963 | 964 |
| 964 // We've started syncing, so set our origin member to the base Sync value. | 965 // We've started syncing, so set our origin member to the base Sync value. |
| 965 // As we move through Sync Code, we may set this to increasingly specific | 966 // As we move through Sync Code, we may set this to increasingly specific |
| 966 // origins so we can tell what exactly caused a DSP change. | 967 // origins so we can tell what exactly caused a DSP change. |
| 967 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, | 968 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
| 968 DSP_CHANGE_SYNC_UNINTENTIONAL); | 969 DSP_CHANGE_SYNC_UNINTENTIONAL); |
| 969 | 970 |
| 970 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 971 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 971 | 972 |
| 972 syncer::SyncChangeList new_changes; | 973 syncer::SyncChangeList new_changes; |
| 973 syncer::SyncError error; | 974 syncer::SyncError error; |
| 974 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); | 975 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); |
| 975 iter != change_list.end(); ++iter) { | 976 iter != change_list.end(); ++iter) { |
| 976 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); | 977 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); |
| 977 | 978 |
| 978 std::string guid = | 979 std::string guid = |
| 979 iter->sync_data().GetSpecifics().search_engine().sync_guid(); | 980 iter->sync_data().GetSpecifics().search_engine().sync_guid(); |
| 980 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); | 981 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, | 1120 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
| 1120 DSP_CHANGE_SYNC_UNINTENTIONAL); | 1121 DSP_CHANGE_SYNC_UNINTENTIONAL); |
| 1121 | 1122 |
| 1122 syncer::SyncChangeList new_changes; | 1123 syncer::SyncChangeList new_changes; |
| 1123 | 1124 |
| 1124 // Build maps of our sync GUIDs to syncer::SyncData. | 1125 // Build maps of our sync GUIDs to syncer::SyncData. |
| 1125 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( | 1126 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( |
| 1126 GetAllSyncData(syncer::SEARCH_ENGINES)); | 1127 GetAllSyncData(syncer::SEARCH_ENGINES)); |
| 1127 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); | 1128 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); |
| 1128 | 1129 |
| 1129 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1130 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 1130 | 1131 |
| 1131 merge_result.set_num_items_before_association(local_data_map.size()); | 1132 merge_result.set_num_items_before_association(local_data_map.size()); |
| 1132 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); | 1133 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); |
| 1133 iter != sync_data_map.end(); ++iter) { | 1134 iter != sync_data_map.end(); ++iter) { |
| 1134 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); | 1135 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); |
| 1135 scoped_ptr<TemplateURL> sync_turl( | 1136 scoped_ptr<TemplateURL> sync_turl( |
| 1136 CreateTemplateURLFromTemplateURLAndSyncData( | 1137 CreateTemplateURLFromTemplateURLAndSyncData( |
| 1137 prefs_, search_terms_data(), local_turl, iter->second, | 1138 prefs_, search_terms_data(), local_turl, iter->second, |
| 1138 &new_changes)); | 1139 &new_changes)); |
| 1139 if (!sync_turl.get()) | 1140 if (!sync_turl.get()) |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 TemplateURLData* dse = | 1453 TemplateURLData* dse = |
| 1453 default_search_manager_.GetDefaultSearchEngine(&source); | 1454 default_search_manager_.GetDefaultSearchEngine(&source); |
| 1454 ApplyDefaultSearchChange(dse, source); | 1455 ApplyDefaultSearchChange(dse, source); |
| 1455 | 1456 |
| 1456 if (num_initializers > 0) { | 1457 if (num_initializers > 0) { |
| 1457 // This path is only hit by test code and is used to simulate a loaded | 1458 // This path is only hit by test code and is used to simulate a loaded |
| 1458 // TemplateURLService. | 1459 // TemplateURLService. |
| 1459 ChangeToLoadedState(); | 1460 ChangeToLoadedState(); |
| 1460 | 1461 |
| 1461 // Add specific initializers, if any. | 1462 // Add specific initializers, if any. |
| 1462 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1463 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 1463 for (int i(0); i < num_initializers; ++i) { | 1464 for (int i(0); i < num_initializers; ++i) { |
| 1464 DCHECK(initializers[i].keyword); | 1465 DCHECK(initializers[i].keyword); |
| 1465 DCHECK(initializers[i].url); | 1466 DCHECK(initializers[i].url); |
| 1466 DCHECK(initializers[i].content); | 1467 DCHECK(initializers[i].content); |
| 1467 | 1468 |
| 1468 // TemplateURLService ends up owning the TemplateURL, don't try and free | 1469 // TemplateURLService ends up owning the TemplateURL, don't try and free |
| 1469 // it. | 1470 // it. |
| 1470 TemplateURLData data; | 1471 TemplateURLData data; |
| 1471 data.short_name = base::UTF8ToUTF16(initializers[i].content); | 1472 data.short_name = base::UTF8ToUTF16(initializers[i].content); |
| 1472 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); | 1473 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 RemoveNoNotify(existing_keyword_turl); | 1692 RemoveNoNotify(existing_keyword_turl); |
| 1692 } else { | 1693 } else { |
| 1693 existing_turl->data_.SetKeyword(old_keyword); | 1694 existing_turl->data_.SetKeyword(old_keyword); |
| 1694 keyword_to_template_map_[old_keyword] = existing_turl; | 1695 keyword_to_template_map_[old_keyword] = existing_turl; |
| 1695 } | 1696 } |
| 1696 } | 1697 } |
| 1697 } | 1698 } |
| 1698 if (!existing_turl->sync_guid().empty()) | 1699 if (!existing_turl->sync_guid().empty()) |
| 1699 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; | 1700 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; |
| 1700 | 1701 |
| 1701 if (service_) | 1702 if (web_data_service_) |
| 1702 service_->UpdateKeyword(existing_turl->data()); | 1703 web_data_service_->UpdateKeyword(existing_turl->data()); |
| 1703 | 1704 |
| 1704 // Inform sync of the update. | 1705 // Inform sync of the update. |
| 1705 ProcessTemplateURLChange( | 1706 ProcessTemplateURLChange( |
| 1706 FROM_HERE, existing_turl, syncer::SyncChange::ACTION_UPDATE); | 1707 FROM_HERE, existing_turl, syncer::SyncChange::ACTION_UPDATE); |
| 1707 | 1708 |
| 1708 if (default_search_provider_ == existing_turl && | 1709 if (default_search_provider_ == existing_turl && |
| 1709 default_search_provider_source_ == DefaultSearchManager::FROM_USER) { | 1710 default_search_provider_source_ == DefaultSearchManager::FROM_USER) { |
| 1710 default_search_manager_.SetUserSelectedDefaultSearchEngine( | 1711 default_search_manager_.SetUserSelectedDefaultSearchEngine( |
| 1711 default_search_provider_->data()); | 1712 default_search_provider_->data()); |
| 1712 } | 1713 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1795 | 1796 |
| 1796 // Synthesize a visit for the keyword. This ensures the url for the keyword is | 1797 // Synthesize a visit for the keyword. This ensures the url for the keyword is |
| 1797 // autocompleted even if the user doesn't type the url in directly. | 1798 // autocompleted even if the user doesn't type the url in directly. |
| 1798 history->AddPage(url, base::Time::Now(), NULL, 0, GURL(), | 1799 history->AddPage(url, base::Time::Now(), NULL, 0, GURL(), |
| 1799 history::RedirectList(), | 1800 history::RedirectList(), |
| 1800 content::PAGE_TRANSITION_KEYWORD_GENERATED, | 1801 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
| 1801 history::SOURCE_BROWSED, false); | 1802 history::SOURCE_BROWSED, false); |
| 1802 } | 1803 } |
| 1803 | 1804 |
| 1804 void TemplateURLService::GoogleBaseURLChanged() { | 1805 void TemplateURLService::GoogleBaseURLChanged() { |
| 1805 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1806 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 1806 bool something_changed = false; | 1807 bool something_changed = false; |
| 1807 for (TemplateURLVector::iterator i(template_urls_.begin()); | 1808 for (TemplateURLVector::iterator i(template_urls_.begin()); |
| 1808 i != template_urls_.end(); ++i) { | 1809 i != template_urls_.end(); ++i) { |
| 1809 TemplateURL* t_url = *i; | 1810 TemplateURL* t_url = *i; |
| 1810 if (t_url->HasGoogleBaseURLs(search_terms_data())) { | 1811 if (t_url->HasGoogleBaseURLs(search_terms_data())) { |
| 1811 TemplateURL updated_turl(t_url->data()); | 1812 TemplateURL updated_turl(t_url->data()); |
| 1812 updated_turl.ResetKeywordIfNecessary(search_terms_data(), false); | 1813 updated_turl.ResetKeywordIfNecessary(search_terms_data(), false); |
| 1813 KeywordToTemplateMap::const_iterator existing_entry = | 1814 KeywordToTemplateMap::const_iterator existing_entry = |
| 1814 keyword_to_template_map_.find(updated_turl.keyword()); | 1815 keyword_to_template_map_.find(updated_turl.keyword()); |
| 1815 if ((existing_entry != keyword_to_template_map_.end()) && | 1816 if ((existing_entry != keyword_to_template_map_.end()) && |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 // NULL due to policy. We'll never actually get recursion with data == NULL. | 1893 // NULL due to policy. We'll never actually get recursion with data == NULL. |
| 1893 if (source == default_search_provider_source_ && data != NULL && | 1894 if (source == default_search_provider_source_ && data != NULL && |
| 1894 TemplateURL::MatchesData(default_search_provider_, data, | 1895 TemplateURL::MatchesData(default_search_provider_, data, |
| 1895 search_terms_data())) | 1896 search_terms_data())) |
| 1896 return false; | 1897 return false; |
| 1897 | 1898 |
| 1898 // This may be deleted later. Use exclusively for pointer comparison to detect | 1899 // This may be deleted later. Use exclusively for pointer comparison to detect |
| 1899 // a change. | 1900 // a change. |
| 1900 TemplateURL* previous_default_search_engine = default_search_provider_; | 1901 TemplateURL* previous_default_search_engine = default_search_provider_; |
| 1901 | 1902 |
| 1902 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1903 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| 1903 if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || | 1904 if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || |
| 1904 source == DefaultSearchManager::FROM_POLICY) { | 1905 source == DefaultSearchManager::FROM_POLICY) { |
| 1905 // We do this both to remove any no-longer-applicable policy-defined DSE as | 1906 // We do this both to remove any no-longer-applicable policy-defined DSE as |
| 1906 // well as to add the new one, if appropriate. | 1907 // well as to add the new one, if appropriate. |
| 1907 UpdateProvidersCreatedByPolicy( | 1908 UpdateProvidersCreatedByPolicy( |
| 1908 &template_urls_, | 1909 &template_urls_, |
| 1909 source == DefaultSearchManager::FROM_POLICY ? data : NULL); | 1910 source == DefaultSearchManager::FROM_POLICY ? data : NULL); |
| 1910 } | 1911 } |
| 1911 | 1912 |
| 1912 if (!data) { | 1913 if (!data) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 existing_keyword_turl->short_name(), new_keyword, | 2023 existing_keyword_turl->short_name(), new_keyword, |
| 2023 existing_keyword_turl->url()); | 2024 existing_keyword_turl->url()); |
| 2024 } | 2025 } |
| 2025 } | 2026 } |
| 2026 template_urls_.push_back(template_url); | 2027 template_urls_.push_back(template_url); |
| 2027 AddToMaps(template_url); | 2028 AddToMaps(template_url); |
| 2028 | 2029 |
| 2029 if (newly_adding && | 2030 if (newly_adding && |
| 2030 (template_url->GetType() != | 2031 (template_url->GetType() != |
| 2031 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { | 2032 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { |
| 2032 if (service_) | 2033 if (web_data_service_) |
| 2033 service_->AddKeyword(template_url->data()); | 2034 web_data_service_->AddKeyword(template_url->data()); |
| 2034 | 2035 |
| 2035 // Inform sync of the addition. Note that this will assign a GUID to | 2036 // Inform sync of the addition. Note that this will assign a GUID to |
| 2036 // template_url and add it to the guid_to_template_map_. | 2037 // template_url and add it to the guid_to_template_map_. |
| 2037 ProcessTemplateURLChange(FROM_HERE, | 2038 ProcessTemplateURLChange(FROM_HERE, |
| 2038 template_url, | 2039 template_url, |
| 2039 syncer::SyncChange::ACTION_ADD); | 2040 syncer::SyncChange::ACTION_ADD); |
| 2040 } | 2041 } |
| 2041 | 2042 |
| 2042 return true; | 2043 return true; |
| 2043 } | 2044 } |
| 2044 | 2045 |
| 2045 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { | 2046 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { |
| 2046 DCHECK(template_url != default_search_provider_); | 2047 DCHECK(template_url != default_search_provider_); |
| 2047 | 2048 |
| 2048 TemplateURLVector::iterator i = | 2049 TemplateURLVector::iterator i = |
| 2049 std::find(template_urls_.begin(), template_urls_.end(), template_url); | 2050 std::find(template_urls_.begin(), template_urls_.end(), template_url); |
| 2050 if (i == template_urls_.end()) | 2051 if (i == template_urls_.end()) |
| 2051 return; | 2052 return; |
| 2052 | 2053 |
| 2053 RemoveFromMaps(template_url); | 2054 RemoveFromMaps(template_url); |
| 2054 | 2055 |
| 2055 // Remove it from the vector containing all TemplateURLs. | 2056 // Remove it from the vector containing all TemplateURLs. |
| 2056 template_urls_.erase(i); | 2057 template_urls_.erase(i); |
| 2057 | 2058 |
| 2058 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { | 2059 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { |
| 2059 if (service_) | 2060 if (web_data_service_) |
| 2060 service_->RemoveKeyword(template_url->id()); | 2061 web_data_service_->RemoveKeyword(template_url->id()); |
| 2061 | 2062 |
| 2062 // Inform sync of the deletion. | 2063 // Inform sync of the deletion. |
| 2063 ProcessTemplateURLChange(FROM_HERE, | 2064 ProcessTemplateURLChange(FROM_HERE, |
| 2064 template_url, | 2065 template_url, |
| 2065 syncer::SyncChange::ACTION_DELETE); | 2066 syncer::SyncChange::ACTION_DELETE); |
| 2066 | 2067 |
| 2067 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, | 2068 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, |
| 2068 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); | 2069 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); |
| 2069 } | 2070 } |
| 2070 | 2071 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2132 // database and the |default_search_provider|. | 2133 // database and the |default_search_provider|. |
| 2133 default_search_provider_ = template_url; | 2134 default_search_provider_ = template_url; |
| 2134 // Prevent us from saving any other entries, or creating a new one. | 2135 // Prevent us from saving any other entries, or creating a new one. |
| 2135 default_from_prefs = NULL; | 2136 default_from_prefs = NULL; |
| 2136 ++i; | 2137 ++i; |
| 2137 continue; | 2138 continue; |
| 2138 } | 2139 } |
| 2139 | 2140 |
| 2140 RemoveFromMaps(template_url); | 2141 RemoveFromMaps(template_url); |
| 2141 i = template_urls->erase(i); | 2142 i = template_urls->erase(i); |
| 2142 if (service_) | 2143 if (web_data_service_) |
| 2143 service_->RemoveKeyword(template_url->id()); | 2144 web_data_service_->RemoveKeyword(template_url->id()); |
| 2144 delete template_url; | 2145 delete template_url; |
| 2145 } else { | 2146 } else { |
| 2146 ++i; | 2147 ++i; |
| 2147 } | 2148 } |
| 2148 } | 2149 } |
| 2149 | 2150 |
| 2150 if (default_from_prefs) { | 2151 if (default_from_prefs) { |
| 2151 default_search_provider_ = NULL; | 2152 default_search_provider_ = NULL; |
| 2152 default_search_provider_source_ = DefaultSearchManager::FROM_POLICY; | 2153 default_search_provider_source_ = DefaultSearchManager::FROM_POLICY; |
| 2153 TemplateURLData new_data(*default_from_prefs); | 2154 TemplateURLData new_data(*default_from_prefs); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2325 TemplateURLVector* template_urls) { | 2326 TemplateURLVector* template_urls) { |
| 2326 DCHECK(template_urls); | 2327 DCHECK(template_urls); |
| 2327 for (TemplateURLVector::iterator i = template_urls->begin(); | 2328 for (TemplateURLVector::iterator i = template_urls->begin(); |
| 2328 i != template_urls->end(); ++i) { | 2329 i != template_urls->end(); ++i) { |
| 2329 TemplateURL* template_url = *i; | 2330 TemplateURL* template_url = *i; |
| 2330 DCHECK(template_url); | 2331 DCHECK(template_url); |
| 2331 if (template_url->sync_guid().empty() && | 2332 if (template_url->sync_guid().empty() && |
| 2332 (template_url->GetType() != | 2333 (template_url->GetType() != |
| 2333 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { | 2334 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { |
| 2334 template_url->data_.sync_guid = base::GenerateGUID(); | 2335 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2335 if (service_) | 2336 if (web_data_service_) |
| 2336 service_->UpdateKeyword(template_url->data()); | 2337 web_data_service_->UpdateKeyword(template_url->data()); |
| 2337 } | 2338 } |
| 2338 } | 2339 } |
| 2339 } | 2340 } |
| 2340 | 2341 |
| 2341 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { | 2342 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { |
| 2342 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2343 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2343 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); | 2344 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); |
| 2344 | 2345 |
| 2345 std::string new_guid = | 2346 std::string new_guid = |
| 2346 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID); | 2347 prefs_->GetString(prefs::kSyncedDefaultSearchProviderGUID); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 | 2406 |
| 2406 if (most_recently_intalled_default) { | 2407 if (most_recently_intalled_default) { |
| 2407 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2408 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2408 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2409 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2409 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2410 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2410 most_recently_intalled_default->data()); | 2411 most_recently_intalled_default->data()); |
| 2411 } else { | 2412 } else { |
| 2412 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2413 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2413 } | 2414 } |
| 2414 } | 2415 } |
| OLD | NEW |