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