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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 struct DownloadCreateInfo; | 30 struct DownloadCreateInfo; |
31 | 31 |
32 // Forwards data to the download thread. | 32 // Forwards data to the download thread. |
33 class DownloadResourceHandler | 33 class DownloadResourceHandler |
34 : public ResourceHandler, | 34 : public ResourceHandler, |
35 public base::SupportsWeakPtr<DownloadResourceHandler> { | 35 public base::SupportsWeakPtr<DownloadResourceHandler> { |
36 public: | 36 public: |
37 typedef DownloadUrlParameters::OnStartedCallback OnStartedCallback; | 37 typedef DownloadUrlParameters::OnStartedCallback OnStartedCallback; |
38 | 38 |
39 // started_cb will be called exactly once on the UI thread. | 39 // started_cb will be called exactly once on the UI thread. |
| 40 // |id| should be invalid if the id should be automatically assigned. |
40 DownloadResourceHandler( | 41 DownloadResourceHandler( |
| 42 DownloadId id, |
41 net::URLRequest* request, | 43 net::URLRequest* request, |
42 const OnStartedCallback& started_cb, | 44 const OnStartedCallback& started_cb, |
43 scoped_ptr<DownloadSaveInfo> save_info); | 45 scoped_ptr<DownloadSaveInfo> save_info); |
44 | 46 |
45 virtual bool OnUploadProgress(int request_id, | 47 virtual bool OnUploadProgress(int request_id, |
46 uint64 position, | 48 uint64 position, |
47 uint64 size) OVERRIDE; | 49 uint64 size) OVERRIDE; |
48 | 50 |
49 // Not needed, as this event handler ought to be the final resource. | 51 // Not needed, as this event handler ought to be the final resource. |
50 virtual bool OnRequestRedirected(int request_id, | 52 virtual bool OnRequestRedirected(int request_id, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // on the IO thread. | 92 // on the IO thread. |
91 void CallStartedCB(DownloadItem* item, net::Error error); | 93 void CallStartedCB(DownloadItem* item, net::Error error); |
92 | 94 |
93 // If the content-length header is not present (or contains something other | 95 // If the content-length header is not present (or contains something other |
94 // than numbers), the incoming content_length is -1 (unknown size). | 96 // than numbers), the incoming content_length is -1 (unknown size). |
95 // Set the content length to 0 to indicate unknown size to DownloadManager. | 97 // Set the content length to 0 to indicate unknown size to DownloadManager. |
96 void SetContentLength(const int64& content_length); | 98 void SetContentLength(const int64& content_length); |
97 | 99 |
98 void SetContentDisposition(const std::string& content_disposition); | 100 void SetContentDisposition(const std::string& content_disposition); |
99 | 101 |
| 102 DownloadId download_id_; |
100 GlobalRequestID global_id_; | 103 GlobalRequestID global_id_; |
101 int render_view_id_; | 104 int render_view_id_; |
102 std::string content_disposition_; | 105 std::string content_disposition_; |
103 int64 content_length_; | 106 int64 content_length_; |
104 net::URLRequest* request_; | 107 net::URLRequest* request_; |
105 // This is read only on the IO thread, but may only | 108 // This is read only on the IO thread, but may only |
106 // be called on the UI thread. | 109 // be called on the UI thread. |
107 OnStartedCallback started_cb_; | 110 OnStartedCallback started_cb_; |
108 scoped_ptr<DownloadSaveInfo> save_info_; | 111 scoped_ptr<DownloadSaveInfo> save_info_; |
109 | 112 |
(...skipping 18 matching lines...) Expand all Loading... |
128 | 131 |
129 static const int kReadBufSize = 32768; // bytes | 132 static const int kReadBufSize = 32768; // bytes |
130 static const int kThrottleTimeMs = 200; // milliseconds | 133 static const int kThrottleTimeMs = 200; // milliseconds |
131 | 134 |
132 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 135 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
133 }; | 136 }; |
134 | 137 |
135 } // namespace content | 138 } // namespace content |
136 | 139 |
137 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 140 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
OLD | NEW |