Change to let media_stream_devices_controller.cc decide if a gUM request fail if...
[chromium-blink-merge.git] / components / domain_reliability / config.h
blob64533035d245d789ddc6941ef84dd6c9118d2cd3
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/compiler_specific.h"
12 #include "base/json/json_value_converter.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_piece.h"
15 #include "base/values.h"
16 #include "components/domain_reliability/domain_reliability_export.h"
17 #include "url/gurl.h"
19 namespace domain_reliability {
21 // The configuration that controls which requests are measured and reported,
22 // with what frequency, and where the beacons are uploaded.
23 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
24 public:
25 // A particular resource named in the config -- includes a set of URL
26 // patterns that the resource will match, along with sample rates for
27 // successful and unsuccessful requests.
28 class DOMAIN_RELIABILITY_EXPORT Resource {
29 public:
30 Resource();
31 ~Resource();
33 // Returns whether |url_string| matches at least one of the |url_patterns|
34 // in this Resource.
35 bool MatchesUrlString(const std::string& url_string) const;
37 // Returns whether a request (that was successful if |success| is true)
38 // should be reported (with a full beacon). (The output is random; it
39 // compares a random number to |success_sample_rate| or
40 // |failure_sample_rate|.)
41 bool DecideIfShouldReportRequest(bool success) const;
43 // Registers with the JSONValueConverter so it will know how to convert the
44 // JSON for a named resource into the struct.
45 static void RegisterJSONConverter(
46 base::JSONValueConverter<Resource>* converter);
48 // Name of the Resource, as will be reported in uploads.
49 std::string name;
51 // List of URL patterns to assign requests to this Resource.
52 ScopedVector<std::string> url_patterns;
54 // Sample rates for successful and unsuccessful requests, respectively.
55 // 0.0 reports no requests, and 1.0 reports every request.
56 double success_sample_rate;
57 double failure_sample_rate;
59 private:
60 DISALLOW_COPY_AND_ASSIGN(Resource);
63 // A particular endpoint for report uploads. Includes the URL to upload
64 // reports to. May include a verification URL or backoff/load management
65 // configuration in the future.
66 struct DOMAIN_RELIABILITY_EXPORT Collector {
67 public:
68 Collector();
69 ~Collector();
71 // Registers with the JSONValueConverter so it will know how to convert the
72 // JSON for a collector into the struct.
73 static void RegisterJSONConverter(
74 base::JSONValueConverter<Collector>* converter);
76 GURL upload_url;
78 private:
79 DISALLOW_COPY_AND_ASSIGN(Collector);
82 DomainReliabilityConfig();
83 ~DomainReliabilityConfig();
85 // Uses the JSONValueConverter to parse the JSON for a config into a struct.
86 static scoped_ptr<const DomainReliabilityConfig> FromJSON(
87 const base::StringPiece& json);
89 // Finds the index (in resources) of the first Resource that matches a
90 // particular URL. Returns -1 if the URL is not matched by any Resources.
91 int GetResourceIndexForUrl(const GURL& url) const;
93 // Registers with the JSONValueConverter so it will know how to convert the
94 // JSON for a config into the struct.
95 static void RegisterJSONConverter(
96 base::JSONValueConverter<DomainReliabilityConfig>* converter);
98 std::string config_version;
99 std::string domain;
100 ScopedVector<Resource> resources;
101 ScopedVector<Collector> collectors;
103 // TODO(ttuttle): Add config_valid_util when fetching and expiring configs
104 // is implemented.
106 private:
107 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig);
110 } // namespace domain_reliability
112 #endif // COMPONENTS_DOMAIN_RELIABILITY_CONFIG_H_