| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RENDERER_HOST_ASYNC_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_ASYNC_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_ASYNC_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_ASYNC_RESOURCE_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "content/browser/renderer_host/resource_handler.h" | 11 #include "content/browser/renderer_host/resource_handler.h" |
| 12 | 12 |
| 13 class HostZoomMap; | 13 class HostZoomMap; |
| 14 class ResourceDispatcherHost; | 14 class ResourceDispatcherHost; |
| 15 class ResourceMessageFilter; | 15 class ResourceMessageFilter; |
| 16 class SharedIOBuffer; | 16 class SharedIOBuffer; |
| 17 | 17 |
| 18 // Used to complete an asynchronous resource request in response to resource | 18 // Used to complete an asynchronous resource request in response to resource |
| 19 // load events from the resource dispatcher host. | 19 // load events from the resource dispatcher host. |
| 20 class AsyncResourceHandler : public ResourceHandler { | 20 class AsyncResourceHandler : public ResourceHandler { |
| 21 public: | 21 public: |
| 22 AsyncResourceHandler(ResourceMessageFilter* filter, | 22 AsyncResourceHandler(ResourceMessageFilter* filter, |
| 23 int routing_id, | 23 int routing_id, |
| 24 const GURL& url, | 24 const GURL& url, |
| 25 ResourceDispatcherHost* resource_dispatcher_host); | 25 ResourceDispatcherHost* resource_dispatcher_host); |
| 26 | 26 |
| 27 // ResourceHandler implementation: | 27 // ResourceHandler implementation: |
| 28 virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size); | 28 virtual bool OnUploadProgress(int request_id, |
| 29 virtual bool OnRequestRedirected(int request_id, const GURL& new_url, | 29 uint64 position, |
| 30 ResourceResponse* response, bool* defer); | 30 uint64 size) OVERRIDE; |
| 31 virtual bool OnResponseStarted(int request_id, ResourceResponse* response); | 31 virtual bool OnRequestRedirected(int request_id, |
| 32 virtual bool OnWillStart(int request_id, const GURL& url, bool* defer); | 32 const GURL& new_url, |
| 33 virtual bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size, | 33 ResourceResponse* response, |
| 34 int min_size); | 34 bool* defer) OVERRIDE; |
| 35 virtual bool OnReadCompleted(int request_id, int* bytes_read); | 35 virtual bool OnResponseStarted(int request_id, |
| 36 ResourceResponse* response) OVERRIDE; |
| 37 virtual bool OnWillStart(int request_id, |
| 38 const GURL& url, |
| 39 bool* defer) OVERRIDE; |
| 40 virtual bool OnWillRead(int request_id, |
| 41 net::IOBuffer** buf, |
| 42 int* buf_size, |
| 43 int min_size) OVERRIDE; |
| 44 virtual bool OnReadCompleted(int request_id, |
| 45 int* bytes_read) OVERRIDE; |
| 36 virtual bool OnResponseCompleted(int request_id, | 46 virtual bool OnResponseCompleted(int request_id, |
| 37 const net::URLRequestStatus& status, | 47 const net::URLRequestStatus& status, |
| 38 const std::string& security_info); | 48 const std::string& security_info) OVERRIDE; |
| 39 virtual void OnRequestClosed(); | 49 virtual void OnRequestClosed() OVERRIDE; |
| 40 virtual void OnDataDownloaded(int request_id, int bytes_downloaded); | 50 virtual void OnDataDownloaded(int request_id, |
| 51 int bytes_downloaded) OVERRIDE; |
| 41 | 52 |
| 42 static void GlobalCleanup(); | 53 static void GlobalCleanup(); |
| 43 | 54 |
| 44 private: | 55 private: |
| 45 virtual ~AsyncResourceHandler(); | 56 virtual ~AsyncResourceHandler(); |
| 46 | 57 |
| 47 scoped_refptr<SharedIOBuffer> read_buffer_; | 58 scoped_refptr<SharedIOBuffer> read_buffer_; |
| 48 ResourceMessageFilter* filter_; | 59 ResourceMessageFilter* filter_; |
| 49 int routing_id_; | 60 int routing_id_; |
| 50 HostZoomMap* host_zoom_map_; | 61 HostZoomMap* host_zoom_map_; |
| 51 ResourceDispatcherHost* rdh_; | 62 ResourceDispatcherHost* rdh_; |
| 52 | 63 |
| 53 // |next_buffer_size_| is the size of the buffer to be allocated on the next | 64 // |next_buffer_size_| is the size of the buffer to be allocated on the next |
| 54 // OnWillRead() call. We exponentially grow the size of the buffer allocated | 65 // OnWillRead() call. We exponentially grow the size of the buffer allocated |
| 55 // when our owner fills our buffers. On the first OnWillRead() call, we | 66 // when our owner fills our buffers. On the first OnWillRead() call, we |
| 56 // allocate a buffer of 32k and double it in OnReadCompleted() if the buffer | 67 // allocate a buffer of 32k and double it in OnReadCompleted() if the buffer |
| 57 // was filled, up to a maximum size of 512k. | 68 // was filled, up to a maximum size of 512k. |
| 58 int next_buffer_size_; | 69 int next_buffer_size_; |
| 59 | 70 |
| 60 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); | 71 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); |
| 61 }; | 72 }; |
| 62 | 73 |
| 63 #endif // CONTENT_BROWSER_RENDERER_HOST_ASYNC_RESOURCE_HANDLER_H_ | 74 #endif // CONTENT_BROWSER_RENDERER_HOST_ASYNC_RESOURCE_HANDLER_H_ |
| OLD | NEW |