Now that TemplateURLs are guaranteed to have a unique, non-empty keyword, replace AutocompleteMatch's TemplateURL* with a std::string |keyword_|. This has two benefits:
* It's safer in general, because the pointer can't be deleted out from under us. Users inherently have to recheck the TemplateURL* they get via the keyword each time they re-fetch it.
* It allows the SearchProvider to stop keeping copied TemplateURLs for the default and keyword providers (in an attempt to mitigate the above problem) and instead just keep their keywords. This will also help in removing the TemplateURL copy constructor in a later patch.
Note that there already was a |keyword_| field on AutocompleteMatch, so to make this change we have to expand its meaning a bit to cover the scenarios where before we would have had a |template_url_| but not a keyword. Code that cares about this distinction has already been migrated to using functions like GetKeywordUIState() instead of checking the member directly so this isn't terribly invasive.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10382066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135905 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/autocomplete/autocomplete_match.h b/chrome/browser/autocomplete/autocomplete_match.h
index dd53932..cef1892 100644
--- a/chrome/browser/autocomplete/autocomplete_match.h
+++ b/chrome/browser/autocomplete/autocomplete_match.h
@@ -14,6 +14,7 @@
#include "googleurl/src/gurl.h"
class AutocompleteProvider;
+class Profile;
class TemplateURL;
// AutocompleteMatch ----------------------------------------------------------
@@ -168,8 +169,11 @@
// to the associated keyword and |is_keyword_hint| will be set to true. Note
// that only one of these states can be in effect at once. In all other
// cases, |keyword| will be cleared, even when our member variable |keyword|
- // is non-empty. See also GetSubstitutingExplicitlyInvokedKeyword().
- void GetKeywordUIState(string16* keyword,
+ // is non-empty -- such as with non-substituting keywords or matches that
+ // represent searches using the default search engine. See also
+ // GetSubstitutingExplicitlyInvokedKeyword().
+ void GetKeywordUIState(Profile* profile,
+ string16* keyword,
bool* is_keyword_hint) const;
// Returns |keyword|, but only if it represents a substituting keyword that
@@ -178,10 +182,12 @@
// invoke its keyword), this returns the empty string. The result is that
// this function returns a non-empty string in the same cases as when the UI
// should show up as being "in keyword mode".
- string16 GetSubstitutingExplicitlyInvokedKeyword() const;
+ string16 GetSubstitutingExplicitlyInvokedKeyword(Profile* profile) const;
- // Returns the TemplateURL associated with this match.
- TemplateURL* GetTemplateURL() const;
+ // Returns the TemplateURL associated with this match. This may be NULL if
+ // the match has no keyword OR if the keyword no longer corresponds to a valid
+ // TemplateURL. See comments on |keyword| below.
+ TemplateURL* GetTemplateURL(Profile* profile) const;
// The provider of this match, used to remember which provider the user had
// selected when the input changes. This may be NULL, in which case there is
@@ -243,21 +249,19 @@
// |associated_keyword| could be a KeywordProvider match for "amazon.com".
scoped_ptr<AutocompleteMatch> associated_keyword;
- // For matches that correspond to valid substituting keywords ("search
- // engines" that aren't the default engine, or extension keywords), this
- // is the keyword. If this is set, then when displaying this match, the
- // edit will use the "keyword mode" UI that shows a blue
- // "Search <engine name>" chit before the user's typing. This should be
- // set for any match that's an |associated_keyword| of a match in the main
- // result list, as well as any other matches in the main result list that
- // are direct keyword matches (e.g. if the user types in a keyword name and
- // some search terms directly).
+ // The keyword of the TemplateURL the match originated from. This is nonempty
+ // for both explicit "keyword mode" matches as well as matches for the default
+ // search provider (so, any match for which we're doing substitution); it
+ // doesn't imply (alone) that the UI is going to show a keyword hint or
+ // keyword mode. For that, see GetKeywordUIState() or
+ // GetSubstitutingExplicitlyInvokedKeyword().
+ //
+ // CAUTION: The TemplateURL associated with this keyword may be deleted or
+ // modified while the AutocompleteMatch is alive. This means anyone who
+ // accesses it must perform any necessary sanity checks before blindly using
+ // it!
string16 keyword;
- // Indicates the TemplateURL the match originated from. This is set for
- // keywords as well as matches for the default search provider.
- TemplateURL* template_url;
-
// True if the user has starred the destination URL.
bool starred;