| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "content/browser/download/download_file.h" | 13 #include "content/browser/download/download_file.h" |
| 14 #include "content/browser/download/download_id.h" | |
| 15 #include "content/browser/renderer_host/global_request_id.h" | 14 #include "content/browser/renderer_host/global_request_id.h" |
| 16 #include "content/browser/renderer_host/resource_handler.h" | 15 #include "content/browser/renderer_host/resource_handler.h" |
| 17 | 16 |
| 18 class DownloadFileManager; | 17 class DownloadFileManager; |
| 19 class ResourceDispatcherHost; | 18 class ResourceDispatcherHost; |
| 20 struct DownloadBuffer; | 19 struct DownloadBuffer; |
| 21 | 20 |
| 22 namespace net { | 21 namespace net { |
| 23 class URLRequest; | 22 class URLRequest; |
| 24 } // namespace net | 23 } // namespace net |
| 25 | 24 |
| 26 // Forwards data to the download thread. | 25 // Forwards data to the download thread. |
| 27 class DownloadResourceHandler : public ResourceHandler { | 26 class DownloadResourceHandler : public ResourceHandler { |
| 28 public: | 27 public: |
| 29 DownloadResourceHandler( | 28 DownloadResourceHandler(ResourceDispatcherHost* rdh, |
| 30 ResourceDispatcherHost* rdh, | 29 int render_process_host_id, |
| 31 int render_process_host_id, | 30 int render_view_id, |
| 32 int render_view_id, | 31 int request_id, |
| 33 int request_id, | 32 const GURL& url, |
| 34 const GURL& url, | 33 DownloadFileManager* download_file_manager, |
| 35 DownloadId dl_id, | 34 net::URLRequest* request, |
| 36 DownloadFileManager* download_file_manager, | 35 bool save_as, |
| 37 net::URLRequest* request, | 36 const DownloadSaveInfo& save_info); |
| 38 bool save_as, | |
| 39 const DownloadSaveInfo& save_info); | |
| 40 | 37 |
| 41 virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size); | 38 virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size); |
| 42 | 39 |
| 43 // Not needed, as this event handler ought to be the final resource. | 40 // Not needed, as this event handler ought to be the final resource. |
| 44 virtual bool OnRequestRedirected(int request_id, const GURL& url, | 41 virtual bool OnRequestRedirected(int request_id, const GURL& url, |
| 45 ResourceResponse* response, bool* defer); | 42 ResourceResponse* response, bool* defer); |
| 46 | 43 |
| 47 // Send the download creation information to the download thread. | 44 // Send the download creation information to the download thread. |
| 48 virtual bool OnResponseStarted(int request_id, ResourceResponse* response); | 45 virtual bool OnResponseStarted(int request_id, ResourceResponse* response); |
| 49 | 46 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 71 | 68 |
| 72 void CheckWriteProgress(); | 69 void CheckWriteProgress(); |
| 73 | 70 |
| 74 std::string DebugString() const; | 71 std::string DebugString() const; |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 virtual ~DownloadResourceHandler(); | 74 virtual ~DownloadResourceHandler(); |
| 78 | 75 |
| 79 void StartPauseTimer(); | 76 void StartPauseTimer(); |
| 80 | 77 |
| 81 DownloadId download_id_; | 78 int download_id_; |
| 82 GlobalRequestID global_id_; | 79 GlobalRequestID global_id_; |
| 83 int render_view_id_; | 80 int render_view_id_; |
| 84 scoped_refptr<net::IOBuffer> read_buffer_; | 81 scoped_refptr<net::IOBuffer> read_buffer_; |
| 85 std::string content_disposition_; | 82 std::string content_disposition_; |
| 86 int64 content_length_; | 83 int64 content_length_; |
| 87 DownloadFileManager* download_file_manager_; | 84 DownloadFileManager* download_file_manager_; |
| 88 net::URLRequest* request_; | 85 net::URLRequest* request_; |
| 89 bool save_as_; // Request was initiated via "Save As" by the user. | 86 bool save_as_; // Request was initiated via "Save As" by the user. |
| 90 DownloadSaveInfo save_info_; | 87 DownloadSaveInfo save_info_; |
| 91 scoped_ptr<DownloadBuffer> buffer_; | 88 scoped_ptr<DownloadBuffer> buffer_; |
| 92 ResourceDispatcherHost* rdh_; | 89 ResourceDispatcherHost* rdh_; |
| 93 bool is_paused_; | 90 bool is_paused_; |
| 94 base::OneShotTimer<DownloadResourceHandler> pause_timer_; | 91 base::OneShotTimer<DownloadResourceHandler> pause_timer_; |
| 95 base::TimeTicks download_start_time_; // used to collect stats. | 92 base::TimeTicks download_start_time_; // used to collect stats. |
| 96 static const int kReadBufSize = 32768; // bytes | 93 static const int kReadBufSize = 32768; // bytes |
| 97 static const size_t kLoadsToWrite = 100; // number of data buffers queued | 94 static const size_t kLoadsToWrite = 100; // number of data buffers queued |
| 98 static const int kThrottleTimeMs = 200; // milliseconds | 95 static const int kThrottleTimeMs = 200; // milliseconds |
| 99 | 96 |
| 100 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 97 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 101 }; | 98 }; |
| 102 | 99 |
| 103 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 100 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |