Delete unused downloads page asset.
[chromium-blink-merge.git] / net / ssl / channel_id_store.h
blobefdf7e5e4c43bc966cb28ec01656cdf7bbf41d95
1 // Copyright 2014 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.
5 #ifndef NET_SSL_CHANNEL_ID_STORE_H_
6 #define NET_SSL_CHANNEL_ID_STORE_H_
8 #include <list>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "base/time/time.h"
15 #include "crypto/ec_private_key.h"
16 #include "net/base/net_export.h"
18 namespace net {
20 // An interface for storing and retrieving channel ID keypairs.
21 // See https://tools.ietf.org/html/draft-balfanz-tls-channelid-01
23 // Owned only by a single ChannelIDService object, which is responsible
24 // for deleting it.
25 class NET_EXPORT ChannelIDStore
26 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
27 public:
28 // The ChannelID class contains a keypair, along with the corresponding
29 // hostname (server identifier) and creation time.
30 class NET_EXPORT ChannelID {
31 public:
32 ChannelID();
33 ChannelID(const std::string& server_identifier,
34 base::Time creation_time,
35 scoped_ptr<crypto::ECPrivateKey> key);
36 ChannelID(const ChannelID& other);
37 ChannelID& operator=(const ChannelID& other);
38 ~ChannelID();
40 // Server identifier.
41 const std::string& server_identifier() const { return server_identifier_; }
42 // The time the keypair was created.
43 base::Time creation_time() const { return creation_time_; }
44 // Returns the keypair for the channel ID. This pointer is only valid for
45 // the lifetime of the ChannelID object - the ECPrivateKey object remains
46 // owned by the ChannelID object; no ownership is transferred.
47 crypto::ECPrivateKey* key() const { return key_.get(); }
49 private:
50 std::string server_identifier_;
51 base::Time creation_time_;
52 scoped_ptr<crypto::ECPrivateKey> key_;
55 typedef std::list<ChannelID> ChannelIDList;
57 typedef base::Callback<
58 void(int, const std::string&, scoped_ptr<crypto::ECPrivateKey>)>
59 GetChannelIDCallback;
60 typedef base::Callback<void(const ChannelIDList&)> GetChannelIDListCallback;
62 virtual ~ChannelIDStore() {}
64 // GetChannelID may return the result synchronously through the
65 // output parameters, in which case it will return either OK if a keypair is
66 // found in the store, or ERR_FILE_NOT_FOUND if none is found. If the
67 // result cannot be returned synchronously, GetChannelID will
68 // return ERR_IO_PENDING and the callback will be called with the result
69 // asynchronously.
70 virtual int GetChannelID(const std::string& server_identifier,
71 scoped_ptr<crypto::ECPrivateKey>* key_result,
72 const GetChannelIDCallback& callback) = 0;
74 // Adds the keypair for a hostname to the store.
75 virtual void SetChannelID(scoped_ptr<ChannelID> channel_id) = 0;
77 // Removes a keypair from the store.
78 virtual void DeleteChannelID(
79 const std::string& server_identifier,
80 const base::Closure& completion_callback) = 0;
82 // Deletes all of the channel ID keypairs that have a creation_date greater
83 // than or equal to |delete_begin| and less than |delete_end|. If a
84 // base::Time value is_null, that side of the comparison is unbounded.
85 virtual void DeleteAllCreatedBetween(
86 base::Time delete_begin,
87 base::Time delete_end,
88 const base::Closure& completion_callback) = 0;
90 // Removes all channel ID keypairs from the store.
91 virtual void DeleteAll(const base::Closure& completion_callback) = 0;
93 // Returns all channel ID keypairs.
94 virtual void GetAllChannelIDs(const GetChannelIDListCallback& callback) = 0;
96 // Helper function that adds all keypairs from |list| into this instance.
97 void InitializeFrom(const ChannelIDList& list);
99 // Returns the number of keypairs in the store. May return 0 if the backing
100 // store is not loaded yet.
101 // Public only for unit testing.
102 virtual int GetChannelIDCount() = 0;
104 // When invoked, instructs the store to keep session related data on
105 // destruction.
106 virtual void SetForceKeepSessionState() = 0;
109 } // namespace net
111 #endif // NET_SSL_CHANNEL_ID_STORE_H_