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_REQUEST_CORE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // DownloadRequestCore. | 53 // DownloadRequestCore. |
54 DownloadRequestCore(net::URLRequest* request, Delegate* delegate); | 54 DownloadRequestCore(net::URLRequest* request, Delegate* delegate); |
55 ~DownloadRequestCore(); | 55 ~DownloadRequestCore(); |
56 | 56 |
57 // Should be called when the URLRequest::Delegate receives OnResponseStarted. | 57 // Should be called when the URLRequest::Delegate receives OnResponseStarted. |
58 // Invokes Delegate::OnStart() with download start parameters. The | 58 // Invokes Delegate::OnStart() with download start parameters. The |
59 // |override_mime_type| is used as the MIME type for the download when | 59 // |override_mime_type| is used as the MIME type for the download when |
60 // constructing a DownloadCreateInfo object. | 60 // constructing a DownloadCreateInfo object. |
61 bool OnResponseStarted(const std::string& override_mime_type); | 61 bool OnResponseStarted(const std::string& override_mime_type); |
62 | 62 |
| 63 // Should be called to handle a redirect. The caller should only allow the |
| 64 // redirect to be followed if the return value is true. |
| 65 bool OnRequestRedirected(); |
| 66 |
63 // Starts a read cycle. Creates a new IOBuffer which can be passed into | 67 // Starts a read cycle. Creates a new IOBuffer which can be passed into |
64 // URLRequest::Read(). Call OnReadCompleted() when the Read operation | 68 // URLRequest::Read(). Call OnReadCompleted() when the Read operation |
65 // completes. | 69 // completes. |
66 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 70 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
67 int* buf_size, | 71 int* buf_size, |
68 int min_size); | 72 int min_size); |
69 | 73 |
| 74 // Used to notify DownloadRequestCore that the caller is about to abort the |
| 75 // outer request. |reason| will be used as the final interrupt reason when |
| 76 // OnResponseCompleted() is called. |
| 77 void OnWillAbort(DownloadInterruptReason reason); |
| 78 |
70 // Should be called when the Read() operation completes. |defer| will be set | 79 // Should be called when the Read() operation completes. |defer| will be set |
71 // to true if reading is to be suspended. In the latter case, once more data | 80 // to true if reading is to be suspended. In the latter case, once more data |
72 // can be read, invokes the |on_ready_to_read_callback|. | 81 // can be read, invokes the |on_ready_to_read_callback|. |
73 bool OnReadCompleted(int bytes_read, bool* defer); | 82 bool OnReadCompleted(int bytes_read, bool* defer); |
74 | 83 |
75 // Called to signal that the response is complete. | 84 // Called to signal that the response is complete. |
76 // | 85 // |
77 // It is expected that once this method is invoked, the DownloadRequestCore | 86 // It is expected that once this method is invoked, the DownloadRequestCore |
78 // object will be destroyed in short order without invoking any other methods | 87 // object will be destroyed in short order without invoking any other methods |
79 // other than the destructor. | 88 // other than the destructor. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // The following are used to collect stats. | 145 // The following are used to collect stats. |
137 base::TimeTicks download_start_time_; | 146 base::TimeTicks download_start_time_; |
138 base::TimeTicks last_read_time_; | 147 base::TimeTicks last_read_time_; |
139 base::TimeTicks last_stream_pause_time_; | 148 base::TimeTicks last_stream_pause_time_; |
140 base::TimeDelta total_pause_time_; | 149 base::TimeDelta total_pause_time_; |
141 size_t last_buffer_size_; | 150 size_t last_buffer_size_; |
142 int64_t bytes_read_; | 151 int64_t bytes_read_; |
143 | 152 |
144 int pause_count_; | 153 int pause_count_; |
145 bool was_deferred_; | 154 bool was_deferred_; |
146 bool is_resumption_request_; | 155 bool is_partial_request_; |
147 bool started_; | 156 bool started_; |
148 | 157 |
149 // When DownloadRequestCore initiates an abort (by blocking a redirect, for | 158 // When DownloadRequestCore initiates an abort (by blocking a redirect, for |
150 // example) it expects to eventually receive a OnResponseCompleted() with a | 159 // example) it expects to eventually receive a OnResponseCompleted() with a |
151 // status indicating that the request was aborted. When this happens, the | 160 // status indicating that the request was aborted. When this happens, the |
152 // interrupt reason in |abort_reason_| will be used instead of USER_CANCELED | 161 // interrupt reason in |abort_reason_| will be used instead of USER_CANCELED |
153 // which is vague. | 162 // which is vague. |
154 DownloadInterruptReason abort_reason_; | 163 DownloadInterruptReason abort_reason_; |
155 | 164 |
156 // Each successful OnWillRead will yield a buffer of this size. | 165 // Each successful OnWillRead will yield a buffer of this size. |
157 static const int kReadBufSize = 32768; // bytes | 166 static const int kReadBufSize = 32768; // bytes |
158 | 167 |
159 DISALLOW_COPY_AND_ASSIGN(DownloadRequestCore); | 168 DISALLOW_COPY_AND_ASSIGN(DownloadRequestCore); |
160 }; | 169 }; |
161 | 170 |
162 } // namespace content | 171 } // namespace content |
163 | 172 |
164 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ | 173 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ |
OLD | NEW |