| OLD | NEW |
| 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/json/json_value_converter.h" | 11 #include "base/json/json_value_converter.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.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 per-origin configuration that controls which requests are measured and |
| 23 // with what frequency, and where the beacons are uploaded. | 23 // reported, with what frequency, and where the beacons are uploaded. |
| 24 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig { | 24 struct DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig { |
| 25 public: | 25 public: |
| 26 static const size_t kInvalidResourceIndex; | |
| 27 | |
| 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(); | |
| 35 | |
| 36 // Returns whether |url_string| matches at least one of the |url_patterns| | |
| 37 // in this Resource. | |
| 38 bool MatchesUrl(const GURL& url) const; | |
| 39 | |
| 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; | |
| 44 | |
| 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); | |
| 49 | |
| 50 bool IsValid() const; | |
| 51 | |
| 52 // Name of the Resource, as will be reported in uploads. | |
| 53 std::string name; | |
| 54 | |
| 55 // List of URL patterns to assign requests to this Resource. | |
| 56 ScopedVector<std::string> url_patterns; | |
| 57 | |
| 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; | |
| 62 | |
| 63 private: | |
| 64 DISALLOW_COPY_AND_ASSIGN(Resource); | |
| 65 }; | |
| 66 | |
| 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(); | |
| 74 | |
| 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); | |
| 79 | |
| 80 bool IsValid() const; | |
| 81 | |
| 82 GURL upload_url; | |
| 83 | |
| 84 private: | |
| 85 DISALLOW_COPY_AND_ASSIGN(Collector); | |
| 86 }; | |
| 87 | |
| 88 DomainReliabilityConfig(); | 26 DomainReliabilityConfig(); |
| 89 ~DomainReliabilityConfig(); | 27 ~DomainReliabilityConfig(); |
| 90 | 28 |
| 91 // Uses the JSONValueConverter to parse the JSON for a config into a struct. | 29 // Uses the JSONValueConverter to parse the JSON for a config into a struct. |
| 92 static scoped_ptr<const DomainReliabilityConfig> FromJSON( | 30 static scoped_ptr<const DomainReliabilityConfig> FromJSON( |
| 93 const base::StringPiece& json); | 31 const base::StringPiece& json); |
| 94 | 32 |
| 95 bool IsValid() const; | 33 bool IsValid() const; |
| 96 | 34 |
| 97 // Finds the index (in resources) of the first Resource that matches a | 35 bool DecideIfShouldReportRequest(bool success) const; |
| 98 // particular URL. Returns kInvalidResourceIndex if it is not matched by any | |
| 99 // Resources. | |
| 100 size_t GetResourceIndexForUrl(const GURL& url) const; | |
| 101 | 36 |
| 102 // Registers with the JSONValueConverter so it will know how to convert the | 37 // Registers with the JSONValueConverter so it will know how to convert the |
| 103 // JSON for a config into the struct. | 38 // JSON for a config into the struct. |
| 104 static void RegisterJSONConverter( | 39 static void RegisterJSONConverter( |
| 105 base::JSONValueConverter<DomainReliabilityConfig>* converter); | 40 base::JSONValueConverter<DomainReliabilityConfig>* converter); |
| 106 | 41 |
| 107 std::string version; | 42 GURL origin; |
| 108 std::string domain; | 43 bool include_subdomains; |
| 109 ScopedVector<Resource> resources; | 44 ScopedVector<GURL> collectors; |
| 110 ScopedVector<Collector> collectors; | 45 |
| 46 double success_sample_rate; |
| 47 double failure_sample_rate; |
| 48 ScopedVector<std::string> path_prefixes; |
| 111 | 49 |
| 112 private: | 50 private: |
| 113 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig); | 51 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig); |
| 114 }; | 52 }; |
| 115 | 53 |
| 116 } // namespace domain_reliability | 54 } // namespace domain_reliability |
| 117 | 55 |
| 118 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_ | 56 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_ |
| OLD | NEW |