| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // on the IO thread. | 95 // on the IO thread. |
| 94 void CallStartedCB(DownloadItem* item, net::Error error); | 96 void CallStartedCB(DownloadItem* item, net::Error error); |
| 95 | 97 |
| 96 // If the content-length header is not present (or contains something other | 98 // If the content-length header is not present (or contains something other |
| 97 // than numbers), the incoming content_length is -1 (unknown size). | 99 // than numbers), the incoming content_length is -1 (unknown size). |
| 98 // Set the content length to 0 to indicate unknown size to DownloadManager. | 100 // Set the content length to 0 to indicate unknown size to DownloadManager. |
| 99 void SetContentLength(const int64& content_length); | 101 void SetContentLength(const int64& content_length); |
| 100 | 102 |
| 101 void SetContentDisposition(const std::string& content_disposition); | 103 void SetContentDisposition(const std::string& content_disposition); |
| 102 | 104 |
| 105 DownloadId download_id_; |
| 103 GlobalRequestID global_id_; | 106 GlobalRequestID global_id_; |
| 104 int render_view_id_; | 107 int render_view_id_; |
| 105 std::string content_disposition_; | 108 std::string content_disposition_; |
| 106 int64 content_length_; | 109 int64 content_length_; |
| 107 net::URLRequest* request_; | 110 net::URLRequest* request_; |
| 108 // This is read only on the IO thread, but may only | 111 // This is read only on the IO thread, but may only |
| 109 // be called on the UI thread. | 112 // be called on the UI thread. |
| 110 OnStartedCallback started_cb_; | 113 OnStartedCallback started_cb_; |
| 111 scoped_ptr<DownloadSaveInfo> save_info_; | 114 scoped_ptr<DownloadSaveInfo> save_info_; |
| 112 | 115 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 | 134 |
| 132 static const int kReadBufSize = 32768; // bytes | 135 static const int kReadBufSize = 32768; // bytes |
| 133 static const int kThrottleTimeMs = 200; // milliseconds | 136 static const int kThrottleTimeMs = 200; // milliseconds |
| 134 | 137 |
| 135 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 138 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 136 }; | 139 }; |
| 137 | 140 |
| 138 } // namespace content | 141 } // namespace content |
| 139 | 142 |
| 140 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 143 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |