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

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

Issue 73613002: InstantExtended: remove old flags, add new flag for query extraction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 1 month 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"
10 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
11 #include "base/rand_util.h" 10 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/google/google_util.h" 15 #include "chrome/browser/google/google_util.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/search/instant_service.h" 18 #include "chrome/browser/search/instant_service.h"
(...skipping 26 matching lines...) Expand all
46 namespace { 45 namespace {
47 46
48 // Configuration options for Embedded Search. 47 // Configuration options for Embedded Search.
49 // EmbeddedSearch field trials are named in such a way that we can parse out 48 // EmbeddedSearch field trials are named in such a way that we can parse out
50 // the experiment configuration from the trial's group name in order to give 49 // the experiment configuration from the trial's group name in order to give
51 // us maximum flexability in running experiments. 50 // us maximum flexability in running experiments.
52 // Field trial groups should be named things like "Group7 espv:2 instant:1". 51 // Field trial groups should be named things like "Group7 espv:2 instant:1".
53 // The first token is always GroupN for some integer N, followed by a 52 // The first token is always GroupN for some integer N, followed by a
54 // space-delimited list of key:value pairs which correspond to these flags: 53 // space-delimited list of key:value pairs which correspond to these flags:
55 const char kEmbeddedPageVersionFlagName[] = "espv"; 54 const char kEmbeddedPageVersionFlagName[] = "espv";
56 const uint64 kEmbeddedPageVersionDisabled = 0;
57 #if defined(OS_IOS) || defined(OS_ANDROID) 55 #if defined(OS_IOS) || defined(OS_ANDROID)
58 const uint64 kEmbeddedPageVersionDefault = 1; 56 const uint64 kEmbeddedPageVersionDefault = 1;
59 #else 57 #else
60 const uint64 kEmbeddedPageVersionDefault = 2; 58 const uint64 kEmbeddedPageVersionDefault = 2;
61 #endif 59 #endif
62 60
63 // The staleness timeout can be set (in seconds) via this config. 61 // The staleness timeout can be set (in seconds) via this config.
64 const char kStalePageTimeoutFlagName[] = "stale"; 62 const char kStalePageTimeoutFlagName[] = "stale";
65 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. 63 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours.
66 64
67 const char kHideVerbatimFlagName[] = "hide_verbatim"; 65 const char kHideVerbatimFlagName[] = "hide_verbatim";
68 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup"; 66 const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup";
69 const char kShowNtpFlagName[] = "show_ntp"; 67 const char kShowNtpFlagName[] = "show_ntp";
70 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs"; 68 const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs";
71 const char kUseCacheableNTP[] = "use_cacheable_ntp"; 69 const char kUseCacheableNTP[] = "use_cacheable_ntp";
72 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; 70 const char kPrefetchSearchResultsFlagName[] = "prefetch_results";
73 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; 71 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
74 const char kSuppressInstantExtendedOnSRPFlagName[] = "suppress_on_srp";
75 const char kDisplaySearchButtonFlagName[] = "display_search_button"; 72 const char kDisplaySearchButtonFlagName[] = "display_search_button";
76 const char kEnableOriginChipFlagName[] = "origin_chip"; 73 const char kEnableOriginChipFlagName[] = "origin_chip";
74 #if !defined(OS_IOS) && !defined(OS_ANDROID)
75 const char kEnableQueryExtractionFlagName[] = "query_extraction";
76 #endif
77 77
78 // Constants for the field trial name and group prefix. 78 // Constants for the field trial name and group prefix.
79 // Note in M30 and below this field trial was named "InstantExtended" and in 79 // Note in M30 and below this field trial was named "InstantExtended" and in
80 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we 80 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we
81 // can't easilly sync up Finch configs with the pushing of this change to 81 // can't easilly sync up Finch configs with the pushing of this change to
82 // Dev & Canary, for now the code accepts both names. 82 // Dev & Canary, for now the code accepts both names.
83 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta 83 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta
84 // channel. 84 // channel.
85 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; 85 const char kInstantExtendedFieldTrialName[] = "InstantExtended";
86 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch"; 86 const char kEmbeddedSearchFieldTrialName[] = "EmbeddedSearch";
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 TemplateURLRef ref(template_url, i); 154 TemplateURLRef ref(template_url, i);
155 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false, false); 155 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false, false);
156 if (search_url.is_valid() && 156 if (search_url.is_valid() &&
157 search::MatchesOriginAndPath(url, search_url)) 157 search::MatchesOriginAndPath(url, search_url))
158 return true; 158 return true;
159 } 159 }
160 160
161 return false; 161 return false;
162 } 162 }
163 163
164 void RecordInstantExtendedOptInState() {
165 if (instant_extended_opt_in_state_gate)
166 return;
167
168 instant_extended_opt_in_state_gate = true;
169 OptInState state = INSTANT_EXTENDED_NOT_SET;
170 const CommandLine* command_line = CommandLine::ForCurrentProcess();
171 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI))
172 state = INSTANT_EXTENDED_OPT_OUT;
173 else if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI))
174 state = INSTANT_EXTENDED_OPT_IN;
175
176 UMA_HISTOGRAM_ENUMERATION("InstantExtended.NewOptInState", state,
177 INSTANT_EXTENDED_OPT_IN_STATE_ENUM_COUNT);
178 }
179
180 // Returns true if |contents| is rendered inside the Instant process for 164 // Returns true if |contents| is rendered inside the Instant process for
181 // |profile|. 165 // |profile|.
182 bool IsRenderedInInstantProcess(const content::WebContents* contents, 166 bool IsRenderedInInstantProcess(const content::WebContents* contents,
183 Profile* profile) { 167 Profile* profile) {
184 const content::RenderProcessHost* process_host = 168 const content::RenderProcessHost* process_host =
185 contents->GetRenderProcessHost(); 169 contents->GetRenderProcessHost();
186 if (!process_host) 170 if (!process_host)
187 return false; 171 return false;
188 172
189 const InstantService* instant_service = 173 const InstantService* instant_service =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 213
230 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); 214 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
231 const GURL instant_url = 215 const GURL instant_url =
232 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false, false); 216 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false, false);
233 if (!instant_url.is_valid()) 217 if (!instant_url.is_valid())
234 return false; 218 return false;
235 219
236 if (search::MatchesOriginAndPath(url, instant_url)) 220 if (search::MatchesOriginAndPath(url, instant_url))
237 return true; 221 return true;
238 222
239 return !ShouldSuppressInstantExtendedOnSRP() && 223 return IsQueryExtractionEnabled() && MatchesAnySearchURL(url, template_url);
240 MatchesAnySearchURL(url, template_url);
241 } 224 }
242 225
243 string16 GetSearchTermsImpl(const content::WebContents* contents, 226 string16 GetSearchTermsImpl(const content::WebContents* contents,
244 const content::NavigationEntry* entry) { 227 const content::NavigationEntry* entry) {
245 if (!contents || !IsQueryExtractionEnabled()) 228 if (!contents || !IsQueryExtractionEnabled())
246 return string16(); 229 return string16();
247 230
248 // For security reasons, don't extract search terms if the page is not being 231 // For security reasons, don't extract search terms if the page is not being
249 // rendered in the privileged Instant renderer process. This is to protect 232 // rendered in the privileged Instant renderer process. This is to protect
250 // against a malicious page somehow scripting the search results page and 233 // against a malicious page somehow scripting the search results page and
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 268
286 } // namespace 269 } // namespace
287 270
288 // Negative start-margin values prevent the "es_sm" parameter from being used. 271 // Negative start-margin values prevent the "es_sm" parameter from being used.
289 const int kDisableStartMargin = -1; 272 const int kDisableStartMargin = -1;
290 273
291 bool IsInstantExtendedAPIEnabled() { 274 bool IsInstantExtendedAPIEnabled() {
292 #if defined(OS_IOS) || defined(OS_ANDROID) 275 #if defined(OS_IOS) || defined(OS_ANDROID)
293 return false; 276 return false;
294 #else 277 #else
295 RecordInstantExtendedOptInState(); 278 return true;
296 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled;
297 #endif // defined(OS_IOS) || defined(OS_ANDROID) 279 #endif // defined(OS_IOS) || defined(OS_ANDROID)
298 } 280 }
299 281
300 // Determine what embedded search page version to request from the user's 282 // Determine what embedded search page version to request from the user's
301 // default search provider. If 0, the embedded search UI should not be enabled. 283 // default search provider. If 0, the embedded search UI should not be enabled.
302 uint64 EmbeddedSearchPageVersion() { 284 uint64 EmbeddedSearchPageVersion() {
303 RecordInstantExtendedOptInState();
304
305 // Check the command-line/about:flags setting first, which should have
306 // precedence and allows the trial to not be reported (if it's never queried).
307 const CommandLine* command_line = CommandLine::ForCurrentProcess();
308 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI))
309 return kEmbeddedPageVersionDisabled;
310 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) {
311 // The user has set the about:flags switch to Enabled - give the default
312 // UI version.
313 return kEmbeddedPageVersionDefault;
314 }
315
316 FieldTrialFlags flags; 285 FieldTrialFlags flags;
317 uint64 group_num = 0; 286 if (GetFieldTrialInfo(&flags, NULL)) {
318 if (GetFieldTrialInfo(&flags, &group_num)) {
319 if (group_num == 0)
320 return kEmbeddedPageVersionDefault;
321 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, 287 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
322 kEmbeddedPageVersionDefault, 288 kEmbeddedPageVersionDefault,
323 flags); 289 flags);
324 } 290 }
325 return kEmbeddedPageVersionDefault; 291 return kEmbeddedPageVersionDefault;
326 } 292 }
327 293
328 bool IsQueryExtractionEnabled() { 294 bool IsQueryExtractionEnabled() {
329 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled && 295 #if defined(OS_IOS) || defined(OS_ANDROID)
330 !ShouldSuppressInstantExtendedOnSRP(); 296 return true;
297 #else
298 if (!IsInstantExtendedAPIEnabled())
299 return false;
300
301 const CommandLine* command_line = CommandLine::ForCurrentProcess();
302 if (command_line->HasSwitch(switches::kEnableQueryExtraction))
303 return true;
304
305 FieldTrialFlags flags;
306 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault(
307 kEnableQueryExtractionFlagName, false, flags);
308 #endif // defined(OS_IOS) || defined(OS_ANDROID)
331 } 309 }
332 310
333 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) { 311 string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
334 string16 search_terms; 312 string16 search_terms;
335 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 313 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
336 if (template_url && IsSuitableURLForInstant(url, template_url)) 314 if (template_url && IsSuitableURLForInstant(url, template_url))
337 template_url->ExtractSearchTermsFromURL(url, &search_terms); 315 template_url->ExtractSearchTermsFromURL(url, &search_terms);
338 return search_terms; 316 return search_terms;
339 } 317 }
340 318
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 FieldTrialFlags flags; 490 FieldTrialFlags flags;
513 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( 491 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault(
514 kPrefetchSearchResultsFlagName, false, flags); 492 kPrefetchSearchResultsFlagName, false, flags);
515 } 493 }
516 494
517 GURL GetLocalInstantURL(Profile* profile) { 495 GURL GetLocalInstantURL(Profile* profile) {
518 return GURL(chrome::kChromeSearchLocalNtpUrl); 496 return GURL(chrome::kChromeSearchLocalNtpUrl);
519 } 497 }
520 498
521 bool ShouldPreferRemoteNTPOnStartup() { 499 bool ShouldPreferRemoteNTPOnStartup() {
522 // Check the command-line/about:flags setting first, which should have 500 CommandLine* command_line = CommandLine::ForCurrentProcess();
523 // precedence and allows the trial to not be reported (if it's never queried).
524 const CommandLine* command_line = CommandLine::ForCurrentProcess();
525 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) ||
526 command_line->HasSwitch(switches::kEnableLocalFirstLoadNTP)) {
527 return false;
528 }
529 if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP)) 501 if (command_line->HasSwitch(switches::kDisableLocalFirstLoadNTP))
530 return true; 502 return true;
531 503
532 FieldTrialFlags flags; 504 FieldTrialFlags flags;
533 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( 505 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault(
534 kUseRemoteNTPOnStartupFlagName, true, flags); 506 kUseRemoteNTPOnStartupFlagName, true, flags);
535 } 507 }
536 508
537 bool ShouldHideTopVerbatimMatch() { 509 bool ShouldHideTopVerbatimMatch() {
538 FieldTrialFlags flags; 510 FieldTrialFlags flags;
(...skipping 17 matching lines...) Expand all
556 return !GetFieldTrialInfo(&flags, NULL) || 528 return !GetFieldTrialInfo(&flags, NULL) ||
557 GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); 529 GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags);
558 } 530 }
559 531
560 bool ShouldShowRecentTabsOnNTP() { 532 bool ShouldShowRecentTabsOnNTP() {
561 FieldTrialFlags flags; 533 FieldTrialFlags flags;
562 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( 534 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault(
563 kRecentTabsOnNTPFlagName, false, flags); 535 kRecentTabsOnNTPFlagName, false, flags);
564 } 536 }
565 537
566 bool ShouldSuppressInstantExtendedOnSRP() {
567 FieldTrialFlags flags;
568
569 const CommandLine* command_line = CommandLine::ForCurrentProcess();
570 if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI))
571 return false;
572
573 return !GetFieldTrialInfo(&flags, NULL) || GetBoolValueForFlagWithDefault(
574 kSuppressInstantExtendedOnSRPFlagName, true, flags);
575 }
576
577 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() { 538 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() {
578 FieldTrialFlags flags; 539 FieldTrialFlags flags;
579 if (!GetFieldTrialInfo(&flags, NULL)) 540 if (!GetFieldTrialInfo(&flags, NULL))
580 return DISPLAY_SEARCH_BUTTON_NEVER; 541 return DISPLAY_SEARCH_BUTTON_NEVER;
581 uint64 value = 542 uint64 value =
582 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); 543 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags);
583 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? 544 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ?
584 static_cast<DisplaySearchButtonConditions>(value) : 545 static_cast<DisplaySearchButtonConditions>(value) :
585 DISPLAY_SEARCH_BUTTON_NEVER; 546 DISPLAY_SEARCH_BUTTON_NEVER;
586 } 547 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 InstantSupportState GetInstantSupportStateFromNavigationEntry( 667 InstantSupportState GetInstantSupportStateFromNavigationEntry(
707 const content::NavigationEntry& entry) { 668 const content::NavigationEntry& entry) {
708 string16 value; 669 string16 value;
709 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) 670 if (!entry.GetExtraData(kInstantSupportStateKey, &value))
710 return INSTANT_SUPPORT_UNKNOWN; 671 return INSTANT_SUPPORT_UNKNOWN;
711 672
712 return StringToInstantSupportState(value); 673 return StringToInstantSupportState(value);
713 } 674 }
714 675
715 bool ShouldPrefetchSearchResultsOnSRP() { 676 bool ShouldPrefetchSearchResultsOnSRP() {
716 // Check the command-line/about:flags setting first, which should have
717 // precedence and allows the trial to not be reported (if it's never queried).
718 const CommandLine* command_line = CommandLine::ForCurrentProcess();
719 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) ||
720 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) {
721 return false;
722 }
723
724 FieldTrialFlags flags; 677 FieldTrialFlags flags;
725 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( 678 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault(
726 kPrefetchSearchResultsOnSRP, false, flags); 679 kPrefetchSearchResultsOnSRP, false, flags);
727 } 680 }
728 681
729 void EnableInstantExtendedAPIForTesting() { 682 void EnableQueryExtractionForTesting() {
730 CommandLine* cl = CommandLine::ForCurrentProcess(); 683 CommandLine* cl = CommandLine::ForCurrentProcess();
731 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); 684 cl->AppendSwitch(switches::kEnableQueryExtraction);
732 }
733
734 void DisableInstantExtendedAPIForTesting() {
735 CommandLine* cl = CommandLine::ForCurrentProcess();
736 cl->AppendSwitch(switches::kDisableInstantExtendedAPI);
737 } 685 }
738 686
739 bool GetFieldTrialInfo(FieldTrialFlags* flags, 687 bool GetFieldTrialInfo(FieldTrialFlags* flags,
740 uint64* group_number) { 688 uint64* group_number) {
741 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for 689 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for
742 // the older InstantExtended name. 690 // the older InstantExtended name.
743 std::string group_name = base::FieldTrialList::FindFullName( 691 std::string group_name = base::FieldTrialList::FindFullName(
744 kEmbeddedSearchFieldTrialName); 692 kEmbeddedSearchFieldTrialName);
745 if (group_name.empty()) { 693 if (group_name.empty()) {
746 group_name = base::FieldTrialList::FindFullName( 694 group_name = base::FieldTrialList::FindFullName(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 bool default_value, 763 bool default_value,
816 const FieldTrialFlags& flags) { 764 const FieldTrialFlags& flags) {
817 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); 765 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
818 } 766 }
819 767
820 void ResetInstantExtendedOptInStateGateForTest() { 768 void ResetInstantExtendedOptInStateGateForTest() {
821 instant_extended_opt_in_state_gate = false; 769 instant_extended_opt_in_state_gate = false;
822 } 770 }
823 771
824 } // namespace chrome 772 } // 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