OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
6 #define CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // Starting state of the MimeSniffingResourceHandler. In this state, it is | 59 // Starting state of the MimeSniffingResourceHandler. In this state, it is |
60 // acting as a blind pass-through ResourceHandler until the response is | 60 // acting as a blind pass-through ResourceHandler until the response is |
61 // received. | 61 // received. |
62 STATE_STARTING, | 62 STATE_STARTING, |
63 | 63 |
64 // In this state, the MimeSniffingResourceHandler is buffering the response | 64 // In this state, the MimeSniffingResourceHandler is buffering the response |
65 // data in read_buffer_, waiting to sniff the mime type and make a choice | 65 // data in read_buffer_, waiting to sniff the mime type and make a choice |
66 // about request interception. | 66 // about request interception. |
67 STATE_BUFFERING, | 67 STATE_BUFFERING, |
68 | 68 |
69 // In these states, the MimeSniffingResourceHandler is calling OnWillRead on | |
70 // the downstream ResourceHandler and then waiting for the response. | |
71 STATE_CALLING_ON_WILL_READ, | |
72 STATE_WAITING_FOR_BUFFER, | |
73 | |
74 // In this state, the MimeSniffingResourceHandler has identified the mime | 69 // In this state, the MimeSniffingResourceHandler has identified the mime |
75 // type and made a decision on whether the request should be intercepted or | 70 // type and made a decision on whether the request should be intercepted or |
76 // not. It is nows attempting to replay the response to downstream | 71 // not. It is nows attempting to replay the response to downstream |
77 // handlers. | 72 // handlers. |
78 STATE_INTERCEPTION_CHECK_DONE, | 73 STATE_INTERCEPTION_CHECK_DONE, |
79 | 74 |
80 // In this state, the MimeSniffingResourceHandler is replaying the buffered | 75 // In this state, the MimeSniffingResourceHandler is replaying the buffered |
81 // OnResponseStarted event to the downstream ResourceHandlers. | 76 // OnResponseStarted event to the downstream ResourceHandlers. This state |
| 77 // will transition to the next state if there is more data to replay, or |
| 78 // to STATE_STREAMING when replay is done. |
82 STATE_REPLAYING_RESPONSE_RECEIVED, | 79 STATE_REPLAYING_RESPONSE_RECEIVED, |
83 | 80 |
| 81 // In this state, the MimeSniffingResourceHandler is replaying the buffered |
| 82 // OnResponseStarted event to the downstream ResourceHandlers, and is |
| 83 // waiting for a buffer from those handlers. This state always |
| 84 // transitions to the previous one. |
| 85 STATE_REPLAYING_WAIT_FOR_WILL_READ, |
| 86 |
84 // In this state, the MimeSniffingResourceHandler is just a blind | 87 // In this state, the MimeSniffingResourceHandler is just a blind |
85 // pass-through | 88 // pass-through |
86 // ResourceHandler. | 89 // ResourceHandler. |
87 STATE_STREAMING, | 90 STATE_STREAMING, |
88 }; | 91 }; |
89 | 92 |
90 // ResourceHandler implementation: | 93 // ResourceHandler implementation: |
91 void OnWillStart(const GURL&, | 94 void OnWillStart(const GURL&, |
92 std::unique_ptr<ResourceController> controller) override; | 95 std::unique_ptr<ResourceController> controller) override; |
93 void OnResponseStarted( | 96 void OnResponseStarted( |
(...skipping 15 matching lines...) Expand all Loading... |
109 // ResourceHandlers. They return false if the request should be cancelled, | 112 // ResourceHandlers. They return false if the request should be cancelled, |
110 // true otherwise. Each of them will set |defer| to true if the request will | 113 // true otherwise. Each of them will set |defer| to true if the request will |
111 // proceed to the next stage asynchronously. | 114 // proceed to the next stage asynchronously. |
112 | 115 |
113 // Used to advance through the states of the state machine. | 116 // Used to advance through the states of the state machine. |
114 void AdvanceState(); | 117 void AdvanceState(); |
115 | 118 |
116 // Intercepts the request as a stream/download if needed. | 119 // Intercepts the request as a stream/download if needed. |
117 void MaybeIntercept(); | 120 void MaybeIntercept(); |
118 | 121 |
119 // Calls OnWillRead on the downstream handlers. | |
120 void CallOnWillRead(); | |
121 | |
122 // Copies received buffer to parent. | |
123 void BufferReceived(); | |
124 | |
125 // Replays OnResponseStarted on the downstream handlers. | 122 // Replays OnResponseStarted on the downstream handlers. |
126 void ReplayResponseReceived(); | 123 void ReplayResponseReceived(); |
127 | 124 |
| 125 // Gets a buffer for read completion. |
| 126 void ReplayGetBuffer(); |
| 127 |
128 // Replays OnReadCompleted on the downstreams handlers. | 128 // Replays OnReadCompleted on the downstreams handlers. |
129 void ReplayReadCompleted(); | 129 void ReplayReadCompleted(); |
130 | 130 |
131 // -------------------------------------------------------------------------- | 131 // -------------------------------------------------------------------------- |
132 | 132 |
133 // Whether the response body should be sniffed in order to determine the MIME | 133 // Whether the response body should be sniffed in order to determine the MIME |
134 // type of the response. | 134 // type of the response. |
135 bool ShouldSniffContent(); | 135 bool ShouldSniffContent(); |
136 | 136 |
137 // Checks whether this request should be intercepted as a stream or a | 137 // Checks whether this request should be intercepted as a stream or a |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 #endif | 171 #endif |
172 | 172 |
173 bool must_download_; | 173 bool must_download_; |
174 bool must_download_is_set_; | 174 bool must_download_is_set_; |
175 | 175 |
176 // Used to buffer the reponse received until replay. | 176 // Used to buffer the reponse received until replay. |
177 scoped_refptr<ResourceResponse> response_; | 177 scoped_refptr<ResourceResponse> response_; |
178 scoped_refptr<net::IOBuffer> read_buffer_; | 178 scoped_refptr<net::IOBuffer> read_buffer_; |
179 int read_buffer_size_; | 179 int read_buffer_size_; |
180 int bytes_read_; | 180 int bytes_read_; |
| 181 int bytes_replayed_; |
181 | 182 |
182 // Pointers to parent-owned read buffer and its size. Only used for first | 183 // Downstream buffer information for replay. |
183 // OnWillRead call. | 184 scoped_refptr<net::IOBuffer> out_buffer_; |
184 scoped_refptr<net::IOBuffer>* parent_read_buffer_; | 185 int out_buffer_size_; |
185 int* parent_read_buffer_size_; | |
186 | 186 |
187 // The InterceptingResourceHandler that will perform ResourceHandler swap if | 187 // The InterceptingResourceHandler that will perform ResourceHandler swap if |
188 // needed. | 188 // needed. |
189 InterceptingResourceHandler* intercepting_handler_; | 189 InterceptingResourceHandler* intercepting_handler_; |
190 | 190 |
191 RequestContextType request_context_type_; | 191 RequestContextType request_context_type_; |
192 | 192 |
193 // True if current in an AdvanceState loop. Used to prevent re-entrancy and | 193 // True if current in an AdvanceState loop. Used to prevent re-entrancy and |
194 // avoid an extra PostTask. | 194 // avoid an extra PostTask. |
195 bool in_state_loop_; | 195 bool in_state_loop_; |
196 // Set to true if Resume() is called while |in_state_loop_| is true. When | 196 // Set to true if Resume() is called while |in_state_loop_| is true. When |
197 // returning to the parent AdvanceState loop, will synchronously advance to | 197 // returning to the parent AdvanceState loop, will synchronously advance to |
198 // the next state when control returns to the AdvanceState loop. | 198 // the next state when control returns to the AdvanceState loop. |
199 bool advance_state_; | 199 bool advance_state_; |
200 | 200 |
201 base::WeakPtrFactory<MimeSniffingResourceHandler> weak_ptr_factory_; | 201 base::WeakPtrFactory<MimeSniffingResourceHandler> weak_ptr_factory_; |
202 | 202 |
203 DISALLOW_COPY_AND_ASSIGN(MimeSniffingResourceHandler); | 203 DISALLOW_COPY_AND_ASSIGN(MimeSniffingResourceHandler); |
204 }; | 204 }; |
205 | 205 |
206 } // namespace content | 206 } // namespace content |
207 | 207 |
208 #endif // CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 208 #endif // CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
OLD | NEW |