Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/browser/search_engines/template_url_id.h" | 14 #include "chrome/browser/search_engines/template_url_id.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 | 16 |
| 17 class Profile; | 17 class Profile; |
| 18 class SearchTermsData; | 18 class SearchTermsData; |
| 19 class TemplateURL; | 19 class TemplateURL; |
| 20 | 20 |
| 21 | 21 |
| 22 // SearchTermsArgs ------------------------------------------------------------ | |
|
Peter Kasting
2012/06/16 03:14:17
Nit: While I'm loathe to spoil the simplicity of t
Bart N
2012/06/16 23:38:10
Yes. I also think it makes more sense.
| |
| 23 | |
| 24 // This struct encapsulates arguments passed to | |
| 25 // TemplateURLRef::ReplaceSearchTerms methods. By default, only search_terms | |
| 26 // is required and is passed in the constructor. | |
| 27 struct SearchTermsArgs { | |
| 28 explicit SearchTermsArgs(const string16& search_terms); | |
| 29 | |
| 30 // The search terms (query). | |
| 31 const string16 search_terms; | |
| 32 // The original (input) query. | |
| 33 string16 original_query; | |
| 34 // Teh optional query stats, aka AQS, used for logging purposes. | |
|
Peter Kasting
2012/06/16 03:14:17
Nit: Teh->The
Bart N
2012/06/16 23:38:10
Done.
| |
| 35 string16 assisted_query_stats; | |
|
Peter Kasting
2012/06/16 03:14:17
Use a std::string here. This isn't a UI string, a
Bart N
2012/06/16 23:38:10
Done.
| |
| 36 | |
| 37 // TODO: Remove along with "aq" CGI param. | |
| 38 int accepted_suggestion; | |
| 39 }; | |
| 40 | |
| 22 // TemplateURLRef ------------------------------------------------------------- | 41 // TemplateURLRef ------------------------------------------------------------- |
| 23 | 42 |
| 24 // A TemplateURLRef represents a single URL within the larger TemplateURL class | 43 // A TemplateURLRef represents a single URL within the larger TemplateURL class |
| 25 // (which represents an entire "search engine", see below). If | 44 // (which represents an entire "search engine", see below). If |
| 26 // SupportsReplacement() is true, this URL has placeholders in it, for which | 45 // SupportsReplacement() is true, this URL has placeholders in it, for which |
| 27 // callers can substitute values to get a "real" URL using ReplaceSearchTerms(). | 46 // callers can substitute values to get a "real" URL using ReplaceSearchTerms(). |
| 28 // | 47 // |
| 29 // TemplateURLRefs always have a non-NULL |owner_| TemplateURL, which they | 48 // TemplateURLRefs always have a non-NULL |owner_| TemplateURL, which they |
| 30 // access in order to get at important data like the underlying URL string or | 49 // access in order to get at important data like the underlying URL string or |
| 31 // the associated Profile. | 50 // the associated Profile. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 55 std::string GetURL() const; | 74 std::string GetURL() const; |
| 56 | 75 |
| 57 // Returns true if this URL supports replacement. | 76 // Returns true if this URL supports replacement. |
| 58 bool SupportsReplacement() const; | 77 bool SupportsReplacement() const; |
| 59 | 78 |
| 60 // Like SupportsReplacement but usable on threads other than the UI thread. | 79 // Like SupportsReplacement but usable on threads other than the UI thread. |
| 61 bool SupportsReplacementUsingTermsData( | 80 bool SupportsReplacementUsingTermsData( |
| 62 const SearchTermsData& search_terms_data) const; | 81 const SearchTermsData& search_terms_data) const; |
| 63 | 82 |
| 64 // Returns a string that is the result of replacing the search terms in | 83 // 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. | 84 // the url with the specified arguments. We use our owner's input encoding. |
| 66 // | 85 // |
| 67 // If this TemplateURLRef does not support replacement (SupportsReplacement | 86 // If this TemplateURLRef does not support replacement (SupportsReplacement |
| 68 // returns false), an empty string is returned. | 87 // returns false), an empty string is returned. |
| 69 std::string ReplaceSearchTerms( | 88 std::string ReplaceSearchTerms( |
| 70 const string16& terms, | 89 const SearchTermsArgs& search_terms_args) const; |
| 71 int accepted_suggestion, | |
| 72 const string16& original_query_for_suggestion) const; | |
| 73 | 90 |
| 74 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply | 91 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply |
| 75 // the data for some search terms. Most of the time ReplaceSearchTerms should | 92 // the data for some search terms. Most of the time ReplaceSearchTerms should |
| 76 // be called. | 93 // be called. |
| 77 std::string ReplaceSearchTermsUsingTermsData( | 94 std::string ReplaceSearchTermsUsingTermsData( |
| 78 const string16& terms, | 95 const SearchTermsArgs& search_terms_args, |
| 79 int accepted_suggestion, | |
| 80 const string16& original_query_for_suggestion, | |
| 81 const SearchTermsData& search_terms_data) const; | 96 const SearchTermsData& search_terms_data) const; |
| 82 | 97 |
| 83 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is | 98 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is |
| 84 // one that contains unknown terms, or invalid characters. | 99 // one that contains unknown terms, or invalid characters. |
| 85 bool IsValid() const; | 100 bool IsValid() const; |
| 86 | 101 |
| 87 // Like IsValid but usable on threads other than the UI thread. | 102 // Like IsValid but usable on threads other than the UI thread. |
| 88 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; | 103 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; |
| 89 | 104 |
| 90 // Returns a string representation of this TemplateURLRef suitable for | 105 // Returns a string representation of this TemplateURLRef suitable for |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 119 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); | 134 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); |
| 120 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); | 135 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); |
| 121 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); | 136 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); |
| 122 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); | 137 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); |
| 123 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter); | 138 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNestedParameter); |
| 124 | 139 |
| 125 // Enumeration of the known types. | 140 // Enumeration of the known types. |
| 126 enum ReplacementType { | 141 enum ReplacementType { |
| 127 ENCODING, | 142 ENCODING, |
| 128 GOOGLE_ACCEPTED_SUGGESTION, | 143 GOOGLE_ACCEPTED_SUGGESTION, |
| 144 GOOGLE_ASSISTED_QUERY_STATS, | |
| 129 GOOGLE_BASE_URL, | 145 GOOGLE_BASE_URL, |
| 130 GOOGLE_BASE_SUGGEST_URL, | 146 GOOGLE_BASE_SUGGEST_URL, |
| 131 GOOGLE_INSTANT_ENABLED, | 147 GOOGLE_INSTANT_ENABLED, |
| 132 GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, | 148 GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, |
| 133 GOOGLE_RLZ, | 149 GOOGLE_RLZ, |
| 134 GOOGLE_SEARCH_FIELDTRIAL_GROUP, | 150 GOOGLE_SEARCH_FIELDTRIAL_GROUP, |
| 135 GOOGLE_UNESCAPED_SEARCH_TERMS, | 151 GOOGLE_UNESCAPED_SEARCH_TERMS, |
| 136 LANGUAGE, | 152 LANGUAGE, |
| 137 SEARCH_TERMS, | 153 SEARCH_TERMS, |
| 138 }; | 154 }; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 TemplateURLRef url_ref_; | 440 TemplateURLRef url_ref_; |
| 425 TemplateURLRef suggestions_url_ref_; | 441 TemplateURLRef suggestions_url_ref_; |
| 426 TemplateURLRef instant_url_ref_; | 442 TemplateURLRef instant_url_ref_; |
| 427 | 443 |
| 428 // TODO(sky): Add date last parsed OSD file. | 444 // TODO(sky): Add date last parsed OSD file. |
| 429 | 445 |
| 430 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 446 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
| 431 }; | 447 }; |
| 432 | 448 |
| 433 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 449 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| OLD | NEW |