Fix undefined variable when running bisect (path_to_file -> config_file_path).
[chromium-blink-merge.git] / components / domain_reliability / config.h
blobc17bf5acc45177d1fc45bbaefecb39e29eb42f78
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_
8 #include <string>
9 #include <vector>
11 #include "base/json/json_value_converter.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h"
16 #include "base/values.h"
17 #include "components/domain_reliability/domain_reliability_export.h"
18 #include "url/gurl.h"
20 namespace domain_reliability {
22 // The configuration that controls which requests are measured and reported,
23 // with what frequency, and where the beacons are uploaded.
24 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
25 public:
26 static const size_t kInvalidResourceIndex;
28 // A particular resource named in the config -- includes a set of URL
29 // patterns that the resource will match, along with sample rates for
30 // successful and unsuccessful requests.
31 class DOMAIN_RELIABILITY_EXPORT Resource {
32 public:
33 Resource();
34 ~Resource();
36 // Returns whether |url_string| matches at least one of the |url_patterns|
37 // in this Resource.
38 bool MatchesUrl(const GURL& url) const;
40 // Returns whether a request (that was successful if |success| is true)
41 // should be reported with a full beacon. (The output is non-deterministic;
42 // it |success_sample_rate| or |failure_sample_rate| to a random number.)
43 bool DecideIfShouldReportRequest(bool success) const;
45 // Registers with the JSONValueConverter so it will know how to convert the
46 // JSON for a named resource into the struct.
47 static void RegisterJSONConverter(
48 base::JSONValueConverter<Resource>* converter);
50 bool IsValid() const;
52 // Name of the Resource, as will be reported in uploads.
53 std::string name;
55 // List of URL patterns to assign requests to this Resource.
56 ScopedVector<std::string> url_patterns;
58 // Sample rates for successful and unsuccessful requests, respectively.
59 // 0.0 reports no requests, and 1.0 reports every request.
60 double success_sample_rate;
61 double failure_sample_rate;
63 private:
64 DISALLOW_COPY_AND_ASSIGN(Resource);
67 // A particular endpoint for report uploads. Includes the URL to upload
68 // reports to. May include a verification URL or backoff/load management
69 // configuration in the future.
70 struct DOMAIN_RELIABILITY_EXPORT Collector {
71 public:
72 Collector();
73 ~Collector();
75 // Registers with the JSONValueConverter so it will know how to convert the
76 // JSON for a collector into the struct.
77 static void RegisterJSONConverter(
78 base::JSONValueConverter<Collector>* converter);
80 bool IsValid() const;
82 GURL upload_url;
84 private:
85 DISALLOW_COPY_AND_ASSIGN(Collector);
88 DomainReliabilityConfig();
89 ~DomainReliabilityConfig();
91 // Uses the JSONValueConverter to parse the JSON for a config into a struct.
92 static scoped_ptr<const DomainReliabilityConfig> FromJSON(
93 const base::StringPiece& json);
95 bool IsValid() const;
97 // Checks whether |now| is past the expiration time provided in the config.
98 bool IsExpired(base::Time now) const;
100 // Finds the index (in resources) of the first Resource that matches a
101 // particular URL. Returns kInvalidResourceIndex if it is not matched by any
102 // Resources.
103 size_t GetResourceIndexForUrl(const GURL& url) const;
105 // Registers with the JSONValueConverter so it will know how to convert the
106 // JSON for a config into the struct.
107 static void RegisterJSONConverter(
108 base::JSONValueConverter<DomainReliabilityConfig>* converter);
110 std::string version;
111 double valid_until;
112 std::string domain;
113 ScopedVector<Resource> resources;
114 ScopedVector<Collector> collectors;
116 private:
117 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig);
120 } // namespace domain_reliability
122 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_