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

Side by Side Diff: components/search_engines/template_url_service.h

Issue 2811793007: Make several methods of TemplateUrlService const (Closed)
Patch Set: Remove unnecessary local variable and add a couple TODOs Created 3 years, 8 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
« no previous file with comments | « no previous file | components/search_engines/template_url_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // non-NULL, template_url_to_replace is set to the keyword to replace. 128 // non-NULL, template_url_to_replace is set to the keyword to replace.
129 // 129 //
130 // |url| is the URL of the search query. This is used to prevent auto-adding 130 // |url| is the URL of the search query. This is used to prevent auto-adding
131 // a keyword for hosts already associated with a manually-edited keyword. 131 // a keyword for hosts already associated with a manually-edited keyword.
132 bool CanAddAutogeneratedKeyword(const base::string16& keyword, 132 bool CanAddAutogeneratedKeyword(const base::string16& keyword,
133 const GURL& url, 133 const GURL& url,
134 TemplateURL** template_url_to_replace); 134 TemplateURL** template_url_to_replace);
135 135
136 // Returns whether the engine is a "pre-existing" engine, either from the 136 // Returns whether the engine is a "pre-existing" engine, either from the
137 // prepopulate list or created by policy. 137 // prepopulate list or created by policy.
138 bool IsPrepopulatedOrCreatedByPolicy(const TemplateURL* template_url); 138 bool IsPrepopulatedOrCreatedByPolicy(const TemplateURL* template_url) const;
139 139
140 // Returns whether |template_url| should be shown in the list of engines 140 // Returns whether |template_url| should be shown in the list of engines
141 // most likely to be selected as a default engine. This is meant to highlight 141 // most likely to be selected as a default engine. This is meant to highlight
142 // the current default, as well as the other most likely choices of default 142 // the current default, as well as the other most likely choices of default
143 // engine, separately from a full list of all TemplateURLs (which might be 143 // engine, separately from a full list of all TemplateURLs (which might be
144 // very long). 144 // very long).
145 bool ShowInDefaultList(const TemplateURL* template_url); 145 bool ShowInDefaultList(const TemplateURL* template_url) const;
146 146
147 // Adds to |matches| all TemplateURLs whose keywords begin with |prefix|, 147 // Adds to |matches| all TemplateURLs whose keywords begin with |prefix|,
148 // sorted shortest-keyword-first. If |supports_replacement_only| is true, only 148 // sorted shortest-keyword-first. If |supports_replacement_only| is true, only
149 // TemplateURLs that support replacement are returned. 149 // TemplateURLs that support replacement are returned.
150 void AddMatchingKeywords(const base::string16& prefix, 150 void AddMatchingKeywords(const base::string16& prefix,
151 bool supports_replacement_only, 151 bool supports_replacement_only,
152 TURLsAndMeaningfulLengths* matches); 152 TURLsAndMeaningfulLengths* matches);
153 153
154 // Adds to |matches| all TemplateURLs for search engines with the domain 154 // Adds to |matches| all TemplateURLs for search engines with the domain
155 // name part of the keyword starts with |prefix|, sorted 155 // name part of the keyword starts with |prefix|, sorted
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // Resets the title, keyword and search url of the specified TemplateURL. 241 // Resets the title, keyword and search url of the specified TemplateURL.
242 // The TemplateURL is marked as not replaceable. 242 // The TemplateURL is marked as not replaceable.
243 void ResetTemplateURL(TemplateURL* url, 243 void ResetTemplateURL(TemplateURL* url,
244 const base::string16& title, 244 const base::string16& title,
245 const base::string16& keyword, 245 const base::string16& keyword,
246 const std::string& search_url); 246 const std::string& search_url);
247 247
248 // Return true if the given |url| can be made the default. This returns false 248 // Return true if the given |url| can be made the default. This returns false
249 // regardless of |url| if the default search provider is managed by policy or 249 // regardless of |url| if the default search provider is managed by policy or
250 // controlled by an extension. 250 // controlled by an extension.
251 bool CanMakeDefault(const TemplateURL* url); 251 bool CanMakeDefault(const TemplateURL* url) const;
252 252
253 // Set the default search provider. |url| may be null. 253 // Set the default search provider. |url| may be null.
254 // This will assert if the default search is managed; the UI should not be 254 // This will assert if the default search is managed; the UI should not be
255 // invoking this method in that situation. 255 // invoking this method in that situation.
256 void SetUserSelectedDefaultSearchProvider(TemplateURL* url); 256 void SetUserSelectedDefaultSearchProvider(TemplateURL* url);
257 257
258 // Returns the default search provider. If the TemplateURLService hasn't been 258 // Returns the default search provider. If the TemplateURLService hasn't been
259 // loaded, the default search provider is pulled from preferences. 259 // loaded, the default search provider is pulled from preferences.
260 // 260 //
261 // NOTE: At least in unittest mode, this may return NULL. 261 // NOTE: At least in unittest mode, this may return NULL.
262 // TODO(blundell): See if all callers can be converted to take in const 262 // TODO(blundell): See if all callers can be converted to take in const
263 // pointers and eliminate this version of the method. 263 // pointers and eliminate this version of the method.
264 TemplateURL* GetDefaultSearchProvider(); 264 TemplateURL* GetDefaultSearchProvider();
265 const TemplateURL* GetDefaultSearchProvider() const; 265 const TemplateURL* GetDefaultSearchProvider() const;
266 266
267 // Returns true if the |url| is a search results page from the default search 267 // Returns true if the |url| is a search results page from the default search
268 // provider. 268 // provider.
269 bool IsSearchResultsPageFromDefaultSearchProvider(const GURL& url) const; 269 bool IsSearchResultsPageFromDefaultSearchProvider(const GURL& url) const;
270 270
271 // Returns true if the default search is managed through group policy. 271 // Returns true if the default search is managed through group policy.
272 bool is_default_search_managed() const { 272 bool is_default_search_managed() const {
273 return default_search_provider_source_ == DefaultSearchManager::FROM_POLICY; 273 return default_search_provider_source_ == DefaultSearchManager::FROM_POLICY;
274 } 274 }
275 275
276 // Returns true if the default search provider is controlled by an extension. 276 // Returns true if the default search provider is controlled by an extension.
277 bool IsExtensionControlledDefaultSearch(); 277 bool IsExtensionControlledDefaultSearch() const;
278 278
279 // Returns the default search specified in the prepopulated data, if it 279 // Returns the default search specified in the prepopulated data, if it
280 // exists. If not, returns first URL in |template_urls_|, or NULL if that's 280 // exists. If not, returns first URL in |template_urls_|, or NULL if that's
281 // empty. The returned object is owned by TemplateURLService and can be 281 // empty. The returned object is owned by TemplateURLService and can be
282 // destroyed at any time so should be used right after the call. 282 // destroyed at any time so should be used right after the call.
283 TemplateURL* FindNewDefaultSearchProvider(); 283 TemplateURL* FindNewDefaultSearchProvider();
284 284
285 // Performs the same actions that happen when the prepopulate data version is 285 // Performs the same actions that happen when the prepopulate data version is
286 // revved: all existing prepopulated entries are checked against the current 286 // revved: all existing prepopulated entries are checked against the current
287 // prepopulate data, any now-extraneous safe_for_autoreplace() entries are 287 // prepopulate data, any now-extraneous safe_for_autoreplace() entries are
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Notification that the keywords have been loaded. 323 // Notification that the keywords have been loaded.
324 // This is invoked from WebDataService, and should not be directly 324 // This is invoked from WebDataService, and should not be directly
325 // invoked. 325 // invoked.
326 void OnWebDataServiceRequestDone( 326 void OnWebDataServiceRequestDone(
327 KeywordWebDataService::Handle h, 327 KeywordWebDataService::Handle h,
328 std::unique_ptr<WDTypedResult> result) override; 328 std::unique_ptr<WDTypedResult> result) override;
329 329
330 // Returns the locale-direction-adjusted short name for the given keyword. 330 // Returns the locale-direction-adjusted short name for the given keyword.
331 // Also sets the out param to indicate whether the keyword belongs to an 331 // Also sets the out param to indicate whether the keyword belongs to an
332 // Omnibox extension. 332 // Omnibox extension.
333 base::string16 GetKeywordShortName(const base::string16& keyword, 333 base::string16 GetKeywordShortName(
334 bool* is_omnibox_api_extension_keyword); 334 const base::string16& keyword,
335 bool* is_omnibox_api_extension_keyword) const;
335 336
336 // Called by the history service when a URL is visited. 337 // Called by the history service when a URL is visited.
337 void OnHistoryURLVisited(const URLVisitedDetails& details); 338 void OnHistoryURLVisited(const URLVisitedDetails& details);
338 339
339 // KeyedService implementation. 340 // KeyedService implementation.
340 void Shutdown() override; 341 void Shutdown() override;
341 342
342 // syncer::SyncableService implementation. 343 // syncer::SyncableService implementation.
343 344
344 // Returns all syncable TemplateURLs from this model as SyncData. This should 345 // Returns all syncable TemplateURLs from this model as SyncData. This should
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 DefaultSearchManager::Source source); 537 DefaultSearchManager::Source source);
537 538
538 539
539 // Applies a DSE change. May be called at startup or after transitioning to 540 // Applies a DSE change. May be called at startup or after transitioning to
540 // the loaded state. Returns true if a change actually occurred. 541 // the loaded state. Returns true if a change actually occurred.
541 bool ApplyDefaultSearchChangeNoMetrics(const TemplateURLData* new_dse_data, 542 bool ApplyDefaultSearchChangeNoMetrics(const TemplateURLData* new_dse_data,
542 DefaultSearchManager::Source source); 543 DefaultSearchManager::Source source);
543 544
544 // Returns false if there is a TemplateURL that has a search url with the 545 // Returns false if there is a TemplateURL that has a search url with the
545 // specified host and that TemplateURL has been manually modified. 546 // specified host and that TemplateURL has been manually modified.
546 bool CanAddAutogeneratedKeywordForHost(const std::string& host); 547 bool CanAddAutogeneratedKeywordForHost(const std::string& host) const;
547 548
548 // Returns true if the TemplateURL is replaceable. This doesn't look at the 549 // Returns true if the TemplateURL is replaceable. This doesn't look at the
549 // uniqueness of the keyword or host and is intended to be called after those 550 // uniqueness of the keyword or host and is intended to be called after those
550 // checks have been done. This returns true if the TemplateURL doesn't appear 551 // checks have been done. This returns true if the TemplateURL doesn't appear
551 // in the default list and is marked as safe_for_autoreplace. 552 // in the default list and is marked as safe_for_autoreplace.
552 bool CanReplace(const TemplateURL* t_url); 553 bool CanReplace(const TemplateURL* t_url) const;
553 554
554 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords. 555 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords.
555 TemplateURL* FindNonExtensionTemplateURLForKeyword( 556 TemplateURL* FindNonExtensionTemplateURLForKeyword(
556 const base::string16& keyword); 557 const base::string16& keyword);
557 558
558 // Updates the information in |existing_turl| using the information from 559 // Updates the information in |existing_turl| using the information from
559 // |new_values|, but the ID for |existing_turl| is retained. Notifying 560 // |new_values|, but the ID for |existing_turl| is retained. Notifying
560 // observers is the responsibility of the caller. Returns whether 561 // observers is the responsibility of the caller. Returns whether
561 // |existing_turl| was found in |template_urls_| and thus could be updated. 562 // |existing_turl| was found in |template_urls_| and thus could be updated.
562 // 563 //
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // known to the local model (though it may already be synced), and |sync_turl| 655 // known to the local model (though it may already be synced), and |sync_turl|
655 // is a new TemplateURL known to Sync but not yet known to the local model. 656 // is a new TemplateURL known to Sync but not yet known to the local model.
656 // The criteria for if |local_turl| is better than |sync_turl| is whether any 657 // The criteria for if |local_turl| is better than |sync_turl| is whether any
657 // of the following are true: 658 // of the following are true:
658 // * |local_turl|'s last_modified timestamp is newer than sync_turl. 659 // * |local_turl|'s last_modified timestamp is newer than sync_turl.
659 // * |local_turl| is created by policy. 660 // * |local_turl| is created by policy.
660 // * |prefer_local_default| is true and |local_turl| is the local default 661 // * |prefer_local_default| is true and |local_turl| is the local default
661 // search provider 662 // search provider
662 bool IsLocalTemplateURLBetter(const TemplateURL* local_turl, 663 bool IsLocalTemplateURLBetter(const TemplateURL* local_turl,
663 const TemplateURL* sync_turl, 664 const TemplateURL* sync_turl,
664 bool prefer_local_default = true); 665 bool prefer_local_default = true) const;
665 666
666 // Given two synced TemplateURLs with a conflicting keyword, one of which 667 // Given two synced TemplateURLs with a conflicting keyword, one of which
667 // needs to be added to or updated in the local model (|unapplied_sync_turl|) 668 // needs to be added to or updated in the local model (|unapplied_sync_turl|)
668 // and one which is already known to the local model (|applied_sync_turl|), 669 // and one which is already known to the local model (|applied_sync_turl|),
669 // prepares the local model so that |unapplied_sync_turl| can be added to it, 670 // prepares the local model so that |unapplied_sync_turl| can be added to it,
670 // or applied as an update to an existing TemplateURL. 671 // or applied as an update to an existing TemplateURL.
671 // Since both entries are known to Sync and one of their keywords will change, 672 // Since both entries are known to Sync and one of their keywords will change,
672 // an ACTION_UPDATE will be appended to |change_list| to reflect this change. 673 // an ACTION_UPDATE will be appended to |change_list| to reflect this change.
673 // Note that |applied_sync_turl| must not be an extension keyword. 674 // Note that |applied_sync_turl| must not be an extension keyword.
674 void ResolveSyncKeywordConflict(TemplateURL* unapplied_sync_turl, 675 void ResolveSyncKeywordConflict(TemplateURL* unapplied_sync_turl,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 // Helper class to manage the default search engine. 849 // Helper class to manage the default search engine.
849 DefaultSearchManager default_search_manager_; 850 DefaultSearchManager default_search_manager_;
850 851
851 std::unique_ptr<GoogleURLTracker::Subscription> 852 std::unique_ptr<GoogleURLTracker::Subscription>
852 google_url_updated_subscription_; 853 google_url_updated_subscription_;
853 854
854 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 855 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
855 }; 856 };
856 857
857 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 858 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | components/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698