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

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

Issue 252613002: Domain Reliability: More security review. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: s/&*config/config.get()/g Created 6 years, 7 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 #ifndef COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_ 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_ 6 #define COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/json/json_value_converter.h" 12 #include "base/json/json_value_converter.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "components/domain_reliability/domain_reliability_export.h" 17 #include "components/domain_reliability/domain_reliability_export.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace domain_reliability { 20 namespace domain_reliability {
21 21
22 // The configuration that controls which requests are measured and reported, 22 // The configuration that controls which requests are measured and reported,
23 // with what frequency, and where the beacons are uploaded. 23 // with what frequency, and where the beacons are uploaded.
24 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig { 24 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
25 public: 25 public:
26 static const size_t kInvalidResourceIndex;
27
26 // A particular resource named in the config -- includes a set of URL 28 // A particular resource named in the config -- includes a set of URL
27 // patterns that the resource will match, along with sample rates for 29 // patterns that the resource will match, along with sample rates for
28 // successful and unsuccessful requests. 30 // successful and unsuccessful requests.
29 class DOMAIN_RELIABILITY_EXPORT Resource { 31 class DOMAIN_RELIABILITY_EXPORT Resource {
30 public: 32 public:
31 Resource(); 33 Resource();
32 ~Resource(); 34 ~Resource();
33 35
34 // Returns whether |url_string| matches at least one of the |url_patterns| 36 // Returns whether |url_string| matches at least one of the |url_patterns|
35 // in this Resource. 37 // in this Resource.
36 bool MatchesUrlString(const std::string& url_string) const; 38 bool MatchesUrl(const GURL& url) const;
37 39
38 // Returns whether a request (that was successful if |success| is true) 40 // Returns whether a request (that was successful if |success| is true)
39 // should be reported (with a full beacon). (The output is random; it 41 // should be reported with a full beacon. (The output is non-deterministic;
40 // compares a random number to |success_sample_rate| or 42 // it |success_sample_rate| or |failure_sample_rate| to a random number.)
41 // |failure_sample_rate|.)
42 bool DecideIfShouldReportRequest(bool success) const; 43 bool DecideIfShouldReportRequest(bool success) const;
43 44
44 // Registers with the JSONValueConverter so it will know how to convert the 45 // Registers with the JSONValueConverter so it will know how to convert the
45 // JSON for a named resource into the struct. 46 // JSON for a named resource into the struct.
46 static void RegisterJSONConverter( 47 static void RegisterJSONConverter(
47 base::JSONValueConverter<Resource>* converter); 48 base::JSONValueConverter<Resource>* converter);
48 49
49 bool IsValid() const; 50 bool IsValid() const;
50 51
51 // Name of the Resource, as will be reported in uploads. 52 // Name of the Resource, as will be reported in uploads.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 DomainReliabilityConfig(); 88 DomainReliabilityConfig();
88 ~DomainReliabilityConfig(); 89 ~DomainReliabilityConfig();
89 90
90 // Uses the JSONValueConverter to parse the JSON for a config into a struct. 91 // Uses the JSONValueConverter to parse the JSON for a config into a struct.
91 static scoped_ptr<const DomainReliabilityConfig> FromJSON( 92 static scoped_ptr<const DomainReliabilityConfig> FromJSON(
92 const base::StringPiece& json); 93 const base::StringPiece& json);
93 94
94 bool IsValid() const; 95 bool IsValid() const;
95 96
97 // Checks whether |now| is past the expiration time provided in the config.
96 bool IsExpired(base::Time now) const; 98 bool IsExpired(base::Time now) const;
97 99
98 // Finds the index (in resources) of the first Resource that matches a 100 // Finds the index (in resources) of the first Resource that matches a
99 // particular URL. Returns -1 if the URL is not matched by any Resources. 101 // particular URL. Returns kInvalidResourceIndex if it is not matched by any
100 int GetResourceIndexForUrl(const GURL& url) const; 102 // Resources.
103 size_t GetResourceIndexForUrl(const GURL& url) const;
101 104
102 // Registers with the JSONValueConverter so it will know how to convert the 105 // Registers with the JSONValueConverter so it will know how to convert the
103 // JSON for a config into the struct. 106 // JSON for a config into the struct.
104 static void RegisterJSONConverter( 107 static void RegisterJSONConverter(
105 base::JSONValueConverter<DomainReliabilityConfig>* converter); 108 base::JSONValueConverter<DomainReliabilityConfig>* converter);
106 109
107 std::string version; 110 std::string version;
108 double valid_until; 111 double valid_until;
109 std::string domain; 112 std::string domain;
110 ScopedVector<Resource> resources; 113 ScopedVector<Resource> resources;
111 ScopedVector<Collector> collectors; 114 ScopedVector<Collector> collectors;
112 115
113 private: 116 private:
114 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig); 117 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig);
115 }; 118 };
116 119
117 } // namespace domain_reliability 120 } // namespace domain_reliability
118 121
119 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_ 122 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698