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

Side by Side Diff: components/search/search.cc

Issue 2526753002: Instant cleanup: Remove abandoned EmbeddedSearch Android-only field trials (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « components/search/search.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "components/search/search.h" 5 #include "components/search/search.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "components/google/core/browser/google_util.h" 13 #include "components/google/core/browser/google_util.h"
14 #include "components/search_engines/template_url.h" 14 #include "components/search_engines/template_url.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 namespace search { 17 namespace search {
18 18
19 namespace { 19 namespace {
20 20
21 // Configuration options for Embedded Search. 21 // Configuration options for Embedded Search.
22 // EmbeddedSearch field trials are named in such a way that we can parse out 22 // EmbeddedSearch field trials are named in such a way that we can parse out
23 // the experiment configuration from the trial's group name in order to give 23 // the experiment configuration from the trial's group name in order to give
24 // us maximum flexability in running experiments. 24 // us maximum flexability in running experiments.
25 // Field trial groups should be named things like "Group7 espv:2 instant:1". 25 // Field trial groups should be named things like "Group7 espv:2 instant:1".
26 // The first token is always GroupN for some integer N, followed by a 26 // The first token is always GroupN for some integer N, followed by a
27 // space-delimited list of key:value pairs which correspond to these flags: 27 // space-delimited list of key:value pairs which correspond to these flags:
28 const char kEmbeddedPageVersionFlagName[] = "espv"; 28 const char kEmbeddedPageVersionFlagName[] = "espv";
29 29
30 #if defined(OS_IOS) 30 #if defined(OS_IOS) || defined(OS_ANDROID)
31 const uint64_t kEmbeddedPageVersionDefault = 1; 31 const uint64_t kEmbeddedPageVersionDefault = 1;
32 #elif defined(OS_ANDROID)
33 const uint64_t kEmbeddedPageVersionDefault = 1;
34 // Use this variant to enable EmbeddedSearch SearchBox API in the results page.
35 const uint64_t kEmbeddedSearchEnabledVersion = 2;
36 #else 32 #else
37 const uint64_t kEmbeddedPageVersionDefault = 2; 33 const uint64_t kEmbeddedPageVersionDefault = 2;
38 #endif 34 #endif
39 35
40 // Constants for the field trial name and group prefix. 36 // Constants for the field trial name and group prefix.
41 // Note in M30 and below this field trial was named "InstantExtended" and in 37 // Note in M30 and below this field trial was named "InstantExtended" and in
42 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we 38 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we
43 // can't easilly sync up Finch configs with the pushing of this change to 39 // can't easilly sync up Finch configs with the pushing of this change to
44 // Dev & Canary, for now the code accepts both names. 40 // Dev & Canary, for now the code accepts both names.
45 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta 41 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta
46 // channel. 42 // channel.
47 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; 43 const char kInstantExtendedFieldTrialName[] = "InstantExtended";
48 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; 44 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch";
49 45
50 // If the field trial's group name ends with this string its configuration will 46 // If the field trial's group name ends with this string its configuration will
51 // be ignored and Instant Extended will not be enabled by default. 47 // be ignored and Instant Extended will not be enabled by default.
52 const char kDisablingSuffix[] = "DISABLED"; 48 const char kDisablingSuffix[] = "DISABLED";
53 49
54 #if defined(OS_ANDROID)
55 const char kPrefetchSearchResultsFlagName[] = "prefetch_results";
56
57 // Controls whether to reuse prerendered Instant Search base page to commit any
58 // search query.
59 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page";
60 #endif
61
62 } // namespace 50 } // namespace
63 51
64 bool IsInstantExtendedAPIEnabled() { 52 bool IsInstantExtendedAPIEnabled() {
65 #if defined(OS_IOS) 53 #if defined(OS_IOS) || defined(OS_ANDROID)
66 return false; 54 return false;
67 #elif defined(OS_ANDROID)
68 return EmbeddedSearchPageVersion() == kEmbeddedSearchEnabledVersion;
69 #else 55 #else
70 return true; 56 return true;
71 #endif // defined(OS_IOS) 57 #endif // defined(OS_IOS)
Jered 2016/11/28 23:47:48 nit: please update or remove this comment.
Marc Treib 2016/11/29 14:18:17 Done.
72 } 58 }
73 59
74 // Determine what embedded search page version to request from the user's 60 // Determine what embedded search page version to request from the user's
75 // default search provider. If 0, the embedded search UI should not be enabled. 61 // default search provider. If 0, the embedded search UI should not be enabled.
76 uint64_t EmbeddedSearchPageVersion() { 62 uint64_t EmbeddedSearchPageVersion() {
77 FieldTrialFlags flags; 63 FieldTrialFlags flags;
78 if (GetFieldTrialInfo(&flags)) { 64 if (GetFieldTrialInfo(&flags)) {
79 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, 65 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
80 kEmbeddedPageVersionDefault, 66 kEmbeddedPageVersionDefault,
81 flags); 67 flags);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return std::string(google_util::kInstantExtendedAPIParam) + "=" + 140 return std::string(google_util::kInstantExtendedAPIParam) + "=" +
155 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; 141 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&";
156 } 142 }
157 143
158 std::string ForceInstantResultsParam(bool for_prerender) { 144 std::string ForceInstantResultsParam(bool for_prerender) {
159 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" 145 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&"
160 : std::string(); 146 : std::string();
161 } 147 }
162 148
163 bool ShouldPrefetchSearchResults() { 149 bool ShouldPrefetchSearchResults() {
164 if (!IsInstantExtendedAPIEnabled()) 150 return IsInstantExtendedAPIEnabled();
165 return false;
166
167 #if defined(OS_ANDROID)
168 FieldTrialFlags flags;
169 return GetFieldTrialInfo(&flags) &&
170 GetBoolValueForFlagWithDefault(kPrefetchSearchResultsFlagName, false,
171 flags);
172 #else
173 return true;
174 #endif
175 } 151 }
176 152
177 bool ShouldReuseInstantSearchBasePage() { 153 bool ShouldReuseInstantSearchBasePage() {
178 if (!ShouldPrefetchSearchResults()) 154 return ShouldPrefetchSearchResults();
Jered 2016/11/28 23:47:48 nit: It might be simpler to also have this return
Marc Treib 2016/11/29 14:18:17 Done. (It'd probably make sense to merge all these
179 return false;
180
181 #if defined(OS_ANDROID)
182 FieldTrialFlags flags;
183 return GetFieldTrialInfo(&flags) &&
184 GetBoolValueForFlagWithDefault(kReuseInstantSearchBasePage, false,
185 flags);
186 #else
187 return true;
188 #endif
189 } 155 }
190 156
191 // |url| should either have a secure scheme or have a non-HTTPS base URL that 157 // |url| should either have a secure scheme or have a non-HTTPS base URL that
192 // the user specified using --google-base-url. (This allows testers to use 158 // the user specified using --google-base-url. (This allows testers to use
193 // --google-base-url to point at non-HTTPS servers, which eases testing.) 159 // --google-base-url to point at non-HTTPS servers, which eases testing.)
194 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { 160 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) {
195 return template_url->HasSearchTermsReplacementKey(url) && 161 return template_url->HasSearchTermsReplacementKey(url) &&
196 (url.SchemeIsCryptographic() || 162 (url.SchemeIsCryptographic() ||
197 google_util::StartsWithCommandLineGoogleBaseURL(url)); 163 google_util::StartsWithCommandLineGoogleBaseURL(url));
198 } 164 }
199 165
200 } // namespace search 166 } // namespace search
OLDNEW
« no previous file with comments | « components/search/search.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698