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

Side by Side Diff: chrome/browser/net/safe_search_util.cc

Issue 2695883003: Change uses of base::JoinString to pass StringPieces where possible. (Closed)
Patch Set: Fix android_webview compilation (and made FeatureList::SplitFeatureListString take StringPiece). Created 3 years, 9 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
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 "chrome/browser/net/safe_search_util.h" 5 #include "chrome/browser/net/safe_search_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 int g_force_google_safe_search_count_for_test = 0; 26 int g_force_google_safe_search_count_for_test = 0;
27 int g_force_youtube_restrict_count_for_test = 0; 27 int g_force_youtube_restrict_count_for_test = 0;
28 28
29 const char kYouTubeRestrictHeaderName[] = "YouTube-Restrict"; 29 const char kYouTubeRestrictHeaderName[] = "YouTube-Restrict";
30 const char kYouTubeRestrictHeaderValueModerate[] = "Moderate"; 30 const char kYouTubeRestrictHeaderValueModerate[] = "Moderate";
31 const char kYouTubeRestrictHeaderValueStrict[] = "Strict"; 31 const char kYouTubeRestrictHeaderValueStrict[] = "Strict";
32 32
33 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the 33 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the
34 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters 34 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters
35 // must be in key=value form. 35 // must be in key=value form.
36 bool HasSameParameterKey(const std::string& first_parameter, 36 bool HasSameParameterKey(base::StringPiece first_parameter,
37 const std::string& second_parameter) { 37 base::StringPiece second_parameter) {
38 DCHECK(second_parameter.find("=") != std::string::npos); 38 DCHECK(second_parameter.find("=") != std::string::npos);
39 // Prefix for "foo=bar" is "foo=". 39 // Prefix for "foo=bar" is "foo=".
40 std::string parameter_prefix = second_parameter.substr( 40 base::StringPiece parameter_prefix =
41 0, second_parameter.find("=") + 1); 41 second_parameter.substr(0, second_parameter.find("=") + 1);
42 return base::StartsWith(first_parameter, parameter_prefix, 42 return base::StartsWith(first_parameter, parameter_prefix,
43 base::CompareCase::INSENSITIVE_ASCII); 43 base::CompareCase::INSENSITIVE_ASCII);
44 } 44 }
45 45
46 // Examines the query string containing parameters and adds the necessary ones 46 // Examines the query string containing parameters and adds the necessary ones
47 // so that SafeSearch is active. |query| is the string to examine and the 47 // so that SafeSearch is active. |query| is the string to examine and the
48 // return value is the |query| string modified such that SafeSearch is active. 48 // return value is the |query| string modified such that SafeSearch is active.
49 std::string AddSafeSearchParameters(const std::string& query) { 49 std::string AddSafeSearchParameters(const std::string& query) {
50 std::vector<std::string> new_parameters; 50 std::vector<base::StringPiece> new_parameters;
51 std::string safe_parameter = chrome::kSafeSearchSafeParameter; 51 std::string safe_parameter = chrome::kSafeSearchSafeParameter;
52 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter; 52 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter;
53 53
54 for (const std::string& param : base::SplitString( 54 for (auto param : base::SplitStringPiece(query, "&", base::TRIM_WHITESPACE,
Nico 2017/03/15 13:52:11 const auto& (imho, s/auto/base::StringPiece/ is e
Matt Giuca 2017/03/17 00:16:27 See discussion on https://codereview.chromium.org/
Matt Giuca 2017/03/27 03:24:58 Done.
55 query, "&", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 55 base::SPLIT_WANT_ALL)) {
56 if (!HasSameParameterKey(param, safe_parameter) && 56 if (!HasSameParameterKey(param, safe_parameter) &&
57 !HasSameParameterKey(param, ssui_parameter)) { 57 !HasSameParameterKey(param, ssui_parameter)) {
58 new_parameters.push_back(param); 58 new_parameters.push_back(param);
59 } 59 }
60 } 60 }
61 61
62 new_parameters.push_back(safe_parameter); 62 new_parameters.push_back(safe_parameter);
63 new_parameters.push_back(ssui_parameter); 63 new_parameters.push_back(ssui_parameter);
64 return base::JoinString(new_parameters, "&"); 64 return base::JoinString(new_parameters, "&");
65 } 65 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 void ClearForceGoogleSafeSearchCountForTesting() { 128 void ClearForceGoogleSafeSearchCountForTesting() {
129 g_force_google_safe_search_count_for_test = 0; 129 g_force_google_safe_search_count_for_test = 0;
130 } 130 }
131 131
132 void ClearForceYouTubeRestrictCountForTesting() { 132 void ClearForceYouTubeRestrictCountForTesting() {
133 g_force_youtube_restrict_count_for_test = 0; 133 g_force_youtube_restrict_count_for_test = 0;
134 } 134 }
135 135
136 } // namespace safe_search_util 136 } // namespace safe_search_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698