| 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 #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_types.h" | 14 #include "content/browser/download/download_types.h" |
| 15 #include "content/browser/renderer_host/resource_handler.h" | 15 #include "content/browser/renderer_host/resource_handler.h" |
| 16 #include "content/public/browser/download_id.h" | 16 #include "content/public/browser/download_id.h" |
| 17 #include "content/public/browser/global_request_id.h" | 17 #include "content/public/browser/global_request_id.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/base/net_log.h" |
| 19 | 20 |
| 20 class DownloadFileManager; | 21 class DownloadFileManager; |
| 21 class DownloadRequestHandle; | 22 class DownloadRequestHandle; |
| 22 class ResourceDispatcherHost; | 23 class ResourceDispatcherHost; |
| 23 struct DownloadCreateInfo; | 24 struct DownloadCreateInfo; |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 class DownloadBuffer; | 27 class DownloadBuffer; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 class URLRequest; | 31 class URLRequest; |
| 31 } // namespace net | 32 } // namespace net |
| 32 | 33 |
| 33 // Forwards data to the download thread. | 34 // Forwards data to the download thread. |
| 34 class DownloadResourceHandler : public ResourceHandler { | 35 class DownloadResourceHandler : public ResourceHandler { |
| 35 public: | 36 public: |
| 36 typedef base::Callback<void(content::DownloadId, net::Error)> | 37 typedef base::Callback<void(content::DownloadId, net::Error)> |
| 37 OnStartedCallback; | 38 OnStartedCallback; |
| 38 | 39 |
| 39 static const size_t kLoadsToWrite = 100; // number of data buffers queued | 40 static const size_t kLoadsToWrite = 100; // number of data buffers queued |
| 40 | 41 |
| 41 // started_cb will be called exactly once on the UI thread. | 42 // started_cb will be called exactly once on the UI thread. |
| 42 DownloadResourceHandler(ResourceDispatcherHost* rdh, | 43 DownloadResourceHandler(ResourceDispatcherHost* rdh, |
| 43 int render_process_host_id, | 44 int render_process_host_id, |
| 44 int render_view_id, | 45 int render_view_id, |
| 45 int request_id, | 46 int request_id, |
| 46 const GURL& url, | 47 const GURL& url, |
| 48 const net::BoundNetLog& bound_net_log, |
| 47 DownloadFileManager* download_file_manager, | 49 DownloadFileManager* download_file_manager, |
| 48 net::URLRequest* request, | 50 net::URLRequest* request, |
| 49 const OnStartedCallback& started_cb, | 51 const OnStartedCallback& started_cb, |
| 50 const DownloadSaveInfo& save_info); | 52 const DownloadSaveInfo& save_info); |
| 51 | 53 |
| 52 virtual bool OnUploadProgress(int request_id, | 54 virtual bool OnUploadProgress(int request_id, |
| 53 uint64 position, | 55 uint64 position, |
| 54 uint64 size) OVERRIDE; | 56 uint64 size) OVERRIDE; |
| 55 | 57 |
| 56 // Not needed, as this event handler ought to be the final resource. | 58 // Not needed, as this event handler ought to be the final resource. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 bool is_paused_; | 122 bool is_paused_; |
| 121 base::OneShotTimer<DownloadResourceHandler> pause_timer_; | 123 base::OneShotTimer<DownloadResourceHandler> pause_timer_; |
| 122 | 124 |
| 123 // The following are used to collect stats. | 125 // The following are used to collect stats. |
| 124 base::TimeTicks download_start_time_; | 126 base::TimeTicks download_start_time_; |
| 125 base::TimeTicks last_read_time_; | 127 base::TimeTicks last_read_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 |
| 132 const net::BoundNetLog bound_net_log_; |
| 133 |
| 130 static const int kReadBufSize = 32768; // bytes | 134 static const int kReadBufSize = 32768; // bytes |
| 131 static const int kThrottleTimeMs = 200; // milliseconds | 135 static const int kThrottleTimeMs = 200; // milliseconds |
| 132 | 136 |
| 133 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 137 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 140 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |