| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // received. | 57 // received. |
| 58 STATE_STARTING, | 58 STATE_STARTING, |
| 59 | 59 |
| 60 // In this state, the MimeSniffingResourceHandler is buffering the response | 60 // In this state, the MimeSniffingResourceHandler is buffering the response |
| 61 // data in read_buffer_, waiting to sniff the mime type and make a choice | 61 // data in read_buffer_, waiting to sniff the mime type and make a choice |
| 62 // about request interception. | 62 // about request interception. |
| 63 STATE_BUFFERING, | 63 STATE_BUFFERING, |
| 64 | 64 |
| 65 // In this state, the MimeSniffingResourceHandler has identified the mime | 65 // In this state, the MimeSniffingResourceHandler has identified the mime |
| 66 // type and made a decision on whether the request should be intercepted or | 66 // type and made a decision on whether the request should be intercepted or |
| 67 // not. It is nows attempting to replay the response to downstream | 67 // not. It now needs to prepare the new handler for use, and replay the |
| 68 // handlers. | 68 // already received data. |
| 69 STATE_INTERCEPTION_CHECK_DONE, | 69 STATE_NEED_TO_PREPARE_TO_USE_NEW_HANDLER, |
| 70 |
| 71 // In this state, the MimeSniffingResourceHandler is preparing the new |
| 72 // handler for use. |
| 73 STATE_PREPARING_TO_USE_NEW_HANDLER, |
| 70 | 74 |
| 71 // In this state, the MimeSniffingResourceHandler is replaying the buffered | 75 // In this state, the MimeSniffingResourceHandler is replaying the buffered |
| 72 // OnResponseStarted event to the downstream ResourceHandlers. | 76 // OnResponseStarted event to the downstream ResourceHandlers. |
| 73 STATE_REPLAYING_RESPONSE_RECEIVED, | 77 STATE_REPLAYING_RECEIVED_RESPONSE, |
| 74 | 78 |
| 75 // In this state, the MimeSniffingResourceHandler is just a blind | 79 // In this state, the MimeSniffingResourceHandler is just a blind |
| 76 // pass-through | 80 // pass-through |
| 77 // ResourceHandler. | 81 // ResourceHandler. |
| 78 STATE_STREAMING, | 82 STATE_STREAMING, |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 // ResourceHandler implementation: | 85 // ResourceHandler implementation: |
| 82 void SetController(ResourceController* controller) override; | 86 void SetController(ResourceController* controller) override; |
| 83 bool OnWillStart(const GURL&, bool* defer) override; | 87 bool OnWillStart(const GURL&, bool* defer) override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 101 // true otherwise. Each of them will set |defer| to true if the request will | 105 // true otherwise. Each of them will set |defer| to true if the request will |
| 102 // proceed to the next stage asynchronously. | 106 // proceed to the next stage asynchronously. |
| 103 | 107 |
| 104 // Used to advance through the states of the state machine. | 108 // Used to advance through the states of the state machine. |
| 105 void AdvanceState(); | 109 void AdvanceState(); |
| 106 bool ProcessState(bool* defer); | 110 bool ProcessState(bool* defer); |
| 107 | 111 |
| 108 // Intercepts the request as a stream/download if needed. | 112 // Intercepts the request as a stream/download if needed. |
| 109 bool MaybeIntercept(bool* defer); | 113 bool MaybeIntercept(bool* defer); |
| 110 | 114 |
| 115 // Prepares the new handler for use, advancing it to a state where it can |
| 116 // be swapped in to replace the InterceptingResourceHandler's old one. |
| 117 bool PrepareToUseNewHandler(bool* defer); |
| 118 |
| 111 // Replays OnResponseStarted on the downstream handlers. | 119 // Replays OnResponseStarted on the downstream handlers. |
| 112 bool ReplayResponseReceived(bool* defer); | 120 bool ReplayReceivedResponse(bool* defer); |
| 113 | 121 |
| 114 // Replays OnReadCompleted on the downstreams handlers. | 122 // Replays OnReadCompleted on the downstreams handlers. |
| 115 bool ReplayReadCompleted(bool* defer); | 123 bool ReplayReadCompleted(bool* defer); |
| 116 | 124 |
| 117 // -------------------------------------------------------------------------- | 125 // -------------------------------------------------------------------------- |
| 118 | 126 |
| 119 // Whether the response body should be sniffed in order to determine the MIME | 127 // Whether the response body should be sniffed in order to determine the MIME |
| 120 // type of the response. | 128 // type of the response. |
| 121 bool ShouldSniffContent(); | 129 bool ShouldSniffContent(); |
| 122 | 130 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 scoped_refptr<net::IOBuffer> read_buffer_; | 170 scoped_refptr<net::IOBuffer> read_buffer_; |
| 163 int read_buffer_size_; | 171 int read_buffer_size_; |
| 164 int bytes_read_; | 172 int bytes_read_; |
| 165 | 173 |
| 166 // The InterceptingResourceHandler that will perform ResourceHandler swap if | 174 // The InterceptingResourceHandler that will perform ResourceHandler swap if |
| 167 // needed. | 175 // needed. |
| 168 InterceptingResourceHandler* intercepting_handler_; | 176 InterceptingResourceHandler* intercepting_handler_; |
| 169 | 177 |
| 170 RequestContextType request_context_type_; | 178 RequestContextType request_context_type_; |
| 171 | 179 |
| 180 std::unique_ptr<ResourceHandler> new_handler_; |
| 181 std::string payload_for_old_handler_; |
| 182 |
| 172 base::WeakPtrFactory<MimeSniffingResourceHandler> weak_ptr_factory_; | 183 base::WeakPtrFactory<MimeSniffingResourceHandler> weak_ptr_factory_; |
| 173 | 184 |
| 174 DISALLOW_COPY_AND_ASSIGN(MimeSniffingResourceHandler); | 185 DISALLOW_COPY_AND_ASSIGN(MimeSniffingResourceHandler); |
| 175 }; | 186 }; |
| 176 | 187 |
| 177 } // namespace content | 188 } // namespace content |
| 178 | 189 |
| 179 #endif // CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ | 190 #endif // CONTENT_BROWSER_LOADER_MIME_SNIFFING_RESOURCE_HANDLER_H_ |
| OLD | NEW |