| 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // The staleness timeout can be set (in seconds) via this config. | 62 // The staleness timeout can be set (in seconds) via this config. |
| 63 const char kStalePageTimeoutFlagName[] = "stale"; | 63 const char kStalePageTimeoutFlagName[] = "stale"; |
| 64 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. | 64 const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours. |
| 65 | 65 |
| 66 const char kHideVerbatimFlagName[] = "hide_verbatim"; | 66 const char kHideVerbatimFlagName[] = "hide_verbatim"; |
| 67 const char kShowNtpFlagName[] = "show_ntp"; | 67 const char kShowNtpFlagName[] = "show_ntp"; |
| 68 const char kUseCacheableNTP[] = "use_cacheable_ntp"; | 68 const char kUseCacheableNTP[] = "use_cacheable_ntp"; |
| 69 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; | 69 const char kPrefetchSearchResultsFlagName[] = "prefetch_results"; |
| 70 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; | 70 const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp"; |
| 71 const char kDisplaySearchButtonFlagName[] = "display_search_button"; | 71 const char kDisplaySearchButtonFlagName[] = "display_search_button"; |
| 72 const char kEnableOriginChipFlagName[] = "origin_chip"; | 72 const char kOriginChipFlagName[] = "origin_chip"; |
| 73 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 73 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
| 74 const char kEnableQueryExtractionFlagName[] = "query_extraction"; | 74 const char kEnableQueryExtractionFlagName[] = "query_extraction"; |
| 75 #endif | 75 #endif |
| 76 | 76 |
| 77 // Constants for the field trial name and group prefix. | 77 // Constants for the field trial name and group prefix. |
| 78 // Note in M30 and below this field trial was named "InstantExtended" and in | 78 // Note in M30 and below this field trial was named "InstantExtended" and in |
| 79 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we | 79 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we |
| 80 // can't easilly sync up Finch configs with the pushing of this change to | 80 // can't easilly sync up Finch configs with the pushing of this change to |
| 81 // Dev & Canary, for now the code accepts both names. | 81 // Dev & Canary, for now the code accepts both names. |
| 82 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta | 82 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 if (!GetFieldTrialInfo(&flags)) | 539 if (!GetFieldTrialInfo(&flags)) |
| 540 return DISPLAY_SEARCH_BUTTON_NEVER; | 540 return DISPLAY_SEARCH_BUTTON_NEVER; |
| 541 uint64 value = | 541 uint64 value = |
| 542 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); | 542 GetUInt64ValueForFlagWithDefault(kDisplaySearchButtonFlagName, 0, flags); |
| 543 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? | 543 return (value < DISPLAY_SEARCH_BUTTON_NUM_VALUES) ? |
| 544 static_cast<DisplaySearchButtonConditions>(value) : | 544 static_cast<DisplaySearchButtonConditions>(value) : |
| 545 DISPLAY_SEARCH_BUTTON_NEVER; | 545 DISPLAY_SEARCH_BUTTON_NEVER; |
| 546 } | 546 } |
| 547 | 547 |
| 548 bool ShouldDisplayOriginChip() { | 548 bool ShouldDisplayOriginChip() { |
| 549 return GetOriginChipPosition() != ORIGIN_CHIP_DISABLED; |
| 550 } |
| 551 |
| 552 OriginChipPosition GetOriginChipPosition() { |
| 549 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 553 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 550 if (cl->HasSwitch(switches::kDisableOriginChip)) { | 554 if (cl->HasSwitch(switches::kDisableOriginChip)) { |
| 551 return false; | 555 return ORIGIN_CHIP_DISABLED; |
| 552 } else if (cl->HasSwitch(switches::kEnableOriginChip)) { | 556 } else if (cl->HasSwitch(switches::kEnableOriginChipLeftOfLocationBar)) { |
| 553 return true; | 557 return ORIGIN_CHIP_LEFT_OF_LOCATION_BAR; |
| 558 } else if (cl->HasSwitch(switches::kEnableOriginChip) || |
| 559 cl->HasSwitch(switches::kEnableOriginChipRightOfLocationBar)) { |
| 560 return ORIGIN_CHIP_RIGHT_OF_LOCATION_BAR; |
| 561 } else if (cl->HasSwitch(switches::kEnableOriginChipLeftOfMenu)) { |
| 562 return ORIGIN_CHIP_LEFT_OF_MENU; |
| 554 } | 563 } |
| 555 | 564 |
| 556 FieldTrialFlags flags; | 565 FieldTrialFlags flags; |
| 557 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( | 566 if (!GetFieldTrialInfo(&flags)) |
| 558 kEnableOriginChipFlagName, false, flags); | 567 return ORIGIN_CHIP_DISABLED; |
| 568 uint64 value = |
| 569 GetUInt64ValueForFlagWithDefault(kOriginChipFlagName, 0, flags); |
| 570 return (value < ORIGIN_CHIP_NUM_VALUES) ? |
| 571 static_cast<OriginChipPosition>(value) : |
| 572 ORIGIN_CHIP_DISABLED; |
| 559 } | 573 } |
| 560 | 574 |
| 561 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 575 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
| 562 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 576 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
| 563 << "Error granting Instant access."; | 577 << "Error granting Instant access."; |
| 564 | 578 |
| 565 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 579 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
| 566 return url; | 580 return url; |
| 567 | 581 |
| 568 GURL effective_url(url); | 582 GURL effective_url(url); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 761 |
| 748 // Given a FieldTrialFlags object, returns the boolean value of the provided | 762 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 749 // flag. | 763 // flag. |
| 750 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 764 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 751 bool default_value, | 765 bool default_value, |
| 752 const FieldTrialFlags& flags) { | 766 const FieldTrialFlags& flags) { |
| 753 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 767 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 754 } | 768 } |
| 755 | 769 |
| 756 } // namespace chrome | 770 } // namespace chrome |
| OLD | NEW |