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

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

Issue 1226673003: Move MatchPattern to its own header and the base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 // Make sure stdint.h includes SIZE_MAX. (See C89, p259, footnote 221.) 5 // Make sure stdint.h includes SIZE_MAX. (See C89, p259, footnote 221.)
6 #ifndef __STDC_LIMIT_MACROS 6 #ifndef __STDC_LIMIT_MACROS
7 #define __STDC_LIMIT_MACROS 1 7 #define __STDC_LIMIT_MACROS 1
8 #endif 8 #endif
9 9
10 #include "components/domain_reliability/config.h" 10 #include "components/domain_reliability/config.h"
11 11
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/json/json_value_converter.h" 15 #include "base/json/json_value_converter.h"
16 #include "base/profiler/scoped_tracker.h" 16 #include "base/profiler/scoped_tracker.h"
17 #include "base/rand_util.h" 17 #include "base/rand_util.h"
18 #include "base/strings/pattern.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 20
20 namespace { 21 namespace {
21 22
22 bool ConvertURL(const base::StringPiece& string_piece, GURL* url) { 23 bool ConvertURL(const base::StringPiece& string_piece, GURL* url) {
23 *url = GURL(string_piece.as_string()); 24 *url = GURL(string_piece.as_string());
24 return url->is_valid(); 25 return url->is_valid();
25 } 26 }
26 27
27 bool IsValidSampleRate(double p) { return p >= 0.0 && p <= 1.0; } 28 bool IsValidSampleRate(double p) { return p >= 0.0 && p <= 1.0; }
28 29
29 } // namespace 30 } // namespace
30 31
31 namespace domain_reliability { 32 namespace domain_reliability {
32 33
33 // static 34 // static
34 const size_t DomainReliabilityConfig::kInvalidResourceIndex = SIZE_MAX; 35 const size_t DomainReliabilityConfig::kInvalidResourceIndex = SIZE_MAX;
35 36
36 DomainReliabilityConfig::Resource::Resource() { 37 DomainReliabilityConfig::Resource::Resource() {
37 } 38 }
38 DomainReliabilityConfig::Resource::~Resource() {} 39 DomainReliabilityConfig::Resource::~Resource() {}
39 40
40 bool DomainReliabilityConfig::Resource::MatchesUrl(const GURL& url) const { 41 bool DomainReliabilityConfig::Resource::MatchesUrl(const GURL& url) const {
41 const std::string& spec = url.spec(); 42 const std::string& spec = url.spec();
42 43
43 for (const auto& url_pattern : url_patterns) { 44 for (const auto& url_pattern : url_patterns) {
44 if (MatchPattern(spec, *url_pattern)) 45 if (base::MatchPattern(spec, *url_pattern))
45 return true; 46 return true;
46 } 47 }
47 48
48 return false; 49 return false;
49 } 50 }
50 51
51 bool DomainReliabilityConfig::Resource::DecideIfShouldReportRequest( 52 bool DomainReliabilityConfig::Resource::DecideIfShouldReportRequest(
52 bool success) const { 53 bool success) const {
53 double sample_rate = success ? success_sample_rate : failure_sample_rate; 54 double sample_rate = success ? success_sample_rate : failure_sample_rate;
54 DCHECK(IsValidSampleRate(sample_rate)); 55 DCHECK(IsValidSampleRate(sample_rate));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 &DomainReliabilityConfig::valid_until); 153 &DomainReliabilityConfig::valid_until);
153 converter->RegisterStringField("monitored_domain", 154 converter->RegisterStringField("monitored_domain",
154 &DomainReliabilityConfig::domain); 155 &DomainReliabilityConfig::domain);
155 converter->RegisterRepeatedMessage("monitored_resources", 156 converter->RegisterRepeatedMessage("monitored_resources",
156 &DomainReliabilityConfig::resources); 157 &DomainReliabilityConfig::resources);
157 converter->RegisterRepeatedMessage("collectors", 158 converter->RegisterRepeatedMessage("collectors",
158 &DomainReliabilityConfig::collectors); 159 &DomainReliabilityConfig::collectors);
159 } 160 }
160 161
161 } // namespace domain_reliability 162 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « chrome_elf/elf_imports_unittest.cc ('k') | content/browser/accessibility/accessibility_tree_formatter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698