| 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" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 "ion=1&" : std::string(); | 323 "ion=1&" : std::string(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool IsQueryExtractionEnabled() { | 326 bool IsQueryExtractionEnabled() { |
| 327 #if defined(OS_IOS) || defined(OS_ANDROID) | 327 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 328 return true; | 328 return true; |
| 329 #else | 329 #else |
| 330 if (!IsInstantExtendedAPIEnabled()) | 330 if (!IsInstantExtendedAPIEnabled()) |
| 331 return false; | 331 return false; |
| 332 | 332 |
| 333 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 333 const base::CommandLine* command_line = |
| 334 base::CommandLine::ForCurrentProcess(); |
| 334 if (command_line->HasSwitch(switches::kEnableQueryExtraction)) | 335 if (command_line->HasSwitch(switches::kEnableQueryExtraction)) |
| 335 return true; | 336 return true; |
| 336 | 337 |
| 337 FieldTrialFlags flags; | 338 FieldTrialFlags flags; |
| 338 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 339 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 339 kEnableQueryExtractionFlagName, false, flags); | 340 kEnableQueryExtractionFlagName, false, flags); |
| 340 #endif // defined(OS_IOS) || defined(OS_ANDROID) | 341 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 341 } | 342 } |
| 342 | 343 |
| 343 base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url) { | 344 base::string16 ExtractSearchTermsFromURL(Profile* profile, const GURL& url) { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 | 528 |
| 528 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { | 529 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { |
| 529 return ShouldPrefetchSearchResults() ? GetInstantURL(profile, true) : GURL(); | 530 return ShouldPrefetchSearchResults() ? GetInstantURL(profile, true) : GURL(); |
| 530 } | 531 } |
| 531 | 532 |
| 532 bool ShouldPrefetchSearchResults() { | 533 bool ShouldPrefetchSearchResults() { |
| 533 if (!IsInstantExtendedAPIEnabled()) | 534 if (!IsInstantExtendedAPIEnabled()) |
| 534 return false; | 535 return false; |
| 535 | 536 |
| 536 #if defined(OS_ANDROID) | 537 #if defined(OS_ANDROID) |
| 537 if (CommandLine::ForCurrentProcess()->HasSwitch( | 538 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 538 switches::kPrefetchSearchResults)) { | 539 switches::kPrefetchSearchResults)) { |
| 539 return true; | 540 return true; |
| 540 } | 541 } |
| 541 | 542 |
| 542 FieldTrialFlags flags; | 543 FieldTrialFlags flags; |
| 543 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 544 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 544 kPrefetchSearchResultsFlagName, false, flags); | 545 kPrefetchSearchResultsFlagName, false, flags); |
| 545 #else | 546 #else |
| 546 return true; | 547 return true; |
| 547 #endif | 548 #endif |
| (...skipping 28 matching lines...) Expand all Loading... |
| 576 #else | 577 #else |
| 577 return true; | 578 return true; |
| 578 #endif | 579 #endif |
| 579 } | 580 } |
| 580 | 581 |
| 581 GURL GetLocalInstantURL(Profile* profile) { | 582 GURL GetLocalInstantURL(Profile* profile) { |
| 582 return GURL(chrome::kChromeSearchLocalNtpUrl); | 583 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 583 } | 584 } |
| 584 | 585 |
| 585 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() { | 586 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() { |
| 586 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 587 const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 587 if (cl->HasSwitch(switches::kDisableSearchButtonInOmnibox)) | 588 if (cl->HasSwitch(switches::kDisableSearchButtonInOmnibox)) |
| 588 return DISPLAY_SEARCH_BUTTON_NEVER; | 589 return DISPLAY_SEARCH_BUTTON_NEVER; |
| 589 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxForStr)) | 590 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxForStr)) |
| 590 return DISPLAY_SEARCH_BUTTON_FOR_STR; | 591 return DISPLAY_SEARCH_BUTTON_FOR_STR; |
| 591 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxForStrOrIip)) | 592 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxForStrOrIip)) |
| 592 return DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP; | 593 return DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP; |
| 593 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxAlways)) | 594 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxAlways)) |
| 594 return DISPLAY_SEARCH_BUTTON_ALWAYS; | 595 return DISPLAY_SEARCH_BUTTON_ALWAYS; |
| 595 | 596 |
| 596 FieldTrialFlags flags; | 597 FieldTrialFlags flags; |
| 597 if (!GetFieldTrialInfo(&flags)) | 598 if (!GetFieldTrialInfo(&flags)) |
| 598 return DISPLAY_SEARCH_BUTTON_NEVER; | 599 return DISPLAY_SEARCH_BUTTON_NEVER; |
| 599 uint64 value = | 600 uint64 value = |
| 600 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); | 601 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); |
| 601 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? | 602 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? |
| 602 static_cast<DisplaySearchButtonConditions>(value) : | 603 static_cast<DisplaySearchButtonConditions>(value) : |
| 603 DISPLAY_SEARCH_BUTTON_NEVER; | 604 DISPLAY_SEARCH_BUTTON_NEVER; |
| 604 } | 605 } |
| 605 | 606 |
| 606 bool ShouldDisplayOriginChip() { | 607 bool ShouldDisplayOriginChip() { |
| 607 return GetOriginChipCondition() != ORIGIN_CHIP_DISABLED; | 608 return GetOriginChipCondition() != ORIGIN_CHIP_DISABLED; |
| 608 } | 609 } |
| 609 | 610 |
| 610 OriginChipCondition GetOriginChipCondition() { | 611 OriginChipCondition GetOriginChipCondition() { |
| 611 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 612 const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 612 if (cl->HasSwitch(switches::kDisableOriginChip)) | 613 if (cl->HasSwitch(switches::kDisableOriginChip)) |
| 613 return ORIGIN_CHIP_DISABLED; | 614 return ORIGIN_CHIP_DISABLED; |
| 614 if (cl->HasSwitch(switches::kEnableOriginChipAlways)) | 615 if (cl->HasSwitch(switches::kEnableOriginChipAlways)) |
| 615 return ORIGIN_CHIP_ALWAYS; | 616 return ORIGIN_CHIP_ALWAYS; |
| 616 if (cl->HasSwitch(switches::kEnableOriginChipOnSrp)) | 617 if (cl->HasSwitch(switches::kEnableOriginChipOnSrp)) |
| 617 return ORIGIN_CHIP_ON_SRP; | 618 return ORIGIN_CHIP_ON_SRP; |
| 618 | 619 |
| 619 FieldTrialFlags flags; | 620 FieldTrialFlags flags; |
| 620 if (!GetFieldTrialInfo(&flags)) | 621 if (!GetFieldTrialInfo(&flags)) |
| 621 return ORIGIN_CHIP_DISABLED; | 622 return ORIGIN_CHIP_DISABLED; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 return StringToInstantSupportState(value); | 725 return StringToInstantSupportState(value); |
| 725 } | 726 } |
| 726 | 727 |
| 727 bool ShouldPrefetchSearchResultsOnSRP() { | 728 bool ShouldPrefetchSearchResultsOnSRP() { |
| 728 FieldTrialFlags flags; | 729 FieldTrialFlags flags; |
| 729 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 730 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 730 kPrefetchSearchResultsOnSRP, false, flags); | 731 kPrefetchSearchResultsOnSRP, false, flags); |
| 731 } | 732 } |
| 732 | 733 |
| 733 void EnableQueryExtractionForTesting() { | 734 void EnableQueryExtractionForTesting() { |
| 734 CommandLine* cl = CommandLine::ForCurrentProcess(); | 735 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 735 cl->AppendSwitch(switches::kEnableQueryExtraction); | 736 cl->AppendSwitch(switches::kEnableQueryExtraction); |
| 736 } | 737 } |
| 737 | 738 |
| 738 bool ShouldUseAltInstantURL() { | 739 bool ShouldUseAltInstantURL() { |
| 739 FieldTrialFlags flags; | 740 FieldTrialFlags flags; |
| 740 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 741 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 741 kUseAltInstantURL, false, flags); | 742 kUseAltInstantURL, false, flags); |
| 742 } | 743 } |
| 743 | 744 |
| 744 bool ShouldUseSearchPathForInstant() { | 745 bool ShouldUseSearchPathForInstant() { |
| 745 FieldTrialFlags flags; | 746 FieldTrialFlags flags; |
| 746 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 747 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 747 kUseSearchPathForInstant, false, flags); | 748 kUseSearchPathForInstant, false, flags); |
| 748 } | 749 } |
| 749 | 750 |
| 750 } // namespace chrome | 751 } // namespace chrome |
| OLD | NEW |