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