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

Side by Side Diff: net/quic/crypto/quic_server_info.h

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 months 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
« no previous file with comments | « net/quic/crypto/quic_random_test.cc ('k') | net/quic/crypto/quic_server_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef NET_QUIC_CRYPTO_QUIC_SERVER_INFO_H_
6 #define NET_QUIC_CRYPTO_QUIC_SERVER_INFO_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "net/base/completion_callback.h"
16 #include "net/base/net_export.h"
17 #include "net/quic/quic_server_id.h"
18
19 namespace net {
20
21 class X509Certificate;
22
23 // QuicServerInfo is an interface for fetching information about a QUIC server.
24 // This information may be stored on disk so does not include keys or other
25 // sensitive information. Primarily it's intended for caching the QUIC server's
26 // crypto config.
27 class NET_EXPORT_PRIVATE QuicServerInfo {
28 public:
29 explicit QuicServerInfo(const QuicServerId& server_id);
30 virtual ~QuicServerInfo();
31
32 // Start will commence the lookup. This must be called before any other
33 // methods. By opportunistically calling this early, it may be possible to
34 // overlap this object's lookup and reduce latency.
35 virtual void Start() = 0;
36
37 // WaitForDataReady returns OK if the fetch of the requested data has
38 // completed. Otherwise it returns ERR_IO_PENDING and will call |callback| on
39 // the current thread when ready.
40 //
41 // Only a single callback can be outstanding at a given time and, in the
42 // event that WaitForDataReady returns OK, it's the caller's responsibility
43 // to delete |callback|.
44 //
45 // |callback| may be NULL, in which case ERR_IO_PENDING may still be returned
46 // but, obviously, a callback will never be made.
47 virtual int WaitForDataReady(const CompletionCallback& callback) = 0;
48
49 // Reset's WaitForDataReady callback. This method shouldn't have any side
50 // effects (could be called even if HttpCache doesn't exist).
51 virtual void ResetWaitForDataReadyCallback() = 0;
52
53 // Cancel's WaitForDataReady callback. |callback| passed in WaitForDataReady
54 // will not be called.
55 virtual void CancelWaitForDataReadyCallback() = 0;
56
57 // Returns true if data is loaded from disk cache and ready (WaitForDataReady
58 // doesn't have a pending callback).
59 virtual bool IsDataReady() = 0;
60
61 // Returns true if the object is ready to persist data, in other words, if
62 // data is loaded from disk cache and ready and there are no pending writes.
63 virtual bool IsReadyToPersist() = 0;
64
65 // Persist allows for the server information to be updated for future users.
66 // This is a fire and forget operation: the caller may drop its reference
67 // from this object and the store operation will still complete. This can
68 // only be called once WaitForDataReady has returned OK or called its
69 // callback.
70 virtual void Persist() = 0;
71
72 // Called whenever an external cache reuses quic server config.
73 virtual void OnExternalCacheHit() = 0;
74
75 struct State {
76 State();
77 ~State();
78
79 void Clear();
80
81 // This class matches QuicClientCryptoConfig::CachedState.
82 std::string server_config; // A serialized handshake message.
83 std::string source_address_token; // An opaque proof of IP ownership.
84 std::string cert_sct; // Signed timestamp of the leaf cert.
85 std::string chlo_hash; // Hash of the CHLO message.
86 std::vector<std::string> certs; // A list of certificates in leaf-first
87 // order.
88 std::string server_config_sig; // A signature of |server_config_|.
89
90 private:
91 DISALLOW_COPY_AND_ASSIGN(State);
92 };
93
94 // Once the data is ready, it can be read using the following members. These
95 // members can then be updated before calling |Persist|.
96 const State& state() const;
97 State* mutable_state();
98
99 base::TimeTicks wait_for_data_start_time() const {
100 return wait_for_data_start_time_;
101 }
102
103 base::TimeTicks wait_for_data_end_time() const {
104 return wait_for_data_end_time_;
105 }
106
107 protected:
108 // Parse parses pickled data and fills out the public member fields of this
109 // object. It returns true iff the parse was successful. The public member
110 // fields will be set to something sane in any case.
111 bool Parse(const std::string& data);
112 std::string Serialize();
113
114 State state_;
115
116 // Time when WaitForDataReady was called and when it has finished.
117 base::TimeTicks wait_for_data_start_time_;
118 base::TimeTicks wait_for_data_end_time_;
119
120 // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for
121 // which we restore the crypto_config.
122 const QuicServerId server_id_;
123
124 private:
125 // ParseInner is a helper function for Parse.
126 bool ParseInner(const std::string& data);
127
128 // SerializeInner is a helper function for Serialize.
129 std::string SerializeInner() const;
130
131 DISALLOW_COPY_AND_ASSIGN(QuicServerInfo);
132 };
133
134 class NET_EXPORT_PRIVATE QuicServerInfoFactory {
135 public:
136 QuicServerInfoFactory() {}
137 virtual ~QuicServerInfoFactory();
138
139 // GetForServer returns a fresh, allocated QuicServerInfo for the given
140 // |server_id| or NULL on failure.
141 virtual QuicServerInfo* GetForServer(const QuicServerId& server_id) = 0;
142
143 private:
144 DISALLOW_COPY_AND_ASSIGN(QuicServerInfoFactory);
145 };
146
147 } // namespace net
148
149 #endif // NET_QUIC_CRYPTO_QUIC_SERVER_INFO_H_
OLDNEW
« no previous file with comments | « net/quic/crypto/quic_random_test.cc ('k') | net/quic/crypto/quic_server_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698