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

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

Issue 10381016: Remove the "autogenerate keyword" bit on TemplateURL. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 const char* const keyword; 76 const char* const keyword;
77 const char* const url; 77 const char* const url;
78 const char* const content; 78 const char* const content;
79 }; 79 };
80 80
81 explicit TemplateURLService(Profile* profile); 81 explicit TemplateURLService(Profile* profile);
82 // The following is for testing. 82 // The following is for testing.
83 TemplateURLService(const Initializer* initializers, const int count); 83 TemplateURLService(const Initializer* initializers, const int count);
84 virtual ~TemplateURLService(); 84 virtual ~TemplateURLService();
85 85
86 // Generates a suitable keyword for the specified url. Returns an empty 86 // Generates a suitable keyword for the specified url, which must be valid.
87 // string if a keyword couldn't be generated. If |autodetected| is true, we 87 // This is guaranteed not to return an empty string, since TemplateURLs should
88 // don't generate keywords for a variety of situations where we would probably 88 // never have an empty keyword.
89 // not want to auto-add keywords, such as keywords for searches on pages that 89 static string16 GenerateKeyword(const GURL& url);
90 // themselves come from form submissions.
91 static string16 GenerateKeyword(const GURL& url, bool autodetected);
92 90
93 // Removes any unnecessary characters from a user input keyword. 91 // Removes any unnecessary characters from a user input keyword.
94 // This removes the leading scheme, "www." and any trailing slash. 92 // This removes the leading scheme, "www." and any trailing slash.
95 static string16 CleanUserInputKeyword(const string16& keyword); 93 static string16 CleanUserInputKeyword(const string16& keyword);
96 94
97 // Returns the search url for t_url. Returns an empty GURL if t_url has no 95 // Returns the search url for t_url. Returns an empty GURL if t_url has no
98 // url(). 96 // url().
99 // NOTE: |t_url| is non-const in this version because of the need to access 97 // NOTE: |t_url| is non-const in this version because of the need to access
100 // t_url->profile(). 98 // t_url->profile().
101 static GURL GenerateSearchURL(TemplateURL* t_url); 99 static GURL GenerateSearchURL(TemplateURL* t_url);
102 100
103 // Just like GenerateSearchURL except that it takes SearchTermsData to supply 101 // Just like GenerateSearchURL except that it takes SearchTermsData to supply
104 // the data for some search terms. Most of the time GenerateSearchURL should 102 // the data for some search terms, e.g. so this can be used on threads other
105 // be called. 103 // than the UI thread. See the various TemplateURLRef::XXXUsingTermsData()
104 // functions.
106 static GURL GenerateSearchURLUsingTermsData( 105 static GURL GenerateSearchURLUsingTermsData(
107 const TemplateURL* t_url, 106 const TemplateURL* t_url,
108 const SearchTermsData& search_terms_data); 107 const SearchTermsData& search_terms_data);
109 108
110 // Returns true if there is no TemplateURL that conflicts with the 109 // Returns true if there is no TemplateURL that conflicts with the
111 // keyword/url pair, or there is one but it can be replaced. If there is an 110 // keyword/url pair, or there is one but it can be replaced. If there is an
112 // existing keyword that can be replaced and template_url_to_replace is 111 // existing keyword that can be replaced and template_url_to_replace is
113 // non-NULL, template_url_to_replace is set to the keyword to replace. 112 // non-NULL, template_url_to_replace is set to the keyword to replace.
114 // 113 //
115 // url gives the url of the search query. The url is used to avoid generating 114 // url gives the url of the search query. The url is used to avoid generating
(...skipping 17 matching lines...) Expand all
133 132
134 // Returns that TemplateURL with the specified GUID, or NULL if not found. 133 // Returns that TemplateURL with the specified GUID, or NULL if not found.
135 // The caller should not try to delete the returned pointer; the data store 134 // The caller should not try to delete the returned pointer; the data store
136 // retains ownership of it. 135 // retains ownership of it.
137 TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid); 136 TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid);
138 137
139 // Returns the first TemplateURL found with a URL using the specified |host|, 138 // Returns the first TemplateURL found with a URL using the specified |host|,
140 // or NULL if there are no such TemplateURLs 139 // or NULL if there are no such TemplateURLs
141 TemplateURL* GetTemplateURLForHost(const std::string& host); 140 TemplateURL* GetTemplateURLForHost(const std::string& host);
142 141
143 // Takes ownership of |template_url| and adds it to this model. 142 // Takes ownership of |template_url| and adds it to this model. For obvious
143 // reasons, it is illegal to Add() the same |template_url| pointer twice.
144 void Add(TemplateURL* template_url); 144 void Add(TemplateURL* template_url);
145 145
146 // Like Add(), but overwrites the |template_url|'s values with the provided 146 // Like Add(), but overwrites the |template_url|'s values with the provided
147 // ones. 147 // ones.
148 void AddAndSetProfile(TemplateURL* template_url, Profile* profile); 148 void AddAndSetProfile(TemplateURL* template_url, Profile* profile);
149 void AddWithOverrides(TemplateURL* template_url, 149 void AddWithOverrides(TemplateURL* template_url,
150 const string16& short_name, 150 const string16& short_name,
151 const string16& keyword, 151 const string16& keyword,
152 const std::string& url); 152 const std::string& url);
153 153
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // be replaced. 406 // be replaced.
407 bool CanReplaceKeywordForHost(const std::string& host, 407 bool CanReplaceKeywordForHost(const std::string& host,
408 TemplateURL** to_replace); 408 TemplateURL** to_replace);
409 409
410 // Returns true if the TemplateURL is replaceable. This doesn't look at the 410 // Returns true if the TemplateURL is replaceable. This doesn't look at the
411 // uniqueness of the keyword or host and is intended to be called after those 411 // uniqueness of the keyword or host and is intended to be called after those
412 // checks have been done. This returns true if the TemplateURL doesn't appear 412 // checks have been done. This returns true if the TemplateURL doesn't appear
413 // in the default list and is marked as safe_for_autoreplace. 413 // in the default list and is marked as safe_for_autoreplace.
414 bool CanReplace(const TemplateURL* t_url); 414 bool CanReplace(const TemplateURL* t_url);
415 415
416 // Like GetTemplateURLForKeyword(), but ignores extension-provided keywords.
417 TemplateURL* FindNonExtensionTemplateURLForKeyword(const string16& keyword);
418
416 // Updates the information in |existing_turl| using the information from 419 // Updates the information in |existing_turl| using the information from
417 // |new_values|, but the ID for |existing_turl| is retained. 420 // |new_values|, but the ID for |existing_turl| is retained. Notifying
418 // Notifying observers is the responsibility of the caller. 421 // observers is the responsibility of the caller. Returns whether
422 // |existing_turl| was found in |template_urls_| and thus could be updated.
423 //
419 // NOTE: This should not be called with an extension keyword as there are no 424 // NOTE: This should not be called with an extension keyword as there are no
420 // updates needed in that case. 425 // updates needed in that case.
421 void UpdateNoNotify(TemplateURL* existing_turl, 426 bool UpdateNoNotify(TemplateURL* existing_turl,
422 const TemplateURL& new_values); 427 const TemplateURL& new_values);
423 428
424 // Returns the preferences we use. 429 // Returns the preferences we use.
425 PrefService* GetPrefs(); 430 PrefService* GetPrefs();
426 431
427 // Iterates through the TemplateURLs to see if one matches the visited url. 432 // Iterates through the TemplateURLs to see if one matches the visited url.
428 // For each TemplateURL whose url matches the visited url 433 // For each TemplateURL whose url matches the visited url
429 // SetKeywordSearchTermsForURL is invoked. 434 // SetKeywordSearchTermsForURL is invoked.
430 void UpdateKeywordSearchTermsForURL( 435 void UpdateKeywordSearchTermsForURL(
431 const history::URLVisitedDetails& details); 436 const history::URLVisitedDetails& details);
(...skipping 12 matching lines...) Expand all
444 // Invoked when the Google base URL has changed. Updates the mapping for all 449 // Invoked when the Google base URL has changed. Updates the mapping for all
445 // TemplateURLs that have a replacement term of {google:baseURL} or 450 // TemplateURLs that have a replacement term of {google:baseURL} or
446 // {google:baseSuggestURL}. 451 // {google:baseSuggestURL}.
447 void GoogleBaseURLChanged(); 452 void GoogleBaseURLChanged();
448 453
449 // Update the default search. Called at initialization or when a managed 454 // Update the default search. Called at initialization or when a managed
450 // preference has changed. 455 // preference has changed.
451 void UpdateDefaultSearch(); 456 void UpdateDefaultSearch();
452 457
453 // Set the default search provider even if it is managed. |url| may be null. 458 // Set the default search provider even if it is managed. |url| may be null.
454 // Caller is responsible for notifying observers. 459 // Caller is responsible for notifying observers. Returns whether |url| was
455 void SetDefaultSearchProviderNoNotify(TemplateURL* url); 460 // found in |template_urls_| and thus could be made default.
461 bool SetDefaultSearchProviderNoNotify(TemplateURL* url);
456 462
457 // Adds a new TemplateURL to this model. TemplateURLService will own the 463 // Adds a new TemplateURL to this model. TemplateURLService will own the
458 // reference, and delete it when the TemplateURL is removed. 464 // reference, and delete it when the TemplateURL is removed.
459 // If |newly_adding| is false, we assume that this TemplateURL was already 465 // If |newly_adding| is false, we assume that this TemplateURL was already
460 // part of the model in the past, and therefore we don't need to do things 466 // part of the model in the past, and therefore we don't need to do things
461 // like assign it an ID or notify sync. 467 // like assign it an ID or notify sync.
462 // Caller is responsible for notifying observers. 468 // This function guarantees that on return the model will not have two
463 void AddNoNotify(TemplateURL* template_url, bool newly_adding); 469 // non-extension TemplateURLs with the same keyword. If that means that it
470 // cannot add the provided argument, it will delete it and return false.
471 // Caller is responsible for notifying observers if this function returns
472 // true.
473 bool AddNoNotify(TemplateURL* template_url, bool newly_adding);
464 474
465 // Removes the keyword from the model. This deletes the supplied TemplateURL. 475 // Removes the keyword from the model. This deletes the supplied TemplateURL.
466 // This fails if the supplied template_url is the default search provider. 476 // This fails if the supplied template_url is the default search provider.
467 // Caller is responsible for notifying observers. 477 // Caller is responsible for notifying observers.
468 void RemoveNoNotify(TemplateURL* template_url); 478 void RemoveNoNotify(TemplateURL* template_url);
469 479
470 // Notify the observers that the model has changed. This is done only if the 480 // Notify the observers that the model has changed. This is done only if the
471 // model is loaded. 481 // model is loaded.
472 void NotifyObservers(); 482 void NotifyObservers();
473 483
(...skipping 10 matching lines...) Expand all
484 // to the database. This does not notify observers. 494 // to the database. This does not notify observers.
485 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); 495 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid);
486 496
487 // Attempts to generate a unique keyword for |turl| based on its original 497 // Attempts to generate a unique keyword for |turl| based on its original
488 // keyword. If its keyword is already unique, that is returned. Otherwise, it 498 // keyword. If its keyword is already unique, that is returned. Otherwise, it
489 // tries to return the autogenerated keyword if that is unique to the Service, 499 // tries to return the autogenerated keyword if that is unique to the Service,
490 // and finally it repeatedly appends special characters to the keyword until 500 // and finally it repeatedly appends special characters to the keyword until
491 // it is unique to the Service. 501 // it is unique to the Service.
492 string16 UniquifyKeyword(const TemplateURL& turl); 502 string16 UniquifyKeyword(const TemplateURL& turl);
493 503
494 // Given a TemplateURL from Sync (cloud), resolves any keyword conflicts by 504 // Given a TemplateURL from Sync (cloud) and a local TemplateURL with the same
495 // checking the local keywords and uniquifying either the cloud keyword or a 505 // keyword, resolves the conflict by uniquifying either the cloud keyword or
496 // conflicting local keyword (whichever is older). If the cloud TURL is 506 // the local keyword (whichever is older). If the cloud TURL is changed, then
497 // changed, then an appropriate SyncChange is appended to |change_list|. If 507 // an appropriate SyncChange is appended to |change_list|. If a local TURL is
498 // a local TURL is changed, the service is updated with the new keyword. If 508 // changed, the service is updated with the new keyword. In the case of tied
499 // there was no conflict to begin with, this does nothing. In the case of tied 509 // last_modified dates, |sync_turl| wins.
SteveT 2012/05/08 01:17:15 nit: Please mention that |local_turl| cannot be an
Peter Kasting 2012/05/08 01:31:42 Done.
500 // last_modified dates, |sync_turl| wins. Returns true iff there was a 510 void ResolveSyncKeywordConflict(TemplateURL* sync_turl,
501 // conflict. 511 TemplateURL* local_turl,
502 bool ResolveSyncKeywordConflict(TemplateURL* sync_turl,
503 SyncChangeList* change_list); 512 SyncChangeList* change_list);
504 513
505 // Returns a TemplateURL from the service that has the same keyword and search 514 // Returns a TemplateURL from the service that has the same keyword and search
506 // URL as |sync_turl|, if it exists. 515 // URL as |sync_turl|, if it exists.
507 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); 516 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl);
508 517
509 // Given a TemplateURL from the cloud and a local matching duplicate found by 518 // Given a TemplateURL from the cloud and a local matching duplicate found by
510 // FindDuplcateOfSyncTemplateURL, merges the two. If |sync_url| is newer, this 519 // FindDuplcateOfSyncTemplateURL, merges the two. If |sync_url| is newer, this
511 // replaces |local_url| with |sync_url| using the service's Remove and Add. 520 // replaces |local_url| with |sync_url| using the service's Remove and Add.
512 // If |local_url| is newer, this copies the GUID from |sync_url| over to 521 // If |local_url| is newer, this copies the GUID from |sync_url| over to
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // from Sync. This is to facilitate the fact that changes to the value of 619 // from Sync. This is to facilitate the fact that changes to the value of
611 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the 620 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the
612 // TemplateURL entry it refers to, and to handle the case when we want to use 621 // TemplateURL entry it refers to, and to handle the case when we want to use
613 // the Synced default when the default search provider becomes unmanaged. 622 // the Synced default when the default search provider becomes unmanaged.
614 bool pending_synced_default_search_; 623 bool pending_synced_default_search_;
615 624
616 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 625 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
617 }; 626 };
618 627
619 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 628 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698