OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 // Which kind of URL within our owner we are. This allows us to get at the | 43 // Which kind of URL within our owner we are. This allows us to get at the |
44 // correct string field. | 44 // correct string field. |
45 enum Type { | 45 enum Type { |
46 SEARCH, | 46 SEARCH, |
47 SUGGEST, | 47 SUGGEST, |
48 INSTANT, | 48 INSTANT, |
49 }; | 49 }; |
50 | 50 |
| 51 // This struct encapsulates arguments passed to |
| 52 // TemplateURLRef::ReplaceSearchTerms methods. By default, only search_terms |
| 53 // is required and is passed in the constructor. |
| 54 struct SearchTermsArgs { |
| 55 explicit SearchTermsArgs(const string16& search_terms); |
| 56 |
| 57 // The search terms (query). |
| 58 const string16 search_terms; |
| 59 // The original (input) query. |
| 60 string16 original_query; |
| 61 // The optional query stats, aka AQS, used for logging purposes. |
| 62 std::string assisted_query_stats; |
| 63 |
| 64 // TODO: Remove along with "aq" CGI param. |
| 65 int accepted_suggestion; |
| 66 }; |
| 67 |
51 TemplateURLRef(TemplateURL* owner, Type type); | 68 TemplateURLRef(TemplateURL* owner, Type type); |
52 ~TemplateURLRef(); | 69 ~TemplateURLRef(); |
53 | 70 |
54 // Returns the raw URL. None of the parameters will have been replaced. | 71 // Returns the raw URL. None of the parameters will have been replaced. |
55 std::string GetURL() const; | 72 std::string GetURL() const; |
56 | 73 |
57 // Returns true if this URL supports replacement. | 74 // Returns true if this URL supports replacement. |
58 bool SupportsReplacement() const; | 75 bool SupportsReplacement() const; |
59 | 76 |
60 // Like SupportsReplacement but usable on threads other than the UI thread. | 77 // Like SupportsReplacement but usable on threads other than the UI thread. |
61 bool SupportsReplacementUsingTermsData( | 78 bool SupportsReplacementUsingTermsData( |
62 const SearchTermsData& search_terms_data) const; | 79 const SearchTermsData& search_terms_data) const; |
63 | 80 |
64 // Returns a string that is the result of replacing the search terms in | 81 // Returns a string that is the result of replacing the search terms in |
65 // the url with the specified value. We use our owner's input encoding. | 82 // the url with the specified arguments. We use our owner's input encoding. |
66 // | 83 // |
67 // If this TemplateURLRef does not support replacement (SupportsReplacement | 84 // If this TemplateURLRef does not support replacement (SupportsReplacement |
68 // returns false), an empty string is returned. | 85 // returns false), an empty string is returned. |
69 std::string ReplaceSearchTerms( | 86 std::string ReplaceSearchTerms( |
70 const string16& terms, | 87 const SearchTermsArgs& search_terms_args) const; |
71 int accepted_suggestion, | |
72 const string16& original_query_for_suggestion) const; | |
73 | 88 |
74 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply | 89 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply |
75 // the data for some search terms. Most of the time ReplaceSearchTerms should | 90 // the data for some search terms. Most of the time ReplaceSearchTerms should |
76 // be called. | 91 // be called. |
77 std::string ReplaceSearchTermsUsingTermsData( | 92 std::string ReplaceSearchTermsUsingTermsData( |
78 const string16& terms, | 93 const SearchTermsArgs& search_terms_args, |
79 int accepted_suggestion, | |
80 const string16& original_query_for_suggestion, | |
81 const SearchTermsData& search_terms_data) const; | 94 const SearchTermsData& search_terms_data) const; |
82 | 95 |
83 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is | 96 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is |
84 // one that contains unknown terms, or invalid characters. | 97 // one that contains unknown terms, or invalid characters. |
85 bool IsValid() const; | 98 bool IsValid() const; |
86 | 99 |
87 // Like IsValid but usable on threads other than the UI thread. | 100 // Like IsValid but usable on threads other than the UI thread. |
88 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; | 101 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; |
89 | 102 |
90 // Returns a string representation of this TemplateURLRef suitable for | 103 // Returns a string representation of this TemplateURLRef suitable for |
(...skipping 28 matching lines...) Expand all Loading... |
119 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); | 132 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); |
120 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); | 133 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); |
121 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); | 134 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); |
122 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); | 135 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); |
123 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter); | 136 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter); |
124 | 137 |
125 // Enumeration of the known types. | 138 // Enumeration of the known types. |
126 enum ReplacementType { | 139 enum ReplacementType { |
127 ENCODING, | 140 ENCODING, |
128 GOOGLE_ACCEPTED_SUGGESTION, | 141 GOOGLE_ACCEPTED_SUGGESTION, |
| 142 GOOGLE_ASSISTED_QUERY_STATS, |
129 GOOGLE_BASE_URL, | 143 GOOGLE_BASE_URL, |
130 GOOGLE_BASE_SUGGEST_URL, | 144 GOOGLE_BASE_SUGGEST_URL, |
131 GOOGLE_INSTANT_ENABLED, | 145 GOOGLE_INSTANT_ENABLED, |
132 GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, | 146 GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, |
133 GOOGLE_RLZ, | 147 GOOGLE_RLZ, |
134 GOOGLE_SEARCH_FIELDTRIAL_GROUP, | 148 GOOGLE_SEARCH_FIELDTRIAL_GROUP, |
135 GOOGLE_UNESCAPED_SEARCH_TERMS, | 149 GOOGLE_UNESCAPED_SEARCH_TERMS, |
136 LANGUAGE, | 150 LANGUAGE, |
137 SEARCH_TERMS, | 151 SEARCH_TERMS, |
138 }; | 152 }; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 TemplateURLRef url_ref_; | 438 TemplateURLRef url_ref_; |
425 TemplateURLRef suggestions_url_ref_; | 439 TemplateURLRef suggestions_url_ref_; |
426 TemplateURLRef instant_url_ref_; | 440 TemplateURLRef instant_url_ref_; |
427 | 441 |
428 // TODO(sky): Add date last parsed OSD file. | 442 // TODO(sky): Add date last parsed OSD file. |
429 | 443 |
430 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 444 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
431 }; | 445 }; |
432 | 446 |
433 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 447 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |