| OLD | NEW |
| 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 Loading... |
| 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"; |
| 87 const char kGroupNumberPrefix[] = "Group"; | |
| 88 | 87 |
| 89 // If the field trial's group name ends with this string its configuration will | 88 // If the field trial's group name ends with this string its configuration will |
| 90 // be ignored and Instant Extended will not be enabled by default. | 89 // be ignored and Instant Extended will not be enabled by default. |
| 91 const char kDisablingSuffix[] = "DISABLED"; | 90 const char kDisablingSuffix[] = "DISABLED"; |
| 92 | 91 |
| 93 // Remember if we reported metrics about opt-in/out state. | |
| 94 bool instant_extended_opt_in_state_gate = false; | |
| 95 | |
| 96 // Used to set the Instant support state of the Navigation entry. | 92 // Used to set the Instant support state of the Navigation entry. |
| 97 const char kInstantSupportStateKey[] = "instant_support_state"; | 93 const char kInstantSupportStateKey[] = "instant_support_state"; |
| 98 | 94 |
| 99 const char kInstantSupportEnabled[] = "Instant support enabled"; | 95 const char kInstantSupportEnabled[] = "Instant support enabled"; |
| 100 const char kInstantSupportDisabled[] = "Instant support disabled"; | 96 const char kInstantSupportDisabled[] = "Instant support disabled"; |
| 101 const char kInstantSupportUnknown[] = "Instant support unknown"; | 97 const char kInstantSupportUnknown[] = "Instant support unknown"; |
| 102 | 98 |
| 103 InstantSupportState StringToInstantSupportState(const string16& value) { | 99 InstantSupportState StringToInstantSupportState(const string16& value) { |
| 104 if (value == ASCIIToUTF16(kInstantSupportEnabled)) | 100 if (value == ASCIIToUTF16(kInstantSupportEnabled)) |
| 105 return INSTANT_SUPPORT_YES; | 101 return INSTANT_SUPPORT_YES; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 TemplateURLRef ref(template_url, i); | 150 TemplateURLRef ref(template_url, i); |
| 155 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false, false); | 151 search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false, false); |
| 156 if (search_url.is_valid() && | 152 if (search_url.is_valid() && |
| 157 search::MatchesOriginAndPath(url, search_url)) | 153 search::MatchesOriginAndPath(url, search_url)) |
| 158 return true; | 154 return true; |
| 159 } | 155 } |
| 160 | 156 |
| 161 return false; | 157 return false; |
| 162 } | 158 } |
| 163 | 159 |
| 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 | 160 // Returns true if |contents| is rendered inside the Instant process for |
| 181 // |profile|. | 161 // |profile|. |
| 182 bool IsRenderedInInstantProcess(const content::WebContents* contents, | 162 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
| 183 Profile* profile) { | 163 Profile* profile) { |
| 184 const content::RenderProcessHost* process_host = | 164 const content::RenderProcessHost* process_host = |
| 185 contents->GetRenderProcessHost(); | 165 contents->GetRenderProcessHost(); |
| 186 if (!process_host) | 166 if (!process_host) |
| 187 return false; | 167 return false; |
| 188 | 168 |
| 189 const InstantService* instant_service = | 169 const InstantService* instant_service = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 209 |
| 230 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); | 210 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); |
| 231 const GURL instant_url = | 211 const GURL instant_url = |
| 232 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false, false); | 212 TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false, false); |
| 233 if (!instant_url.is_valid()) | 213 if (!instant_url.is_valid()) |
| 234 return false; | 214 return false; |
| 235 | 215 |
| 236 if (search::MatchesOriginAndPath(url, instant_url)) | 216 if (search::MatchesOriginAndPath(url, instant_url)) |
| 237 return true; | 217 return true; |
| 238 | 218 |
| 239 return !ShouldSuppressInstantExtendedOnSRP() && | 219 return IsQueryExtractionEnabled() && MatchesAnySearchURL(url, template_url); |
| 240 MatchesAnySearchURL(url, template_url); | |
| 241 } | 220 } |
| 242 | 221 |
| 243 string16 GetSearchTermsImpl(const content::WebContents* contents, | 222 string16 GetSearchTermsImpl(const content::WebContents* contents, |
| 244 const content::NavigationEntry* entry) { | 223 const content::NavigationEntry* entry) { |
| 245 if (!contents || !IsQueryExtractionEnabled()) | 224 if (!contents || !IsQueryExtractionEnabled()) |
| 246 return string16(); | 225 return string16(); |
| 247 | 226 |
| 248 // For security reasons, don't extract search terms if the page is not being | 227 // 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 | 228 // rendered in the privileged Instant renderer process. This is to protect |
| 250 // against a malicious page somehow scripting the search results page and | 229 // against a malicious page somehow scripting the search results page and |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 264 |
| 286 } // namespace | 265 } // namespace |
| 287 | 266 |
| 288 // Negative start-margin values prevent the "es_sm" parameter from being used. | 267 // Negative start-margin values prevent the "es_sm" parameter from being used. |
| 289 const int kDisableStartMargin = -1; | 268 const int kDisableStartMargin = -1; |
| 290 | 269 |
| 291 bool IsInstantExtendedAPIEnabled() { | 270 bool IsInstantExtendedAPIEnabled() { |
| 292 #if defined(OS_IOS) || defined(OS_ANDROID) | 271 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 293 return false; | 272 return false; |
| 294 #else | 273 #else |
| 295 RecordInstantExtendedOptInState(); | 274 return true; |
| 296 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; | |
| 297 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 275 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 298 } | 276 } |
| 299 | 277 |
| 300 // Determine what embedded search page version to request from the user's | 278 // 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. | 279 // default search provider. |
| 302 uint64 EmbeddedSearchPageVersion() { | 280 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; | 281 FieldTrialFlags flags; |
| 317 uint64 group_num = 0; | 282 if (GetFieldTrialInfo(&flags)) { |
| 318 if (GetFieldTrialInfo(&flags, &group_num)) { | |
| 319 if (group_num == 0) | |
| 320 return kEmbeddedPageVersionDisabled; | |
| 321 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 283 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
| 322 kEmbeddedPageVersionDefault, | 284 kEmbeddedPageVersionDefault, |
| 323 flags); | 285 flags); |
| 324 } | 286 } |
| 325 return kEmbeddedPageVersionDisabled; | 287 return kEmbeddedPageVersionDefault; |
| 326 } | 288 } |
| 327 | 289 |
| 328 bool IsQueryExtractionEnabled() { | 290 bool IsQueryExtractionEnabled() { |
| 329 return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled && | 291 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 330 !ShouldSuppressInstantExtendedOnSRP(); | 292 return true; |
| 293 #else |
| 294 if (!IsInstantExtendedAPIEnabled()) |
| 295 return false; |
| 296 |
| 297 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 298 if (command_line->HasSwitch(switches::kEnableQueryExtraction)) |
| 299 return true; |
| 300 |
| 301 FieldTrialFlags flags; |
| 302 if (GetFieldTrialInfo(&flags)) { |
| 303 return GetBoolValueForFlagWithDefault( |
| 304 kEnableQueryExtractionFlagName, false, flags); |
| 305 } |
| 306 |
| 307 return false; |
| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { | 481 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { |
| 504 return ShouldPrefetchSearchResults() ? | 482 return ShouldPrefetchSearchResults() ? |
| 505 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); | 483 GetInstantURL(profile, kDisableStartMargin, true) : GURL(); |
| 506 } | 484 } |
| 507 | 485 |
| 508 bool ShouldPrefetchSearchResults() { | 486 bool ShouldPrefetchSearchResults() { |
| 509 if (!ShouldUseCacheableNTP()) | 487 if (!ShouldUseCacheableNTP()) |
| 510 return false; | 488 return false; |
| 511 | 489 |
| 512 FieldTrialFlags flags; | 490 FieldTrialFlags flags; |
| 513 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 491 return GetFieldTrialInfo(&flags) && 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 | |
| 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)) | |
| 530 return true; | |
| 531 | |
| 532 FieldTrialFlags flags; | 500 FieldTrialFlags flags; |
| 533 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 501 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 534 kUseRemoteNTPOnStartupFlagName, true, flags); | 502 kUseRemoteNTPOnStartupFlagName, true, flags); |
| 535 } | 503 } |
| 536 | 504 |
| 537 bool ShouldHideTopVerbatimMatch() { | 505 bool ShouldHideTopVerbatimMatch() { |
| 538 FieldTrialFlags flags; | 506 FieldTrialFlags flags; |
| 539 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 507 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 540 kHideVerbatimFlagName, false, flags); | 508 kHideVerbatimFlagName, false, flags); |
| 541 } | 509 } |
| 542 | 510 |
| 543 bool ShouldUseCacheableNTP() { | 511 bool ShouldUseCacheableNTP() { |
| 544 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 545 if (command_line->HasSwitch(switches::kUseCacheableNewTabPage)) | |
| 546 return true; | |
| 547 | |
| 548 FieldTrialFlags flags; | 512 FieldTrialFlags flags; |
| 549 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 513 return !GetFieldTrialInfo(&flags) || |
| 550 kUseCacheableNTP, false, flags); | 514 GetBoolValueForFlagWithDefault(kUseCacheableNTP, true, flags); |
| 551 } | 515 } |
| 552 | 516 |
| 553 bool ShouldShowInstantNTP() { | 517 bool ShouldShowInstantNTP() { |
| 554 // If using the cacheable NTP, load the NTP directly instead of preloading its | 518 // If using the cacheable NTP, load the NTP directly instead of preloading its |
| 555 // contents using InstantNTP. | 519 // contents using InstantNTP. |
| 556 if (ShouldUseCacheableNTP()) | 520 if (ShouldUseCacheableNTP()) |
| 557 return false; | 521 return false; |
| 558 | 522 |
| 559 FieldTrialFlags flags; | 523 FieldTrialFlags flags; |
| 560 return !GetFieldTrialInfo(&flags, NULL) || | 524 return !GetFieldTrialInfo(&flags) || |
| 561 GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); | 525 GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); |
| 562 } | 526 } |
| 563 | 527 |
| 564 bool ShouldShowRecentTabsOnNTP() { | 528 bool ShouldShowRecentTabsOnNTP() { |
| 565 FieldTrialFlags flags; | 529 FieldTrialFlags flags; |
| 566 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 530 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 567 kRecentTabsOnNTPFlagName, false, flags); | 531 kRecentTabsOnNTPFlagName, false, flags); |
| 568 } | 532 } |
| 569 | 533 |
| 570 bool ShouldSuppressInstantExtendedOnSRP() { | |
| 571 FieldTrialFlags flags; | |
| 572 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | |
| 573 kSuppressInstantExtendedOnSRPFlagName, false, flags); | |
| 574 } | |
| 575 | |
| 576 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() { | 534 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() { |
| 577 FieldTrialFlags flags; | 535 FieldTrialFlags flags; |
| 578 if (!GetFieldTrialInfo(&flags, NULL)) | 536 if (!GetFieldTrialInfo(&flags)) |
| 579 return DISPLAY_SEARCH_BUTTON_NEVER; | 537 return DISPLAY_SEARCH_BUTTON_NEVER; |
| 580 uint64 value = | 538 uint64 value = |
| 581 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); | 539 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); |
| 582 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? | 540 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? |
| 583 static_cast<DisplaySearchButtonConditions>(value) : | 541 static_cast<DisplaySearchButtonConditions>(value) : |
| 584 DISPLAY_SEARCH_BUTTON_NEVER; | 542 DISPLAY_SEARCH_BUTTON_NEVER; |
| 585 } | 543 } |
| 586 | 544 |
| 587 bool ShouldDisplayOriginChip() { | 545 bool ShouldDisplayOriginChip() { |
| 588 FieldTrialFlags flags; | 546 FieldTrialFlags flags; |
| 589 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 547 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 590 kEnableOriginChipFlagName, false, flags); | 548 kEnableOriginChipFlagName, false, flags); |
| 591 } | 549 } |
| 592 | 550 |
| 593 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 551 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| 594 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 552 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
| 595 << "Error granting Instant access."; | 553 << "Error granting Instant access."; |
| 596 | 554 |
| 597 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 555 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
| 598 return url; | 556 return url; |
| 599 | 557 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 619 } | 577 } |
| 620 } | 578 } |
| 621 | 579 |
| 622 effective_url = effective_url.ReplaceComponents(replacements); | 580 effective_url = effective_url.ReplaceComponents(replacements); |
| 623 return effective_url; | 581 return effective_url; |
| 624 } | 582 } |
| 625 | 583 |
| 626 int GetInstantLoaderStalenessTimeoutSec() { | 584 int GetInstantLoaderStalenessTimeoutSec() { |
| 627 int timeout_sec = kStalePageTimeoutDefault; | 585 int timeout_sec = kStalePageTimeoutDefault; |
| 628 FieldTrialFlags flags; | 586 FieldTrialFlags flags; |
| 629 if (GetFieldTrialInfo(&flags, NULL)) { | 587 if (GetFieldTrialInfo(&flags)) { |
| 630 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, | 588 timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName, |
| 631 kStalePageTimeoutDefault, | 589 kStalePageTimeoutDefault, |
| 632 flags); | 590 flags); |
| 633 } | 591 } |
| 634 | 592 |
| 635 // Require a minimum 5 minute timeout. | 593 // Require a minimum 5 minute timeout. |
| 636 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) | 594 if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300)) |
| 637 timeout_sec = kStalePageTimeoutDefault; | 595 timeout_sec = kStalePageTimeoutDefault; |
| 638 | 596 |
| 639 // Randomize by upto 15% either side. | 597 // Randomize by upto 15% either side. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 InstantSupportState GetInstantSupportStateFromNavigationEntry( | 663 InstantSupportState GetInstantSupportStateFromNavigationEntry( |
| 706 const content::NavigationEntry& entry) { | 664 const content::NavigationEntry& entry) { |
| 707 string16 value; | 665 string16 value; |
| 708 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) | 666 if (!entry.GetExtraData(kInstantSupportStateKey, &value)) |
| 709 return INSTANT_SUPPORT_UNKNOWN; | 667 return INSTANT_SUPPORT_UNKNOWN; |
| 710 | 668 |
| 711 return StringToInstantSupportState(value); | 669 return StringToInstantSupportState(value); |
| 712 } | 670 } |
| 713 | 671 |
| 714 bool ShouldPrefetchSearchResultsOnSRP() { | 672 bool ShouldPrefetchSearchResultsOnSRP() { |
| 715 // Check the command-line/about:flags setting first, which should have | |
| 716 // precedence and allows the trial to not be reported (if it's never queried). | |
| 717 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 718 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | |
| 719 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | |
| 720 return false; | |
| 721 } | |
| 722 | |
| 723 FieldTrialFlags flags; | 673 FieldTrialFlags flags; |
| 724 return GetFieldTrialInfo(&flags, NULL) && GetBoolValueForFlagWithDefault( | 674 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 725 kPrefetchSearchResultsOnSRP, false, flags); | 675 kPrefetchSearchResultsOnSRP, false, flags); |
| 726 } | 676 } |
| 727 | 677 |
| 728 void EnableInstantExtendedAPIForTesting() { | 678 void EnableQueryExtractionForTesting() { |
| 729 CommandLine* cl = CommandLine::ForCurrentProcess(); | 679 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 730 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 680 cl->AppendSwitch(switches::kEnableQueryExtraction); |
| 731 } | 681 } |
| 732 | 682 |
| 733 void DisableInstantExtendedAPIForTesting() { | 683 bool GetFieldTrialInfo(FieldTrialFlags* flags) { |
| 734 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 735 cl->AppendSwitch(switches::kDisableInstantExtendedAPI); | |
| 736 } | |
| 737 | |
| 738 bool GetFieldTrialInfo(FieldTrialFlags* flags, | |
| 739 uint64* group_number) { | |
| 740 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for | 684 // Get the group name. If the EmbeddedSearch trial doesn't exist, look for |
| 741 // the older InstantExtended name. | 685 // the older InstantExtended name. |
| 742 std::string group_name = base::FieldTrialList::FindFullName( | 686 std::string group_name = base::FieldTrialList::FindFullName( |
| 743 kEmbeddedSearchFieldTrialName); | 687 kEmbeddedSearchFieldTrialName); |
| 744 if (group_name.empty()) { | 688 if (group_name.empty()) { |
| 745 group_name = base::FieldTrialList::FindFullName( | 689 group_name = base::FieldTrialList::FindFullName( |
| 746 kInstantExtendedFieldTrialName); | 690 kInstantExtendedFieldTrialName); |
| 747 } | 691 } |
| 748 | 692 |
| 749 if (EndsWith(group_name, kDisablingSuffix, true)) | 693 if (EndsWith(group_name, kDisablingSuffix, true)) |
| 750 return false; | 694 return false; |
| 751 | 695 |
| 752 // We have a valid trial that isn't disabled. | 696 // We have a valid trial that isn't disabled. Extract the flags. |
| 753 // First extract the flags. | |
| 754 std::string group_prefix(group_name); | 697 std::string group_prefix(group_name); |
| 755 | |
| 756 size_t first_space = group_name.find(" "); | 698 size_t first_space = group_name.find(" "); |
| 757 if (first_space != std::string::npos) { | 699 if (first_space != std::string::npos) { |
| 758 // There is a flags section of the group name. Split that out and parse it. | 700 // There is a flags section of the group name. Split that out and parse it. |
| 759 group_prefix = group_name.substr(0, first_space); | 701 group_prefix = group_name.substr(0, first_space); |
| 760 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), | 702 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), |
| 761 ':', ' ', flags)) { | 703 ':', ' ', flags)) { |
| 762 // Failed to parse the flags section. Assume the whole group name is | 704 // Failed to parse the flags section. Assume the whole group name is |
| 763 // invalid. | 705 // invalid. |
| 764 return false; | 706 return false; |
| 765 } | 707 } |
| 766 } | 708 } |
| 767 | 709 |
| 768 // Now extract the group number, making sure we get a non-zero value. | |
| 769 uint64 temp_group_number = 0; | |
| 770 if (StartsWithASCII(group_name, kGroupNumberPrefix, true)) { | |
| 771 std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); | |
| 772 if (!base::StringToUint64(group_suffix, &temp_group_number)) | |
| 773 return false; | |
| 774 if (group_number) | |
| 775 *group_number = temp_group_number; | |
| 776 } else { | |
| 777 // Instant Extended is not enabled. | |
| 778 if (group_number) | |
| 779 *group_number = 0; | |
| 780 } | |
| 781 | |
| 782 return true; | 710 return true; |
| 783 } | 711 } |
| 784 | 712 |
| 785 // Given a FieldTrialFlags object, returns the string value of the provided | 713 // Given a FieldTrialFlags object, returns the string value of the provided |
| 786 // flag. | 714 // flag. |
| 787 std::string GetStringValueForFlagWithDefault(const std::string& flag, | 715 std::string GetStringValueForFlagWithDefault(const std::string& flag, |
| 788 const std::string& default_value, | 716 const std::string& default_value, |
| 789 const FieldTrialFlags& flags) { | 717 const FieldTrialFlags& flags) { |
| 790 FieldTrialFlags::const_iterator i; | 718 FieldTrialFlags::const_iterator i; |
| 791 for (i = flags.begin(); i != flags.end(); i++) { | 719 for (i = flags.begin(); i != flags.end(); i++) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 809 } | 737 } |
| 810 | 738 |
| 811 // Given a FieldTrialFlags object, returns the boolean value of the provided | 739 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 812 // flag. | 740 // flag. |
| 813 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 741 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 814 bool default_value, | 742 bool default_value, |
| 815 const FieldTrialFlags& flags) { | 743 const FieldTrialFlags& flags) { |
| 816 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 744 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 817 } | 745 } |
| 818 | 746 |
| 819 void ResetInstantExtendedOptInStateGateForTest() { | |
| 820 instant_extended_opt_in_state_gate = false; | |
| 821 } | |
| 822 | |
| 823 } // namespace chrome | 747 } // namespace chrome |
| OLD | NEW |