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

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

Issue 2811793007: Make several methods of TemplateUrlService const (Closed)
Patch Set: Remove extra line 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
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 // Returns true if there is no TemplateURL that conflicts with the 125 // Returns true if there is no TemplateURL that conflicts with the
126 // keyword/url pair, or there is one but it can be replaced. If there is an 126 // keyword/url pair, or there is one but it can be replaced. If there is an
127 // existing keyword that can be replaced and template_url_to_replace is 127 // existing keyword that can be replaced and template_url_to_replace is
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) const;
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 487
487 void Init(const Initializer* initializers, int num_initializers); 488 void Init(const Initializer* initializers, int num_initializers);
488 489
489 // Given two engines with the same keyword, returns which should take 490 // Given two engines with the same keyword, returns which should take
490 // precedence. While normal engines must all have distinct keywords, 491 // precedence. While normal engines must all have distinct keywords,
491 // extension-controlled and omnibox API engines may have the same keywords as 492 // extension-controlled and omnibox API engines may have the same keywords as
492 // each other or as normal engines. In these cases, omnibox API engines 493 // each other or as normal engines. In these cases, omnibox API engines
493 // override extension-controlled engines, which override normal engines; if 494 // override extension-controlled engines, which override normal engines; if
494 // there is still a conflict after this, the most recently-added extension 495 // there is still a conflict after this, the most recently-added extension
495 // wins. 496 // wins.
496 TemplateURL* BestEngineForKeyword(TemplateURL* engine1, TemplateURL* engine2); 497 TemplateURL* BestEngineForKeyword(TemplateURL* engine1,
498 TemplateURL* engine2);
Peter Kasting 2017/04/13 06:15:35 Nit: Can probably revert this
497 499
498 // Removes |template_url| from various internal maps 500 // Removes |template_url| from various internal maps
499 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, 501 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|,
500 // |guid_to_turl_|, |provider_map_|). 502 // |guid_to_turl_|, |provider_map_|).
501 void RemoveFromMaps(TemplateURL* template_url); 503 void RemoveFromMaps(TemplateURL* template_url);
502 504
503 // Adds |template_url| to various internal maps 505 // Adds |template_url| to various internal maps
504 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, 506 // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|,
505 // |guid_to_turl_|, |provider_map_|) if appropriate. (It might not be 507 // |guid_to_turl_|, |provider_map_|) if appropriate. (It might not be
506 // appropriate if, for instance, |template_url|'s keyword conflicts with 508 // appropriate if, for instance, |template_url|'s keyword conflicts with
(...skipping 29 matching lines...) Expand all
536 DefaultSearchManager::Source source); 538 DefaultSearchManager::Source source);
537 539
538 540
539 // Applies a DSE change. May be called at startup or after transitioning to 541 // Applies a DSE change. May be called at startup or after transitioning to
540 // the loaded state. Returns true if a change actually occurred. 542 // the loaded state. Returns true if a change actually occurred.
541 bool ApplyDefaultSearchChangeNoMetrics(const TemplateURLData* new_dse_data, 543 bool ApplyDefaultSearchChangeNoMetrics(const TemplateURLData* new_dse_data,
542 DefaultSearchManager::Source source); 544 DefaultSearchManager::Source source);
543 545
544 // Returns false if there is a TemplateURL that has a search url with the 546 // Returns false if there is a TemplateURL that has a search url with the
545 // specified host and that TemplateURL has been manually modified. 547 // specified host and that TemplateURL has been manually modified.
546 bool CanAddAutogeneratedKeywordForHost(const std::string& host); 548 bool CanAddAutogeneratedKeywordForHost(const std::string& host) const;
547 549
548 // Returns true if the TemplateURL is replaceable. This doesn't look at the 550 // 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 551 // 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 552 // 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. 553 // in the default list and is marked as safe_for_autoreplace.
552 bool CanReplace(const TemplateURL* t_url); 554 bool CanReplace(const TemplateURL* t_url) const;
553 555
554 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords. 556 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords.
555 TemplateURL* FindNonExtensionTemplateURLForKeyword( 557 TemplateURL* FindNonExtensionTemplateURLForKeyword(
556 const base::string16& keyword); 558 const base::string16& keyword);
557 559
558 // Updates the information in |existing_turl| using the information from 560 // Updates the information in |existing_turl| using the information from
559 // |new_values|, but the ID for |existing_turl| is retained. Notifying 561 // |new_values|, but the ID for |existing_turl| is retained. Notifying
560 // observers is the responsibility of the caller. Returns whether 562 // observers is the responsibility of the caller. Returns whether
561 // |existing_turl| was found in |template_urls_| and thus could be updated. 563 // |existing_turl| was found in |template_urls_| and thus could be updated.
562 // 564 //
(...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| 656 // 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. 657 // 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 658 // The criteria for if |local_turl| is better than |sync_turl| is whether any
657 // of the following are true: 659 // of the following are true:
658 // * |local_turl|'s last_modified timestamp is newer than sync_turl. 660 // * |local_turl|'s last_modified timestamp is newer than sync_turl.
659 // * |local_turl| is created by policy. 661 // * |local_turl| is created by policy.
660 // * |prefer_local_default| is true and |local_turl| is the local default 662 // * |prefer_local_default| is true and |local_turl| is the local default
661 // search provider 663 // search provider
662 bool IsLocalTemplateURLBetter(const TemplateURL* local_turl, 664 bool IsLocalTemplateURLBetter(const TemplateURL* local_turl,
663 const TemplateURL* sync_turl, 665 const TemplateURL* sync_turl,
664 bool prefer_local_default = true); 666 bool prefer_local_default = true) const;
665 667
666 // Given two synced TemplateURLs with a conflicting keyword, one of which 668 // 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|) 669 // 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|), 670 // 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, 671 // prepares the local model so that |unapplied_sync_turl| can be added to it,
670 // or applied as an update to an existing TemplateURL. 672 // or applied as an update to an existing TemplateURL.
671 // Since both entries are known to Sync and one of their keywords will change, 673 // 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. 674 // 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. 675 // Note that |applied_sync_turl| must not be an extension keyword.
674 void ResolveSyncKeywordConflict(TemplateURL* unapplied_sync_turl, 676 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. 850 // Helper class to manage the default search engine.
849 DefaultSearchManager default_search_manager_; 851 DefaultSearchManager default_search_manager_;
850 852
851 std::unique_ptr<GoogleURLTracker::Subscription> 853 std::unique_ptr<GoogleURLTracker::Subscription>
852 google_url_updated_subscription_; 854 google_url_updated_subscription_;
853 855
854 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 856 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
855 }; 857 };
856 858
857 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 859 #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') | components/search_engines/template_url_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698