| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_INTERCEPTING_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // The InterceptingResourceHandler is waiting for the mime type of the | 74 // The InterceptingResourceHandler is waiting for the mime type of the |
| 75 // response to be identified, to check if the next handler should be | 75 // response to be identified, to check if the next handler should be |
| 76 // replaced with an appropriate one. | 76 // replaced with an appropriate one. |
| 77 STARTING, | 77 STARTING, |
| 78 | 78 |
| 79 // The InterceptingResourceHandler is sending the payload given via | 79 // The InterceptingResourceHandler is sending the payload given via |
| 80 // UseNewHandler to the old handler and waiting for its completion via | 80 // UseNewHandler to the old handler and waiting for its completion via |
| 81 // Resume(). | 81 // Resume(). |
| 82 SENDING_PAYLOAD_TO_OLD_HANDLER, | 82 SENDING_PAYLOAD_TO_OLD_HANDLER, |
| 83 | 83 |
| 84 // The InterceptingResourcHandler is notifying OnResponseStarted to the new | 84 // The InterceptingResourcHandler is calling the new handler's |
| 85 // handler and waiting for its completion via Resume(). After the | 85 // OnResponseStarted method and waiting for its completion via Resume(). |
| 86 // completion, the InterceptingResourcHandler will transit to | 86 // After completion, the InterceptingResourceHandler will transition to |
| 87 // SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER on success. |
| 88 SENDING_ON_WILL_START_TO_NEW_HANDLER, |
| 89 |
| 90 // The InterceptingResourcHandler is calling the new handler's |
| 91 // OnResponseStarted method and waiting for its completion via Resume(). |
| 92 // After completion, the InterceptingResourceHandler will transition to |
| 87 // WAITING_FOR_ON_READ_COMPLETED on success. | 93 // WAITING_FOR_ON_READ_COMPLETED on success. |
| 88 NOTIFYING_ON_RESPONSE_STARTED_TO_NEW_HANDLER, | 94 SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER, |
| 89 | 95 |
| 90 // The InterceptingResourcHandler is waiting for OnReadCompleted to be | 96 // The InterceptingResourcHandler is waiting for OnReadCompleted to be |
| 91 // called. | 97 // called. |
| 92 WAITING_FOR_ON_READ_COMPLETED, | 98 WAITING_FOR_ON_READ_COMPLETED, |
| 93 | 99 |
| 94 // The InterceptingResourceHandler is sending the old handler's contents to | 100 // The InterceptingResourceHandler is sending the old handler's contents to |
| 95 // the new handler and waiting for its completion via Resume(). | 101 // the new handler and waiting for its completion via Resume(). |
| 96 SENDING_BUFFER_TO_NEW_HANDLER, | 102 SENDING_BUFFER_TO_NEW_HANDLER, |
| 97 | 103 |
| 98 // The InterceptingResourceHandler has replaced its next ResourceHandler if | 104 // The InterceptingResourceHandler has replaced its next ResourceHandler if |
| 99 // needed, and has ensured the buffered read data was properly transmitted | 105 // needed, and has ensured the buffered read data was properly transmitted |
| 100 // to the new ResourceHandler. The InterceptingResourceHandler now acts as | 106 // to the new ResourceHandler. The InterceptingResourceHandler now acts as |
| 101 // a pass-through ResourceHandler. | 107 // a pass-through ResourceHandler. |
| 102 PASS_THROUGH, | 108 PASS_THROUGH, |
| 103 }; | 109 }; |
| 104 | 110 |
| 105 // Runs necessary operations depending on |state_|. Returns false when an | 111 // Runs necessary operations depending on |state_|. Returns false when an |
| 106 // error happens, and set |*defer| to true if the operation continues upon | 112 // error happens, and set |*defer| to true if the operation continues upon |
| 107 // return. | 113 // return. |
| 108 bool DoLoop(bool* defer); | 114 bool DoLoop(bool* defer); |
| 109 | 115 |
| 110 // The return value and |defer| has the same meaning as DoLoop. | 116 // The return value and |defer| has the same meaning as DoLoop. |
| 111 bool SendPayloadToOldHandler(bool* defer); | 117 bool SendPayloadToOldHandler(bool* defer); |
| 112 bool SendFirstReadBufferToNewHandler(bool* defer); | 118 bool SendFirstReadBufferToNewHandler(bool* defer); |
| 113 bool SendCompletionToOldHandler(bool* defer); | 119 bool SendOnResponseStartedToNewHandler(bool* defer); |
| 114 | 120 |
| 115 State state_ = State::STARTING; | 121 State state_ = State::STARTING; |
| 116 | 122 |
| 117 std::unique_ptr<ResourceHandler> new_handler_; | 123 std::unique_ptr<ResourceHandler> new_handler_; |
| 118 std::string payload_for_old_handler_; | 124 std::string payload_for_old_handler_; |
| 119 size_t payload_bytes_written_ = 0; | 125 size_t payload_bytes_written_ = 0; |
| 120 | 126 |
| 121 // Result of the first read, that may have to be passed to an alternate | 127 // Result of the first read, that may have to be passed to an alternate |
| 122 // ResourceHandler instead of the original ResourceHandler. | 128 // ResourceHandler instead of the original ResourceHandler. |
| 123 scoped_refptr<net::IOBuffer> first_read_buffer_; | 129 scoped_refptr<net::IOBuffer> first_read_buffer_; |
| 124 // Instead of |first_read_buffer_|, this handler creates a new IOBuffer with | 130 // Instead of |first_read_buffer_|, this handler creates a new IOBuffer with |
| 125 // the same size and return it to the client. | 131 // the same size and return it to the client. |
| 126 scoped_refptr<net::IOBuffer> first_read_buffer_double_; | 132 scoped_refptr<net::IOBuffer> first_read_buffer_double_; |
| 127 size_t first_read_buffer_size_ = 0; | 133 size_t first_read_buffer_size_ = 0; |
| 128 size_t first_read_buffer_bytes_read_ = 0; | 134 size_t first_read_buffer_bytes_read_ = 0; |
| 129 size_t first_read_buffer_bytes_written_ = 0; | 135 size_t first_read_buffer_bytes_written_ = 0; |
| 130 | 136 |
| 131 scoped_refptr<ResourceResponse> response_; | 137 scoped_refptr<ResourceResponse> response_; |
| 132 | 138 |
| 133 DISALLOW_COPY_AND_ASSIGN(InterceptingResourceHandler); | 139 DISALLOW_COPY_AND_ASSIGN(InterceptingResourceHandler); |
| 134 }; | 140 }; |
| 135 | 141 |
| 136 } // namespace content | 142 } // namespace content |
| 137 | 143 |
| 138 #endif // CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ | 144 #endif // CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ |
| OLD | NEW |