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

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

Issue 2526753002: Instant cleanup: Remove abandoned EmbeddedSearch Android-only field trials (Closed)
Patch Set: review 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
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return std::string(google_util::kInstantExtendedAPIParam) + "=" + 137 return std::string(google_util::kInstantExtendedAPIParam) + "=" +
152 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; 138 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&";
153 } 139 }
154 140
155 std::string ForceInstantResultsParam(bool for_prerender) { 141 std::string ForceInstantResultsParam(bool for_prerender) {
156 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" 142 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&"
157 : std::string(); 143 : std::string();
158 } 144 }
159 145
160 bool ShouldPrefetchSearchResults() { 146 bool ShouldPrefetchSearchResults() {
161 if (!IsInstantExtendedAPIEnabled()) 147 return IsInstantExtendedAPIEnabled();
162 return false;
163
164 #if defined(OS_ANDROID)
165 FieldTrialFlags flags;
166 return GetFieldTrialInfo(&flags) &&
167 GetBoolValueForFlagWithDefault(kPrefetchSearchResultsFlagName, false,
168 flags);
169 #else
170 return true;
171 #endif
172 } 148 }
173 149
174 bool ShouldReuseInstantSearchBasePage() { 150 bool ShouldReuseInstantSearchBasePage() {
175 if (!ShouldPrefetchSearchResults()) 151 return IsInstantExtendedAPIEnabled();
176 return false;
177
178 #if defined(OS_ANDROID)
179 FieldTrialFlags flags;
180 return GetFieldTrialInfo(&flags) &&
181 GetBoolValueForFlagWithDefault(kReuseInstantSearchBasePage, false,
182 flags);
183 #else
184 return true;
185 #endif
186 } 152 }
187 153
188 // |url| should either have a secure scheme or have a non-HTTPS base URL that 154 // |url| should either have a secure scheme or have a non-HTTPS base URL that
189 // the user specified using --google-base-url. (This allows testers to use 155 // the user specified using --google-base-url. (This allows testers to use
190 // --google-base-url to point at non-HTTPS servers, which eases testing.) 156 // --google-base-url to point at non-HTTPS servers, which eases testing.)
191 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { 157 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) {
192 return template_url->HasSearchTermsReplacementKey(url) && 158 return template_url->HasSearchTermsReplacementKey(url) &&
193 (url.SchemeIsCryptographic() || 159 (url.SchemeIsCryptographic() ||
194 google_util::StartsWithCommandLineGoogleBaseURL(url)); 160 google_util::StartsWithCommandLineGoogleBaseURL(url));
195 } 161 }
196 162
197 } // namespace search 163 } // 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