Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/browser/google/google_url_tracker_factory.h" | 26 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 27 #include "chrome/browser/history/history_service.h" | 27 #include "chrome/browser/history/history_service.h" |
| 28 #include "chrome/browser/history/history_service_factory.h" | 28 #include "chrome/browser/history/history_service_factory.h" |
| 29 #include "chrome/browser/metrics/rappor/sampling.h" | 29 #include "chrome/browser/metrics/rappor/sampling.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/rlz/rlz.h" | 31 #include "chrome/browser/rlz/rlz.h" |
| 32 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 32 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
| 33 #include "chrome/browser/search_engines/template_url_service_observer.h" | 33 #include "chrome/browser/search_engines/template_url_service_observer.h" |
| 34 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 34 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 35 #include "chrome/browser/search_engines/util.h" | 35 #include "chrome/browser/search_engines/util.h" |
| 36 #include "chrome/browser/webdata/web_data_service.h" | 36 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 37 #include "chrome/common/env_vars.h" | 37 #include "chrome/common/env_vars.h" |
| 38 #include "components/search_engines/search_engines_pref_names.h" | 38 #include "components/search_engines/search_engines_pref_names.h" |
| 39 #include "components/search_engines/template_url.h" | 39 #include "components/search_engines/template_url.h" |
| 40 #include "components/search_engines/template_url_prepopulate_data.h" | 40 #include "components/search_engines/template_url_prepopulate_data.h" |
| 41 #include "components/url_fixer/url_fixer.h" | 41 #include "components/url_fixer/url_fixer.h" |
| 42 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| 43 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
| 44 #include "sync/api/sync_change.h" | 44 #include "sync/api/sync_change.h" |
| 45 #include "sync/api/sync_error_factory.h" | 45 #include "sync/api/sync_error_factory.h" |
| 46 #include "sync/protocol/search_engine_specifics.pb.h" | 46 #include "sync/protocol/search_engine_specifics.pb.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 } | 236 } |
| 237 | 237 |
| 238 TemplateURLService::TemplateURLService(const Initializer* initializers, | 238 TemplateURLService::TemplateURLService(const Initializer* initializers, |
| 239 const int count) | 239 const int count) |
| 240 : provider_map_(new SearchHostToURLsMap), | 240 : provider_map_(new SearchHostToURLsMap), |
| 241 profile_(NULL), | 241 profile_(NULL), |
| 242 search_terms_data_(new UIThreadSearchTermsData(NULL)), | 242 search_terms_data_(new UIThreadSearchTermsData(NULL)), |
| 243 loaded_(false), | 243 loaded_(false), |
| 244 load_failed_(false), | 244 load_failed_(false), |
| 245 load_handle_(0), | 245 load_handle_(0), |
| 246 service_(NULL), | |
| 247 default_search_provider_(NULL), | 246 default_search_provider_(NULL), |
| 248 next_id_(kInvalidTemplateURLID + 1), | 247 next_id_(kInvalidTemplateURLID + 1), |
| 249 time_provider_(&base::Time::Now), | 248 time_provider_(&base::Time::Now), |
| 250 models_associated_(false), | 249 models_associated_(false), |
| 251 processing_syncer_changes_(false), | 250 processing_syncer_changes_(false), |
| 252 dsp_change_origin_(DSP_CHANGE_OTHER), | 251 dsp_change_origin_(DSP_CHANGE_OTHER), |
| 253 default_search_manager_( | 252 default_search_manager_( |
| 254 GetPrefs(), | 253 GetPrefs(), |
| 255 base::Bind(&TemplateURLService::OnDefaultSearchChange, | 254 base::Bind(&TemplateURLService::OnDefaultSearchChange, |
| 256 base::Unretained(this))) { | 255 base::Unretained(this))) { |
| 257 Init(initializers, count); | 256 Init(initializers, count); |
| 258 } | 257 } |
| 259 | 258 |
| 260 TemplateURLService::~TemplateURLService() { | 259 TemplateURLService::~TemplateURLService() { |
| 261 // |service_| should be deleted during Shutdown(). | 260 // |web_data_service_| should be deleted during Shutdown(). |
| 262 DCHECK(!service_); | 261 DCHECK(!web_data_service_); |
| 263 STLDeleteElements(&template_urls_); | 262 STLDeleteElements(&template_urls_); |
| 264 } | 263 } |
| 265 | 264 |
| 266 // static | 265 // static |
| 267 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( | 266 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( |
| 268 PrefService* prefs, | 267 PrefService* prefs, |
| 269 scoped_ptr<TemplateURLData>* default_provider_data, | 268 scoped_ptr<TemplateURLData>* default_provider_data, |
| 270 bool* is_managed) { | 269 bool* is_managed) { |
| 271 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL) || | 270 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL) || |
| 272 !prefs->HasPrefPath(prefs::kDefaultSearchProviderKeyword)) | 271 !prefs->HasPrefPath(prefs::kDefaultSearchProviderKeyword)) |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 if (loaded_) | 553 if (loaded_) |
| 555 return provider_map_->GetTemplateURLForHost(host); | 554 return provider_map_->GetTemplateURLForHost(host); |
| 556 TemplateURL* initial_dsp = initial_default_search_provider_.get(); | 555 TemplateURL* initial_dsp = initial_default_search_provider_.get(); |
| 557 if (!initial_dsp) | 556 if (!initial_dsp) |
| 558 return NULL; | 557 return NULL; |
| 559 return (initial_dsp->GenerateSearchURL(search_terms_data()).host() == host) ? | 558 return (initial_dsp->GenerateSearchURL(search_terms_data()).host() == host) ? |
| 560 initial_dsp : NULL; | 559 initial_dsp : NULL; |
| 561 } | 560 } |
| 562 | 561 |
| 563 bool TemplateURLService::Add(TemplateURL* template_url) { | 562 bool TemplateURLService::Add(TemplateURL* template_url) { |
| 564 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 563 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
|
Peter Kasting
2014/06/30 22:50:01
Nit: If you rename KeywordBatchModeScoper to Batch
hashimoto
2014/07/01 01:06:50
Sounds good.
Done.
Also renamed KeywordWebDataSer
| |
| 564 web_data_service_.get()); | |
| 565 if (!AddNoNotify(template_url, true)) | 565 if (!AddNoNotify(template_url, true)) |
| 566 return false; | 566 return false; |
| 567 NotifyObservers(); | 567 NotifyObservers(); |
| 568 return true; | 568 return true; |
| 569 } | 569 } |
| 570 | 570 |
| 571 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, | 571 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, |
| 572 const base::string16& short_name, | 572 const base::string16& short_name, |
| 573 const base::string16& keyword, | 573 const base::string16& keyword, |
| 574 const std::string& url) { | 574 const std::string& url) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 586 DCHECK(loaded_); | 586 DCHECK(loaded_); |
| 587 DCHECK(template_url); | 587 DCHECK(template_url); |
| 588 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); | 588 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); |
| 589 DCHECK(info); | 589 DCHECK(info); |
| 590 DCHECK_NE(TemplateURL::NORMAL, info->type); | 590 DCHECK_NE(TemplateURL::NORMAL, info->type); |
| 591 DCHECK_EQ(info->wants_to_be_default_engine, | 591 DCHECK_EQ(info->wants_to_be_default_engine, |
| 592 template_url->show_in_default_list()); | 592 template_url->show_in_default_list()); |
| 593 DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); | 593 DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); |
| 594 template_url->extension_info_.swap(info); | 594 template_url->extension_info_.swap(info); |
| 595 | 595 |
| 596 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 596 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 597 web_data_service_.get()); | |
| 597 if (AddNoNotify(template_url, true)) { | 598 if (AddNoNotify(template_url, true)) { |
| 598 if (template_url->extension_info_->wants_to_be_default_engine) | 599 if (template_url->extension_info_->wants_to_be_default_engine) |
| 599 UpdateExtensionDefaultSearchEngine(); | 600 UpdateExtensionDefaultSearchEngine(); |
| 600 NotifyObservers(); | 601 NotifyObservers(); |
| 601 } | 602 } |
| 602 } | 603 } |
| 603 | 604 |
| 604 void TemplateURLService::Remove(TemplateURL* template_url) { | 605 void TemplateURLService::Remove(TemplateURL* template_url) { |
| 605 RemoveNoNotify(template_url); | 606 RemoveNoNotify(template_url); |
| 606 NotifyObservers(); | 607 NotifyObservers(); |
| 607 } | 608 } |
| 608 | 609 |
| 609 void TemplateURLService::RemoveExtensionControlledTURL( | 610 void TemplateURLService::RemoveExtensionControlledTURL( |
| 610 const std::string& extension_id, | 611 const std::string& extension_id, |
| 611 TemplateURL::Type type) { | 612 TemplateURL::Type type) { |
| 612 DCHECK(loaded_); | 613 DCHECK(loaded_); |
| 613 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); | 614 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); |
| 614 if (!url) | 615 if (!url) |
| 615 return; | 616 return; |
| 616 // NULL this out so that we can call RemoveNoNotify. | 617 // NULL this out so that we can call RemoveNoNotify. |
| 617 // UpdateExtensionDefaultSearchEngine will cause it to be reset. | 618 // UpdateExtensionDefaultSearchEngine will cause it to be reset. |
| 618 if (default_search_provider_ == url) | 619 if (default_search_provider_ == url) |
| 619 default_search_provider_ = NULL; | 620 default_search_provider_ = NULL; |
| 620 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 621 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 622 web_data_service_.get()); | |
| 621 RemoveNoNotify(url); | 623 RemoveNoNotify(url); |
| 622 UpdateExtensionDefaultSearchEngine(); | 624 UpdateExtensionDefaultSearchEngine(); |
| 623 NotifyObservers(); | 625 NotifyObservers(); |
| 624 } | 626 } |
| 625 | 627 |
| 626 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { | 628 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { |
| 627 RemoveAutoGeneratedBetween(created_after, base::Time()); | 629 RemoveAutoGeneratedBetween(created_after, base::Time()); |
| 628 } | 630 } |
| 629 | 631 |
| 630 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, | 632 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, |
| 631 base::Time created_before) { | 633 base::Time created_before) { |
| 632 RemoveAutoGeneratedForOriginBetween(GURL(), created_after, created_before); | 634 RemoveAutoGeneratedForOriginBetween(GURL(), created_after, created_before); |
| 633 } | 635 } |
| 634 | 636 |
| 635 void TemplateURLService::RemoveAutoGeneratedForOriginBetween( | 637 void TemplateURLService::RemoveAutoGeneratedForOriginBetween( |
| 636 const GURL& origin, | 638 const GURL& origin, |
| 637 base::Time created_after, | 639 base::Time created_after, |
| 638 base::Time created_before) { | 640 base::Time created_before) { |
| 639 GURL o(origin.GetOrigin()); | 641 GURL o(origin.GetOrigin()); |
| 640 bool should_notify = false; | 642 bool should_notify = false; |
| 641 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 643 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 644 web_data_service_.get()); | |
| 642 for (size_t i = 0; i < template_urls_.size();) { | 645 for (size_t i = 0; i < template_urls_.size();) { |
| 643 if (template_urls_[i]->date_created() >= created_after && | 646 if (template_urls_[i]->date_created() >= created_after && |
| 644 (created_before.is_null() || | 647 (created_before.is_null() || |
| 645 template_urls_[i]->date_created() < created_before) && | 648 template_urls_[i]->date_created() < created_before) && |
| 646 CanReplace(template_urls_[i]) && | 649 CanReplace(template_urls_[i]) && |
| 647 (o.is_empty() || | 650 (o.is_empty() || |
| 648 template_urls_[i]->GenerateSearchURL( | 651 template_urls_[i]->GenerateSearchURL( |
| 649 search_terms_data()).GetOrigin() == o)) { | 652 search_terms_data()).GetOrigin() == o)) { |
| 650 RemoveNoNotify(template_urls_[i]); | 653 RemoveNoNotify(template_urls_[i]); |
| 651 should_notify = true; | 654 should_notify = true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { | 689 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { |
| 687 DCHECK(url); | 690 DCHECK(url); |
| 688 // Extension-controlled search engines are not persisted. | 691 // Extension-controlled search engines are not persisted. |
| 689 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) | 692 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) |
| 690 return; | 693 return; |
| 691 if (std::find(template_urls_.begin(), template_urls_.end(), url) == | 694 if (std::find(template_urls_.begin(), template_urls_.end(), url) == |
| 692 template_urls_.end()) | 695 template_urls_.end()) |
| 693 return; | 696 return; |
| 694 ++url->data_.usage_count; | 697 ++url->data_.usage_count; |
| 695 | 698 |
| 696 if (service_) | 699 if (web_data_service_) |
| 697 service_->UpdateKeyword(url->data()); | 700 web_data_service_->UpdateKeyword(url->data()); |
| 698 } | 701 } |
| 699 | 702 |
| 700 void TemplateURLService::ResetTemplateURL(TemplateURL* url, | 703 void TemplateURLService::ResetTemplateURL(TemplateURL* url, |
| 701 const base::string16& title, | 704 const base::string16& title, |
| 702 const base::string16& keyword, | 705 const base::string16& keyword, |
| 703 const std::string& search_url) { | 706 const std::string& search_url) { |
| 704 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) | 707 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) |
| 705 NotifyObservers(); | 708 NotifyObservers(); |
| 706 } | 709 } |
| 707 | 710 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 } | 772 } |
| 770 | 773 |
| 771 size_t default_search_provider_index = 0; | 774 size_t default_search_provider_index = 0; |
| 772 ScopedVector<TemplateURLData> prepopulated_urls = | 775 ScopedVector<TemplateURLData> prepopulated_urls = |
| 773 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 776 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 774 GetPrefs(), &default_search_provider_index); | 777 GetPrefs(), &default_search_provider_index); |
| 775 DCHECK(!prepopulated_urls.empty()); | 778 DCHECK(!prepopulated_urls.empty()); |
| 776 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( | 779 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
| 777 &prepopulated_urls, template_urls_, default_search_provider_)); | 780 &prepopulated_urls, template_urls_, default_search_provider_)); |
| 778 | 781 |
| 779 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 782 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 783 web_data_service_.get()); | |
| 780 | 784 |
| 781 // Remove items. | 785 // Remove items. |
| 782 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); | 786 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); |
| 783 i < actions.removed_engines.end(); ++i) | 787 i < actions.removed_engines.end(); ++i) |
| 784 RemoveNoNotify(*i); | 788 RemoveNoNotify(*i); |
| 785 | 789 |
| 786 // Edit items. | 790 // Edit items. |
| 787 for (EditedEngines::iterator i(actions.edited_engines.begin()); | 791 for (EditedEngines::iterator i(actions.edited_engines.begin()); |
| 788 i < actions.edited_engines.end(); ++i) { | 792 i < actions.edited_engines.end(); ++i) { |
| 789 UIThreadSearchTermsData search_terms_data(profile()); | 793 UIThreadSearchTermsData search_terms_data(profile()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 } | 829 } |
| 826 | 830 |
| 827 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { | 831 void TemplateURLService::RemoveObserver(TemplateURLServiceObserver* observer) { |
| 828 model_observers_.RemoveObserver(observer); | 832 model_observers_.RemoveObserver(observer); |
| 829 } | 833 } |
| 830 | 834 |
| 831 void TemplateURLService::Load() { | 835 void TemplateURLService::Load() { |
| 832 if (loaded_ || load_handle_) | 836 if (loaded_ || load_handle_) |
| 833 return; | 837 return; |
| 834 | 838 |
| 835 if (!service_) | 839 if (!web_data_service_) { |
| 836 service_ = WebDataService::FromBrowserContext(profile_); | 840 web_data_service_ = WebDataServiceFactory::GetKeywordWebDataForProfile( |
| 841 profile_, Profile::EXPLICIT_ACCESS); | |
| 842 } | |
| 837 | 843 |
| 838 if (service_) | 844 if (web_data_service_) |
| 839 load_handle_ = service_->GetKeywords(this); | 845 load_handle_ = web_data_service_->GetKeywords(this); |
| 840 else | 846 else |
| 841 ChangeToLoadedState(); | 847 ChangeToLoadedState(); |
| 842 } | 848 } |
| 843 | 849 |
| 844 scoped_ptr<TemplateURLService::Subscription> | 850 scoped_ptr<TemplateURLService::Subscription> |
| 845 TemplateURLService::RegisterOnLoadedCallback( | 851 TemplateURLService::RegisterOnLoadedCallback( |
| 846 const base::Closure& callback) { | 852 const base::Closure& callback) { |
| 847 return loaded_ ? | 853 return loaded_ ? |
| 848 scoped_ptr<TemplateURLService::Subscription>() : | 854 scoped_ptr<TemplateURLService::Subscription>() : |
| 849 on_loaded_callbacks_.Add(callback); | 855 on_loaded_callbacks_.Add(callback); |
| 850 } | 856 } |
| 851 | 857 |
| 852 void TemplateURLService::OnWebDataServiceRequestDone( | 858 void TemplateURLService::OnWebDataServiceRequestDone( |
| 853 WebDataService::Handle h, | 859 KeywordWebDataService::Handle h, |
| 854 const WDTypedResult* result) { | 860 const WDTypedResult* result) { |
| 855 // Reset the load_handle so that we don't try and cancel the load in | 861 // Reset the load_handle so that we don't try and cancel the load in |
| 856 // the destructor. | 862 // the destructor. |
| 857 load_handle_ = 0; | 863 load_handle_ = 0; |
| 858 | 864 |
| 859 if (!result) { | 865 if (!result) { |
| 860 // Results are null if the database went away or (most likely) wasn't | 866 // Results are null if the database went away or (most likely) wasn't |
| 861 // loaded. | 867 // loaded. |
| 862 load_failed_ = true; | 868 load_failed_ = true; |
| 863 service_ = NULL; | 869 web_data_service_ = NULL; |
| 864 ChangeToLoadedState(); | 870 ChangeToLoadedState(); |
| 865 return; | 871 return; |
| 866 } | 872 } |
| 867 | 873 |
| 868 TemplateURLVector template_urls; | 874 TemplateURLVector template_urls; |
| 869 int new_resource_keyword_version = 0; | 875 int new_resource_keyword_version = 0; |
| 870 GetSearchProvidersUsingKeywordResult( | 876 GetSearchProvidersUsingKeywordResult( |
| 871 *result, | 877 *result, |
| 872 service_.get(), | 878 web_data_service_.get(), |
| 873 GetPrefs(), | 879 GetPrefs(), |
| 874 &template_urls, | 880 &template_urls, |
| 875 (default_search_provider_source_ == DefaultSearchManager::FROM_USER) ? | 881 (default_search_provider_source_ == DefaultSearchManager::FROM_USER) ? |
| 876 initial_default_search_provider_.get() : NULL, | 882 initial_default_search_provider_.get() : NULL, |
| 877 search_terms_data(), | 883 search_terms_data(), |
| 878 &new_resource_keyword_version, | 884 &new_resource_keyword_version, |
| 879 &pre_sync_deletes_); | 885 &pre_sync_deletes_); |
| 880 | 886 |
| 881 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 887 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 888 web_data_service_.get()); | |
| 882 | 889 |
| 883 PatchMissingSyncGUIDs(&template_urls); | 890 PatchMissingSyncGUIDs(&template_urls); |
| 884 SetTemplateURLs(&template_urls); | 891 SetTemplateURLs(&template_urls); |
| 885 | 892 |
| 886 // This initializes provider_map_ which should be done before | 893 // This initializes provider_map_ which should be done before |
| 887 // calling UpdateKeywordSearchTermsForURL. | 894 // calling UpdateKeywordSearchTermsForURL. |
| 888 // This also calls NotifyObservers. | 895 // This also calls NotifyObservers. |
| 889 ChangeToLoadedState(); | 896 ChangeToLoadedState(); |
| 890 | 897 |
| 891 // Index any visits that occurred before we finished loading. | 898 // Index any visits that occurred before we finished loading. |
| 892 for (size_t i = 0; i < visits_to_add_.size(); ++i) | 899 for (size_t i = 0; i < visits_to_add_.size(); ++i) |
| 893 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); | 900 UpdateKeywordSearchTermsForURL(visits_to_add_[i]); |
| 894 visits_to_add_.clear(); | 901 visits_to_add_.clear(); |
| 895 | 902 |
| 896 if (new_resource_keyword_version) | 903 if (new_resource_keyword_version) |
| 897 service_->SetBuiltinKeywordVersion(new_resource_keyword_version); | 904 web_data_service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
| 898 | 905 |
| 899 if (default_search_provider_) { | 906 if (default_search_provider_) { |
| 900 UMA_HISTOGRAM_ENUMERATION( | 907 UMA_HISTOGRAM_ENUMERATION( |
| 901 "Search.DefaultSearchProviderType", | 908 "Search.DefaultSearchProviderType", |
| 902 TemplateURLPrepopulateData::GetEngineType( | 909 TemplateURLPrepopulateData::GetEngineType( |
| 903 *default_search_provider_, search_terms_data()), | 910 *default_search_provider_, search_terms_data()), |
| 904 SEARCH_ENGINE_MAX); | 911 SEARCH_ENGINE_MAX); |
| 905 rappor::SampleDomainAndRegistryFromHost( | 912 rappor::SampleDomainAndRegistryFromHost( |
| 906 "Search.DefaultSearchProvider", | 913 "Search.DefaultSearchProvider", |
| 907 default_search_provider_->url_ref().GetHost(search_terms_data())); | 914 default_search_provider_->url_ref().GetHost(search_terms_data())); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 930 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED); | 937 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED); |
| 931 content::Details<history::URLVisitedDetails> visit_details(details); | 938 content::Details<history::URLVisitedDetails> visit_details(details); |
| 932 if (!loaded_) | 939 if (!loaded_) |
| 933 visits_to_add_.push_back(*visit_details.ptr()); | 940 visits_to_add_.push_back(*visit_details.ptr()); |
| 934 else | 941 else |
| 935 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); | 942 UpdateKeywordSearchTermsForURL(*visit_details.ptr()); |
| 936 } | 943 } |
| 937 | 944 |
| 938 void TemplateURLService::Shutdown() { | 945 void TemplateURLService::Shutdown() { |
| 939 // This check has to be done at Shutdown() instead of in the dtor to ensure | 946 // This check has to be done at Shutdown() instead of in the dtor to ensure |
| 940 // that no clients of WebDataService are holding ptrs to it after the first | 947 // that no clients of KeywordWebDataService are holding ptrs to it after the |
| 941 // phase of the KeyedService Shutdown() process. | 948 // first phase of the KeyedService Shutdown() process. |
| 942 if (load_handle_) { | 949 if (load_handle_) { |
| 943 DCHECK(service_.get()); | 950 DCHECK(web_data_service_.get()); |
| 944 service_->CancelRequest(load_handle_); | 951 web_data_service_->CancelRequest(load_handle_); |
| 945 } | 952 } |
| 946 service_ = NULL; | 953 web_data_service_ = NULL; |
| 947 } | 954 } |
| 948 | 955 |
| 949 syncer::SyncDataList TemplateURLService::GetAllSyncData( | 956 syncer::SyncDataList TemplateURLService::GetAllSyncData( |
| 950 syncer::ModelType type) const { | 957 syncer::ModelType type) const { |
| 951 DCHECK_EQ(syncer::SEARCH_ENGINES, type); | 958 DCHECK_EQ(syncer::SEARCH_ENGINES, type); |
| 952 | 959 |
| 953 syncer::SyncDataList current_data; | 960 syncer::SyncDataList current_data; |
| 954 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); | 961 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); |
| 955 iter != template_urls_.end(); ++iter) { | 962 iter != template_urls_.end(); ++iter) { |
| 956 // We don't sync keywords managed by policy. | 963 // We don't sync keywords managed by policy. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 978 DCHECK(loaded_); | 985 DCHECK(loaded_); |
| 979 | 986 |
| 980 base::AutoReset<bool> processing_changes(&processing_syncer_changes_, true); | 987 base::AutoReset<bool> processing_changes(&processing_syncer_changes_, true); |
| 981 | 988 |
| 982 // We've started syncing, so set our origin member to the base Sync value. | 989 // We've started syncing, so set our origin member to the base Sync value. |
| 983 // As we move through Sync Code, we may set this to increasingly specific | 990 // As we move through Sync Code, we may set this to increasingly specific |
| 984 // origins so we can tell what exactly caused a DSP change. | 991 // origins so we can tell what exactly caused a DSP change. |
| 985 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, | 992 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
| 986 DSP_CHANGE_SYNC_UNINTENTIONAL); | 993 DSP_CHANGE_SYNC_UNINTENTIONAL); |
| 987 | 994 |
| 988 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 995 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 996 web_data_service_.get()); | |
| 989 | 997 |
| 990 syncer::SyncChangeList new_changes; | 998 syncer::SyncChangeList new_changes; |
| 991 syncer::SyncError error; | 999 syncer::SyncError error; |
| 992 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); | 1000 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); |
| 993 iter != change_list.end(); ++iter) { | 1001 iter != change_list.end(); ++iter) { |
| 994 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); | 1002 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); |
| 995 | 1003 |
| 996 std::string guid = | 1004 std::string guid = |
| 997 iter->sync_data().GetSpecifics().search_engine().sync_guid(); | 1005 iter->sync_data().GetSpecifics().search_engine().sync_guid(); |
| 998 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); | 1006 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, | 1144 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
| 1137 DSP_CHANGE_SYNC_UNINTENTIONAL); | 1145 DSP_CHANGE_SYNC_UNINTENTIONAL); |
| 1138 | 1146 |
| 1139 syncer::SyncChangeList new_changes; | 1147 syncer::SyncChangeList new_changes; |
| 1140 | 1148 |
| 1141 // Build maps of our sync GUIDs to syncer::SyncData. | 1149 // Build maps of our sync GUIDs to syncer::SyncData. |
| 1142 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( | 1150 SyncDataMap local_data_map = CreateGUIDToSyncDataMap( |
| 1143 GetAllSyncData(syncer::SEARCH_ENGINES)); | 1151 GetAllSyncData(syncer::SEARCH_ENGINES)); |
| 1144 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); | 1152 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); |
| 1145 | 1153 |
| 1146 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1154 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 1155 web_data_service_.get()); | |
| 1147 | 1156 |
| 1148 merge_result.set_num_items_before_association(local_data_map.size()); | 1157 merge_result.set_num_items_before_association(local_data_map.size()); |
| 1149 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); | 1158 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); |
| 1150 iter != sync_data_map.end(); ++iter) { | 1159 iter != sync_data_map.end(); ++iter) { |
| 1151 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); | 1160 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); |
| 1152 scoped_ptr<TemplateURL> sync_turl( | 1161 scoped_ptr<TemplateURL> sync_turl( |
| 1153 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, | 1162 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, |
| 1154 iter->second, &new_changes)); | 1163 iter->second, &new_changes)); |
| 1155 if (!sync_turl.get()) | 1164 if (!sync_turl.get()) |
| 1156 continue; | 1165 continue; |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 TemplateURLData* dse = | 1477 TemplateURLData* dse = |
| 1469 default_search_manager_.GetDefaultSearchEngine(&source); | 1478 default_search_manager_.GetDefaultSearchEngine(&source); |
| 1470 ApplyDefaultSearchChange(dse, source); | 1479 ApplyDefaultSearchChange(dse, source); |
| 1471 | 1480 |
| 1472 if (num_initializers > 0) { | 1481 if (num_initializers > 0) { |
| 1473 // This path is only hit by test code and is used to simulate a loaded | 1482 // This path is only hit by test code and is used to simulate a loaded |
| 1474 // TemplateURLService. | 1483 // TemplateURLService. |
| 1475 ChangeToLoadedState(); | 1484 ChangeToLoadedState(); |
| 1476 | 1485 |
| 1477 // Add specific initializers, if any. | 1486 // Add specific initializers, if any. |
| 1478 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1487 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 1488 web_data_service_.get()); | |
| 1479 for (int i(0); i < num_initializers; ++i) { | 1489 for (int i(0); i < num_initializers; ++i) { |
| 1480 DCHECK(initializers[i].keyword); | 1490 DCHECK(initializers[i].keyword); |
| 1481 DCHECK(initializers[i].url); | 1491 DCHECK(initializers[i].url); |
| 1482 DCHECK(initializers[i].content); | 1492 DCHECK(initializers[i].content); |
| 1483 | 1493 |
| 1484 // TemplateURLService ends up owning the TemplateURL, don't try and free | 1494 // TemplateURLService ends up owning the TemplateURL, don't try and free |
| 1485 // it. | 1495 // it. |
| 1486 TemplateURLData data; | 1496 TemplateURLData data; |
| 1487 data.short_name = base::UTF8ToUTF16(initializers[i].content); | 1497 data.short_name = base::UTF8ToUTF16(initializers[i].content); |
| 1488 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); | 1498 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1716 RemoveNoNotify(existing_keyword_turl); | 1726 RemoveNoNotify(existing_keyword_turl); |
| 1717 } else { | 1727 } else { |
| 1718 existing_turl->data_.SetKeyword(old_keyword); | 1728 existing_turl->data_.SetKeyword(old_keyword); |
| 1719 keyword_to_template_map_[old_keyword] = existing_turl; | 1729 keyword_to_template_map_[old_keyword] = existing_turl; |
| 1720 } | 1730 } |
| 1721 } | 1731 } |
| 1722 } | 1732 } |
| 1723 if (!existing_turl->sync_guid().empty()) | 1733 if (!existing_turl->sync_guid().empty()) |
| 1724 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; | 1734 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; |
| 1725 | 1735 |
| 1726 if (service_) | 1736 if (web_data_service_) |
| 1727 service_->UpdateKeyword(existing_turl->data()); | 1737 web_data_service_->UpdateKeyword(existing_turl->data()); |
| 1728 | 1738 |
| 1729 // Inform sync of the update. | 1739 // Inform sync of the update. |
| 1730 ProcessTemplateURLChange( | 1740 ProcessTemplateURLChange( |
| 1731 FROM_HERE, existing_turl, syncer::SyncChange::ACTION_UPDATE); | 1741 FROM_HERE, existing_turl, syncer::SyncChange::ACTION_UPDATE); |
| 1732 | 1742 |
| 1733 if (default_search_provider_ == existing_turl && | 1743 if (default_search_provider_ == existing_turl && |
| 1734 default_search_provider_source_ == DefaultSearchManager::FROM_USER) { | 1744 default_search_provider_source_ == DefaultSearchManager::FROM_USER) { |
| 1735 default_search_manager_.SetUserSelectedDefaultSearchEngine( | 1745 default_search_manager_.SetUserSelectedDefaultSearchEngine( |
| 1736 default_search_provider_->data()); | 1746 default_search_provider_->data()); |
| 1737 } | 1747 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1824 | 1834 |
| 1825 // Synthesize a visit for the keyword. This ensures the url for the keyword is | 1835 // Synthesize a visit for the keyword. This ensures the url for the keyword is |
| 1826 // autocompleted even if the user doesn't type the url in directly. | 1836 // autocompleted even if the user doesn't type the url in directly. |
| 1827 history->AddPage(url, base::Time::Now(), NULL, 0, GURL(), | 1837 history->AddPage(url, base::Time::Now(), NULL, 0, GURL(), |
| 1828 history::RedirectList(), | 1838 history::RedirectList(), |
| 1829 content::PAGE_TRANSITION_KEYWORD_GENERATED, | 1839 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
| 1830 history::SOURCE_BROWSED, false); | 1840 history::SOURCE_BROWSED, false); |
| 1831 } | 1841 } |
| 1832 | 1842 |
| 1833 void TemplateURLService::GoogleBaseURLChanged(const GURL& old_base_url) { | 1843 void TemplateURLService::GoogleBaseURLChanged(const GURL& old_base_url) { |
| 1834 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1844 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 1845 web_data_service_.get()); | |
| 1835 bool something_changed = false; | 1846 bool something_changed = false; |
| 1836 for (TemplateURLVector::iterator i(template_urls_.begin()); | 1847 for (TemplateURLVector::iterator i(template_urls_.begin()); |
| 1837 i != template_urls_.end(); ++i) { | 1848 i != template_urls_.end(); ++i) { |
| 1838 TemplateURL* t_url = *i; | 1849 TemplateURL* t_url = *i; |
| 1839 if (t_url->HasGoogleBaseURLs(search_terms_data())) { | 1850 if (t_url->HasGoogleBaseURLs(search_terms_data())) { |
| 1840 TemplateURL updated_turl(t_url->data()); | 1851 TemplateURL updated_turl(t_url->data()); |
| 1841 updated_turl.ResetKeywordIfNecessary(search_terms_data(), false); | 1852 updated_turl.ResetKeywordIfNecessary(search_terms_data(), false); |
| 1842 KeywordToTemplateMap::const_iterator existing_entry = | 1853 KeywordToTemplateMap::const_iterator existing_entry = |
| 1843 keyword_to_template_map_.find(updated_turl.keyword()); | 1854 keyword_to_template_map_.find(updated_turl.keyword()); |
| 1844 if ((existing_entry != keyword_to_template_map_.end()) && | 1855 if ((existing_entry != keyword_to_template_map_.end()) && |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1923 // NULL due to policy. We'll never actually get recursion with data == NULL. | 1934 // NULL due to policy. We'll never actually get recursion with data == NULL. |
| 1924 if (source == default_search_provider_source_ && data != NULL && | 1935 if (source == default_search_provider_source_ && data != NULL && |
| 1925 TemplateURL::MatchesData(default_search_provider_, data, | 1936 TemplateURL::MatchesData(default_search_provider_, data, |
| 1926 search_terms_data())) | 1937 search_terms_data())) |
| 1927 return false; | 1938 return false; |
| 1928 | 1939 |
| 1929 // This may be deleted later. Use exclusively for pointer comparison to detect | 1940 // This may be deleted later. Use exclusively for pointer comparison to detect |
| 1930 // a change. | 1941 // a change. |
| 1931 TemplateURL* previous_default_search_engine = default_search_provider_; | 1942 TemplateURL* previous_default_search_engine = default_search_provider_; |
| 1932 | 1943 |
| 1933 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1944 KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
| 1945 web_data_service_.get()); | |
| 1934 if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || | 1946 if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || |
| 1935 source == DefaultSearchManager::FROM_POLICY) { | 1947 source == DefaultSearchManager::FROM_POLICY) { |
| 1936 // We do this both to remove any no-longer-applicable policy-defined DSE as | 1948 // We do this both to remove any no-longer-applicable policy-defined DSE as |
| 1937 // well as to add the new one, if appropriate. | 1949 // well as to add the new one, if appropriate. |
| 1938 UpdateProvidersCreatedByPolicy( | 1950 UpdateProvidersCreatedByPolicy( |
| 1939 &template_urls_, | 1951 &template_urls_, |
| 1940 source == DefaultSearchManager::FROM_POLICY ? data : NULL); | 1952 source == DefaultSearchManager::FROM_POLICY ? data : NULL); |
| 1941 } | 1953 } |
| 1942 | 1954 |
| 1943 if (!data) { | 1955 if (!data) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2058 existing_keyword_turl->short_name(), new_keyword, | 2070 existing_keyword_turl->short_name(), new_keyword, |
| 2059 existing_keyword_turl->url()); | 2071 existing_keyword_turl->url()); |
| 2060 } | 2072 } |
| 2061 } | 2073 } |
| 2062 template_urls_.push_back(template_url); | 2074 template_urls_.push_back(template_url); |
| 2063 AddToMaps(template_url); | 2075 AddToMaps(template_url); |
| 2064 | 2076 |
| 2065 if (newly_adding && | 2077 if (newly_adding && |
| 2066 (template_url->GetType() != | 2078 (template_url->GetType() != |
| 2067 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { | 2079 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { |
| 2068 if (service_) | 2080 if (web_data_service_) |
| 2069 service_->AddKeyword(template_url->data()); | 2081 web_data_service_->AddKeyword(template_url->data()); |
| 2070 | 2082 |
| 2071 // Inform sync of the addition. Note that this will assign a GUID to | 2083 // Inform sync of the addition. Note that this will assign a GUID to |
| 2072 // template_url and add it to the guid_to_template_map_. | 2084 // template_url and add it to the guid_to_template_map_. |
| 2073 ProcessTemplateURLChange(FROM_HERE, | 2085 ProcessTemplateURLChange(FROM_HERE, |
| 2074 template_url, | 2086 template_url, |
| 2075 syncer::SyncChange::ACTION_ADD); | 2087 syncer::SyncChange::ACTION_ADD); |
| 2076 } | 2088 } |
| 2077 | 2089 |
| 2078 return true; | 2090 return true; |
| 2079 } | 2091 } |
| 2080 | 2092 |
| 2081 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { | 2093 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { |
| 2082 DCHECK(template_url != default_search_provider_); | 2094 DCHECK(template_url != default_search_provider_); |
| 2083 | 2095 |
| 2084 TemplateURLVector::iterator i = | 2096 TemplateURLVector::iterator i = |
| 2085 std::find(template_urls_.begin(), template_urls_.end(), template_url); | 2097 std::find(template_urls_.begin(), template_urls_.end(), template_url); |
| 2086 if (i == template_urls_.end()) | 2098 if (i == template_urls_.end()) |
| 2087 return; | 2099 return; |
| 2088 | 2100 |
| 2089 RemoveFromMaps(template_url); | 2101 RemoveFromMaps(template_url); |
| 2090 | 2102 |
| 2091 // Remove it from the vector containing all TemplateURLs. | 2103 // Remove it from the vector containing all TemplateURLs. |
| 2092 template_urls_.erase(i); | 2104 template_urls_.erase(i); |
| 2093 | 2105 |
| 2094 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { | 2106 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { |
| 2095 if (service_) | 2107 if (web_data_service_) |
| 2096 service_->RemoveKeyword(template_url->id()); | 2108 web_data_service_->RemoveKeyword(template_url->id()); |
| 2097 | 2109 |
| 2098 // Inform sync of the deletion. | 2110 // Inform sync of the deletion. |
| 2099 ProcessTemplateURLChange(FROM_HERE, | 2111 ProcessTemplateURLChange(FROM_HERE, |
| 2100 template_url, | 2112 template_url, |
| 2101 syncer::SyncChange::ACTION_DELETE); | 2113 syncer::SyncChange::ACTION_DELETE); |
| 2102 | 2114 |
| 2103 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, | 2115 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, |
| 2104 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); | 2116 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); |
| 2105 } | 2117 } |
| 2106 | 2118 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2170 // database and the |default_search_provider|. | 2182 // database and the |default_search_provider|. |
| 2171 default_search_provider_ = template_url; | 2183 default_search_provider_ = template_url; |
| 2172 // Prevent us from saving any other entries, or creating a new one. | 2184 // Prevent us from saving any other entries, or creating a new one. |
| 2173 default_from_prefs = NULL; | 2185 default_from_prefs = NULL; |
| 2174 ++i; | 2186 ++i; |
| 2175 continue; | 2187 continue; |
| 2176 } | 2188 } |
| 2177 | 2189 |
| 2178 RemoveFromMaps(template_url); | 2190 RemoveFromMaps(template_url); |
| 2179 i = template_urls->erase(i); | 2191 i = template_urls->erase(i); |
| 2180 if (service_) | 2192 if (web_data_service_) |
| 2181 service_->RemoveKeyword(template_url->id()); | 2193 web_data_service_->RemoveKeyword(template_url->id()); |
| 2182 delete template_url; | 2194 delete template_url; |
| 2183 } else { | 2195 } else { |
| 2184 ++i; | 2196 ++i; |
| 2185 } | 2197 } |
| 2186 } | 2198 } |
| 2187 | 2199 |
| 2188 if (default_from_prefs) { | 2200 if (default_from_prefs) { |
| 2189 default_search_provider_ = NULL; | 2201 default_search_provider_ = NULL; |
| 2190 default_search_provider_source_ = DefaultSearchManager::FROM_POLICY; | 2202 default_search_provider_source_ = DefaultSearchManager::FROM_POLICY; |
| 2191 TemplateURLData new_data(*default_from_prefs); | 2203 TemplateURLData new_data(*default_from_prefs); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2364 TemplateURLVector* template_urls) { | 2376 TemplateURLVector* template_urls) { |
| 2365 DCHECK(template_urls); | 2377 DCHECK(template_urls); |
| 2366 for (TemplateURLVector::iterator i = template_urls->begin(); | 2378 for (TemplateURLVector::iterator i = template_urls->begin(); |
| 2367 i != template_urls->end(); ++i) { | 2379 i != template_urls->end(); ++i) { |
| 2368 TemplateURL* template_url = *i; | 2380 TemplateURL* template_url = *i; |
| 2369 DCHECK(template_url); | 2381 DCHECK(template_url); |
| 2370 if (template_url->sync_guid().empty() && | 2382 if (template_url->sync_guid().empty() && |
| 2371 (template_url->GetType() != | 2383 (template_url->GetType() != |
| 2372 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { | 2384 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { |
| 2373 template_url->data_.sync_guid = base::GenerateGUID(); | 2385 template_url->data_.sync_guid = base::GenerateGUID(); |
| 2374 if (service_) | 2386 if (web_data_service_) |
| 2375 service_->UpdateKeyword(template_url->data()); | 2387 web_data_service_->UpdateKeyword(template_url->data()); |
| 2376 } | 2388 } |
| 2377 } | 2389 } |
| 2378 } | 2390 } |
| 2379 | 2391 |
| 2380 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { | 2392 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { |
| 2381 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2393 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2382 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); | 2394 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); |
| 2383 | 2395 |
| 2384 std::string new_guid = | 2396 std::string new_guid = |
| 2385 GetPrefs()->GetString(prefs::kSyncedDefaultSearchProviderGUID); | 2397 GetPrefs()->GetString(prefs::kSyncedDefaultSearchProviderGUID); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2444 | 2456 |
| 2445 if (most_recently_intalled_default) { | 2457 if (most_recently_intalled_default) { |
| 2446 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2458 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2447 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2459 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2448 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2460 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2449 most_recently_intalled_default->data()); | 2461 most_recently_intalled_default->data()); |
| 2450 } else { | 2462 } else { |
| 2451 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2463 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2452 } | 2464 } |
| 2453 } | 2465 } |
| OLD | NEW |