Index: content/browser/loader/mime_type_resource_handler.h |
diff --git a/content/browser/loader/mime_type_resource_handler.h b/content/browser/loader/mime_type_resource_handler.h |
index f5581a6a8072522363e1f61e1030129b3ec9d4f2..94883a3de4acf64d91a43f1c898cd69b5a82fc2d 100644 |
--- a/content/browser/loader/mime_type_resource_handler.h |
+++ b/content/browser/loader/mime_type_resource_handler.h |
@@ -38,9 +38,8 @@ struct WebPluginInfo; |
// Before a request is sent, this ResourceHandler will also set an appropriate |
// Accept header on the request based on its ResourceType, if one isn't already |
// present. |
-class CONTENT_EXPORT MimeTypeResourceHandler |
- : public LayeredResourceHandler, |
- public ResourceController { |
+class CONTENT_EXPORT MimeTypeResourceHandler : public LayeredResourceHandler, |
+ public ResourceController { |
public: |
// If ENABLE_PLUGINS is defined, |plugin_service| must not be NULL. |
MimeTypeResourceHandler(std::unique_ptr<ResourceHandler> next_handler, |
@@ -50,10 +49,37 @@ class CONTENT_EXPORT MimeTypeResourceHandler |
~MimeTypeResourceHandler() override; |
private: |
+ enum State { |
+ // Starting state of the MimeTypeResourceHandler. In this state, it is |
+ // acting as a blind pass-through ResourceHandler. |
+ STATE_STARTING, |
+ |
+ // In this state, the MimeTypeResourceHandler is buffering the response |
+ // data in read_buffer_. |
+ STATE_BUFFERING, |
+ |
+ // In this state, the request is paused and the MimeTypeResourceHandler is |
+ // waiting to start the replay of the response to the downstream |
+ // ResourceHandlers. |
+ STATE_PROCESSING, |
+ |
+ // In this state, the MimeTypeResourceHandler is replaying the buffered |
+ // OnResponseStarted event to the downstream ResourceHandlers. |
+ STATE_REPLAYING_RESPONSE_RECEIVED, |
+ |
+ // In this state, the MimeTypeResourceHandler is replaying the buffered |
+ // OnResponseStarted event to the new leaf handler, if there is one. |
+ STATE_REPLAYING_RESPONSE_RECEIVED_NEW_HANDLER, |
+ |
+ // In this state, the MimeTypeResourceHandler is just a blind pass-through |
+ // ResourceHandler. |
+ STATE_STREAMING, |
+ }; |
+ |
// ResourceHandler implementation: |
void SetController(ResourceController* controller) override; |
- bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
bool OnWillStart(const GURL&, bool* defer) override; |
+ bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
int* buf_size, |
int min_size) override; |
@@ -62,13 +88,23 @@ class CONTENT_EXPORT MimeTypeResourceHandler |
const std::string& security_info, |
bool* defer) override; |
+ // LayeredResourceHandler implementation: |
+ void InstallNewLeafHandler( |
+ std::unique_ptr<ResourceHandler> new_handler, |
+ const std::string& payload_for_old_handler) override; |
+ |
// ResourceController implementation: |
void Resume() override; |
void Cancel() override; |
void CancelAndIgnore() override; |
void CancelWithError(int error_code) override; |
- bool ProcessResponse(bool* defer); |
+ // Replays the buffered data to the downstream ResourceHandlers. |
+ bool ProcessReplay(bool* defer); |
+ bool MaybeStartReplay(bool* defer); |
+ bool ReplayResponseReceived(bool* defer); |
+ bool ReplayResponseReceivedNewHandler(bool* defer); |
+ bool ReplayReadCompleted(bool* defer); |
bool ShouldSniffContent(); |
bool DetermineMimeType(); |
@@ -85,50 +121,31 @@ class CONTENT_EXPORT MimeTypeResourceHandler |
bool UseAlternateNextHandler(std::unique_ptr<ResourceHandler> handler, |
const std::string& payload_for_old_handler); |
- bool ReplayReadCompleted(bool* defer); |
- void CallReplayReadCompleted(); |
- |
bool MustDownload(); |
- // Copies data from |read_buffer_| to |next_handler_|. |
- bool CopyReadBufferToNextHandler(); |
- |
// Called on the IO thread once the list of plugins has been loaded. |
void OnPluginsLoaded(const std::vector<WebPluginInfo>& plugins); |
- enum State { |
- STATE_STARTING, |
- |
- // In this state, we are filling read_buffer_ with data for the purpose |
- // of sniffing the mime type of the response. |
- STATE_BUFFERING, |
- |
- // In this state, we are select an appropriate downstream ResourceHandler |
- // based on the mime type of the response. We are also potentially waiting |
- // for plugins to load so that we can determine if a plugin is available to |
- // handle the mime type. |
- STATE_PROCESSING, |
- |
- // In this state, we are replaying buffered events (OnResponseStarted and |
- // OnReadCompleted) to the downstream ResourceHandler. |
- STATE_REPLAYING, |
- |
- // In this state, we are just a blind pass-through ResourceHandler. |
- STATE_STREAMING |
- }; |
State state_; |
- scoped_refptr<ResourceResponse> response_; |
ResourceDispatcherHostImpl* host_; |
#if defined(ENABLE_PLUGINS) |
PluginService* plugin_service_; |
#endif |
+ |
+ bool must_download_; |
+ bool must_download_is_set_; |
+ |
+ // Used to buffer the reponse received until replay. |
+ scoped_refptr<ResourceResponse> response_; |
scoped_refptr<net::IOBuffer> read_buffer_; |
int read_buffer_size_; |
int bytes_read_; |
- bool must_download_; |
- bool must_download_is_set_; |
+ // Used to store a new leaf ResourceHandler until the actual one can be |
+ // replaced during the replay of the reponse. |
+ std::unique_ptr<ResourceHandler> new_leaf_handler_; |
+ std::string payload_for_old_handler_; |
base::WeakPtrFactory<MimeTypeResourceHandler> weak_ptr_factory_; |