OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_SEARCH_SEARCH_H_ | 5 #ifndef COMPONENTS_SEARCH_SEARCH_H_ |
6 #define COMPONENTS_SEARCH_SEARCH_H_ | 6 #define COMPONENTS_SEARCH_SEARCH_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 | 13 |
14 class GURL; | |
15 class TemplateURL; | |
16 | |
17 namespace search { | 14 namespace search { |
18 | 15 |
19 // Returns whether the Instant Extended API is enabled. This is always true on | 16 // Returns whether the Instant Extended API is enabled. This is always true on |
20 // desktop and false on mobile. | 17 // desktop and false on mobile. |
21 bool IsInstantExtendedAPIEnabled(); | 18 bool IsInstantExtendedAPIEnabled(); |
22 | 19 |
23 // Returns the value to pass to the &espv CGI parameter when loading the | 20 // Returns the value to pass to the &espv CGI parameter when loading the |
24 // embedded search page from the user's default search provider. Returns 0 if | 21 // embedded search page from the user's default search provider. Returns 0 if |
25 // the Instant Extended API is not enabled. | 22 // the Instant Extended API is not enabled. |
26 uint64_t EmbeddedSearchPageVersion(); | 23 uint64_t EmbeddedSearchPageVersion(); |
27 | 24 |
28 // Type for a collection of experiment configuration parameters. | 25 // Type for a collection of experiment configuration parameters. |
29 typedef base::StringPairs FieldTrialFlags; | 26 typedef base::StringPairs FieldTrialFlags; |
30 | 27 |
31 // Finds the active field trial group name and parses out the configuration | 28 // Finds the active field trial group name and parses out the configuration |
32 // flags. On success, |flags| will be filled with the field trial flags. |flags| | 29 // flags. On success, |flags| will be filled with the field trial flags. |flags| |
33 // must not be NULL. Returns true iff the active field trial is successfully | 30 // must not be NULL. Returns true iff the active field trial is successfully |
34 // parsed and not disabled. | 31 // parsed and not disabled. |
35 // Note that |flags| may be successfully populated in some cases when false is | 32 // Note that |flags| may be successfully populated in some cases when false is |
36 // returned - in these cases it should not be used. | 33 // returned - in these cases it should not be used. |
37 // Exposed for testing only. | 34 // Exposed for testing only. |
38 bool GetFieldTrialInfo(FieldTrialFlags* flags); | 35 bool GetFieldTrialInfo(FieldTrialFlags* flags); |
39 | 36 |
40 // Given a FieldTrialFlags object, returns the string value of the provided | |
41 // flag. | |
42 // Exposed for testing only. | |
43 std::string GetStringValueForFlagWithDefault(const std::string& flag, | |
44 const std::string& default_value, | |
45 const FieldTrialFlags& flags); | |
46 | |
47 // Given a FieldTrialFlags object, returns the uint64_t value of the provided | 37 // Given a FieldTrialFlags object, returns the uint64_t value of the provided |
48 // flag. | 38 // flag. |
49 // Exposed for testing only. | 39 // Exposed for testing only. |
50 uint64_t GetUInt64ValueForFlagWithDefault(const std::string& flag, | 40 uint64_t GetUInt64ValueForFlagWithDefault(const std::string& flag, |
51 uint64_t default_value, | 41 uint64_t default_value, |
52 const FieldTrialFlags& flags); | 42 const FieldTrialFlags& flags); |
53 | 43 |
54 // Given a FieldTrialFlags object, returns the bool value of the provided flag. | |
55 // Exposed for testing only. | |
56 bool GetBoolValueForFlagWithDefault(const std::string& flag, | |
57 bool default_value, | |
58 const FieldTrialFlags& flags); | |
59 | |
60 // Returns a string indicating whether InstantExtended is enabled, suitable | 44 // Returns a string indicating whether InstantExtended is enabled, suitable |
61 // for adding as a query string param to the homepage or search requests. | 45 // for adding as a query string param to the homepage or search requests. |
62 std::string InstantExtendedEnabledParam(); | 46 std::string InstantExtendedEnabledParam(); |
63 | 47 |
64 // Returns a string that will cause the search results page to update | 48 // Returns a string that will cause the search results page to update |
65 // incrementally. Currently, Instant Extended passes a different param to | 49 // incrementally. Currently, Instant Extended passes a different param to |
66 // search results pages that also has this effect, so by default this function | 50 // search results pages that also has this effect, so by default this function |
67 // returns the empty string when Instant Extended is enabled. However, when | 51 // returns the empty string when Instant Extended is enabled. However, when |
68 // doing instant search result prerendering, we still need to pass this param, | 52 // doing instant search result prerendering, we still need to pass this param, |
69 // as Instant Extended does not cause incremental updates by default for the | 53 // as Instant Extended does not cause incremental updates by default for the |
70 // prerender page. Callers should set |for_prerender| in this case to force | 54 // prerender page. Callers should set |for_prerender| in this case to force |
71 // the returned string to be non-empty. | 55 // the returned string to be non-empty. |
72 std::string ForceInstantResultsParam(bool for_prerender); | 56 std::string ForceInstantResultsParam(bool for_prerender); |
73 | 57 |
74 // Returns whether to prefetch high-confidence search suggestions. True iff | |
75 // the Instant Extended API is enabled. | |
76 bool ShouldPrefetchSearchResults(); | |
77 | |
78 // Returns whether to reuse the prerendered page to commit any search query. | |
79 // True iff the Instant Extended API is enabled. | |
80 bool ShouldReuseInstantSearchBasePage(); | |
81 | |
82 // |url| should either have a secure scheme or have a non-HTTPS base URL that | |
83 // the user specified using --google-base-url. (This allows testers to use | |
84 // --google-base-url to point at non-HTTPS servers, which eases testing.) | |
85 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url); | |
86 | |
87 } // namespace search | 58 } // namespace search |
88 | 59 |
89 #endif // COMPONENTS_SEARCH_SEARCH_H_ | 60 #endif // COMPONENTS_SEARCH_SEARCH_H_ |
OLD | NEW |