Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / net / quic / crypto / quic_server_info.h
blob1e4e1bd4874695edf67aae4f8d15b3eb19443570
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 // Reset's WaitForDataReady callback. This method shouldn't have any side
49 // effects (could be called even if HttpCache doesn't exist).
50 virtual void ResetWaitForDataReadyCallback() = 0;
52 // Cancel's WaitForDataReady callback. |callback| passed in WaitForDataReady
53 // will not be called.
54 virtual void CancelWaitForDataReadyCallback() = 0;
56 // Returns true if data is loaded from disk cache and ready (WaitForDataReady
57 // doesn't have a pending callback).
58 virtual bool IsDataReady() = 0;
60 // Returns true if the object is ready to persist data, in other words, if
61 // data is loaded from disk cache and ready and there are no pending writes.
62 virtual bool IsReadyToPersist() = 0;
64 // Persist allows for the server information to be updated for future users.
65 // This is a fire and forget operation: the caller may drop its reference
66 // from this object and the store operation will still complete. This can
67 // only be called once WaitForDataReady has returned OK or called its
68 // callback.
69 virtual void Persist() = 0;
71 // Called whenever an external cache reuses quic server config.
72 virtual void OnExternalCacheHit() = 0;
74 struct State {
75 State();
76 ~State();
78 void Clear();
80 // This class matches QuicClientCryptoConfig::CachedState.
81 std::string server_config; // A serialized handshake message.
82 std::string source_address_token; // An opaque proof of IP ownership.
83 std::vector<std::string> certs; // A list of certificates in leaf-first
84 // order.
85 std::string server_config_sig; // A signature of |server_config_|.
87 private:
88 DISALLOW_COPY_AND_ASSIGN(State);
91 // Once the data is ready, it can be read using the following members. These
92 // members can then be updated before calling |Persist|.
93 const State& state() const;
94 State* mutable_state();
96 base::TimeTicks wait_for_data_start_time() const {
97 return wait_for_data_start_time_;
100 base::TimeTicks wait_for_data_end_time() const {
101 return wait_for_data_end_time_;
104 protected:
105 // Parse parses pickled data and fills out the public member fields of this
106 // object. It returns true iff the parse was successful. The public member
107 // fields will be set to something sane in any case.
108 bool Parse(const std::string& data);
109 std::string Serialize();
110 State state_;
112 // Time when WaitForDataReady was called and when it has finished.
113 base::TimeTicks wait_for_data_start_time_;
114 base::TimeTicks wait_for_data_end_time_;
116 private:
117 // ParseInner is a helper function for Parse.
118 bool ParseInner(const std::string& data);
120 // SerializeInner is a helper function for Serialize.
121 std::string SerializeInner() const;
123 // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for
124 // which we restore the crypto_config.
125 const QuicServerId server_id_;
127 DISALLOW_COPY_AND_ASSIGN(QuicServerInfo);
130 class NET_EXPORT_PRIVATE QuicServerInfoFactory {
131 public:
132 QuicServerInfoFactory() {}
133 virtual ~QuicServerInfoFactory();
135 // GetForServer returns a fresh, allocated QuicServerInfo for the given
136 // |server_id| or NULL on failure.
137 virtual QuicServerInfo* GetForServer(const QuicServerId& server_id) = 0;
139 DISALLOW_COPY_AND_ASSIGN(QuicServerInfoFactory);
142 } // namespace net
144 #endif // NET_QUIC_CRYPTO_QUIC_SERVER_INFO_H_