Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_ | |
| 6 #define CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/time/time.h" | |
| 11 #include "content/common/content_export.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 // The Experimental Framework (EF) provides limited access to experimental APIs, | |
| 17 // on a per-origin basis. This class defines the API key data structure, used | |
| 18 // to securely provide access to an experimental API. | |
| 19 // | |
| 20 // Experimental APIs are defined by string names, provided by the implementers. | |
| 21 // The EF code does not maintain an enum or constant list for experiment names. | |
| 22 // Instead, the EF validates the name provided by the API implementation against | |
| 23 // any provided API keys. | |
| 24 // TODO(chasej): Link to documentation, or provide more detail on keys, .etc | |
| 25 class CONTENT_EXPORT ApiKey { | |
| 26 public: | |
| 27 ~ApiKey(); | |
| 28 | |
| 29 // Returns a key object if the string represents a well-formed key, or | |
| 30 // nullptr otherwise. | |
| 31 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.
| |
| 32 | |
| 33 // Returns true if this API key has a valid signature, and has not expired. | |
| 34 bool IsValidNow(const base::Time& now) const; | |
| 35 | |
| 36 std::string signature() { return signature_; } | |
| 37 std::string data() { return data_; } | |
| 38 GURL origin() { return origin_; } | |
| 39 std::string api_name() { return api_name_; } | |
| 40 uint64_t expiry_timestamp() { return expiry_timestamp_; } | |
| 41 | |
| 42 private: | |
| 43 ApiKey(); | |
| 44 ApiKey(const std::string& signature, | |
| 45 const std::string& data, | |
| 46 const GURL& origin, | |
| 47 const std::string& api_name, | |
| 48 uint64_t expiry_timestamp); | |
| 49 | |
| 50 // The base64-encoded-signature portion of the key. For the key to be valid, | |
| 51 // this must be a valid signature for the data portion of the key, as verified | |
| 52 // 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.
| |
| 53 std::string signature_; | |
| 54 | |
| 55 // The portion of the key string which is signed, and whose signature is | |
| 56 // contained in the signature_ member. | |
| 57 std::string data_; | |
| 58 | |
| 59 // The origin for which this key is valid. Must be a secure origin. | |
| 60 GURL origin_; | |
| 61 | |
| 62 // 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.
| |
| 63 std::string api_name_; | |
| 64 | |
| 65 // The time until which this key should be considered valid, in UTC, as | |
| 66 // seconds since the Unix epoch. | |
| 67 uint64_t expiry_timestamp_; | |
| 68 }; | |
| 69 | |
| 70 } // namespace | |
| 71 #endif // CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_ | |
| OLD | NEW |