Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search/search.h" | 5 #include "components/search/search.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), | 92 if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), |
| 93 ':', ' ', flags)) { | 93 ':', ' ', flags)) { |
| 94 // Failed to parse the flags section. Assume the whole group name is | 94 // Failed to parse the flags section. Assume the whole group name is |
| 95 // invalid. | 95 // invalid. |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Given a FieldTrialFlags object, returns the string value of the provided | |
| 103 // flag. | |
| 104 std::string GetStringValueForFlagWithDefault(const std::string& flag, | |
| 105 const std::string& default_value, | |
| 106 const FieldTrialFlags& flags) { | |
| 107 FieldTrialFlags::const_iterator i; | |
| 108 for (i = flags.begin(); i != flags.end(); i++) { | |
| 109 if (i->first == flag) | |
| 110 return i->second; | |
| 111 } | |
| 112 return default_value; | |
| 113 } | |
| 114 | |
| 115 // Given a FieldTrialFlags object, returns the uint64_t value of the provided | 102 // Given a FieldTrialFlags object, returns the uint64_t value of the provided |
| 116 // flag. | 103 // flag. |
| 117 uint64_t GetUInt64ValueForFlagWithDefault(const std::string& flag, | 104 uint64_t GetUInt64ValueForFlagWithDefault(const std::string& flag, |
| 118 uint64_t default_value, | 105 uint64_t default_value, |
| 119 const FieldTrialFlags& flags) { | 106 const FieldTrialFlags& flags) { |
| 120 uint64_t value; | 107 FieldTrialFlags::const_iterator i; |
|
sfiera
2017/01/24 11:16:49
Move declaration into loop?
Marc Treib
2017/01/24 12:37:22
I replaced the loop with a for-each. Iterators mus
| |
| 121 std::string str_value = | 108 for (i = flags.begin(); i != flags.end(); i++) { |
| 122 GetStringValueForFlagWithDefault(flag, std::string(), flags); | 109 if (i->first == flag) { |
| 123 if (base::StringToUint64(str_value, &value)) | 110 const std::string& str_value = i->second; |
| 124 return value; | 111 uint64_t value; |
| 112 if (base::StringToUint64(str_value, &value)) | |
| 113 return value; | |
| 114 } | |
| 115 } | |
| 125 return default_value; | 116 return default_value; |
| 126 } | 117 } |
| 127 | 118 |
| 128 // Given a FieldTrialFlags object, returns the boolean value of the provided | |
| 129 // flag. | |
| 130 bool GetBoolValueForFlagWithDefault(const std::string& flag, | |
| 131 bool default_value, | |
| 132 const FieldTrialFlags& flags) { | |
| 133 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | |
| 134 } | |
| 135 | |
| 136 std::string InstantExtendedEnabledParam() { | 119 std::string InstantExtendedEnabledParam() { |
| 137 return std::string(google_util::kInstantExtendedAPIParam) + "=" + | 120 return std::string(google_util::kInstantExtendedAPIParam) + "=" + |
| 138 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; | 121 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; |
| 139 } | 122 } |
| 140 | 123 |
| 141 std::string ForceInstantResultsParam(bool for_prerender) { | 124 std::string ForceInstantResultsParam(bool for_prerender) { |
| 142 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" | 125 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" |
| 143 : std::string(); | 126 : std::string(); |
| 144 } | 127 } |
| 145 | 128 |
| 146 bool ShouldPrefetchSearchResults() { | |
| 147 return IsInstantExtendedAPIEnabled(); | |
| 148 } | |
| 149 | |
| 150 bool ShouldReuseInstantSearchBasePage() { | |
| 151 return IsInstantExtendedAPIEnabled(); | |
| 152 } | |
| 153 | |
| 154 // |url| should either have a secure scheme or have a non-HTTPS base URL that | |
| 155 // the user specified using --google-base-url. (This allows testers to use | |
| 156 // --google-base-url to point at non-HTTPS servers, which eases testing.) | |
| 157 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { | |
| 158 return template_url->HasSearchTermsReplacementKey(url) && | |
| 159 (url.SchemeIsCryptographic() || | |
| 160 google_util::StartsWithCommandLineGoogleBaseURL(url)); | |
| 161 } | |
| 162 | |
| 163 } // namespace search | 129 } // namespace search |
| OLD | NEW |