diff options
Diffstat (limited to 'chrome/browser/search_engines')
14 files changed, 208 insertions, 208 deletions
diff --git a/chrome/browser/search_engines/search_host_to_urls_map.cc b/chrome/browser/search_engines/search_host_to_urls_map.cc index 57e1564..878d108 100644 --- a/chrome/browser/search_engines/search_host_to_urls_map.cc +++ b/chrome/browser/search_engines/search_host_to_urls_map.cc @@ -16,18 +16,14 @@ SearchHostToURLsMap::~SearchHostToURLsMap() { } void SearchHostToURLsMap::Init( - const std::vector<const TemplateURL*>& template_urls, + const TemplateURLService::TemplateURLVector& template_urls, const SearchTermsData& search_terms_data) { DCHECK(!initialized_); - - // Set as initialized here so Add doesn't assert. - initialized_ = true; - - for (size_t i = 0; i < template_urls.size(); ++i) - Add(template_urls[i], search_terms_data); + initialized_ = true; // Set here so Add doesn't assert. + Add(template_urls, search_terms_data); } -void SearchHostToURLsMap::Add(const TemplateURL* template_url, +void SearchHostToURLsMap::Add(TemplateURL* template_url, const SearchTermsData& search_terms_data) { DCHECK(initialized_); DCHECK(template_url); @@ -40,7 +36,7 @@ void SearchHostToURLsMap::Add(const TemplateURL* template_url, host_to_urls_map_[url.host()].insert(template_url); } -void SearchHostToURLsMap::Remove(const TemplateURL* template_url) { +void SearchHostToURLsMap::Remove(TemplateURL* template_url) { DCHECK(initialized_); DCHECK(template_url); @@ -64,7 +60,7 @@ void SearchHostToURLsMap::UpdateGoogleBaseURLs( DCHECK(initialized_); // Create a list of the the TemplateURLs to update. - std::vector<const TemplateURL*> t_urls_using_base_url; + TemplateURLService::TemplateURLVector t_urls_using_base_url; for (HostToURLsMap::iterator i(host_to_urls_map_.begin()); i != host_to_urls_map_.end(); ++i) { for (TemplateURLSet::const_iterator j(i->second.begin()); @@ -75,15 +71,15 @@ void SearchHostToURLsMap::UpdateGoogleBaseURLs( } } - for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) - RemoveByPointer(t_urls_using_base_url[i]); + for (TemplateURLService::TemplateURLVector::const_iterator i( + t_urls_using_base_url.begin()); i != t_urls_using_base_url.end(); ++i) + RemoveByPointer(*i); - for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) - Add(t_urls_using_base_url[i], search_terms_data); + Add(t_urls_using_base_url, search_terms_data); } -const TemplateURL* SearchHostToURLsMap::GetTemplateURLForHost( - const std::string& host) const { +TemplateURL* SearchHostToURLsMap::GetTemplateURLForHost( + const std::string& host) { DCHECK(initialized_); HostToURLsMap::const_iterator iter = host_to_urls_map_.find(host); @@ -92,18 +88,25 @@ const TemplateURL* SearchHostToURLsMap::GetTemplateURLForHost( return *(iter->second.begin()); // Return the 1st element. } -const SearchHostToURLsMap::TemplateURLSet* SearchHostToURLsMap::GetURLsForHost( - const std::string& host) const { +SearchHostToURLsMap::TemplateURLSet* SearchHostToURLsMap::GetURLsForHost( + const std::string& host) { DCHECK(initialized_); - HostToURLsMap::const_iterator urls_for_host = host_to_urls_map_.find(host); + HostToURLsMap::iterator urls_for_host = host_to_urls_map_.find(host); if (urls_for_host == host_to_urls_map_.end() || urls_for_host->second.empty()) return NULL; return &urls_for_host->second; } -void SearchHostToURLsMap::RemoveByPointer( - const TemplateURL* template_url) { +void SearchHostToURLsMap::Add( + const TemplateURLService::TemplateURLVector& template_urls, + const SearchTermsData& search_terms_data) { + for (TemplateURLService::TemplateURLVector::const_iterator i( + template_urls.begin()); i != template_urls.end(); ++i) + Add(*i, search_terms_data); +} + +void SearchHostToURLsMap::RemoveByPointer(TemplateURL* template_url) { for (HostToURLsMap::iterator i = host_to_urls_map_.begin(); i != host_to_urls_map_.end(); ++i) { TemplateURLSet::iterator url_set_iterator = i->second.find(template_url); diff --git a/chrome/browser/search_engines/search_host_to_urls_map.h b/chrome/browser/search_engines/search_host_to_urls_map.h index cd21a87..cdd31a5 100644 --- a/chrome/browser/search_engines/search_host_to_urls_map.h +++ b/chrome/browser/search_engines/search_host_to_urls_map.h @@ -9,55 +9,56 @@ #include <map> #include <set> #include <string> -#include <vector> #include "base/basictypes.h" - -class SearchTermsData; -class TemplateURL; +#include "chrome/browser/search_engines/template_url_service.h" // Holds the host to template url mappings for the search providers. WARNING: // This class does not own any TemplateURLs passed to it and it is up to the // caller to ensure the right lifetime of them. class SearchHostToURLsMap { public: - typedef std::set<const TemplateURL*> TemplateURLSet; + typedef std::set<TemplateURL*> TemplateURLSet; SearchHostToURLsMap(); ~SearchHostToURLsMap(); // Initializes the map. - void Init(const std::vector<const TemplateURL*>& template_urls, + void Init(const TemplateURLService::TemplateURLVector& template_urls, const SearchTermsData& search_terms_data); // Adds a new TemplateURL to the map. Since |template_url| is owned // externally, Remove or RemoveAll should be called if it becomes invalid. - void Add(const TemplateURL* template_url, + void Add(TemplateURL* template_url, const SearchTermsData& search_terms_data); // Removes the TemplateURL from the lookup. - void Remove(const TemplateURL* template_url); + void Remove(TemplateURL* template_url); // Updates all search providers which have a google base url. void UpdateGoogleBaseURLs(const SearchTermsData& search_terms_data); // Returns the first TemplateURL found with a URL using the specified |host|, // or NULL if there are no such TemplateURLs - const TemplateURL* GetTemplateURLForHost(const std::string& host) const; + TemplateURL* GetTemplateURLForHost(const std::string& host); // Return the TemplateURLSet for the given the |host| or NULL if there are // none. - const TemplateURLSet* GetURLsForHost(const std::string& host) const; + TemplateURLSet* GetURLsForHost(const std::string& host); private: friend class SearchHostToURLsMapTest; typedef std::map<std::string, TemplateURLSet> HostToURLsMap; + // Adds many URLs to the map. + void Add(const TemplateURLService::TemplateURLVector& template_urls, + const SearchTermsData& search_terms_data); + // Removes the given template_url using only the pointer instead of the value. // This is useful when the value may have changed before being updated in the // map. (Specifically when the GoogleBaseURLValue changes.) - void RemoveByPointer(const TemplateURL* template_url); + void RemoveByPointer(TemplateURL* template_url); // Maps from host to set of TemplateURLs whose search url host is host. HostToURLsMap host_to_urls_map_; diff --git a/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc b/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc index edbec3d..2a0aec0 100644 --- a/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc +++ b/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc @@ -34,7 +34,7 @@ void SearchHostToURLsMapTest::SetUp() { t_urls_[0].reset(new TemplateURL(NULL, data)); data.SetURL("http://" + host_ + "/path2"); t_urls_[1].reset(new TemplateURL(NULL, data)); - std::vector<const TemplateURL*> template_urls; + std::vector<TemplateURL*> template_urls; template_urls.push_back(t_urls_[0].get()); template_urls.push_back(t_urls_[1].get()); diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc index c3af1aa..defd639 100644 --- a/chrome/browser/search_engines/search_provider_install_data.cc +++ b/chrome/browser/search_engines/search_provider_install_data.cc @@ -141,7 +141,7 @@ void GoogleURLObserver::Observe(int type, // |requested_origin| should only be a security origin (no path, etc.). // It is ok if |template_url| is NULL. static bool IsSameOrigin(const GURL& requested_origin, - const TemplateURL* template_url, + TemplateURL* template_url, const SearchTermsData& search_terms_data) { DCHECK(requested_origin == requested_origin.GetOrigin()); return requested_origin == @@ -237,7 +237,7 @@ void SearchProviderInstallData::OnWebDataServiceRequestDone( return; } - const TemplateURL* default_search_provider = NULL; + TemplateURL* default_search_provider = NULL; int new_resource_keyword_version = 0; std::vector<TemplateURL*> extracted_template_urls; GetSearchProvidersUsingKeywordResult(*result, diff --git a/chrome/browser/search_engines/search_provider_install_data.h b/chrome/browser/search_engines/search_provider_install_data.h index bd03fd6..246f5a3 100644 --- a/chrome/browser/search_engines/search_provider_install_data.h +++ b/chrome/browser/search_engines/search_provider_install_data.h @@ -97,7 +97,7 @@ class SearchProviderInstallData : public WebDataServiceConsumer, scoped_ptr<SearchHostToURLsMap> provider_map_; // The list of template urls that are owned by the class. - ScopedVector<const TemplateURL> template_urls_; + ScopedVector<TemplateURL> template_urls_; // The security origin for the default search provider. std::string default_search_origin_; diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index b47696a..157fdc7 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -584,7 +584,7 @@ void TemplateURLData::SetKeyword(const string16& keyword) { autogenerate_keyword_ = false; } -const string16& TemplateURLData::keyword(const TemplateURL* t_url) const { +const string16& TemplateURLData::keyword(TemplateURL* t_url) const { EnsureKeyword(t_url); return keyword_; } @@ -597,7 +597,7 @@ void TemplateURLData::SetAutogenerateKeyword(bool autogenerate_keyword) { } } -void TemplateURLData::EnsureKeyword(const TemplateURL* t_url) const { +void TemplateURLData::EnsureKeyword(TemplateURL* t_url) const { if (autogenerate_keyword_ && !keyword_generated_) { // Generate a keyword and cache it. keyword_ = base::i18n::ToLower(TemplateURLService::GenerateKeyword( diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index a0d703a..d81a5b3 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -244,7 +244,7 @@ struct TemplateURLData { // The shortcut for this TemplateURL. May be empty. void SetKeyword(const string16& keyword); - const string16& keyword(const TemplateURL* t_url) const; + const string16& keyword(TemplateURL* t_url) const; // TODO(pkasting): This should only be necessary until we eliminate keyword // autogeneration. const string16& raw_keyword() const { return keyword_; } @@ -259,7 +259,7 @@ struct TemplateURLData { // Ensures that the keyword is generated. Most consumers should not need this // because it is done automatically. Use this method on the UI thread, so // the keyword may be accessed on another thread. - void EnsureKeyword(const TemplateURL* t_url) const; + void EnsureKeyword(TemplateURL* t_url) const; // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because // it requires substitutions first). This must be non-empty. @@ -376,11 +376,18 @@ class TemplateURL { // displayed even if it is LTR and the UI is RTL. string16 AdjustedShortNameForLocaleDirection() const; - const string16& keyword() const { return data_.keyword(this); } + const string16& keyword() const { + // TODO(pkasting): See comment on EnsureKeyword() below. + return data_.keyword(const_cast<TemplateURL*>(this)); + } bool autogenerate_keyword() const { return data_.autogenerate_keyword(); } - void EnsureKeyword() const { data_.EnsureKeyword(this); } + void EnsureKeyword() const { + // TODO(pkasting): EnsureKeyword() will die soon so it's not worth jumping + // through hoops to fix this const_cast<>(). + data_.EnsureKeyword(const_cast<TemplateURL*>(this)); + } const std::string& url() const { return data_.url(); } const std::string& suggestions_url() const { return data_.suggestions_url; } diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index 575fef3..fade852 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -182,7 +182,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { DCHECK(model); DCHECK(model->loaded()); - const TemplateURL* existing_url = NULL; + TemplateURL* existing_url = NULL; if (model->CanReplaceKeyword(keyword_, GURL(template_url_->url()), &existing_url)) { if (existing_url) diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index edabfec..7bdbe87 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -80,6 +80,16 @@ bool TemplateURLsHaveSamePrefs(const TemplateURL* url1, (url1->input_encodings() == url2->input_encodings()); } +TemplateURL* FirstPotentialDefaultEngine( + const TemplateURLService::TemplateURLVector& template_urls) { + for (TemplateURLService::TemplateURLVector::const_iterator i( + template_urls.begin()); i != template_urls.end(); ++i) { + if (!(*i)->IsExtensionKeyword() && (*i)->SupportsReplacement()) + return *i; + } + return NULL; +} + } // namespace @@ -106,7 +116,8 @@ class TemplateURLService::LessWithPrefix { }; TemplateURLService::TemplateURLService(Profile* profile) - : profile_(profile), + : provider_map_(new SearchHostToURLsMap), + profile_(profile), loaded_(false), load_failed_(false), load_handle_(0), @@ -123,7 +134,8 @@ TemplateURLService::TemplateURLService(Profile* profile) TemplateURLService::TemplateURLService(const Initializer* initializers, const int count) - : profile_(NULL), + : provider_map_(new SearchHostToURLsMap), + profile_(NULL), loaded_(false), load_failed_(false), load_handle_(0), @@ -208,7 +220,7 @@ string16 TemplateURLService::CleanUserInputKeyword(const string16& keyword) { } // static -GURL TemplateURLService::GenerateSearchURL(const TemplateURL* t_url) { +GURL TemplateURLService::GenerateSearchURL(TemplateURL* t_url) { DCHECK(t_url); UIThreadSearchTermsData search_terms_data; return GenerateSearchURLUsingTermsData(t_url, search_terms_data); @@ -236,11 +248,11 @@ GURL TemplateURLService::GenerateSearchURLUsingTermsData( bool TemplateURLService::CanReplaceKeyword( const string16& keyword, const GURL& url, - const TemplateURL** template_url_to_replace) { + TemplateURL** template_url_to_replace) { DCHECK(!keyword.empty()); // This should only be called for non-empty // keywords. If we need to support empty kewords // the code needs to change slightly. - const TemplateURL* existing_url = GetTemplateURLForKeyword(keyword); + TemplateURL* existing_url = GetTemplateURLForKeyword(keyword); if (template_url_to_replace) *template_url_to_replace = existing_url; if (existing_url) { @@ -269,7 +281,7 @@ void TemplateURLService::FindMatchingKeywords( DCHECK(matches->empty()); // The code for exact matches assumes this. // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/details/520043/error-converting-from-null-to-a-pointer-type-in-std-pair - const TemplateURL* const kNullTemplateURL = NULL; + TemplateURL* const kNullTemplateURL = NULL; // Find matching keyword range. Searches the element map for keywords // beginning with |prefix| and stores the endpoints of the resulting set in @@ -289,8 +301,8 @@ void TemplateURLService::FindMatchingKeywords( } } -const TemplateURL* TemplateURLService::GetTemplateURLForKeyword( - const string16& keyword) const { +TemplateURL* TemplateURLService::GetTemplateURLForKeyword( + const string16& keyword) { KeywordToTemplateMap::const_iterator elem( keyword_to_template_map_.find(keyword)); if (elem != keyword_to_template_map_.end()) @@ -300,8 +312,8 @@ const TemplateURL* TemplateURLService::GetTemplateURLForKeyword( initial_default_search_provider_.get() : NULL; } -const TemplateURL* TemplateURLService::GetTemplateURLForGUID( - const std::string& sync_guid) const { +TemplateURL* TemplateURLService::GetTemplateURLForGUID( + const std::string& sync_guid) { GUIDToTemplateMap::const_iterator elem( guid_to_template_map_.find(sync_guid)); if (elem != guid_to_template_map_.end()) @@ -311,9 +323,9 @@ const TemplateURL* TemplateURLService::GetTemplateURLForGUID( initial_default_search_provider_.get() : NULL; } -const TemplateURL* TemplateURLService::GetTemplateURLForHost( - const std::string& host) const { - const TemplateURL* t_url = provider_map_.GetTemplateURLForHost(host); +TemplateURL* TemplateURLService::GetTemplateURLForHost( + const std::string& host) { + TemplateURL* t_url = provider_map_->GetTemplateURLForHost(host); if (t_url) return t_url; return (initial_default_search_provider_.get() && @@ -332,19 +344,18 @@ void TemplateURLService::AddAndSetProfile(TemplateURL* template_url, Add(template_url); } -void TemplateURLService::AddWithOverrides(const TemplateURL* template_url, +void TemplateURLService::AddWithOverrides(TemplateURL* template_url, const string16& short_name, const string16& keyword, const std::string& url) { DCHECK(!url.empty()); - TemplateURL* modifiable_url = const_cast<TemplateURL*>(template_url); - modifiable_url->data_.short_name = short_name; - modifiable_url->data_.SetKeyword(keyword); - modifiable_url->SetURL(url); - Add(modifiable_url); + template_url->data_.short_name = short_name; + template_url->data_.SetKeyword(keyword); + template_url->SetURL(url); + Add(template_url); } -void TemplateURLService::Remove(const TemplateURL* template_url) { +void TemplateURLService::Remove(TemplateURL* template_url) { RemoveNoNotify(template_url); NotifyObservers(); } @@ -408,7 +419,7 @@ void TemplateURLService::RegisterExtensionKeyword(const Extension* extension) { void TemplateURLService::UnregisterExtensionKeyword( const Extension* extension) { if (loaded_) { - const TemplateURL* url = GetTemplateURLForExtension(extension); + TemplateURL* url = GetTemplateURLForExtension(extension); if (url) Remove(url); } else { @@ -419,8 +430,8 @@ void TemplateURLService::UnregisterExtensionKeyword( } } -const TemplateURL* TemplateURLService::GetTemplateURLForExtension( - const Extension* extension) const { +TemplateURL* TemplateURLService::GetTemplateURLForExtension( + const Extension* extension) { for (TemplateURLVector::const_iterator i = template_urls_.begin(); i != template_urls_.end(); ++i) { if ((*i)->IsExtensionKeyword() && @@ -431,15 +442,14 @@ const TemplateURL* TemplateURLService::GetTemplateURLForExtension( return NULL; } -TemplateURLService::TemplateURLVector - TemplateURLService::GetTemplateURLs() const { +TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { return template_urls_; } -void TemplateURLService::IncrementUsageCount(const TemplateURL* url) { +void TemplateURLService::IncrementUsageCount(TemplateURL* url) { DCHECK(url && std::find(template_urls_.begin(), template_urls_.end(), url) != template_urls_.end()); - ++const_cast<TemplateURL*>(url)->data_.usage_count; + ++url->data_.usage_count; // Extension keywords are not persisted. // TODO(mpcomplete): If we allow editing extension keywords, then those should // be persisted to disk and synced. @@ -447,7 +457,7 @@ void TemplateURLService::IncrementUsageCount(const TemplateURL* url) { service_.get()->UpdateKeyword(*url); } -void TemplateURLService::ResetTemplateURL(const TemplateURL* url, +void TemplateURLService::ResetTemplateURL(TemplateURL* url, const string16& title, const string16& keyword, const std::string& search_url) { @@ -462,7 +472,7 @@ void TemplateURLService::ResetTemplateURL(const TemplateURL* url, } data.safe_for_autoreplace = false; data.last_modified = time_provider_(); - TemplateURL new_url(const_cast<TemplateURL*>(url)->profile(), data); + TemplateURL new_url(url->profile(), data); UpdateNoNotify(url, new_url); NotifyObservers(); } @@ -472,7 +482,7 @@ bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { url->url_ref().SupportsReplacement() && !is_default_search_managed(); } -void TemplateURLService::SetDefaultSearchProvider(const TemplateURL* url) { +void TemplateURLService::SetDefaultSearchProvider(TemplateURL* url) { DCHECK(!is_default_search_managed_); // Extension keywords cannot be made default, as they are inherently async. DCHECK(!url || !url->IsExtensionKeyword()); @@ -483,7 +493,7 @@ void TemplateURLService::SetDefaultSearchProvider(const TemplateURL* url) { NotifyObservers(); } -const TemplateURL* TemplateURLService::GetDefaultSearchProvider() { +TemplateURL* TemplateURLService::GetDefaultSearchProvider() { if (loaded_ && !load_failed_) return default_search_provider_; @@ -491,7 +501,7 @@ const TemplateURL* TemplateURLService::GetDefaultSearchProvider() { return initial_default_search_provider_.get(); } -const TemplateURL* TemplateURLService::FindNewDefaultSearchProvider() { +TemplateURL* TemplateURLService::FindNewDefaultSearchProvider() { // See if the prepopulated default still exists. scoped_ptr<TemplateURL> prepopulated_default( TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(profile_)); @@ -502,12 +512,7 @@ const TemplateURL* TemplateURLService::FindNewDefaultSearchProvider() { } // If not, use the first non-extension keyword of the templates that supports // search term replacement. - for (TemplateURLVector::const_iterator i(template_urls_.begin()); - i != template_urls_.end(); ++i) { - if (!(*i)->IsExtensionKeyword() && (*i)->SupportsReplacement()) - return *i; - } - return NULL; + return FirstPotentialDefaultEngine(template_urls_); } void TemplateURLService::AddObserver(TemplateURLServiceObserver* observer) { @@ -554,8 +559,8 @@ void TemplateURLService::OnWebDataServiceRequestDone( initial_default_search_provider_.reset(); is_default_search_managed_ = false; - std::vector<TemplateURL*> template_urls; - const TemplateURL* default_search_provider = NULL; + TemplateURLVector template_urls; + TemplateURL* default_search_provider = NULL; int new_resource_keyword_version = 0; GetSearchProvidersUsingKeywordResult(*result, service_.get(), profile_, &template_urls, &default_search_provider, &new_resource_keyword_version); @@ -571,7 +576,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( // another program. No immediate action is performed because the default // search may be changed below by Sync which effectively undoes the hijacking. bool is_default_search_hijacked = false; - const TemplateURL* hijacked_default_search_provider = NULL; + TemplateURL* hijacked_default_search_provider = NULL; scoped_ptr<TemplateURL> backup_default_search_provider; // No check is required if the default search is managed. // |DidDefaultSearchProviderChange| must always be called because it will @@ -605,9 +610,8 @@ void TemplateURLService::OnWebDataServiceRequestDone( TemplateURLData data(default_from_prefs->data()); data.created_by_policy = true; data.id = kInvalidTemplateURLID; - TemplateURL* managed_default = new TemplateURL(profile_, data); - AddNoNotify(managed_default, true); - default_search_provider = managed_default; + default_search_provider = new TemplateURL(profile_, data); + AddNoNotify(default_search_provider, true); } } // Note that this saves the default search provider to prefs. @@ -618,19 +622,13 @@ void TemplateURLService::OnWebDataServiceRequestDone( } else { // If we had a managed default, replace it with the synced default if // applicable, or the first provider of the list. - const TemplateURL* synced_default = GetPendingSyncedDefaultSearchProvider(); + TemplateURL* synced_default = GetPendingSyncedDefaultSearchProvider(); if (synced_default) { default_search_provider = synced_default; pending_synced_default_search_ = false; } else if (database_specified_a_default && default_search_provider == NULL) { - for (std::vector<TemplateURL*>::const_iterator i = template_urls.begin(); - i != template_urls.end(); ++i) { - if (!(*i)->IsExtensionKeyword() && (*i)->SupportsReplacement()) { - default_search_provider = *i; - break; - } - } + default_search_provider = FirstPotentialDefaultEngine(template_urls); } // If the default search provider existed previously, then just @@ -746,7 +744,7 @@ void TemplateURLService::Observe(int type, DCHECK_EQ(std::string(prefs::kSyncedDefaultSearchProviderGUID), *content::Details<std::string>(details).ptr()); PrefService* prefs = GetPrefs(); - const TemplateURL* new_default_search = GetTemplateURLForGUID( + TemplateURL* new_default_search = GetTemplateURLForGUID( prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID)); if (new_default_search && !is_default_search_managed_) { if (new_default_search != GetDefaultSearchProvider()) { @@ -805,13 +803,13 @@ SyncError TemplateURLService::ProcessSyncChanges( std::string guid = iter->sync_data().GetSpecifics().search_engine().sync_guid(); - const TemplateURL* existing_turl = GetTemplateURLForGUID(guid); + TemplateURL* existing_turl = GetTemplateURLForGUID(guid); scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData( profile_, existing_turl, iter->sync_data(), &new_changes)); if (!turl.get()) continue; - const TemplateURL* existing_keyword_turl = + TemplateURL* existing_keyword_turl = GetTemplateURLForKeyword(turl->keyword()); if (iter->change_type() == SyncChange::ACTION_DELETE && existing_turl) { @@ -909,7 +907,7 @@ SyncError TemplateURLService::MergeDataAndStartSyncing( for (SyncDataMap::const_iterator iter = sync_data_map.begin(); iter != sync_data_map.end(); ++iter) { - const TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); + TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); scoped_ptr<TemplateURL> sync_turl( CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, iter->second, &new_changes)); @@ -939,12 +937,11 @@ SyncError TemplateURLService::MergeDataAndStartSyncing( // The search engine from the cloud has not been synced locally, but there // might be a local search engine that is a duplicate that needs to be // merged. - const TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); + TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); if (dupe_turl) { // Merge duplicates and remove the processed local TURL from the map. std::string old_guid = dupe_turl->sync_guid(); - MergeSyncAndLocalURLDuplicates(sync_turl.release(), - const_cast<TemplateURL*>(dupe_turl), + MergeSyncAndLocalURLDuplicates(sync_turl.release(), dupe_turl, &new_changes); local_data_map.erase(old_guid); } else { @@ -1046,7 +1043,7 @@ SyncData TemplateURLService::CreateSyncDataFromTemplateURL( // static TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( Profile* profile, - const TemplateURL* existing_turl, + TemplateURL* existing_turl, const SyncData& sync_data, SyncChangeList* change_list) { DCHECK(change_list); @@ -1169,7 +1166,7 @@ void TemplateURLService::Init(const Initializer* initializers, } } -void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) { +void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { if (!template_url->keyword().empty()) keyword_to_template_map_.erase(template_url->keyword()); @@ -1183,11 +1180,11 @@ void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) { if (!template_url->sync_guid().empty()) guid_to_template_map_.erase(template_url->sync_guid()); if (loaded_) - provider_map_.Remove(template_url); + provider_map_->Remove(template_url); } void TemplateURLService::RemoveFromKeywordMapByPointer( - const TemplateURL* template_url) { + TemplateURL* template_url) { DCHECK(template_url); for (KeywordToTemplateMap::iterator i = keyword_to_template_map_.begin(); i != keyword_to_template_map_.end(); ++i) { @@ -1200,7 +1197,7 @@ void TemplateURLService::RemoveFromKeywordMapByPointer( } } -void TemplateURLService::AddToMaps(const TemplateURL* template_url) { +void TemplateURLService::AddToMaps(TemplateURL* template_url) { if (!template_url->keyword().empty()) keyword_to_template_map_[template_url->keyword()] = template_url; @@ -1216,18 +1213,17 @@ void TemplateURLService::AddToMaps(const TemplateURL* template_url) { guid_to_template_map_[template_url->sync_guid()] = template_url; if (loaded_) { UIThreadSearchTermsData search_terms_data; - provider_map_.Add(template_url, search_terms_data); + provider_map_->Add(template_url, search_terms_data); } } -void TemplateURLService::SetTemplateURLs( - const std::vector<TemplateURL*>& urls) { +void TemplateURLService::SetTemplateURLs(const TemplateURLVector& urls) { // Add mappings for the new items. // First, add the items that already have id's, so that the next_id_ // gets properly set. - for (std::vector<TemplateURL*>::const_iterator i = urls.begin(); - i != urls.end(); ++i) { + for (TemplateURLVector::const_iterator i = urls.begin(); i != urls.end(); + ++i) { if ((*i)->id() != kInvalidTemplateURLID) { next_id_ = std::max(next_id_, (*i)->id()); AddNoNotify(*i, false); @@ -1235,8 +1231,8 @@ void TemplateURLService::SetTemplateURLs( } // Next add the new items that don't have id's. - for (std::vector<TemplateURL*>::const_iterator i = urls.begin(); - i != urls.end(); ++i) { + for (TemplateURLVector::const_iterator i = urls.begin(); i != urls.end(); + ++i) { if ((*i)->id() == kInvalidTemplateURLID) AddNoNotify(*i, true); } @@ -1246,7 +1242,7 @@ void TemplateURLService::ChangeToLoadedState() { DCHECK(!loaded_); UIThreadSearchTermsData search_terms_data; - provider_map_.Init(template_urls_, search_terms_data); + provider_map_->Init(template_urls_, search_terms_data); loaded_ = true; } @@ -1375,9 +1371,9 @@ bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( bool TemplateURLService::CanReplaceKeywordForHost( const std::string& host, - const TemplateURL** to_replace) { + TemplateURL** to_replace) { DCHECK(!to_replace || !*to_replace); - const TemplateURLSet* urls = provider_map_.GetURLsForHost(host); + const TemplateURLSet* urls = provider_map_->GetURLsForHost(host); if (!urls) return true; for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { @@ -1395,7 +1391,7 @@ bool TemplateURLService::CanReplace(const TemplateURL* t_url) { t_url->safe_for_autoreplace()); } -void TemplateURLService::UpdateNoNotify(const TemplateURL* existing_turl, +void TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, const TemplateURL& new_values) { DCHECK(loaded_); DCHECK(existing_turl); @@ -1413,13 +1409,12 @@ void TemplateURLService::UpdateNoNotify(const TemplateURL* existing_turl, if (!existing_turl->sync_guid().empty()) guid_to_template_map_.erase(existing_turl->sync_guid()); - provider_map_.Remove(existing_turl); + provider_map_->Remove(existing_turl); TemplateURLID previous_id = existing_turl->id(); - TemplateURL* modifiable_turl = const_cast<TemplateURL*>(existing_turl); - *modifiable_turl = new_values; - modifiable_turl->data_.id = previous_id; + *existing_turl = new_values; + existing_turl->data_.id = previous_id; UIThreadSearchTermsData search_terms_data; - provider_map_.Add(existing_turl, search_terms_data); + provider_map_->Add(existing_turl, search_terms_data); const string16& keyword = existing_turl->keyword(); if (!keyword.empty()) @@ -1450,7 +1445,7 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL( } const TemplateURLSet* urls_for_host = - provider_map_.GetURLsForHost(row.url().host()); + provider_map_->GetURLsForHost(row.url().host()); if (!urls_for_host) return; @@ -1562,7 +1557,7 @@ void TemplateURLService::GoogleBaseURLChanged() { bool something_changed = false; for (TemplateURLVector::iterator i(template_urls_.begin()); i != template_urls_.end(); ++i) { - TemplateURL* t_url = const_cast<TemplateURL*>(*i); + TemplateURL* t_url = *i; if (t_url->url_ref().HasGoogleBaseURLs() || t_url->suggestions_url_ref().HasGoogleBaseURLs()) { something_changed = true; @@ -1577,7 +1572,7 @@ void TemplateURLService::GoogleBaseURLChanged() { if (something_changed && loaded_) { UIThreadSearchTermsData search_terms_data; - provider_map_.UpdateGoogleBaseURLs(search_terms_data); + provider_map_->UpdateGoogleBaseURLs(search_terms_data); NotifyObservers(); } } @@ -1622,7 +1617,7 @@ void TemplateURLService::UpdateDefaultSearch() { // default_search_provider_ can't be NULL otherwise // TemplateURLsHaveSamePrefs would have returned true. Remove this now // invalid value. - const TemplateURL* old_default = default_search_provider_; + TemplateURL* old_default = default_search_provider_; SetDefaultSearchProviderNoNotify(NULL); RemoveNoNotify(old_default); } else if (default_search_provider_) { @@ -1660,14 +1655,14 @@ void TemplateURLService::UpdateDefaultSearch() { // and set a likely default. if ((default_search_provider_ != NULL) && default_search_provider_->created_by_policy()) { - const TemplateURL* old_default = default_search_provider_; + TemplateURL* old_default = default_search_provider_; default_search_provider_ = NULL; RemoveNoNotify(old_default); } // The likely default should be from Sync if we were waiting on Sync. // Otherwise, it should be FindNewDefaultSearchProvider. - const TemplateURL* synced_default = GetPendingSyncedDefaultSearchProvider(); + TemplateURL* synced_default = GetPendingSyncedDefaultSearchProvider(); if (synced_default) pending_synced_default_search_ = false; SetDefaultSearchProviderNoNotify(synced_default ? synced_default : @@ -1676,8 +1671,7 @@ void TemplateURLService::UpdateDefaultSearch() { NotifyObservers(); } -void TemplateURLService::SetDefaultSearchProviderNoNotify( - const TemplateURL* url) { +void TemplateURLService::SetDefaultSearchProviderNoNotify(TemplateURL* url) { if (url) { DCHECK(std::find(template_urls_.begin(), template_urls_.end(), url) != template_urls_.end()); @@ -1688,10 +1682,9 @@ void TemplateURLService::SetDefaultSearchProviderNoNotify( default_search_provider_ = url; if (url) { - TemplateURL* modifiable_url = const_cast<TemplateURL*>(url); // Don't mark the url as edited, otherwise we won't be able to rev the // template urls we ship with. - modifiable_url->data_.show_in_default_list = true; + url->data_.show_in_default_list = true; if (service_.get()) service_->UpdateKeyword(*url); @@ -1755,7 +1748,7 @@ void TemplateURLService::AddNoNotify(TemplateURL* template_url, } } -void TemplateURLService::RemoveNoNotify(const TemplateURL* template_url) { +void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { TemplateURLVector::iterator i = std::find(template_urls_.begin(), template_urls_.end(), template_url); if (i == template_urls_.end()) @@ -1811,12 +1804,12 @@ void TemplateURLService::NotifyObservers() { // that were set by policy, unless it is the current default search provider // and matches what is set by a managed preference. void TemplateURLService::RemoveProvidersCreatedByPolicy( - std::vector<TemplateURL*>* template_urls, - const TemplateURL** default_search_provider, - const TemplateURL* default_from_prefs) { + TemplateURLVector* template_urls, + TemplateURL** default_search_provider, + TemplateURL* default_from_prefs) { DCHECK(template_urls); DCHECK(default_search_provider); - for (std::vector<TemplateURL*>::iterator i = template_urls->begin(); + for (TemplateURLVector::iterator i = template_urls->begin(); i != template_urls->end(); ) { TemplateURL* template_url = *i; if (template_url->created_by_policy()) { @@ -1852,17 +1845,17 @@ void TemplateURLService::RemoveProvidersCreatedByPolicy( } } -void TemplateURLService::ResetTemplateURLGUID(const TemplateURL* url, +void TemplateURLService::ResetTemplateURLGUID(TemplateURL* url, const std::string& guid) { DCHECK(!guid.empty()); TemplateURLData data(url->data()); data.sync_guid = guid; - TemplateURL new_url(const_cast<TemplateURL*>(url)->profile(), data); + TemplateURL new_url(url->profile(), data); UpdateNoNotify(url, new_url); } -string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl) const { +string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl) { // Already unique. if (!GetTemplateURLForKeyword(turl.keyword())) return turl.keyword(); @@ -1893,7 +1886,7 @@ bool TemplateURLService::ResolveSyncKeywordConflict( DCHECK(sync_turl); DCHECK(change_list); - const TemplateURL* existing_turl = + TemplateURL* existing_turl = GetTemplateURLForKeyword(sync_turl->keyword()); // If there is no conflict, or it's just conflicting with itself, return. if (!existing_turl || existing_turl->sync_guid() == sync_turl->sync_guid()) @@ -1912,18 +1905,16 @@ bool TemplateURLService::ResolveSyncKeywordConflict( string16 new_keyword = UniquifyKeyword(*existing_turl); TemplateURLData data(existing_turl->data()); data.SetKeyword(new_keyword); - TemplateURL new_turl(const_cast<TemplateURL*>(existing_turl)->profile(), - data); + TemplateURL new_turl(existing_turl->profile(), data); UpdateNoNotify(existing_turl, new_turl); NotifyObservers(); } return true; } -const TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( +TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( const TemplateURL& sync_turl) { - const TemplateURL* existing_turl = - GetTemplateURLForKeyword(sync_turl.keyword()); + TemplateURL* existing_turl = GetTemplateURLForKeyword(sync_turl.keyword()); return existing_turl && (existing_turl->url() == sync_turl.url()) ? existing_turl : NULL; } @@ -1975,14 +1966,14 @@ void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( prefs->GetString(prefs::kSyncedDefaultSearchProviderGUID) == guid) { // Make sure this actually exists. We should not be calling this unless we // really just added this TemplateURL. - const TemplateURL* turl_from_sync = GetTemplateURLForGUID(guid); + TemplateURL* turl_from_sync = GetTemplateURLForGUID(guid); if (turl_from_sync && turl_from_sync->SupportsReplacement()) SetDefaultSearchProvider(turl_from_sync); pending_synced_default_search_ = false; } } -const TemplateURL* TemplateURLService::GetPendingSyncedDefaultSearchProvider() { +TemplateURL* TemplateURLService::GetPendingSyncedDefaultSearchProvider() { PrefService* prefs = GetPrefs(); if (!prefs || !pending_synced_default_search_) return NULL; @@ -1993,9 +1984,9 @@ const TemplateURL* TemplateURLService::GetPendingSyncedDefaultSearchProvider() { } void TemplateURLService::PatchMissingSyncGUIDs( - std::vector<TemplateURL*>* template_urls) { + TemplateURLVector* template_urls) { DCHECK(template_urls); - for (std::vector<TemplateURL*>::iterator i = template_urls->begin(); + for (TemplateURLVector::iterator i = template_urls->begin(); i != template_urls->end(); ++i) { TemplateURL* template_url = *i; DCHECK(template_url); diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h index 764df40..60618e204 100644 --- a/chrome/browser/search_engines/template_url_service.h +++ b/chrome/browser/search_engines/template_url_service.h @@ -17,7 +17,6 @@ #include "base/observer_list.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/profiles/profile_keyed_service.h" -#include "chrome/browser/search_engines/search_host_to_urls_map.h" #include "chrome/browser/search_engines/template_url_id.h" #include "chrome/browser/sync/api/sync_change.h" #include "chrome/browser/sync/api/syncable_service.h" @@ -66,7 +65,7 @@ class TemplateURLService : public WebDataServiceConsumer, public SyncableService { public: typedef std::map<std::string, std::string> QueryTerms; - typedef std::vector<const TemplateURL*> TemplateURLVector; + typedef std::vector<TemplateURL*> TemplateURLVector; // Type for a static function pointer that acts as a time source. typedef base::Time(TimeProvider)(); typedef std::map<std::string, SyncData> SyncDataMap; @@ -97,7 +96,9 @@ class TemplateURLService : public WebDataServiceConsumer, // Returns the search url for t_url. Returns an empty GURL if t_url has no // url(). - static GURL GenerateSearchURL(const TemplateURL* t_url); + // NOTE: |t_url| is non-const in this version because of the need to access + // t_url->profile(). + static GURL GenerateSearchURL(TemplateURL* t_url); // Just like GenerateSearchURL except that it takes SearchTermsData to supply // the data for some search terms. Most of the time GenerateSearchURL should @@ -115,7 +116,7 @@ class TemplateURLService : public WebDataServiceConsumer, // a TemplateURL for an existing TemplateURL that shares the same host. bool CanReplaceKeyword(const string16& keyword, const GURL& url, - const TemplateURL** template_url_to_replace); + TemplateURL** template_url_to_replace); // Returns (in |matches|) all keywords beginning with |prefix|, sorted // shortest-first. If support_replacement_only is true, only keywords that @@ -128,16 +129,16 @@ class TemplateURLService : public WebDataServiceConsumer, // the keyword was not found. // The caller should not try to delete the returned pointer; the data store // retains ownership of it. - const TemplateURL* GetTemplateURLForKeyword(const string16& keyword) const; + TemplateURL* GetTemplateURLForKeyword(const string16& keyword); // Returns that TemplateURL with the specified GUID, or NULL if not found. // The caller should not try to delete the returned pointer; the data store // retains ownership of it. - const TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid) const; + TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid); // Returns the first TemplateURL found with a URL using the specified |host|, // or NULL if there are no such TemplateURLs - const TemplateURL* GetTemplateURLForHost(const std::string& host) const; + TemplateURL* GetTemplateURLForHost(const std::string& host); // Takes ownership of |template_url| and adds it to this model. void Add(TemplateURL* template_url); @@ -145,14 +146,14 @@ class TemplateURLService : public WebDataServiceConsumer, // Like Add(), but overwrites the |template_url|'s values with the provided // ones. void AddAndSetProfile(TemplateURL* template_url, Profile* profile); - void AddWithOverrides(const TemplateURL* template_url, + void AddWithOverrides(TemplateURL* template_url, const string16& short_name, const string16& keyword, const std::string& url); // Removes the keyword from the model. This deletes the supplied TemplateURL. // This fails if the supplied template_url is the default search provider. - void Remove(const TemplateURL* template_url); + void Remove(TemplateURL* template_url); // Removes all auto-generated keywords that were created on or after the // date passed in. @@ -182,20 +183,19 @@ class TemplateURLService : public WebDataServiceConsumer, // Returns the TemplateURL associated with the keyword for this extension. // This works by checking the extension ID, not the keyword, so it will work // even if the user changed the keyword. - const TemplateURL* GetTemplateURLForExtension( - const Extension* extension) const; + TemplateURL* GetTemplateURLForExtension(const Extension* extension); // Returns the set of URLs describing the keywords. The elements are owned // by TemplateURLService and should not be deleted. - TemplateURLVector GetTemplateURLs() const; + TemplateURLVector GetTemplateURLs(); // Increment the usage count of a keyword. // Called when a URL is loaded that was generated from a keyword. - void IncrementUsageCount(const TemplateURL* url); + void IncrementUsageCount(TemplateURL* url); // Resets the title, keyword and search url of the specified TemplateURL. // The TemplateURL is marked as not replaceable. - void ResetTemplateURL(const TemplateURL* url, + void ResetTemplateURL(TemplateURL* url, const string16& title, const string16& keyword, const std::string& search_url); @@ -206,13 +206,13 @@ class TemplateURLService : public WebDataServiceConsumer, // Set the default search provider. |url| may be null. // This will assert if the default search is managed; the UI should not be // invoking this method in that situation. - void SetDefaultSearchProvider(const TemplateURL* url); + void SetDefaultSearchProvider(TemplateURL* url); // Returns the default search provider. If the TemplateURLService hasn't been // loaded, the default search provider is pulled from preferences. // // NOTE: At least in unittest mode, this may return NULL. - const TemplateURL* GetDefaultSearchProvider(); + TemplateURL* GetDefaultSearchProvider(); // Returns true if the default search is managed through group policy. bool is_default_search_managed() const { return is_default_search_managed_; } @@ -221,7 +221,7 @@ class TemplateURLService : public WebDataServiceConsumer, // exists. If not, returns first URL in |template_urls_|, or NULL if that's // empty. The returned object is owned by TemplateURLService and can be // destroyed at any time so should be used right after the call. - const TemplateURL* FindNewDefaultSearchProvider(); + TemplateURL* FindNewDefaultSearchProvider(); // Observers used to listen for changes to the model. // TemplateURLService does NOT delete the observers when deleted. @@ -310,7 +310,7 @@ class TemplateURLService : public WebDataServiceConsumer, // function returns NULL. static TemplateURL* CreateTemplateURLFromTemplateURLAndSyncData( Profile* profile, - const TemplateURL* existing_turl, + TemplateURL* existing_turl, const SyncData& sync_data, SyncChangeList* change_list); @@ -357,8 +357,8 @@ class TemplateURLService : public WebDataServiceConsumer, friend class TemplateURLServiceTestUtil; - typedef std::map<string16, const TemplateURL*> KeywordToTemplateMap; - typedef std::map<std::string, const TemplateURL*> GUIDToTemplateMap; + typedef std::map<string16, TemplateURL*> KeywordToTemplateMap; + typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; typedef std::list<std::string> PendingExtensionIDs; // Helper functor for FindMatchingKeywords(), for finding the range of @@ -367,18 +367,18 @@ class TemplateURLService : public WebDataServiceConsumer, void Init(const Initializer* initializers, int num_initializers); - void RemoveFromMaps(const TemplateURL* template_url); + void RemoveFromMaps(TemplateURL* template_url); // Removes the supplied template_url from the keyword maps. This searches // through all entries in the keyword map and does not generate the host or // keyword. This is used when the cached content of the TemplateURL changes. - void RemoveFromKeywordMapByPointer(const TemplateURL* template_url); + void RemoveFromKeywordMapByPointer(TemplateURL* template_url); - void AddToMaps(const TemplateURL* template_url); + void AddToMaps(TemplateURL* template_url); // Sets the keywords. This is used once the keywords have been loaded. // This does NOT notify the delegate or the database. - void SetTemplateURLs(const std::vector<TemplateURL*>& urls); + void SetTemplateURLs(const TemplateURLVector& urls); // Transitions to the loaded state. void ChangeToLoadedState(); @@ -405,7 +405,7 @@ class TemplateURLService : public WebDataServiceConsumer, // specified host, or the only TemplateURLs matching the specified host can // be replaced. bool CanReplaceKeywordForHost(const std::string& host, - const TemplateURL** to_replace); + TemplateURL** to_replace); // Returns true if the TemplateURL is replaceable. This doesn't look at the // uniqueness of the keyword or host and is intended to be called after those @@ -418,7 +418,7 @@ class TemplateURLService : public WebDataServiceConsumer, // Notifying observers is the responsibility of the caller. // NOTE: This should not be called with an extension keyword as there are no // updates needed in that case. - void UpdateNoNotify(const TemplateURL* existing_turl, + void UpdateNoNotify(TemplateURL* existing_turl, const TemplateURL& new_values); // Returns the preferences we use. @@ -452,7 +452,7 @@ class TemplateURLService : public WebDataServiceConsumer, // Set the default search provider even if it is managed. |url| may be null. // Caller is responsible for notifying observers. - void SetDefaultSearchProviderNoNotify(const TemplateURL* url); + void SetDefaultSearchProviderNoNotify(TemplateURL* url); // Adds a new TemplateURL to this model. TemplateURLService will own the // reference, and delete it when the TemplateURL is removed. @@ -465,7 +465,7 @@ class TemplateURLService : public WebDataServiceConsumer, // Removes the keyword from the model. This deletes the supplied TemplateURL. // This fails if the supplied template_url is the default search provider. // Caller is responsible for notifying observers. - void RemoveNoNotify(const TemplateURL* template_url); + void RemoveNoNotify(TemplateURL* template_url); // Notify the observers that the model has changed. This is done only if the // model is loaded. @@ -476,20 +476,20 @@ class TemplateURLService : public WebDataServiceConsumer, // Sets default_search_provider to NULL if it was one of them, unless it is // the same as the current default from preferences and it is managed. void RemoveProvidersCreatedByPolicy( - std::vector<TemplateURL*>* template_urls, - const TemplateURL** default_search_provider, - const TemplateURL* default_from_prefs); + TemplateURLVector* template_urls, + TemplateURL** default_search_provider, + TemplateURL* default_from_prefs); // Resets the sync GUID of the specified TemplateURL and persists the change // to the database. This does not notify observers. - void ResetTemplateURLGUID(const TemplateURL* url, const std::string& guid); + void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); // Attempts to generate a unique keyword for |turl| based on its original // keyword. If its keyword is already unique, that is returned. Otherwise, it // tries to return the autogenerated keyword if that is unique to the Service, // and finally it repeatedly appends special characters to the keyword until // it is unique to the Service. - string16 UniquifyKeyword(const TemplateURL& turl) const; + string16 UniquifyKeyword(const TemplateURL& turl); // Given a TemplateURL from Sync (cloud), resolves any keyword conflicts by // checking the local keywords and uniquifying either the cloud keyword or a @@ -504,8 +504,7 @@ class TemplateURLService : public WebDataServiceConsumer, // Returns a TemplateURL from the service that has the same keyword and search // URL as |sync_turl|, if it exists. - const TemplateURL* FindDuplicateOfSyncTemplateURL( - const TemplateURL& sync_turl); + TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); // Given a TemplateURL from the cloud and a local matching duplicate found by // FindDuplcateOfSyncTemplateURL, merges the two. If |sync_url| is newer, this @@ -524,12 +523,12 @@ class TemplateURLService : public WebDataServiceConsumer, // Retrieve the pending default search provider according to Sync. Returns // NULL if there was no pending search provider from Sync. - const TemplateURL* GetPendingSyncedDefaultSearchProvider(); + TemplateURL* GetPendingSyncedDefaultSearchProvider(); // Goes through a vector of TemplateURLs and ensure that both the in-memory // and database copies have valid sync_guids. This is to fix crbug.com/102038, // where old entries were being pushed to Sync without a sync_guid. - void PatchMissingSyncGUIDs(std::vector<TemplateURL*>* template_urls); + void PatchMissingSyncGUIDs(TemplateURLVector* template_urls); content::NotificationRegistrar notification_registrar_; PrefChangeRegistrar pref_change_registrar_; @@ -545,7 +544,9 @@ class TemplateURLService : public WebDataServiceConsumer, ObserverList<TemplateURLServiceObserver> model_observers_; // Maps from host to set of TemplateURLs whose search url host is host. - SearchHostToURLsMap provider_map_; + // NOTE: This is always non-NULL; we use a scoped_ptr<> to avoid circular + // header dependencies. + scoped_ptr<SearchHostToURLsMap> provider_map_; // Used to obtain the WebDataService. // When Load is invoked, if we haven't yet loaded, the WebDataService is @@ -570,7 +571,7 @@ class TemplateURLService : public WebDataServiceConsumer, // Once loaded, the default search provider. This is a pointer to a // TemplateURL owned by template_urls_. - const TemplateURL* default_search_provider_; + TemplateURL* default_search_provider_; // The initial search provider extracted from preferences. This is only valid // if we haven't been loaded or loading failed. diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc index 7cec55b..451538e 100644 --- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc +++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc @@ -410,7 +410,7 @@ TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) { for (SyncDataList::const_iterator iter = all_sync_data.begin(); iter != all_sync_data.end(); ++iter) { std::string guid = GetGUID(*iter); - const TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); + TemplateURL* service_turl = model()->GetTemplateURLForGUID(guid); scoped_ptr<TemplateURL> deserialized(Deserialize(*iter)); ASSERT_FALSE(service_turl->created_by_policy()); AssertEquals(*service_turl, *deserialized); @@ -564,8 +564,7 @@ TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { // The sync TemplateURL is newer. It should replace the original TemplateURL. // Note that MergeSyncAndLocalURLDuplicates takes ownership of sync_turl. model()->MergeSyncAndLocalURLDuplicates(sync_turl, original_turl, &changes); - const TemplateURL* result = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); + TemplateURL* result = model()->GetTemplateURLForKeyword(ASCIIToUTF16("key1")); ASSERT_TRUE(result); EXPECT_EQ(9001, result->last_modified().ToTimeT()); EXPECT_EQ(0U, changes.size()); @@ -984,7 +983,7 @@ TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { EXPECT_EQ("http://baidu.cn", GetURL(change.sync_data())); // Change a keyword. - const TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); + TemplateURL* existing_turl = model()->GetTemplateURLForGUID("key1"); model()->ResetTemplateURL(existing_turl, existing_turl->short_name(), ASCIIToUTF16("k"), existing_turl->url()); EXPECT_EQ(1U, processor()->change_list_size()); @@ -1133,10 +1132,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { // We should have updated the original TemplateURL with Sync's version. // Keep a copy of it so we can compare it after we re-merge. - const TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); + TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1"); ASSERT_TRUE(key1_url); - scoped_ptr<TemplateURL> updated_turl(new TemplateURL( - const_cast<TemplateURL*>(key1_url)->profile(), key1_url->data())); + scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->profile(), + key1_url->data())); EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified()); // Modify a single field of the initial data. This should not be updated in diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc index 4bf0e23..d214f15 100644 --- a/chrome/browser/search_engines/template_url_service_unittest.cc +++ b/chrome/browser/search_engines/template_url_service_unittest.cc @@ -370,7 +370,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) { // Reload the model to verify it was actually saved to the database. test_util_.ResetModel(true); ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); - const TemplateURL* loaded_url = + TemplateURL* loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); ASSERT_TRUE(loaded_url != NULL); AssertEquals(*cloned_url, *loaded_url); @@ -394,8 +394,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) { ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(), NULL)); ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); - cloned_url.reset(new TemplateURL( - const_cast<TemplateURL*>(loaded_url)->profile(), loaded_url->data())); + cloned_url.reset(new TemplateURL(loaded_url->profile(), loaded_url->data())); test_util_.BlockTillServiceProcessesRequests(); test_util_.ResetModel(true); ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); @@ -1007,11 +1006,10 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) { TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) { test_util_.VerifyLoad(); // Verify that the default search provider is set to something. - const TemplateURL* default_search = model()->GetDefaultSearchProvider(); + TemplateURL* default_search = model()->GetDefaultSearchProvider(); ASSERT_TRUE(default_search != NULL); - scoped_ptr<TemplateURL> cloned_url(new TemplateURL( - const_cast<TemplateURL*>(default_search)->profile(), - default_search->data())); + scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->profile(), + default_search->data())); // Wait for any saves to finish. test_util_.BlockTillServiceProcessesRequests(); @@ -1086,7 +1084,7 @@ TEST_F(TemplateURLServiceTest, LoadUpdatesSearchURL) { TEST_F(TemplateURLServiceTest, LoadEnsuresDefaultSearchProviderExists) { // Force the model to load and make sure we have a default search provider. test_util_.VerifyLoad(); - const TemplateURL* old_default = model()->GetDefaultSearchProvider(); + TemplateURL* old_default = model()->GetDefaultSearchProvider(); EXPECT_TRUE(old_default); // Now remove it. diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc index 63d71a5..c8bd3c6 100644 --- a/chrome/browser/search_engines/util.cc +++ b/chrome/browser/search_engines/util.cc @@ -85,7 +85,7 @@ void MergeEnginesFromPrepopulateData( Profile* profile, WebDataService* service, std::vector<TemplateURL*>* template_urls, - const TemplateURL** default_search_provider) { + TemplateURL** default_search_provider) { DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(template_urls); DCHECK(default_search_provider); @@ -176,7 +176,7 @@ void GetSearchProvidersUsingKeywordResult( WebDataService* service, Profile* profile, std::vector<TemplateURL*>* template_urls, - const TemplateURL** default_search_provider, + TemplateURL** default_search_provider, int* new_resource_keyword_version) { DCHECK(service == NULL || BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(template_urls); diff --git a/chrome/browser/search_engines/util.h b/chrome/browser/search_engines/util.h index bba6a9a..31b8fb2 100644 --- a/chrome/browser/search_engines/util.h +++ b/chrome/browser/search_engines/util.h @@ -37,7 +37,7 @@ void GetSearchProvidersUsingKeywordResult( WebDataService* service, Profile* profile, std::vector<TemplateURL*>* template_urls, - const TemplateURL** default_search_provider, + TemplateURL** default_search_provider, int* new_resource_keyword_version); // Returns true if the default search provider setting has been changed or |