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

Side by Side Diff: content/common/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: Merge blink and chromium code; fixing issues from review 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 unified diff | Download patch
OLDNEW
(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_COMMON_EXPERIMENTS_API_KEY_H_
6 #define CONTENT_COMMON_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 //
25 // More documentation on the key format can be found at
26 // https://docs.google.com/document/d/1v5fi0EUV_QHckVHVF2K4P72iNywnrJtNhNZ6i2NPt 0M
27
28 class CONTENT_EXPORT ApiKey {
29 public:
30 ~ApiKey();
31
32 // Returns a key object if the string represents a well-formed key, or
33 // nullptr otherwise. (This does not mean that the key is valid, just that it
34 // can be parsed.)
35 static scoped_ptr<ApiKey> Parse(const std::string& key_text);
Marijn Kruisselbrink 2016/01/05 00:59:14 nit: explicitly include #include "base/memory/scop
iclelland 2016/01/05 20:26:31 Done.
36
37 // Returns true if this API is appropriate for use by the given origin, for
38 // the given API name. This does not check whether the signature is valid, or
39 // whether the key itself has expired.
40 bool IsAppropriate(const std::string& origin,
41 const std::string& apiName) const;
42
43 // Returns true if this API key has a valid signature, and has not expired.
44 bool IsValid(const base::Time& now) const;
Marijn Kruisselbrink 2016/01/05 00:59:14 (not really related to this particular line of cod
iclelland 2016/01/05 20:26:31 That's reasonable -- I've gone back and forth on t
45
46 std::string signature() { return signature_; }
47 std::string data() { return data_; }
48 GURL origin() { return origin_; }
49 std::string api_name() { return api_name_; }
50 uint64_t expiry_timestamp() { return expiry_timestamp_; }
51
52 protected:
53 friend class ApiKeyTest;
54
55 bool ValidateOrigin(const std::string& origin) const;
56 bool ValidateApiName(const std::string& api_name) const;
57 bool ValidateDate(const base::Time& now) const;
58
59 private:
60 ApiKey(const std::string& signature,
61 const std::string& data,
62 const GURL& origin,
63 const std::string& api_name,
64 uint64_t expiry_timestamp);
65
66 // The base64-encoded-signature portion of the key. For the key to be valid,
67 // this must be a valid signature for the data portion of the key, as verified
68 // by the public key in api_key.cc.
69 std::string signature_;
70
71 // The portion of the key string which is signed, and whose signature is
72 // contained in the signature_ member.
73 std::string data_;
74
75 // The origin for which this key is valid. Must be a secure origin.
76 GURL origin_;
77
78 // The name of the API experiment which this key enables.
79 std::string api_name_;
80
81 // The time until which this key should be considered valid, in UTC, as
82 // seconds since the Unix epoch.
83 uint64_t expiry_timestamp_;
84 };
85
86 } // namespace content
87
88 #endif // CONTENT_COMMON_EXPERIMENTS_API_KEY_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/experiments/api_key.cc » ('j') | content/common/experiments/api_key.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698