OLD | NEW |
| (Empty) |
1 // Copyright 2016 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_QUIC_CLIENT_PUSH_PROMISE_INDEX_H_ | |
6 #define NET_QUIC_QUIC_CLIENT_PUSH_PROMISE_INDEX_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "net/quic/quic_client_session_base.h" | |
11 #include "net/quic/quic_types.h" | |
12 | |
13 namespace net { | |
14 | |
15 // QuicClientPushPromiseIndex is the interface to support rendezvous | |
16 // between client requests and resources delivered via server push. | |
17 // The same index can be shared across multiple sessions (e.g. for the | |
18 // same browser users profile), since cross-origin pushes are allowed | |
19 // (subject to authority constraints). | |
20 | |
21 class NET_EXPORT_PRIVATE QuicClientPushPromiseIndex { | |
22 public: | |
23 // Delegate is used to complete the rendezvous that began with | |
24 // |Try()|. | |
25 class NET_EXPORT_PRIVATE Delegate { | |
26 public: | |
27 virtual ~Delegate() {} | |
28 | |
29 // The primary lookup matched request with push promise by URL. A | |
30 // secondary match is necessary to ensure Vary (RFC 2616, 14.14) | |
31 // is honored. If Vary is not present, return true. If Vary is | |
32 // present, return whether designated header fields of | |
33 // |promise_request| and |client_request| match. | |
34 virtual bool CheckVary(const SpdyHeaderBlock& client_request, | |
35 const SpdyHeaderBlock& promise_request, | |
36 const SpdyHeaderBlock& promise_response) = 0; | |
37 | |
38 // On rendezvous success, provides the promised |stream|. Callee | |
39 // does not inherit ownership of |stream|. On rendezvous failure, | |
40 // |stream| is |nullptr| and the client should retry the request. | |
41 // Rendezvous can fail due to promise validation failure or RST on | |
42 // promised stream. |url| will have been removed from the index | |
43 // before |OnRendezvousResult()| is invoked, so a recursive call to | |
44 // |Try()| will return |QUIC_FAILURE|, which may be convenient for | |
45 // retry purposes. | |
46 virtual void OnRendezvousResult(QuicSpdyStream* stream) = 0; | |
47 }; | |
48 | |
49 class NET_EXPORT_PRIVATE TryHandle { | |
50 public: | |
51 // Cancel the request. | |
52 virtual void Cancel() = 0; | |
53 | |
54 protected: | |
55 TryHandle() {} | |
56 ~TryHandle(); | |
57 | |
58 private: | |
59 DISALLOW_COPY_AND_ASSIGN(TryHandle); | |
60 }; | |
61 | |
62 QuicClientPushPromiseIndex(); | |
63 virtual ~QuicClientPushPromiseIndex(); | |
64 | |
65 // Called by client code, used to enforce affinity between requests | |
66 // for promised streams and the session the promise came from. | |
67 QuicClientPromisedInfo* GetPromised(const std::string& url); | |
68 | |
69 // Called by client code, to initiate rendezvous between a request | |
70 // and a server push stream. If |request|'s url is in the index, | |
71 // rendezvous will be attempted and may complete immediately or | |
72 // asynchronously. If the matching promise and response headers | |
73 // have already arrived, the delegate's methods will fire | |
74 // recursively from within |Try()|. Returns |QUIC_SUCCESS| if the | |
75 // rendezvous was a success. Returns |QUIC_FAILURE| if there was no | |
76 // matching promise, or if there was but the rendezvous has failed. | |
77 // Returns QUIC_PENDING if a matching promise was found, but the | |
78 // rendezvous needs to complete asynchronously because the promised | |
79 // response headers are not yet available. If result is | |
80 // QUIC_PENDING, then |*handle| will set so that the caller may | |
81 // cancel the request if need be. The caller does not inherit | |
82 // ownership of |*handle|, and it ceases to be valid if the caller | |
83 // invokes |handle->Cancel()| or if |delegate->OnReponse()| fires. | |
84 QuicAsyncStatus Try(const SpdyHeaderBlock& request, | |
85 Delegate* delegate, | |
86 TryHandle** handle); | |
87 | |
88 QuicPromisedByUrlMap* promised_by_url() { return &promised_by_url_; } | |
89 | |
90 private: | |
91 QuicPromisedByUrlMap promised_by_url_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(QuicClientPushPromiseIndex); | |
94 }; | |
95 | |
96 } // namespace net | |
97 | |
98 #endif // NET_QUIC_QUIC_CLIENT_PUSH_PROMISE_INDEX_H_ | |
OLD | NEW |