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

Side by Side Diff: components/domain_reliability/header.cc

Issue 2613223002: Remove ScopedVector from base::JSONValueConverter (Closed)
Patch Set: Created 3 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/domain_reliability/header.h" 5 #include "components/domain_reliability/header.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10
11 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_tokenizer.h" 12 #include "base/strings/string_tokenizer.h"
14 #include "components/domain_reliability/config.h" 13 #include "components/domain_reliability/config.h"
15 #include "content/public/common/origin_util.h" 14 #include "content/public/common/origin_util.h"
16 15
17 namespace { 16 namespace {
18 17
19 // Parses directives in the format ("foo; bar=value for bar; baz; quux=123") 18 // Parses directives in the format ("foo; bar=value for bar; baz; quux=123")
20 // used by NEL. 19 // used by NEL.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return false; 150 return false;
152 151
153 if ((first == '"') || (first == '<')) 152 if ((first == '"') || (first == '<'))
154 *out = in.substr(1, in.length() - 2); 153 *out = in.substr(1, in.length() - 2);
155 else 154 else
156 *out = in; 155 *out = in;
157 return true; 156 return true;
158 } 157 }
159 158
160 bool ParseReportUri(const std::vector<base::StringPiece> in, 159 bool ParseReportUri(const std::vector<base::StringPiece> in,
161 ScopedVector<GURL>* out) { 160 std::vector<std::unique_ptr<GURL>>* out) {
162 if (in.size() < 1u) 161 if (in.size() < 1u)
163 return false; 162 return false;
164 163
165 out->clear(); 164 out->clear();
166 for (const auto& in_token : in) { 165 for (const auto& in_token : in) {
167 std::string unquoted; 166 std::string unquoted;
168 if (!Unquote(in_token.as_string(), &unquoted)) 167 if (!Unquote(in_token.as_string(), &unquoted))
169 return false; 168 return false;
170 GURL url(unquoted); 169 GURL url(unquoted);
171 if (!url.is_valid() || !content::IsOriginSecure(url)) 170 if (!url.is_valid() || !content::IsOriginSecure(url))
172 return false; 171 return false;
173 out->push_back(new GURL(url)); 172 out->push_back(base::MakeUnique<GURL>(url));
174 } 173 }
175 174
176 return true; 175 return true;
177 } 176 }
178 177
179 bool ParseMaxAge(const std::vector<base::StringPiece> in, 178 bool ParseMaxAge(const std::vector<base::StringPiece> in,
180 base::TimeDelta* out) { 179 base::TimeDelta* out) {
181 if (in.size() != 1u) 180 if (in.size() != 1u)
182 return false; 181 return false;
183 182
(...skipping 10 matching lines...) Expand all
194 193
195 } // namespace 194 } // namespace
196 195
197 namespace domain_reliability { 196 namespace domain_reliability {
198 197
199 DomainReliabilityHeader::~DomainReliabilityHeader() {} 198 DomainReliabilityHeader::~DomainReliabilityHeader() {}
200 199
201 // static 200 // static
202 std::unique_ptr<DomainReliabilityHeader> DomainReliabilityHeader::Parse( 201 std::unique_ptr<DomainReliabilityHeader> DomainReliabilityHeader::Parse(
203 base::StringPiece value) { 202 base::StringPiece value) {
204 ScopedVector<GURL> report_uri; 203 std::vector<std::unique_ptr<GURL>> report_uri;
205 base::TimeDelta max_age; 204 base::TimeDelta max_age;
206 bool include_subdomains = false; 205 bool include_subdomains = false;
207 206
208 bool got_report_uri = false; 207 bool got_report_uri = false;
209 bool got_max_age = false; 208 bool got_max_age = false;
210 bool got_include_subdomains = false; 209 bool got_include_subdomains = false;
211 210
212 DirectiveHeaderValueParser parser(value); 211 DirectiveHeaderValueParser parser(value);
213 while (parser.GetNext()) { 212 while (parser.GetNext()) {
214 base::StringPiece name = parser.directive_name(); 213 base::StringPiece name = parser.directive_name();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 276 }
278 277
279 std::string DomainReliabilityHeader::ToString() const { 278 std::string DomainReliabilityHeader::ToString() const {
280 std::string string = ""; 279 std::string string = "";
281 int64_t max_age_s = max_age_.InSeconds(); 280 int64_t max_age_s = max_age_.InSeconds();
282 281
283 if (config_->collectors.empty()) { 282 if (config_->collectors.empty()) {
284 DCHECK_EQ(0, max_age_s); 283 DCHECK_EQ(0, max_age_s);
285 } else { 284 } else {
286 string += "report-uri="; 285 string += "report-uri=";
287 for (const auto* uri : config_->collectors) 286 for (const auto& uri : config_->collectors)
288 string += uri->spec() + " "; 287 string += uri->spec() + " ";
289 // Remove trailing space. 288 // Remove trailing space.
290 string.erase(string.length() - 1, 1); 289 string.erase(string.length() - 1, 1);
291 string += "; "; 290 string += "; ";
292 } 291 }
293 292
294 string += "max-age=" + base::Int64ToString(max_age_s) + "; "; 293 string += "max-age=" + base::Int64ToString(max_age_s) + "; ";
295 294
296 if (config_->include_subdomains) 295 if (config_->include_subdomains)
297 string += "includeSubdomains; "; 296 string += "includeSubdomains; ";
(...skipping 13 matching lines...) Expand all
311 ParseStatus status, 310 ParseStatus status,
312 std::unique_ptr<DomainReliabilityConfig> config, 311 std::unique_ptr<DomainReliabilityConfig> config,
313 base::TimeDelta max_age) 312 base::TimeDelta max_age)
314 : status_(status), config_(std::move(config)), max_age_(max_age) { 313 : status_(status), config_(std::move(config)), max_age_(max_age) {
315 DCHECK_EQ(PARSE_SET_CONFIG, status_); 314 DCHECK_EQ(PARSE_SET_CONFIG, status_);
316 DCHECK(config_.get()); 315 DCHECK(config_.get());
317 DCHECK_NE(0, max_age_.InMicroseconds()); 316 DCHECK_NE(0, max_age_.InMicroseconds());
318 } 317 }
319 318
320 } // namespace domain_reliability 319 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698