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

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);
sky 2012/05/04 23:20:25 Can you add a comment to this and GenerateSearchUR
Peter Kasting 2012/05/07 17:50:24 Is there a reason to call that out for this functi
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);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 131
134 // Returns that TemplateURL with the specified GUID, or NULL if not found. 132 // 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 133 // The caller should not try to delete the returned pointer; the data store
136 // retains ownership of it. 134 // retains ownership of it.
137 TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid); 135 TemplateURL* GetTemplateURLForGUID(const std::string& sync_guid);
138 136
139 // Returns the first TemplateURL found with a URL using the specified |host|, 137 // Returns the first TemplateURL found with a URL using the specified |host|,
140 // or NULL if there are no such TemplateURLs 138 // or NULL if there are no such TemplateURLs
141 TemplateURL* GetTemplateURLForHost(const std::string& host); 139 TemplateURL* GetTemplateURLForHost(const std::string& host);
142 140
143 // Takes ownership of |template_url| and adds it to this model. 141 // Takes ownership of |template_url| and adds it to this model. For obvious
142 // reasons, it is illegal to Add() the same |template_url| pointer twice.
144 void Add(TemplateURL* template_url); 143 void Add(TemplateURL* template_url);
145 144
146 // Like Add(), but overwrites the |template_url|'s values with the provided 145 // Like Add(), but overwrites the |template_url|'s values with the provided
147 // ones. 146 // ones.
148 void AddAndSetProfile(TemplateURL* template_url, Profile* profile); 147 void AddAndSetProfile(TemplateURL* template_url, Profile* profile);
149 void AddWithOverrides(TemplateURL* template_url, 148 void AddWithOverrides(TemplateURL* template_url,
150 const string16& short_name, 149 const string16& short_name,
151 const string16& keyword, 150 const string16& keyword,
152 const std::string& url); 151 const std::string& url);
153 152
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // be replaced. 405 // be replaced.
407 bool CanReplaceKeywordForHost(const std::string& host, 406 bool CanReplaceKeywordForHost(const std::string& host,
408 TemplateURL** to_replace); 407 TemplateURL** to_replace);
409 408
410 // Returns true if the TemplateURL is replaceable. This doesn't look at the 409 // 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 410 // 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 411 // 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. 412 // in the default list and is marked as safe_for_autoreplace.
414 bool CanReplace(const TemplateURL* t_url); 413 bool CanReplace(const TemplateURL* t_url);
415 414
415 // It's possible for an extension TemplateURL to mask a replaceable
416 // non-extension TemplateURL with the same keyword (see comments in
417 // AddToMaps()). Find the masked TemplateURL, if any.
SteveT 2012/05/07 18:17:47 This returns NULL if no such masked TemplateURL ex
Peter Kasting 2012/05/07 19:39:14 I rewrote this comment entirely in more recent pat
418 TemplateURL* FindNonExtensionTemplateURLForKeyword(const string16& keyword);
419
416 // Updates the information in |existing_turl| using the information from 420 // Updates the information in |existing_turl| using the information from
417 // |new_values|, but the ID for |existing_turl| is retained. 421 // |new_values|, but the ID for |existing_turl| is retained.
418 // Notifying observers is the responsibility of the caller. 422 // Notifying observers is the responsibility of the caller.
419 // NOTE: This should not be called with an extension keyword as there are no 423 // NOTE: This should not be called with an extension keyword as there are no
420 // updates needed in that case. 424 // updates needed in that case.
421 void UpdateNoNotify(TemplateURL* existing_turl, 425 void UpdateNoNotify(TemplateURL* existing_turl,
422 const TemplateURL& new_values); 426 const TemplateURL& new_values);
423 427
424 // Returns the preferences we use. 428 // Returns the preferences we use.
425 PrefService* GetPrefs(); 429 PrefService* GetPrefs();
(...skipping 26 matching lines...) Expand all
452 456
453 // Set the default search provider even if it is managed. |url| may be null. 457 // Set the default search provider even if it is managed. |url| may be null.
454 // Caller is responsible for notifying observers. 458 // Caller is responsible for notifying observers.
455 void SetDefaultSearchProviderNoNotify(TemplateURL* url); 459 void SetDefaultSearchProviderNoNotify(TemplateURL* url);
456 460
457 // Adds a new TemplateURL to this model. TemplateURLService will own the 461 // Adds a new TemplateURL to this model. TemplateURLService will own the
458 // reference, and delete it when the TemplateURL is removed. 462 // reference, and delete it when the TemplateURL is removed.
459 // If |newly_adding| is false, we assume that this TemplateURL was already 463 // 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 464 // 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. 465 // like assign it an ID or notify sync.
462 // Caller is responsible for notifying observers. 466 // This function guarantees that on return the model will not have two
463 void AddNoNotify(TemplateURL* template_url, bool newly_adding); 467 // non-extension TemplateURLs with the same keyword. If that means that it
468 // cannot add the provided argument, it will delete it and return false.
469 // Caller is responsible for notifying observers if this function returns
470 // true.
471 bool AddNoNotify(TemplateURL* template_url, bool newly_adding);
464 472
465 // Removes the keyword from the model. This deletes the supplied TemplateURL. 473 // Removes the keyword from the model. This deletes the supplied TemplateURL.
466 // This fails if the supplied template_url is the default search provider. 474 // This fails if the supplied template_url is the default search provider.
467 // Caller is responsible for notifying observers. 475 // Caller is responsible for notifying observers.
468 void RemoveNoNotify(TemplateURL* template_url); 476 void RemoveNoNotify(TemplateURL* template_url);
469 477
470 // Notify the observers that the model has changed. This is done only if the 478 // Notify the observers that the model has changed. This is done only if the
471 // model is loaded. 479 // model is loaded.
472 void NotifyObservers(); 480 void NotifyObservers();
473 481
(...skipping 10 matching lines...) Expand all
484 // to the database. This does not notify observers. 492 // to the database. This does not notify observers.
485 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid); 493 void ResetTemplateURLGUID(TemplateURL* url, const std::string& guid);
486 494
487 // Attempts to generate a unique keyword for |turl| based on its original 495 // 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 496 // 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, 497 // 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 498 // and finally it repeatedly appends special characters to the keyword until
491 // it is unique to the Service. 499 // it is unique to the Service.
492 string16 UniquifyKeyword(const TemplateURL& turl); 500 string16 UniquifyKeyword(const TemplateURL& turl);
493 501
494 // Given a TemplateURL from Sync (cloud), resolves any keyword conflicts by 502 // 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 503 // keyword, resolves the conflict by uniquifying either the cloud keyword or
496 // conflicting local keyword (whichever is older). If the cloud TURL is 504 // 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 505 // 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 506 // 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 507 // last_modified dates, |sync_turl| wins.
500 // last_modified dates, |sync_turl| wins. Returns true iff there was a 508 void ResolveSyncKeywordConflict(TemplateURL* sync_turl,
501 // conflict. 509 TemplateURL* local_turl,
502 bool ResolveSyncKeywordConflict(TemplateURL* sync_turl,
503 SyncChangeList* change_list); 510 SyncChangeList* change_list);
504 511
505 // Returns a TemplateURL from the service that has the same keyword and search 512 // Returns a TemplateURL from the service that has the same keyword and search
506 // URL as |sync_turl|, if it exists. 513 // URL as |sync_turl|, if it exists.
507 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl); 514 TemplateURL* FindDuplicateOfSyncTemplateURL(const TemplateURL& sync_turl);
508 515
509 // Given a TemplateURL from the cloud and a local matching duplicate found by 516 // Given a TemplateURL from the cloud and a local matching duplicate found by
510 // FindDuplcateOfSyncTemplateURL, merges the two. If |sync_url| is newer, this 517 // FindDuplcateOfSyncTemplateURL, merges the two. If |sync_url| is newer, this
511 // replaces |local_url| with |sync_url| using the service's Remove and Add. 518 // 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 519 // 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 617 // from Sync. This is to facilitate the fact that changes to the value of
611 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the 618 // prefs::kSyncedDefaultSearchProviderGUID do not always come before the
612 // TemplateURL entry it refers to, and to handle the case when we want to use 619 // 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. 620 // the Synced default when the default search provider becomes unmanaged.
614 bool pending_synced_default_search_; 621 bool pending_synced_default_search_;
615 622
616 DISALLOW_COPY_AND_ASSIGN(TemplateURLService); 623 DISALLOW_COPY_AND_ASSIGN(TemplateURLService);
617 }; 624 };
618 625
619 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_ 626 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698