Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: components/search/search.cc

Issue 2651763002: Cleanup in components/search and chrome/browser/search (Closed)
Patch Set: for each Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/search/search.h ('k') | components/search/search_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 for (const std::pair<std::string, std::string>& flag_and_value : flags) {
121 std::string str_value = 108 if (flag_and_value.first == flag) {
122 GetStringValueForFlagWithDefault(flag, std::string(), flags); 109 const std::string& str_value = flag_and_value.second;
123 if (base::StringToUint64(str_value, &value)) 110 uint64_t value;
124 return value; 111 if (base::StringToUint64(str_value, &value))
112 return value;
113 }
114 }
125 return default_value; 115 return default_value;
126 } 116 }
127 117
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() { 118 std::string InstantExtendedEnabledParam() {
137 return std::string(google_util::kInstantExtendedAPIParam) + "=" + 119 return std::string(google_util::kInstantExtendedAPIParam) + "=" +
138 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&"; 120 base::Uint64ToString(EmbeddedSearchPageVersion()) + "&";
139 } 121 }
140 122
141 std::string ForceInstantResultsParam(bool for_prerender) { 123 std::string ForceInstantResultsParam(bool for_prerender) {
142 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&" 124 return (for_prerender || !IsInstantExtendedAPIEnabled()) ? "ion=1&"
143 : std::string(); 125 : std::string();
144 } 126 }
145 127
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 128 } // namespace search
OLDNEW
« no previous file with comments | « components/search/search.h ('k') | components/search/search_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698