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

Side by Side Diff: components/variations/net/variations_http_header_provider.cc

Issue 1234973004: Update SplitString calls in components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 5 years, 4 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 "components/variations/net/variations_http_header_provider.h" 5 #include "components/variations/net/variations_http_header_provider.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (!variation_ids_header_copy.empty()) { 81 if (!variation_ids_header_copy.empty()) {
82 // Note that prior to M33 this header was named X-Chrome-Variations. 82 // Note that prior to M33 this header was named X-Chrome-Variations.
83 headers->SetHeaderIfMissing(kClientData, variation_ids_header_copy); 83 headers->SetHeaderIfMissing(kClientData, variation_ids_header_copy);
84 } 84 }
85 } 85 }
86 86
87 bool VariationsHttpHeaderProvider::SetDefaultVariationIds( 87 bool VariationsHttpHeaderProvider::SetDefaultVariationIds(
88 const std::string& variation_ids) { 88 const std::string& variation_ids) {
89 default_variation_ids_set_.clear(); 89 default_variation_ids_set_.clear();
90 default_trigger_id_set_.clear(); 90 default_trigger_id_set_.clear();
91 std::vector<std::string> entries; 91 for (const base::StringPiece& entry : base::SplitStringPiece(
92 base::SplitString(variation_ids, ',', &entries); 92 variation_ids, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
93 for (std::vector<std::string>::const_iterator it = entries.begin(); 93 if (entry.empty()) {
94 it != entries.end(); ++it) {
95 if (it->empty()) {
96 default_variation_ids_set_.clear(); 94 default_variation_ids_set_.clear();
97 default_trigger_id_set_.clear(); 95 default_trigger_id_set_.clear();
98 return false; 96 return false;
99 } 97 }
100 bool trigger_id = base::StartsWith(*it, "t", base::CompareCase::SENSITIVE); 98 bool trigger_id =
99 base::StartsWith(entry, "t", base::CompareCase::SENSITIVE);
101 // Remove the "t" prefix if it's there. 100 // Remove the "t" prefix if it's there.
102 std::string entry = trigger_id ? it->substr(1) : *it; 101 base::StringPiece trimmed_entry = trigger_id ? entry.substr(1) : entry;
103 102
104 int variation_id = 0; 103 int variation_id = 0;
105 if (!base::StringToInt(entry, &variation_id)) { 104 if (!base::StringToInt(trimmed_entry, &variation_id)) {
106 default_variation_ids_set_.clear(); 105 default_variation_ids_set_.clear();
107 default_trigger_id_set_.clear(); 106 default_trigger_id_set_.clear();
108 return false; 107 return false;
109 } 108 }
110 if (trigger_id) 109 if (trigger_id)
111 default_trigger_id_set_.insert(variation_id); 110 default_trigger_id_set_.insert(variation_id);
112 else 111 else
113 default_variation_ids_set_.insert(variation_id); 112 default_variation_ids_set_.insert(variation_id);
114 } 113 }
115 return true; 114 return true;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i], 282 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
284 base::CompareCase::INSENSITIVE_ASCII)) 283 base::CompareCase::INSENSITIVE_ASCII))
285 return true; 284 return true;
286 } 285 }
287 286
288 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 287 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
289 google_util::ALLOW_NON_STANDARD_PORTS); 288 google_util::ALLOW_NON_STANDARD_PORTS);
290 } 289 }
291 290
292 } // namespace variations 291 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698