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

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

Issue 9965143: Revert 130431 - Move the URL string from TemplateURLRef onto the owning TemplateURL. This will mak… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | 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_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 public: 43 public:
44 // Magic numbers to pass to ReplaceSearchTerms() for the |accepted_suggestion| 44 // Magic numbers to pass to ReplaceSearchTerms() for the |accepted_suggestion|
45 // parameter. Most callers aren't using Suggest capabilities and should just 45 // parameter. Most callers aren't using Suggest capabilities and should just
46 // pass NO_SUGGESTIONS_AVAILABLE. 46 // pass NO_SUGGESTIONS_AVAILABLE.
47 // NOTE: Because positive values are meaningful, make sure these are negative! 47 // NOTE: Because positive values are meaningful, make sure these are negative!
48 enum AcceptedSuggestion { 48 enum AcceptedSuggestion {
49 NO_SUGGESTION_CHOSEN = -1, 49 NO_SUGGESTION_CHOSEN = -1,
50 NO_SUGGESTIONS_AVAILABLE = -2, 50 NO_SUGGESTIONS_AVAILABLE = -2,
51 }; 51 };
52 52
53 // Which kind of URL within our owner we are. This allows us to get at the 53 explicit TemplateURLRef(TemplateURL* owner);
54 // correct string field. 54 TemplateURLRef(TemplateURL* owner, const std::string& url);
55 enum Type {
56 SEARCH,
57 SUGGEST,
58 INSTANT,
59 };
60
61 TemplateURLRef(TemplateURL* owner, Type type);
62 ~TemplateURLRef(); 55 ~TemplateURLRef();
63 56
64 // Returns the raw URL. None of the parameters will have been replaced.
65 std::string GetURL() const;
66
67 // Returns true if this URL supports replacement. 57 // Returns true if this URL supports replacement.
68 bool SupportsReplacement() const; 58 bool SupportsReplacement() const;
69 59
70 // Like SupportsReplacement but usable on threads other than the UI thread. 60 // Like SupportsReplacement but usable on threads other than the UI thread.
71 bool SupportsReplacementUsingTermsData( 61 bool SupportsReplacementUsingTermsData(
72 const SearchTermsData& search_terms_data) const; 62 const SearchTermsData& search_terms_data) const;
73 63
74 // Returns a string that is the result of replacing the search terms in 64 // Returns a string that is the result of replacing the search terms in
75 // the url with the specified value. We use our owner's input encoding. 65 // the url with the specified value. We use our owner's input encoding.
76 // 66 //
(...skipping 15 matching lines...) Expand all
92 82
93 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply 83 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply
94 // the data for some search terms. Most of the time ReplaceSearchTerms should 84 // the data for some search terms. Most of the time ReplaceSearchTerms should
95 // be called. 85 // be called.
96 std::string ReplaceSearchTermsUsingTermsData( 86 std::string ReplaceSearchTermsUsingTermsData(
97 const string16& terms, 87 const string16& terms,
98 int accepted_suggestion, 88 int accepted_suggestion,
99 const string16& original_query_for_suggestion, 89 const string16& original_query_for_suggestion,
100 const SearchTermsData& search_terms_data) const; 90 const SearchTermsData& search_terms_data) const;
101 91
92 // Returns the raw URL. None of the parameters will have been replaced.
93 const std::string& url() const { return url_; }
94
102 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is 95 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is
103 // one that contains unknown terms, or invalid characters. 96 // one that contains unknown terms, or invalid characters.
104 bool IsValid() const; 97 bool IsValid() const;
105 98
106 // Like IsValid but usable on threads other than the UI thread. 99 // Like IsValid but usable on threads other than the UI thread.
107 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; 100 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const;
108 101
109 // Returns a string representation of this TemplateURLRef suitable for 102 // Returns a string representation of this TemplateURLRef suitable for
110 // display. The display format is the same as the format used by Firefox. 103 // display. The display format is the same as the format used by Firefox.
111 string16 DisplayURL() const; 104 string16 DisplayURL() const;
(...skipping 11 matching lines...) Expand all
123 // the key of the search term, otherwise this returns an empty string. 116 // the key of the search term, otherwise this returns an empty string.
124 const std::string& GetSearchTermKey() const; 117 const std::string& GetSearchTermKey() const;
125 118
126 // Converts the specified term in our owner's encoding to a string16. 119 // Converts the specified term in our owner's encoding to a string16.
127 string16 SearchTermToString16(const std::string& term) const; 120 string16 SearchTermToString16(const std::string& term) const;
128 121
129 // Returns true if this TemplateURLRef has a replacement term of 122 // Returns true if this TemplateURLRef has a replacement term of
130 // {google:baseURL} or {google:baseSuggestURL}. 123 // {google:baseURL} or {google:baseSuggestURL}.
131 bool HasGoogleBaseURLs() const; 124 bool HasGoogleBaseURLs() const;
132 125
126 // Returns true if both refs are NULL or have the same values.
127 static bool SameUrlRefs(const TemplateURLRef* ref1,
128 const TemplateURLRef* ref2);
129
133 // Collects metrics whether searches through Google are sent with RLZ string. 130 // Collects metrics whether searches through Google are sent with RLZ string.
134 void CollectRLZMetrics() const; 131 void CollectRLZMetrics() const;
135 132
136 private: 133 private:
137 friend class TemplateURL; 134 friend class TemplateURL;
138 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse); 135 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse);
139 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); 136 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown);
140 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); 137 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown);
141 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); 138 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty);
142 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); 139 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd);
(...skipping 25 matching lines...) Expand all
168 size_t index; 165 size_t index;
169 }; 166 };
170 167
171 // The list of elements to replace. 168 // The list of elements to replace.
172 typedef std::vector<struct Replacement> Replacements; 169 typedef std::vector<struct Replacement> Replacements;
173 170
174 // TemplateURLRef internally caches values to make replacement quick. This 171 // TemplateURLRef internally caches values to make replacement quick. This
175 // method invalidates any cached values. 172 // method invalidates any cached values.
176 void InvalidateCachedValues() const; 173 void InvalidateCachedValues() const;
177 174
175 // Resets the url.
176 void Set(const std::string& url);
177
178 // Parses the parameter in url at the specified offset. start/end specify the 178 // Parses the parameter in url at the specified offset. start/end specify the
179 // range of the parameter in the url, including the braces. If the parameter 179 // range of the parameter in the url, including the braces. If the parameter
180 // is valid, url is updated to reflect the appropriate parameter. If 180 // is valid, url is updated to reflect the appropriate parameter. If
181 // the parameter is one of the known parameters an element is added to 181 // the parameter is one of the known parameters an element is added to
182 // replacements indicating the type and range of the element. The original 182 // replacements indicating the type and range of the element. The original
183 // parameter is erased from the url. 183 // parameter is erased from the url.
184 // 184 //
185 // If the parameter is not a known parameter, false is returned. If this is a 185 // If the parameter is not a known parameter, false is returned. If this is a
186 // prepopulated URL, the parameter is erased, otherwise it is left alone. 186 // prepopulated URL, the parameter is erased, otherwise it is left alone.
187 bool ParseParameter(size_t start, 187 bool ParseParameter(size_t start,
(...skipping 17 matching lines...) Expand all
205 205
206 // Like ParseIfNecessary but usable on threads other than the UI thread. 206 // Like ParseIfNecessary but usable on threads other than the UI thread.
207 void ParseIfNecessaryUsingTermsData( 207 void ParseIfNecessaryUsingTermsData(
208 const SearchTermsData& search_terms_data) const; 208 const SearchTermsData& search_terms_data) const;
209 209
210 // Extracts the query key and host from the url. 210 // Extracts the query key and host from the url.
211 void ParseHostAndSearchTermKey( 211 void ParseHostAndSearchTermKey(
212 const SearchTermsData& search_terms_data) const; 212 const SearchTermsData& search_terms_data) const;
213 213
214 // The TemplateURL that contains us. This should outlive us. 214 // The TemplateURL that contains us. This should outlive us.
215 TemplateURL* const owner_; 215 TemplateURL* owner_;
216 216
217 // What kind of URL we are. 217 // The raw URL. Where as this contains all the terms (such as {searchTerms}),
218 const Type type_; 218 // parsed_url_ has them all stripped out.
219 std::string url_;
219 220
220 // Whether the URL has been parsed. 221 // Whether the URL has been parsed.
221 mutable bool parsed_; 222 mutable bool parsed_;
222 223
223 // Whether the url was successfully parsed. 224 // Whether the url was successfully parsed.
224 mutable bool valid_; 225 mutable bool valid_;
225 226
226 // The parsed URL. All terms have been stripped out of this with 227 // The parsed URL. All terms have been stripped out of this with
227 // replacements_ giving the index of the terms to replace. 228 // replacements_ giving the index of the terms to replace.
228 mutable std::string parsed_url_; 229 mutable std::string parsed_url_;
(...skipping 30 matching lines...) Expand all
259 // Generates a favicon URL from the specified url. 260 // Generates a favicon URL from the specified url.
260 static GURL GenerateFaviconURL(const GURL& url); 261 static GURL GenerateFaviconURL(const GURL& url);
261 262
262 // A short description of the template. This is the name we show to the user 263 // A short description of the template. This is the name we show to the user
263 // in various places that use keywords. For example, the location bar shows 264 // in various places that use keywords. For example, the location bar shows
264 // this when the user selects the keyword. 265 // this when the user selects the keyword.
265 void set_short_name(const string16& short_name) { 266 void set_short_name(const string16& short_name) {
266 short_name_ = short_name; 267 short_name_ = short_name;
267 } 268 }
268 const string16& short_name() const { return short_name_; } 269 const string16& short_name() const { return short_name_; }
270
269 // An accessor for the short_name, but adjusted so it can be appropriately 271 // An accessor for the short_name, but adjusted so it can be appropriately
270 // displayed even if it is LTR and the UI is RTL. 272 // displayed even if it is LTR and the UI is RTL.
271 string16 AdjustedShortNameForLocaleDirection() const; 273 string16 AdjustedShortNameForLocaleDirection() const;
272 274
273 // Parameterized URL for providing the results. 275 // Parameterized URL for providing the results. This may be NULL.
276 // Be sure and check the resulting TemplateURLRef for SupportsReplacement
277 // before using.
274 void SetURL(const std::string& url); 278 void SetURL(const std::string& url);
275 const std::string& url() const { return url_; } 279 // Returns the TemplateURLRef that may be used for search results. This
280 // returns NULL if a url element was not specified.
281 const TemplateURLRef* url() const {
282 return url_.url().empty() ? NULL : &url_;
283 }
276 284
277 // URL providing JSON results. This is typically used to provide suggestions 285 // URL providing JSON results. This is typically used to provide suggestions
278 // as you type. 286 // as your type. If NULL, this url does not support suggestions.
287 // Be sure and check the resulting TemplateURLRef for SupportsReplacement
288 // before using.
279 void SetSuggestionsURL(const std::string& url); 289 void SetSuggestionsURL(const std::string& url);
280 const std::string& suggestions_url() const { return suggestions_url_; } 290 const TemplateURLRef* suggestions_url() const {
291 return suggestions_url_.url().empty() ? NULL : &suggestions_url_;
292 }
281 293
282 // Parameterized URL for instant results. 294 // Parameterized URL for instant results. This may be NULL. Be sure and check
295 // the resulting TemplateURLRef for SupportsReplacement before using.
283 void SetInstantURL(const std::string& url); 296 void SetInstantURL(const std::string& url);
284 const std::string& instant_url() const { return instant_url_; } 297 // Returns the TemplateURLRef that may be used for search results. This
298 // returns NULL if a url element was not specified.
299 const TemplateURLRef* instant_url() const {
300 return instant_url_.url().empty() ? NULL : &instant_url_;
301 }
285 302
286 // URL to the OSD file this came from. May be empty. 303 // URL to the OSD file this came from. May be empty.
287 void set_originating_url(const GURL& url) { 304 void set_originating_url(const GURL& url) {
288 originating_url_ = url; 305 originating_url_ = url;
289 } 306 }
290 const GURL& originating_url() const { return originating_url_; } 307 const GURL& originating_url() const { return originating_url_; }
291 308
292 // The shortcut for this template url. May be empty. 309 // The shortcut for this template url. May be empty.
293 void set_keyword(const string16& keyword); 310 void set_keyword(const string16& keyword);
294 const string16& keyword() const; 311 const string16& keyword() const;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 407
391 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0. 408 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0.
392 // SetPrepopulateId also sets any TemplateURLRef's prepopulated flag to true 409 // SetPrepopulateId also sets any TemplateURLRef's prepopulated flag to true
393 // if |id| > 0 and false otherwise. 410 // if |id| > 0 and false otherwise.
394 void SetPrepopulateId(int id); 411 void SetPrepopulateId(int id);
395 int prepopulate_id() const { return prepopulate_id_; } 412 int prepopulate_id() const { return prepopulate_id_; }
396 413
397 const std::string& sync_guid() const { return sync_guid_; } 414 const std::string& sync_guid() const { return sync_guid_; }
398 void set_sync_guid(const std::string& guid) { sync_guid_ = guid; } 415 void set_sync_guid(const std::string& guid) { sync_guid_ = guid; }
399 416
400 const TemplateURLRef& url_ref() const { return url_ref_; }
401 const TemplateURLRef& suggestions_url_ref() const {
402 return suggestions_url_ref_;
403 }
404 const TemplateURLRef& instant_url_ref() const { return instant_url_ref_; }
405
406 // Returns true if |url| supports replacement. 417 // Returns true if |url| supports replacement.
407 bool SupportsReplacement() const; 418 bool SupportsReplacement() const;
408 419
409 // Like SupportsReplacement but usable on threads other than the UI thread. 420 // Like SupportsReplacement but usable on threads other than the UI thread.
410 bool SupportsReplacementUsingTermsData( 421 bool SupportsReplacementUsingTermsData(
411 const SearchTermsData& search_terms_data) const; 422 const SearchTermsData& search_terms_data) const;
412 423
413 std::string GetExtensionId() const; 424 std::string GetExtensionId() const;
414 bool IsExtensionKeyword() const; 425 bool IsExtensionKeyword() const;
415 426
(...skipping 11 matching lines...) Expand all
427 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, 438 FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
428 ResolveSyncKeywordConflict); 439 ResolveSyncKeywordConflict);
429 440
430 // Invalidates cached values on this object and its child TemplateURLRefs. 441 // Invalidates cached values on this object and its child TemplateURLRefs.
431 void InvalidateCachedValues() const; 442 void InvalidateCachedValues() const;
432 443
433 // Unique identifier, used when archived to the database. 444 // Unique identifier, used when archived to the database.
434 void set_id(TemplateURLID id) { id_ = id; } 445 void set_id(TemplateURLID id) { id_ = id; }
435 446
436 string16 short_name_; 447 string16 short_name_;
437 std::string url_; 448 TemplateURLRef url_;
438 std::string suggestions_url_; 449 TemplateURLRef suggestions_url_;
439 std::string instant_url_; 450 TemplateURLRef instant_url_;
440 GURL originating_url_; 451 GURL originating_url_;
441 mutable string16 keyword_; 452 mutable string16 keyword_;
442 bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached 453 bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached
443 // generated keyword if available. 454 // generated keyword if available.
444 mutable bool keyword_generated_; // True if the keyword was generated. This 455 mutable bool keyword_generated_; // True if the keyword was generated. This
445 // is used to avoid multiple attempts if 456 // is used to avoid multiple attempts if
446 // generating a keyword failed. 457 // generating a keyword failed.
447 bool show_in_default_list_; 458 bool show_in_default_list_;
448 bool safe_for_autoreplace_; 459 bool safe_for_autoreplace_;
449 GURL favicon_url_; 460 GURL favicon_url_;
450 // List of supported input encodings. 461 // List of supported input encodings.
451 std::vector<std::string> input_encodings_; 462 std::vector<std::string> input_encodings_;
452 TemplateURLID id_; 463 TemplateURLID id_;
453 base::Time date_created_; 464 base::Time date_created_;
454 base::Time last_modified_; 465 base::Time last_modified_;
455 bool created_by_policy_; 466 bool created_by_policy_;
456 int usage_count_; 467 int usage_count_;
457 int prepopulate_id_; 468 int prepopulate_id_;
458 // The primary unique identifier for Sync. This is only set on TemplateURLs 469 // The primary unique identifier for Sync. This is only set on TemplateURLs
459 // that have been associated with Sync. 470 // that have been associated with Sync.
460 std::string sync_guid_; 471 std::string sync_guid_;
461 472
462 TemplateURLRef url_ref_;
463 TemplateURLRef suggestions_url_ref_;
464 TemplateURLRef instant_url_ref_;
465
466 // TODO(sky): Add date last parsed OSD file. 473 // TODO(sky): Add date last parsed OSD file.
467 }; 474 };
468 475
469 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 476 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/search_host_to_urls_map.cc ('k') | chrome/browser/search_engines/template_url.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698