| 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_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/timer.h" | 13 #include "base/timer.h" |
| 14 #include "content/browser/download/download_file.h" | |
| 15 #include "content/browser/download/download_id.h" | 14 #include "content/browser/download/download_id.h" |
| 15 #include "content/browser/download/download_types.h" |
| 16 #include "content/browser/renderer_host/global_request_id.h" | 16 #include "content/browser/renderer_host/global_request_id.h" |
| 17 #include "content/browser/renderer_host/resource_handler.h" | 17 #include "content/browser/renderer_host/resource_handler.h" |
| 18 #include "net/base/net_errors.h" |
| 18 | 19 |
| 19 class DownloadFileManager; | 20 class DownloadFileManager; |
| 20 class ResourceDispatcherHost; | 21 class ResourceDispatcherHost; |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 class DownloadBuffer; | 24 class DownloadBuffer; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 class URLRequest; | 28 class URLRequest; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 const std::string& security_info); | 71 const std::string& security_info); |
| 71 virtual void OnRequestClosed(); | 72 virtual void OnRequestClosed(); |
| 72 | 73 |
| 73 // If the content-length header is not present (or contains something other | 74 // If the content-length header is not present (or contains something other |
| 74 // than numbers), the incoming content_length is -1 (unknown size). | 75 // than numbers), the incoming content_length is -1 (unknown size). |
| 75 // Set the content length to 0 to indicate unknown size to DownloadManager. | 76 // Set the content length to 0 to indicate unknown size to DownloadManager. |
| 76 void set_content_length(const int64& content_length); | 77 void set_content_length(const int64& content_length); |
| 77 | 78 |
| 78 void set_content_disposition(const std::string& content_disposition); | 79 void set_content_disposition(const std::string& content_disposition); |
| 79 | 80 |
| 81 // Request had a network error, and a new request must be issued. Should be |
| 82 // used only by |ResourceDispatcherHost::BeginDownload()|. |
| 83 void set_was_interrupted(bool interrupted) { was_interrupted_ = interrupted; } |
| 84 |
| 85 // How many bytes were read before this request was interrupted. Should be |
| 86 // used only by |ResourceDispatcherHost::BeginDownload()|. |
| 87 void set_interrupted_bytes(int64 bytes) { interrupted_bytes_ = bytes; } |
| 88 |
| 80 void CheckWriteProgress(); | 89 void CheckWriteProgress(); |
| 81 | 90 |
| 82 std::string DebugString() const; | 91 std::string DebugString() const; |
| 83 | 92 |
| 84 private: | 93 private: |
| 85 virtual ~DownloadResourceHandler(); | 94 virtual ~DownloadResourceHandler(); |
| 86 | 95 |
| 87 void StartPauseTimer(); | 96 void StartPauseTimer(); |
| 88 void CallStartedCB(net::Error error); | 97 void CallStartedCB(net::Error error); |
| 89 | 98 |
| 90 DownloadId download_id_; | 99 DownloadId download_id_; |
| 91 GlobalRequestID global_id_; | 100 GlobalRequestID global_id_; |
| 92 int render_view_id_; | 101 int render_view_id_; |
| 93 scoped_refptr<net::IOBuffer> read_buffer_; | 102 scoped_refptr<net::IOBuffer> read_buffer_; |
| 94 std::string content_disposition_; | 103 std::string content_disposition_; |
| 95 int64 content_length_; | 104 int64 content_length_; |
| 96 DownloadFileManager* download_file_manager_; | 105 DownloadFileManager* download_file_manager_; |
| 97 net::URLRequest* request_; | 106 net::URLRequest* request_; |
| 98 bool save_as_; // Request was initiated via "Save As" by the user. | 107 bool save_as_; // Request was initiated via "Save As" by the user. |
| 99 OnStartedCallback started_cb_; | 108 OnStartedCallback started_cb_; |
| 100 DownloadSaveInfo save_info_; | 109 DownloadSaveInfo save_info_; |
| 101 scoped_refptr<content::DownloadBuffer> buffer_; | 110 scoped_refptr<content::DownloadBuffer> buffer_; |
| 102 ResourceDispatcherHost* rdh_; | 111 ResourceDispatcherHost* rdh_; |
| 103 bool is_paused_; | 112 bool is_paused_; |
| 104 base::OneShotTimer<DownloadResourceHandler> pause_timer_; | 113 base::OneShotTimer<DownloadResourceHandler> pause_timer_; |
| 105 base::TimeTicks download_start_time_; // used to collect stats. | 114 base::TimeTicks download_start_time_; // used to collect stats. |
| 115 bool was_interrupted_; |
| 116 int64 interrupted_bytes_; |
| 106 static const int kReadBufSize = 32768; // bytes | 117 static const int kReadBufSize = 32768; // bytes |
| 107 static const size_t kLoadsToWrite = 100; // number of data buffers queued | 118 static const size_t kLoadsToWrite = 100; // number of data buffers queued |
| 108 static const int kThrottleTimeMs = 200; // milliseconds | 119 static const int kThrottleTimeMs = 200; // milliseconds |
| 109 | 120 |
| 110 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 121 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 111 }; | 122 }; |
| 112 | 123 |
| 113 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 124 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |