| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; | 58 const char kReuseInstantSearchBasePage[] = "reuse_instant_search_base_page"; |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 // Controls whether to use the alternate Instant search base URL. This allows | 61 // Controls whether to use the alternate Instant search base URL. This allows |
| 62 // experimentation of Instant search. | 62 // experimentation of Instant search. |
| 63 const char kUseAltInstantURL[] = "use_alternate_instant_url"; | 63 const char kUseAltInstantURL[] = "use_alternate_instant_url"; |
| 64 const char kUseSearchPathForInstant[] = "use_search_path_for_instant"; | 64 const char kUseSearchPathForInstant[] = "use_search_path_for_instant"; |
| 65 const char kAltInstantURLPath[] = "search"; | 65 const char kAltInstantURLPath[] = "search"; |
| 66 const char kAltInstantURLQueryParams[] = "&qbp=1"; | 66 const char kAltInstantURLQueryParams[] = "&qbp=1"; |
| 67 | 67 |
| 68 const char kDisplaySearchButtonFlagName[] = "display_search_button"; | |
| 69 const char kOriginChipFlagName[] = "origin_chip"; | |
| 70 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 68 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 71 const char kEnableQueryExtractionFlagName[] = "query_extraction"; | 69 const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
| 72 #endif | 70 #endif |
| 73 const char kShouldShowGoogleLocalNTPFlagName[] = "google_local_ntp"; | 71 const char kShouldShowGoogleLocalNTPFlagName[] = "google_local_ntp"; |
| 74 | 72 |
| 75 // Status of the New Tab URL for the default Search provider. NOTE: Used in a | 73 // Status of the New Tab URL for the default Search provider. NOTE: Used in a |
| 76 // UMA histogram so values should only be added at the end and not reordered. | 74 // UMA histogram so values should only be added at the end and not reordered. |
| 77 enum NewTabURLState { | 75 enum NewTabURLState { |
| 78 // Valid URL that should be used. | 76 // Valid URL that should be used. |
| 79 NEW_TAB_URL_VALID = 0, | 77 NEW_TAB_URL_VALID = 0, |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 kReuseInstantSearchBasePage, false, flags); | 574 kReuseInstantSearchBasePage, false, flags); |
| 577 #else | 575 #else |
| 578 return true; | 576 return true; |
| 579 #endif | 577 #endif |
| 580 } | 578 } |
| 581 | 579 |
| 582 GURL GetLocalInstantURL(Profile* profile) { | 580 GURL GetLocalInstantURL(Profile* profile) { |
| 583 return GURL(chrome::kChromeSearchLocalNtpUrl); | 581 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 584 } | 582 } |
| 585 | 583 |
| 586 DisplaySearchButtonConditions GetDisplaySearchButtonConditions() { | |
| 587 const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | |
| 588 if (cl->HasSwitch(switches::kDisableSearchButtonInOmnibox)) | |
| 589 return DISPLAY_SEARCH_BUTTON_NEVER; | |
| 590 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxForStr)) | |
| 591 return DISPLAY_SEARCH_BUTTON_FOR_STR; | |
| 592 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxForStrOrIip)) | |
| 593 return DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP; | |
| 594 if (cl->HasSwitch(switches::kEnableSearchButtonInOmniboxAlways)) | |
| 595 return DISPLAY_SEARCH_BUTTON_ALWAYS; | |
| 596 | |
| 597 FieldTrialFlags flags; | |
| 598 if (!GetFieldTrialInfo(&flags)) | |
| 599 return DISPLAY_SEARCH_BUTTON_NEVER; | |
| 600 uint64 value = | |
| 601 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); | |
| 602 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? | |
| 603 static_cast<DisplaySearchButtonConditions>(value) : | |
| 604 DISPLAY_SEARCH_BUTTON_NEVER; | |
| 605 } | |
| 606 | |
| 607 bool ShouldDisplayOriginChip() { | |
| 608 return GetOriginChipCondition() != ORIGIN_CHIP_DISABLED; | |
| 609 } | |
| 610 | |
| 611 OriginChipCondition GetOriginChipCondition() { | |
| 612 const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | |
| 613 if (cl->HasSwitch(switches::kDisableOriginChip)) | |
| 614 return ORIGIN_CHIP_DISABLED; | |
| 615 if (cl->HasSwitch(switches::kEnableOriginChipAlways)) | |
| 616 return ORIGIN_CHIP_ALWAYS; | |
| 617 if (cl->HasSwitch(switches::kEnableOriginChipOnSrp)) | |
| 618 return ORIGIN_CHIP_ON_SRP; | |
| 619 | |
| 620 FieldTrialFlags flags; | |
| 621 if (!GetFieldTrialInfo(&flags)) | |
| 622 return ORIGIN_CHIP_DISABLED; | |
| 623 uint64 value = | |
| 624 GetUInt64ValueForFlagWithDefault(kOriginChipFlagName, 0, flags); | |
| 625 return (value < ORIGIN_CHIP_NUM_VALUES) ? | |
| 626 static_cast<OriginChipCondition>(value) : ORIGIN_CHIP_DISABLED; | |
| 627 } | |
| 628 | |
| 629 bool ShouldShowGoogleLocalNTP() { | 584 bool ShouldShowGoogleLocalNTP() { |
| 630 FieldTrialFlags flags; | 585 FieldTrialFlags flags; |
| 631 return !GetFieldTrialInfo(&flags) || GetBoolValueForFlagWithDefault( | 586 return !GetFieldTrialInfo(&flags) || GetBoolValueForFlagWithDefault( |
| 632 kShouldShowGoogleLocalNTPFlagName, true, flags); | 587 kShouldShowGoogleLocalNTPFlagName, true, flags); |
| 633 } | 588 } |
| 634 | 589 |
| 635 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 590 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| 636 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 591 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
| 637 << "Error granting Instant access."; | 592 << "Error granting Instant access."; |
| 638 | 593 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 kUseAltInstantURL, false, flags); | 697 kUseAltInstantURL, false, flags); |
| 743 } | 698 } |
| 744 | 699 |
| 745 bool ShouldUseSearchPathForInstant() { | 700 bool ShouldUseSearchPathForInstant() { |
| 746 FieldTrialFlags flags; | 701 FieldTrialFlags flags; |
| 747 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 702 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( |
| 748 kUseSearchPathForInstant, false, flags); | 703 kUseSearchPathForInstant, false, flags); |
| 749 } | 704 } |
| 750 | 705 |
| 751 } // namespace chrome | 706 } // namespace chrome |
| OLD | NEW |