Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / search / search.h
blob2ce62047b68cef2597071108e4bba200a1b24c08
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SEARCH_SEARCH_H_
6 #define COMPONENTS_SEARCH_SEARCH_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_split.h"
16 class GURL;
17 class TemplateURL;
19 namespace search {
21 // Use this value for "start margin" to prevent the "es_sm" parameter from
22 // being used.
23 extern const int kDisableStartMargin;
25 // Returns whether the Instant Extended API is enabled.
26 bool IsInstantExtendedAPIEnabled();
28 // Returns the value to pass to the &espv CGI parameter when loading the
29 // embedded search page from the user's default search provider. Returns 0 if
30 // the Instant Extended API is not enabled.
31 uint64 EmbeddedSearchPageVersion();
33 // Type for a collection of experiment configuration parameters.
34 typedef base::StringPairs FieldTrialFlags;
36 // Finds the active field trial group name and parses out the configuration
37 // flags. On success, |flags| will be filled with the field trial flags. |flags|
38 // must not be NULL. Returns true iff the active field trial is successfully
39 // parsed and not disabled.
40 // Note that |flags| may be successfully populated in some cases when false is
41 // returned - in these cases it should not be used.
42 // Exposed for testing only.
43 bool GetFieldTrialInfo(FieldTrialFlags* flags);
45 // Given a FieldTrialFlags object, returns the string value of the provided
46 // flag.
47 // Exposed for testing only.
48 std::string GetStringValueForFlagWithDefault(const std::string& flag,
49 const std::string& default_value,
50 const FieldTrialFlags& flags);
52 // Given a FieldTrialFlags object, returns the uint64 value of the provided
53 // flag.
54 // Exposed for testing only.
55 uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag,
56 uint64 default_value,
57 const FieldTrialFlags& flags);
59 // Given a FieldTrialFlags object, returns the bool value of the provided flag.
60 // Exposed for testing only.
61 bool GetBoolValueForFlagWithDefault(const std::string& flag,
62 bool default_value,
63 const FieldTrialFlags& flags);
65 // Returns a string indicating whether InstantExtended is enabled, suitable
66 // for adding as a query string param to the homepage or search requests.
67 // Returns an empty string otherwise.
69 // |for_search| should be set to true for search requests, in which case this
70 // returns a non-empty string only if query extraction is enabled.
71 std::string InstantExtendedEnabledParam(bool for_search);
73 // Returns a string that will cause the search results page to update
74 // incrementally. Currently, Instant Extended passes a different param to
75 // search results pages that also has this effect, so by default this function
76 // returns the empty string when Instant Extended is enabled. However, when
77 // doing instant search result prerendering, we still need to pass this param,
78 // as Instant Extended does not cause incremental updates by default for the
79 // prerender page. Callers should set |for_prerender| in this case to force
80 // the returned string to be non-empty.
81 std::string ForceInstantResultsParam(bool for_prerender);
83 // Returns whether query extraction is enabled.
84 bool IsQueryExtractionEnabled();
86 // Returns true if 'prefetch_results' flag is set to true in field trials to
87 // prefetch high-confidence search suggestions.
88 bool ShouldPrefetchSearchResults();
90 // Returns true if 'reuse_instant_search_base_page' flag is set to true in field
91 // trials to reuse the prerendered page to commit any search query.
92 bool ShouldReuseInstantSearchBasePage();
94 // Returns true if 'allow_prefetch_non_default_match' flag is enabled in field
95 // trials to allow prefetching the suggestion marked to be prefetched by the
96 // suggest server even if it is not the default match.
97 bool ShouldAllowPrefetchNonDefaultMatch();
99 // |url| should either have a secure scheme or have a non-HTTPS base URL that
100 // the user specified using --google-base-url. (This allows testers to use
101 // --google-base-url to point at non-HTTPS servers, which eases testing.)
102 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url);
104 // -----------------------------------------------------
105 // The following APIs are exposed for use in tests only.
106 // -----------------------------------------------------
108 // Forces query in the omnibox to be on for tests.
109 void EnableQueryExtractionForTesting();
111 } // namespace search
113 #endif // COMPONENTS_SEARCH_SEARCH_H_