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

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

Issue 263823007: Handle TemplateURLService load failure better (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove initial default copying 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
120 // Generates a suitable keyword for the specified url, which must be valid. 115 // Generates a suitable keyword for the specified url, which must be valid.
121 // This is guaranteed not to return an empty string, since TemplateURLs should 116 // This is guaranteed not to return an empty string, since TemplateURLs should
122 // never have an empty keyword. 117 // never have an empty keyword.
123 static base::string16 GenerateKeyword(const GURL& url); 118 static base::string16 GenerateKeyword(const GURL& url);
124 119
125 // Removes any unnecessary characters from a user input keyword. 120 // Removes any unnecessary characters from a user input keyword.
126 // This removes the leading scheme, "www." and any trailing slash. 121 // This removes the leading scheme, "www." and any trailing slash.
127 static base::string16 CleanUserInputKeyword(const base::string16& keyword); 122 static base::string16 CleanUserInputKeyword(const base::string16& keyword);
128 123
129 // Returns the search url for t_url. Returns an empty GURL if t_url has no 124 // Returns the search url for t_url. Returns an empty GURL if t_url has no
130 // url(). 125 // url().
131 // NOTE: |t_url| is non-const in this version because of the need to access 126 // NOTE: |t_url| is non-const in this version because of the need to access
132 // t_url->profile(). 127 // t_url->profile().
133 static GURL GenerateSearchURL(TemplateURL* t_url); 128 static GURL GenerateSearchURL(TemplateURL* t_url);
134 129
135 // Just like GenerateSearchURL except that it takes SearchTermsData to supply 130 // Just like GenerateSearchURL except that it takes SearchTermsData to supply
136 // the data for some search terms, e.g. so this can be used on threads other 131 // the data for some search terms, e.g. so this can be used on threads other
137 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData() 132 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData()
138 // functions. 133 // functions.
139 static GURL GenerateSearchURLUsingTermsData( 134 static GURL GenerateSearchURLUsingTermsData(
140 const TemplateURL* t_url, 135 const TemplateURL* t_url,
141 const SearchTermsData& search_terms_data); 136 const SearchTermsData& search_terms_data);
142 137
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, UniquifyKeyword);
412 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, 413 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
413 CreateSyncDataFromTemplateURL); 414 IsLocalTemplateURLBetter);
414 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
415 CreateTemplateURLFromSyncData);
416 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword);
417 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, 415 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
418 ResolveSyncKeywordConflict); 416 ResolveSyncKeywordConflict);
419 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes); 417 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, PreSyncDeletes);
420 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
421 IsLocalTemplateURLBetter);
422 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL); 418 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL);
423 419
424 friend class TemplateURLServiceTestUtilBase; 420 friend class TemplateURLServiceTestUtilBase;
425 421
426 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap; 422 typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap;
427 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap; 423 typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap;
428 424
429 // Declaration of values to be used in an enumerated histogram to tally 425 // Declaration of values to be used in an enumerated histogram to tally
430 // changes to the default search provider from various entry points. In 426 // changes to the default search provider from various entry points. In
431 // particular, we use this to see what proportion of changes are from Sync 427 // particular, we use this to see what proportion of changes are from Sync
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 scoped_ptr<SearchHostToURLsMap> provider_map_; 702 scoped_ptr<SearchHostToURLsMap> provider_map_;
707 703
708 // Used to obtain the WebDataService. 704 // Used to obtain the WebDataService.
709 // When Load is invoked, if we haven't yet loaded, the WebDataService is 705 // When Load is invoked, if we haven't yet loaded, the WebDataService is
710 // obtained from the Profile. This allows us to lazily access the database. 706 // obtained from the Profile. This allows us to lazily access the database.
711 Profile* profile_; 707 Profile* profile_;
712 708
713 // Whether the keywords have been loaded. 709 // Whether the keywords have been loaded.
714 bool loaded_; 710 bool loaded_;
715 711
716 // Did loading fail? This is only valid if loaded_ is true. 712 // Set when the web data service fails to load properly. This prevents
713 // further communication with sync or writing to prefs, so we don't persist
714 // inconsistent state data anywhere.
717 bool load_failed_; 715 bool load_failed_;
718 716
719 // If non-zero, we're waiting on a load. 717 // If non-zero, we're waiting on a load.
720 WebDataService::Handle load_handle_; 718 WebDataService::Handle load_handle_;
721 719
722 // Service used to store entries. 720 // Service used to store entries.
723 scoped_refptr<WebDataService> service_; 721 scoped_refptr<WebDataService> service_;
724 722
725 // All visits that occurred before we finished loading. Once loaded 723 // All visits that occurred before we finished loading. Once loaded
726 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector. 724 // UpdateKeywordSearchTermsForURL is invoked for each element of the vector.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 base::CallbackList<void(void)> on_loaded_callbacks_; 780 base::CallbackList<void(void)> on_loaded_callbacks_;
783 781
784 // Helper class to manage the default search engine. This will be NULL when 782 // Helper class to manage the default search engine. This will be NULL when
785 // using the testing-specific constructor. 783 // using the testing-specific constructor.
786 scoped_ptr<DefaultSearchManager> default_search_manager_; 784 scoped_ptr<DefaultSearchManager> default_search_manager_;
787 785
788 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 786 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
789 }; 787 };
790 788
791 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 789 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698