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