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

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

Issue 273153004: Revert of Handle TemplateURLService load failure better, and make some test correctness fixes that will be ne… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // SaveDefaultSearchProviderToPrefs or set via policy. 105 // SaveDefaultSearchProviderToPrefs or set via policy.
106 // Returns true if successful, false otherwise. 106 // Returns true if successful, false otherwise.
107 // If the user or the policy has opted for no default search, this 107 // If the user or the policy has opted for no default search, this
108 // returns true but default_provider is set to NULL. 108 // returns true but default_provider is set to NULL.
109 // |*is_managed| specifies whether the default is managed via policy. 109 // |*is_managed| specifies whether the default is managed via policy.
110 static bool LoadDefaultSearchProviderFromPrefs( 110 static bool LoadDefaultSearchProviderFromPrefs(
111 PrefService* prefs, 111 PrefService* prefs,
112 scoped_ptr<TemplateURLData>* default_provider_data, 112 scoped_ptr<TemplateURLData>* default_provider_data,
113 bool* is_managed); 113 bool* is_managed);
114 114
115 // Saves enough of url to |prefs| so that it can be loaded from preferences on
116 // start up.
117 static void SaveDefaultSearchProviderToPrefs(const TemplateURL* url,
118 PrefService* prefs);
119
115 // Generates a suitable keyword for the specified url, which must be valid. 120 // Generates a suitable keyword for the specified url, which must be valid.
116 // This is guaranteed not to return an empty string, since TemplateURLs should 121 // This is guaranteed not to return an empty string, since TemplateURLs should
117 // never have an empty keyword. 122 // never have an empty keyword.
118 static base::string16 GenerateKeyword(const GURL& url); 123 static base::string16 GenerateKeyword(const GURL& url);
119 124
120 // Removes any unnecessary characters from a user input keyword. 125 // Removes any unnecessary characters from a user input keyword.
121 // This removes the leading scheme, "www." and any trailing slash. 126 // This removes the leading scheme, "www." and any trailing slash.
122 static base::string16 CleanUserInputKeyword(const base::string16& keyword); 127 static base::string16 CleanUserInputKeyword(const base::string16& keyword);
123 128
124 // Returns the search url for t_url. Returns an empty GURL if t_url has no 129 // Returns the search url for t_url. Returns an empty GURL if t_url has no
125 // url(). 130 // url().
126 // NOTE: |t_url| is non-const in this version because of the need to access 131 // NOTE: |t_url| is non-const in this version because of the need to access
127 // t_url->profile(). 132 // t_url->profile().
128 static GURL GenerateSearchURL(TemplateURL* t_url); 133 static GURL GenerateSearchURL(TemplateURL* t_url);
129 134
130 // Just like GenerateSearchURL except that it takes SearchTermsData to supply 135 // Just like GenerateSearchURL except that it takes SearchTermsData to supply
131 // the data for some search terms, e.g. so this can be used on threads other 136 // the data for some search terms, e.g. so this can be used on threads other
132 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData() 137 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData()
133 // functions. 138 // functions.
134 static GURL GenerateSearchURLUsingTermsData( 139 static GURL GenerateSearchURLUsingTermsData(
135 const TemplateURL* t_url, 140 const TemplateURL* t_url,
136 const SearchTermsData& search_terms_data); 141 const SearchTermsData& search_terms_data);
137 142
138 // Saves enough of url to |prefs| so that it can be loaded from preferences on
139 // start up.
140 void SaveDefaultSearchProviderToPrefs(const TemplateURL* url,
141 PrefService* prefs) const;
142
143 // Returns true if there is no TemplateURL that conflicts with the 143 // Returns true if there is no TemplateURL that conflicts with the
144 // keyword/url pair, or there is one but it can be replaced. If there is an 144 // keyword/url pair, or there is one but it can be replaced. If there is an
145 // existing keyword that can be replaced and template_url_to_replace is 145 // existing keyword that can be replaced and template_url_to_replace is
146 // non-NULL, template_url_to_replace is set to the keyword to replace. 146 // non-NULL, template_url_to_replace is set to the keyword to replace.
147 // 147 //
148 // url gives the url of the search query. The url is used to avoid generating 148 // url gives the url of the search query. The url is used to avoid generating
149 // a TemplateURL for an existing TemplateURL that shares the same host. 149 // a TemplateURL for an existing TemplateURL that shares the same host.
150 bool CanReplaceKeyword(const base::string16& keyword, 150 bool CanReplaceKeyword(const base::string16& keyword,
151 const GURL& url, 151 const GURL& url,
152 TemplateURL** template_url_to_replace); 152 TemplateURL** template_url_to_replace);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 const base::string16& term); 402 const base::string16& term);
403 403
404 private: 404 private:
405 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch); 405 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, TestManagedDefaultSearch);
406 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, 406 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest,
407 UpdateKeywordSearchTermsForURL); 407 UpdateKeywordSearchTermsForURL);
408 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, 408 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest,
409 DontUpdateKeywordSearchForNonReplaceable); 409 DontUpdateKeywordSearchForNonReplaceable);
410 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue); 410 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue);
411 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders); 411 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders);
412 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
413 CreateSyncDataFromTemplateURL);
414 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
415 CreateTemplateURLFromSyncData);
412 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword); 416 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword);
413 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, 417 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
414 IsLocalTemplateURLBetter);
415 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
416 ResolveSyncKeywordConflict); 418 ResolveSyncKeywordConflict);
417 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); 419 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes);
420 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
421 IsLocalTemplateURLBetter);
418 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); 422 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL);
419 423
420 friend class TemplateURLServiceTestUtilBase; 424 friend class TemplateURLServiceTestUtilBase;
421 425
422 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap; 426 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap;
423 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; 427 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap;
424 428
425 // Declaration of values to be used in an enumerated histogram to tally 429 // Declaration of values to be used in an enumerated histogram to tally
426 // changes to the default search provider from various entry points. In 430 // changes to the default search provider from various entry points. In
427 // particular, we use this to see what proportion of changes are from Sync 431 // particular, we use this to see what proportion of changes are from Sync
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // cannot add the provided argument, it will delete it and return false. 561 // cannot add the provided argument, it will delete it and return false.
558 // Caller is responsible for notifying observers if this function returns 562 // Caller is responsible for notifying observers if this function returns
559 // true. 563 // true.
560 bool AddNoNotify(TemplateURL* template_url, bool newly_adding); 564 bool AddNoNotify(TemplateURL* template_url, bool newly_adding);
561 565
562 // Removes the keyword from the model. This deletes the supplied TemplateURL. 566 // Removes the keyword from the model. This deletes the supplied TemplateURL.
563 // This fails if the supplied template_url is the default search provider. 567 // This fails if the supplied template_url is the default search provider.
564 // Caller is responsible for notifying observers. 568 // Caller is responsible for notifying observers.
565 void RemoveNoNotify(TemplateURL* template_url); 569 void RemoveNoNotify(TemplateURL* template_url);
566 570
567 // Like ResetTemplateURL(), but instead of notifying observers, returns
568 // whether anything has changed.
569 bool ResetTemplateURLNoNotify(TemplateURL* url,
570 const base::string16& title,
571 const base::string16& keyword,
572 const std::string& search_url);
573
574 // Notify the observers that the model has changed. This is done only if the 571 // Notify the observers that the model has changed. This is done only if the
575 // model is loaded. 572 // model is loaded.
576 void NotifyObservers(); 573 void NotifyObservers();
577 574
578 // Removes from the vector any template URL that was created because of 575 // Removes from the vector any template URL that was created because of
579 // policy. These TemplateURLs are freed and removed from the database. 576 // policy. These TemplateURLs are freed and removed from the database.
580 // Sets default_search_provider to NULL if it was one of them, unless it is 577 // Sets default_search_provider to NULL if it was one of them, unless it is
581 // the same as the current default from preferences and it is managed. 578 // the same as the current default from preferences and it is managed.
582 void RemoveProvidersCreatedByPolicy( 579 void RemoveProvidersCreatedByPolicy(
583 TemplateURLVector* template_urls, 580 TemplateURLVector* template_urls,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 scoped_ptr<SearchHostToURLsMap> provider_map_; 706 scoped_ptr<SearchHostToURLsMap> provider_map_;
710 707
711 // Used to obtain the WebDataService. 708 // Used to obtain the WebDataService.
712 // When Load is invoked, if we haven't yet loaded, the WebDataService is 709 // When Load is invoked, if we haven't yet loaded, the WebDataService is
713 // obtained from the Profile. This allows us to lazily access the database. 710 // obtained from the Profile. This allows us to lazily access the database.
714 Profile* profile_; 711 Profile* profile_;
715 712
716 // Whether the keywords have been loaded. 713 // Whether the keywords have been loaded.
717 bool loaded_; 714 bool loaded_;
718 715
719 // Set when the web data service fails to load properly. This prevents 716 // Did loading fail? This is only valid if loaded_ is true.
720 // further communication with sync or writing to prefs, so we don't persist
721 // inconsistent state data anywhere.
722 bool load_failed_; 717 bool load_failed_;
723 718
724 // If non-zero, we're waiting on a load. 719 // If non-zero, we're waiting on a load.
725 WebDataService::Handle load_handle_; 720 WebDataService::Handle load_handle_;
726 721
727 // Service used to store entries. 722 // Service used to store entries.
728 scoped_refptr<WebDataService> service_; 723 scoped_refptr<WebDataService> service_;
729 724
730 // All visits that occurred before we finished loading. Once loaded 725 // All visits that occurred before we finished loading. Once loaded
731 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. 726 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 base::CallbackList<void(void)> on_loaded_callbacks_; 782 base::CallbackList<void(void)> on_loaded_callbacks_;
788 783
789 // Helper class to manage the default search engine. This will be NULL when 784 // Helper class to manage the default search engine. This will be NULL when
790 // using the testing-specific constructor. 785 // using the testing-specific constructor.
791 scoped_ptr<DefaultSearchManager> default_search_manager_; 786 scoped_ptr<DefaultSearchManager> default_search_manager_;
792 787
793 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 788 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
794 }; 789 };
795 790
796 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 791 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698