OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "content/browser/loader/resource_handler.h" | 13 #include "content/browser/loader/resource_handler.h" |
| 14 #include "content/public/browser/download_interrupt_reasons.h" |
14 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
15 #include "content/public/browser/download_save_info.h" | 16 #include "content/public/browser/download_save_info.h" |
16 #include "content/public/browser/download_url_parameters.h" | 17 #include "content/public/browser/download_url_parameters.h" |
17 #include "content/public/browser/global_request_id.h" | 18 #include "content/public/browser/global_request_id.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 | 20 |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 class URLRequest; | 23 class URLRequest; |
23 } // namespace net | 24 } // namespace net |
24 | 25 |
25 namespace content { | 26 namespace content { |
| 27 template <typename StatusType> |
26 class ByteStreamWriter; | 28 class ByteStreamWriter; |
27 class ByteStreamReader; | |
28 class DownloadRequestHandle; | 29 class DownloadRequestHandle; |
29 struct DownloadCreateInfo; | 30 struct DownloadCreateInfo; |
30 | 31 |
31 // Forwards data to the download thread. | 32 // Forwards data to the download thread. |
32 class CONTENT_EXPORT DownloadResourceHandler | 33 class CONTENT_EXPORT DownloadResourceHandler |
33 : public ResourceHandler, | 34 : public ResourceHandler, |
34 public base::SupportsWeakPtr<DownloadResourceHandler> { | 35 public base::SupportsWeakPtr<DownloadResourceHandler> { |
35 public: | 36 public: |
36 // Size of the buffer used between the DownloadResourceHandler and the | 37 // Size of the buffer used between the DownloadResourceHandler and the |
37 // downstream receiver of its output. | 38 // downstream receiver of its output. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 std::string content_disposition_; | 110 std::string content_disposition_; |
110 int64 content_length_; | 111 int64 content_length_; |
111 net::URLRequest* request_; | 112 net::URLRequest* request_; |
112 // This is read only on the IO thread, but may only | 113 // This is read only on the IO thread, but may only |
113 // be called on the UI thread. | 114 // be called on the UI thread. |
114 DownloadUrlParameters::OnStartedCallback started_cb_; | 115 DownloadUrlParameters::OnStartedCallback started_cb_; |
115 scoped_ptr<DownloadSaveInfo> save_info_; | 116 scoped_ptr<DownloadSaveInfo> save_info_; |
116 | 117 |
117 // Data flow | 118 // Data flow |
118 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest. | 119 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest. |
119 scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system. | 120 scoped_ptr<ByteStreamWriter<DownloadInterruptReason> > |
| 121 stream_writer_; // To rest of system. |
120 | 122 |
121 // The following are used to collect stats. | 123 // The following are used to collect stats. |
122 base::TimeTicks download_start_time_; | 124 base::TimeTicks download_start_time_; |
123 base::TimeTicks last_read_time_; | 125 base::TimeTicks last_read_time_; |
124 base::TimeTicks last_stream_pause_time_; | 126 base::TimeTicks last_stream_pause_time_; |
125 base::TimeDelta total_pause_time_; | 127 base::TimeDelta total_pause_time_; |
126 size_t last_buffer_size_; | 128 size_t last_buffer_size_; |
127 int64 bytes_read_; | 129 int64 bytes_read_; |
128 std::string accept_ranges_; | 130 std::string accept_ranges_; |
129 | 131 |
130 int pause_count_; | 132 int pause_count_; |
131 bool was_deferred_; | 133 bool was_deferred_; |
132 | 134 |
133 // For DCHECKing | 135 // For DCHECKing |
134 bool on_response_started_called_; | 136 bool on_response_started_called_; |
135 | 137 |
136 static const int kReadBufSize = 32768; // bytes | 138 static const int kReadBufSize = 32768; // bytes |
137 static const int kThrottleTimeMs = 200; // milliseconds | 139 static const int kThrottleTimeMs = 200; // milliseconds |
138 | 140 |
139 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 141 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
140 }; | 142 }; |
141 | 143 |
142 } // namespace content | 144 } // namespace content |
143 | 145 |
144 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 146 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
OLD | NEW |