Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / components / domain_reliability / config.h
index 6453303..1ba3c7a 100644 (file)
@@ -12,6 +12,7 @@
 #include "base/json/json_value_converter.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/strings/string_piece.h"
+#include "base/time/time.h"
 #include "base/values.h"
 #include "components/domain_reliability/domain_reliability_export.h"
 #include "url/gurl.h"
@@ -22,6 +23,8 @@ namespace domain_reliability {
 // with what frequency, and where the beacons are uploaded.
 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
  public:
+  static const size_t kInvalidResourceIndex;
+
   // A particular resource named in the config -- includes a set of URL
   // patterns that the resource will match, along with sample rates for
   // successful and unsuccessful requests.
@@ -32,12 +35,11 @@ class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
 
     // Returns whether |url_string| matches at least one of the |url_patterns|
     // in this Resource.
-    bool MatchesUrlString(const std::string& url_string) const;
+    bool MatchesUrl(const GURL& url) const;
 
     // Returns whether a request (that was successful if |success| is true)
-    // should be reported (with a full beacon). (The output is random; it
-    // compares a random number to |success_sample_rate| or
-    // |failure_sample_rate|.)
+    // should be reported with a full beacon. (The output is non-deterministic;
+    // it |success_sample_rate| or |failure_sample_rate| to a random number.)
     bool DecideIfShouldReportRequest(bool success) const;
 
     // Registers with the JSONValueConverter so it will know how to convert the
@@ -45,6 +47,8 @@ class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
     static void RegisterJSONConverter(
         base::JSONValueConverter<Resource>* converter);
 
+    bool IsValid() const;
+
     // Name of the Resource, as will be reported in uploads.
     std::string name;
 
@@ -73,6 +77,8 @@ class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
     static void RegisterJSONConverter(
         base::JSONValueConverter<Collector>* converter);
 
+    bool IsValid() const;
+
     GURL upload_url;
 
    private:
@@ -86,23 +92,27 @@ class DOMAIN_RELIABILITY_EXPORT DomainReliabilityConfig {
   static scoped_ptr<const DomainReliabilityConfig> FromJSON(
       const base::StringPiece& json);
 
+  bool IsValid() const;
+
+  // Checks whether |now| is past the expiration time provided in the config.
+  bool IsExpired(base::Time now) const;
+
   // Finds the index (in resources) of the first Resource that matches a
-  // particular URL. Returns -1 if the URL is not matched by any Resources.
-  int GetResourceIndexForUrl(const GURL& url) const;
+  // particular URL. Returns kInvalidResourceIndex if it is not matched by any
+  // Resources.
+  size_t GetResourceIndexForUrl(const GURL& url) const;
 
   // Registers with the JSONValueConverter so it will know how to convert the
   // JSON for a config into the struct.
   static void RegisterJSONConverter(
       base::JSONValueConverter<DomainReliabilityConfig>* converter);
 
-  std::string config_version;
+  std::string version;
+  double valid_until;
   std::string domain;
   ScopedVector<Resource> resources;
   ScopedVector<Collector> collectors;
 
-  // TODO(ttuttle): Add config_valid_util when fetching and expiring configs
-  //                is implemented.
-
  private:
   DISALLOW_COPY_AND_ASSIGN(DomainReliabilityConfig);
 };