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

Side by Side Diff: chrome/browser/search/search.cc

Issue 23522025: InstantExtended: add a finch flag to disable Instant Extended on SRP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests. Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/search/search.h ('k') | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/search/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const char kStalePageTimeoutFlagName[] = "stale"; 57 const char kStalePageTimeoutFlagName[] = "stale";
58 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. 58 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours.
59 const int kStalePageTimeoutDisabled = 0; 59 const int kStalePageTimeoutDisabled = 0;
60 60
61 const char kHideVerbatimFlagName[] = "hide_verbatim"; 61 const char kHideVerbatimFlagName[] = "hide_verbatim";
62 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; 62 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup";
63 const char kShowNtpFlagName[] = "show_ntp"; 63 const char kShowNtpFlagName[] = "show_ntp";
64 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; 64 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs";
65 const char kUseCacheableNTP[] = "use_cacheable_ntp"; 65 const char kUseCacheableNTP[] = "use_cacheable_ntp";
66 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; 66 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
67 const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp";
67 68
68 // Constants for the field trial name and group prefix. 69 // Constants for the field trial name and group prefix.
69 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; 70 const char kInstantExtendedFieldTrialName[] = "InstantExtended";
70 const char kGroupNumberPrefix[] = "Group"; 71 const char kGroupNumberPrefix[] = "Group";
71 72
72 // If the field trial's group name ends with this string its configuration will 73 // If the field trial's group name ends with this string its configuration will
73 // be ignored and Instant Extended will not be enabled by default. 74 // be ignored and Instant Extended will not be enabled by default.
74 const char kDisablingSuffix[] = "DISABLED"; 75 const char kDisablingSuffix[] = "DISABLED";
75 76
76 // Remember if we reported metrics about opt-in/out state. 77 // Remember if we reported metrics about opt-in/out state.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 224 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
224 if (!template_url) 225 if (!template_url)
225 return false; 226 return false;
226 227
227 if (!IsSuitableURLForInstant(url, template_url)) 228 if (!IsSuitableURLForInstant(url, template_url))
228 return false; 229 return false;
229 230
230 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); 231 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
231 const GURL instant_url = 232 const GURL instant_url =
232 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); 233 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false);
233 return instant_url.is_valid() && 234 if (!instant_url.is_valid())
234 (MatchesOriginAndPath(url, instant_url) || 235 return false;
235 MatchesAnySearchURL(url, template_url)); 236
237 if (MatchesOriginAndPath(url, instant_url))
238 return true;
239
240 return !ShouldSuppressInstantExtendedOnSRP() &&
241 MatchesAnySearchURL(url, template_url);
236 } 242 }
237 243
238 string16 GetSearchTermsImpl(const content::WebContents* contents, 244 string16 GetSearchTermsImpl(const content::WebContents* contents,
239 const content::NavigationEntry* entry) { 245 const content::NavigationEntry* entry) {
240 if (!contents || !IsQueryExtractionEnabled()) 246 if (!contents || !IsQueryExtractionEnabled())
241 return string16(); 247 return string16();
242 248
243 // For security reasons, don't extract search terms if the page is not being 249 // For security reasons, don't extract search terms if the page is not being
244 // rendered in the privileged Instant renderer process. This is to protect 250 // rendered in the privileged Instant renderer process. This is to protect
245 // against a malicious page somehow scripting the search results page and 251 // against a malicious page somehow scripting the search results page and
(...skipping 20 matching lines...) Expand all
266 272
267 } // namespace 273 } // namespace
268 274
269 // Negative start-margin values prevent the "es_sm" parameter from being used. 275 // Negative start-margin values prevent the "es_sm" parameter from being used.
270 const int kDisableStartMargin = -1; 276 const int kDisableStartMargin = -1;
271 277
272 bool IsInstantExtendedAPIEnabled() { 278 bool IsInstantExtendedAPIEnabled() {
273 #if defined(OS_IOS) || defined(OS_ANDROID) 279 #if defined(OS_IOS) || defined(OS_ANDROID)
274 return false; 280 return false;
275 #else 281 #else
276 // On desktop, query extraction is part of Instant extended, so if one is
277 // enabled, the other is too.
278 RecordInstantExtendedOptInState(); 282 RecordInstantExtendedOptInState();
279 return IsQueryExtractionEnabled(); 283 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled;
280 #endif // defined(OS_IOS) || defined(OS_ANDROID) 284 #endif // defined(OS_IOS) || defined(OS_ANDROID)
281 } 285 }
282 286
283 // Determine what embedded search page version to request from the user's 287 // Determine what embedded search page version to request from the user's
284 // default search provider. If 0, the embedded search UI should not be enabled. 288 // default search provider. If 0, the embedded search UI should not be enabled.
285 uint64 EmbeddedSearchPageVersion() { 289 uint64 EmbeddedSearchPageVersion() {
286 RecordInstantExtendedOptInState(); 290 RecordInstantExtendedOptInState();
287 291
288 // Check the command-line/about:flags setting first, which should have 292 // Check the command-line/about:flags setting first, which should have
289 // precedence and allows the trial to not be reported (if it's never queried). 293 // precedence and allows the trial to not be reported (if it's never queried).
(...skipping 14 matching lines...) Expand all
304 if (group_num == 0) 308 if (group_num == 0)
305 return kEmbeddedPageVersionDisabled; 309 return kEmbeddedPageVersionDisabled;
306 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, 310 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
307 kEmbeddedPageVersionDefault, 311 kEmbeddedPageVersionDefault,
308 flags); 312 flags);
309 } 313 }
310 return kEmbeddedPageVersionDisabled; 314 return kEmbeddedPageVersionDisabled;
311 } 315 }
312 316
313 bool IsQueryExtractionEnabled() { 317 bool IsQueryExtractionEnabled() {
314 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; 318 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled &&
319 !ShouldSuppressInstantExtendedOnSRP();
315 } 320 }
316 321
317 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { 322 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
318 string16 search_terms; 323 string16 search_terms;
319 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 324 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
320 if (template_url && IsSuitableURLForInstant(url, template_url)) 325 if (template_url && IsSuitableURLForInstant(url, template_url))
321 template_url->ExtractSearchTermsFromURL(url, &search_terms); 326 template_url->ExtractSearchTermsFromURL(url, &search_terms);
322 return search_terms; 327 return search_terms;
323 } 328 }
324 329
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 if (GetFieldTrialInfo( 506 if (GetFieldTrialInfo(
502 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), 507 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
503 &flags, NULL)) { 508 &flags, NULL)) {
504 return GetBoolValueForFlagWithDefault( 509 return GetBoolValueForFlagWithDefault(
505 kRecentTabsOnNTPFlagName, false, flags); 510 kRecentTabsOnNTPFlagName, false, flags);
506 } 511 }
507 512
508 return false; 513 return false;
509 } 514 }
510 515
516 bool ShouldSuppressInstantExtendedOnSRP() {
517 FieldTrialFlags flags;
518 if (GetFieldTrialInfo(
519 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
520 &flags, NULL)) {
521 return GetBoolValueForFlagWithDefault(
522 kSuppressInstantExtendedOnSRPFlagName, false, flags);
523 }
524
525 return false;
526 }
527
511 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { 528 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) {
512 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); 529 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path();
513 } 530 }
514 531
515 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { 532 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
516 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) 533 CHECK(ShouldAssignURLToInstantRenderer(url, profile))
517 << "Error granting Instant access."; 534 << "Error granting Instant access.";
518 535
519 if (url.SchemeIs(chrome::kChromeSearchScheme)) 536 if (url.SchemeIs(chrome::kChromeSearchScheme))
520 return url; 537 return url;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 bool default_value, 750 bool default_value,
734 const FieldTrialFlags& flags) { 751 const FieldTrialFlags& flags) {
735 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); 752 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
736 } 753 }
737 754
738 void ResetInstantExtendedOptInStateGateForTest() { 755 void ResetInstantExtendedOptInStateGateForTest() {
739 instant_extended_opt_in_state_gate = false; 756 instant_extended_opt_in_state_gate = false;
740 } 757 }
741 758
742 } // namespace chrome 759 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/search/search.h ('k') | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698