Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / quic / crypto / quic_server_info.h
blobfd54b94ad92e9150bb5c23a0a0717cdfc2ae0368
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_QUIC_CRYPTO_QUIC_SERVER_INFO_H_
6 #define NET_QUIC_CRYPTO_QUIC_SERVER_INFO_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "net/base/completion_callback.h"
15 #include "net/base/net_export.h"
16 #include "net/quic/quic_server_id.h"
18 namespace net {
20 class X509Certificate;
22 // QuicServerInfo is an interface for fetching information about a QUIC server.
23 // This information may be stored on disk so does not include keys or other
24 // sensitive information. Primarily it's intended for caching the QUIC server's
25 // crypto config.
26 class NET_EXPORT_PRIVATE QuicServerInfo {
27 public:
28 QuicServerInfo(const QuicServerId& server_id);
29 virtual ~QuicServerInfo();
31 // Start will commence the lookup. This must be called before any other
32 // methods. By opportunistically calling this early, it may be possible to
33 // overlap this object's lookup and reduce latency.
34 virtual void Start() = 0;
36 // WaitForDataReady returns OK if the fetch of the requested data has
37 // completed. Otherwise it returns ERR_IO_PENDING and will call |callback| on
38 // the current thread when ready.
40 // Only a single callback can be outstanding at a given time and, in the
41 // event that WaitForDataReady returns OK, it's the caller's responsibility
42 // to delete |callback|.
44 // |callback| may be NULL, in which case ERR_IO_PENDING may still be returned
45 // but, obviously, a callback will never be made.
46 virtual int WaitForDataReady(const CompletionCallback& callback) = 0;
48 // Returns true if data is loaded from disk cache and ready (WaitForDataReady
49 // doesn't have a pending callback).
50 virtual bool IsDataReady() = 0;
52 // Returns true if the object is ready to persist data, in other words, if
53 // data is loaded from disk cache and ready and there are no pending writes.
54 virtual bool IsReadyToPersist() = 0;
56 // Persist allows for the server information to be updated for future users.
57 // This is a fire and forget operation: the caller may drop its reference
58 // from this object and the store operation will still complete. This can
59 // only be called once WaitForDataReady has returned OK or called its
60 // callback.
61 virtual void Persist() = 0;
63 struct State {
64 State();
65 ~State();
67 void Clear();
69 // This class matches QuicClientCryptoConfig::CachedState.
70 std::string server_config; // A serialized handshake message.
71 std::string source_address_token; // An opaque proof of IP ownership.
72 std::vector<std::string> certs; // A list of certificates in leaf-first
73 // order.
74 std::string server_config_sig; // A signature of |server_config_|.
76 private:
77 DISALLOW_COPY_AND_ASSIGN(State);
80 // Once the data is ready, it can be read using the following members. These
81 // members can then be updated before calling |Persist|.
82 const State& state() const;
83 State* mutable_state();
85 protected:
86 // Parse parses pickled data and fills out the public member fields of this
87 // object. It returns true iff the parse was successful. The public member
88 // fields will be set to something sane in any case.
89 bool Parse(const std::string& data);
90 std::string Serialize();
91 State state_;
93 private:
94 // ParseInner is a helper function for Parse.
95 bool ParseInner(const std::string& data);
97 // SerializeInner is a helper function for Serialize.
98 std::string SerializeInner() const;
100 // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for
101 // which we restore the crypto_config.
102 const QuicServerId server_id_;
104 DISALLOW_COPY_AND_ASSIGN(QuicServerInfo);
107 class QuicServerInfoFactory {
108 public:
109 virtual ~QuicServerInfoFactory();
111 // GetForServer returns a fresh, allocated QuicServerInfo for the given
112 // |server_id| or NULL on failure.
113 virtual QuicServerInfo* GetForServer(const QuicServerId& server_id) = 0;
116 } // namespace net
118 #endif // NET_QUIC_CRYPTO_QUIC_SERVER_INFO_H_