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

Side by Side 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: Addressing feedback from PS#6 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_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& key_text);
32
33 // Returns true if this API key has a valid signature, and has not expired.
34 bool IsValidNow(const base::Time& now) const;
Marijn Kruisselbrink 2015/12/18 22:03:01 IsValidNow seems a bit of an odd name if "now" is
iclelland 2015/12/21 19:17:17 Renamed to IsValid, mirroring the blink code.
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();
Marijn Kruisselbrink 2015/12/18 22:03:01 Why do you define (but not implement) a default co
iclelland 2015/12/21 19:17:17 Thanks for catching it; we don't need it. One priv
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.
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.
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
Marijn Kruisselbrink 2015/12/18 22:03:01 // namespace content (at least I would otherwise a
iclelland 2015/12/21 19:17:17 Done.
71 #endif // CONTENT_BROWSER_EXPERIMENTS_API_KEY_H_
OLDNEW
« 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