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

Unified Diff: content/browser/experiments/api_key.h

Issue 1521063003: Add API Key parsing for experimental APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove forward declaration to wrong namespace Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/experiments/api_key.cc » ('j') | content/browser/experiments/api_key.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/experiments/api_key.h
diff --git a/content/browser/experiments/api_key.h b/content/browser/experiments/api_key.h
new file mode 100644
index 0000000000000000000000000000000000000000..c11f3f2b16a3596b7bb7c02383af08e6972fe089
--- /dev/null
+++ b/content/browser/experiments/api_key.h
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_
+#define CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_
+
+#include <string>
+
+#include "base/time/time.h"
+#include "content/common/content_export.h"
+#include "url/gurl.h"
+
+namespace content {
+
+// The Experimental Framework (EF) provides limited access to experimental APIs,
+// on a per-origin basis. This class defines the API key data structure, used
+// to securely provide access to an experimental API.
+//
+// Experimental APIs are defined by string names, provided by the implementers.
+// The EF code does not maintain an enum or constant list for experiment names.
+// Instead, the EF validates the name provided by the API implementation against
+// any provided API keys.
+// TODO(chasej): Link to documentation, or provide more detail on keys, .etc
+class CONTENT_EXPORT ApiKey {
+ public:
+ ~ApiKey();
+
+ // Returns a key object if the string represents a well-formed key, or
+ // nullptr otherwise.
+ static scoped_ptr<ApiKey> Parse(const std::string&);
davidben 2015/12/18 19:48:36 Nit: parameter name
iclelland 2015/12/18 21:10:22 Done.
+
+ // Returns true if this API key has a valid signature, and has not expired.
+ bool IsValidNow(const base::Time& now) const;
+
+ std::string signature() { return signature_; }
+ std::string data() { return data_; }
+ GURL origin() { return origin_; }
+ std::string api_name() { return api_name_; }
+ uint64_t expiry_timestamp() { return expiry_timestamp_; }
+
+ private:
+ ApiKey();
+ ApiKey(const std::string& signature,
+ const std::string& data,
+ const GURL& origin,
+ const std::string& api_name,
+ uint64_t expiry_timestamp);
+
+ // The base64-encoded-signature portion of the key. For the key to be valid,
+ // this must be a valid signature for the data portion of the key, as verified
+ // by the public key in api_key.cc
davidben 2015/12/18 19:48:36 Nit: period at the end.
iclelland 2015/12/18 21:10:22 Done.
+ std::string signature_;
+
+ // The portion of the key string which is signed, and whose signature is
+ // contained in the signature_ member.
+ std::string data_;
+
+ // The origin for which this key is valid. Must be a secure origin.
+ GURL origin_;
+
+ // The name of the API experiment which this key enables
davidben 2015/12/18 19:48:36 Nit: period at the end.
iclelland 2015/12/18 21:10:22 Done.
+ std::string api_name_;
+
+ // The time until which this key should be considered valid, in UTC, as
+ // seconds since the Unix epoch.
+ uint64_t expiry_timestamp_;
+};
+
+} // namespace
+#endif // CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_
« no previous file with comments | « no previous file | content/browser/experiments/api_key.cc » ('j') | content/browser/experiments/api_key.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698