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