Home | History | Annotate | Download | only in renderer_host
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_RENDERER_HOST_SAVE_FILE_RESOURCE_HANDLER_H_
      6 #define CHROME_BROWSER_RENDERER_HOST_SAVE_FILE_RESOURCE_HANDLER_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "content/browser/renderer_host/resource_handler.h"
     12 #include "googleurl/src/gurl.h"
     13 
     14 class SaveFileManager;
     15 
     16 // Forwards data to the save thread.
     17 class SaveFileResourceHandler : public ResourceHandler {
     18  public:
     19   SaveFileResourceHandler(int render_process_host_id,
     20                           int render_view_id,
     21                           const GURL& url,
     22                           SaveFileManager* manager);
     23 
     24   // ResourceHandler Implementation:
     25   virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size);
     26 
     27   // Saves the redirected URL to final_url_, we need to use the original
     28   // URL to match original request.
     29   virtual bool OnRequestRedirected(int request_id, const GURL& url,
     30                                    ResourceResponse* response, bool* defer);
     31 
     32   // Sends the download creation information to the download thread.
     33   virtual bool OnResponseStarted(int request_id, ResourceResponse* response);
     34 
     35   // Pass-through implementation.
     36   virtual bool OnWillStart(int request_id, const GURL& url, bool* defer);
     37 
     38   // Creates a new buffer, which will be handed to the download thread for file
     39   // writing and deletion.
     40   virtual bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
     41                           int min_size);
     42 
     43   // Passes the buffer to the download file writer.
     44   virtual bool OnReadCompleted(int request_id, int* bytes_read);
     45 
     46   virtual bool OnResponseCompleted(int request_id,
     47                                    const net::URLRequestStatus& status,
     48                                    const std::string& security_info);
     49 
     50   virtual void OnRequestClosed();
     51 
     52   // If the content-length header is not present (or contains something other
     53   // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and
     54   // is handled correctly by the SaveManager.
     55   void set_content_length(const std::string& content_length);
     56 
     57   void set_content_disposition(const std::string& content_disposition) {
     58     content_disposition_ = content_disposition;
     59   }
     60 
     61  private:
     62   virtual ~SaveFileResourceHandler();
     63 
     64   int save_id_;
     65   int render_process_id_;
     66   int render_view_id_;
     67   scoped_refptr<net::IOBuffer> read_buffer_;
     68   std::string content_disposition_;
     69   GURL url_;
     70   GURL final_url_;
     71   int64 content_length_;
     72   SaveFileManager* save_manager_;
     73 
     74   static const int kReadBufSize = 32768;  // bytes
     75 
     76   DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler);
     77 };
     78 
     79 #endif  // CHROME_BROWSER_RENDERER_HOST_SAVE_FILE_RESOURCE_HANDLER_H_
     80