Chromium Code Reviews| 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 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 uint64 size) OVERRIDE; | 53 uint64 size) OVERRIDE; |
| 54 | 54 |
| 55 // Not needed, as this event handler ought to be the final resource. | 55 // Not needed, as this event handler ought to be the final resource. |
| 56 virtual bool OnRequestRedirected(int request_id, | 56 virtual bool OnRequestRedirected(int request_id, |
| 57 const GURL& url, | 57 const GURL& url, |
| 58 content::ResourceResponse* response, | 58 content::ResourceResponse* response, |
| 59 bool* defer) OVERRIDE; | 59 bool* defer) OVERRIDE; |
| 60 | 60 |
| 61 // Send the download creation information to the download thread. | 61 // Send the download creation information to the download thread. |
| 62 virtual bool OnResponseStarted(int request_id, | 62 virtual bool OnResponseStarted(int request_id, |
| 63 content::ResourceResponse* response) OVERRIDE; | 63 content::ResourceResponse* response, |
| 64 bool* defer) OVERRIDE; | |
| 64 | 65 |
| 65 // Pass-through implementation. | 66 // Pass-through implementation. |
| 66 virtual bool OnWillStart(int request_id, | 67 virtual bool OnWillStart(int request_id, |
| 67 const GURL& url, | 68 const GURL& url, |
| 68 bool* defer) OVERRIDE; | 69 bool* defer) OVERRIDE; |
| 69 | 70 |
| 70 // Create a new buffer, which will be handed to the download thread for file | 71 // Create a new buffer, which will be handed to the download thread for file |
| 71 // writing and deletion. | 72 // writing and deletion. |
| 72 virtual bool OnWillRead(int request_id, | 73 virtual bool OnWillRead(int request_id, |
| 73 net::IOBuffer** buf, | 74 net::IOBuffer** buf, |
| 74 int* buf_size, | 75 int* buf_size, |
| 75 int min_size) OVERRIDE; | 76 int min_size) OVERRIDE; |
| 76 | 77 |
| 77 virtual bool OnReadCompleted(int request_id, int* bytes_read) OVERRIDE; | 78 virtual bool OnReadCompleted(int request_id, int* bytes_read, |
| 79 bool* defer) OVERRIDE; | |
| 78 | 80 |
| 79 virtual bool OnResponseCompleted(int request_id, | 81 virtual bool OnResponseCompleted(int request_id, |
| 80 const net::URLRequestStatus& status, | 82 const net::URLRequestStatus& status, |
| 81 const std::string& security_info) OVERRIDE; | 83 const std::string& security_info) OVERRIDE; |
| 82 virtual void OnRequestClosed() OVERRIDE; | 84 virtual void OnRequestClosed() OVERRIDE; |
| 83 | 85 |
| 84 // If the content-length header is not present (or contains something other | 86 std::string DebugString() const; |
|
Randy Smith (Not in Mondays)
2012/05/18 20:17:02
suggestion: My care factor isn't high, but I have
darin (slow to review)
2012/05/18 23:09:05
OK
| |
| 85 // than numbers), the incoming content_length is -1 (unknown size). | |
| 86 // Set the content length to 0 to indicate unknown size to DownloadManager. | |
| 87 void set_content_length(const int64& content_length); | |
| 88 | 87 |
| 89 void set_content_disposition(const std::string& content_disposition); | 88 void PauseRequest(); |
| 90 | 89 void ResumeRequest(); |
| 91 void CheckWriteProgress(); | 90 void CancelRequest(); |
| 92 | |
| 93 std::string DebugString() const; | |
| 94 | 91 |
| 95 private: | 92 private: |
| 96 virtual ~DownloadResourceHandler(); | 93 virtual ~DownloadResourceHandler(); |
| 97 | 94 |
| 98 void OnResponseCompletedInternal(int request_id, | 95 void OnResponseCompletedInternal(int request_id, |
| 99 const net::URLRequestStatus& status, | 96 const net::URLRequestStatus& status, |
| 100 const std::string& security_info, | 97 const std::string& security_info, |
| 101 int response_code); | 98 int response_code); |
| 102 | 99 |
| 103 void StartPauseTimer(); | 100 void CheckWriteProgressLater(); |
| 101 void CheckWriteProgress(); | |
| 102 void MaybeResumeRequest(); | |
| 104 void CallStartedCB(content::DownloadId id, net::Error error); | 103 void CallStartedCB(content::DownloadId id, net::Error error); |
| 105 | 104 |
| 106 // Generates a DownloadId and calls DownloadFileManager. | 105 // Generates a DownloadId and calls DownloadFileManager. |
| 107 void StartOnUIThread(scoped_ptr<DownloadCreateInfo> info, | 106 void StartOnUIThread(scoped_ptr<DownloadCreateInfo> info, |
| 108 const DownloadRequestHandle& handle); | 107 const DownloadRequestHandle& handle); |
| 109 void set_download_id(content::DownloadId id); | 108 void SetDownloadID(content::DownloadId id); |
| 109 | |
| 110 // If the content-length header is not present (or contains something other | |
| 111 // than numbers), the incoming content_length is -1 (unknown size). | |
| 112 // Set the content length to 0 to indicate unknown size to DownloadManager. | |
| 113 void SetContentLength(const int64& content_length); | |
| 114 | |
| 115 void SetContentDisposition(const std::string& content_disposition); | |
| 110 | 116 |
| 111 content::DownloadId download_id_; | 117 content::DownloadId download_id_; |
| 112 content::GlobalRequestID global_id_; | 118 content::GlobalRequestID global_id_; |
| 113 int render_view_id_; | 119 int render_view_id_; |
| 114 scoped_refptr<net::IOBuffer> read_buffer_; | 120 scoped_refptr<net::IOBuffer> read_buffer_; |
| 115 std::string content_disposition_; | 121 std::string content_disposition_; |
| 116 int64 content_length_; | 122 int64 content_length_; |
| 117 DownloadFileManager* download_file_manager_; | 123 DownloadFileManager* download_file_manager_; |
| 118 net::URLRequest* request_; | 124 net::URLRequest* request_; |
| 119 // This is used only on the UI thread. | 125 // This is used only on the UI thread. |
| 120 OnStartedCallback started_cb_; | 126 OnStartedCallback started_cb_; |
| 121 content::DownloadSaveInfo save_info_; | 127 content::DownloadSaveInfo save_info_; |
| 122 scoped_refptr<content::DownloadBuffer> buffer_; | 128 scoped_refptr<content::DownloadBuffer> buffer_; |
| 123 bool is_paused_; | 129 base::OneShotTimer<DownloadResourceHandler> check_write_progress_timer_; |
| 124 base::OneShotTimer<DownloadResourceHandler> pause_timer_; | |
| 125 | 130 |
| 126 // The following are used to collect stats. | 131 // The following are used to collect stats. |
| 127 base::TimeTicks download_start_time_; | 132 base::TimeTicks download_start_time_; |
| 128 base::TimeTicks last_read_time_; | 133 base::TimeTicks last_read_time_; |
| 129 size_t last_buffer_size_; | 134 size_t last_buffer_size_; |
| 130 int64 bytes_read_; | 135 int64 bytes_read_; |
| 131 std::string accept_ranges_; | 136 std::string accept_ranges_; |
| 132 | 137 |
| 138 int pause_count_; | |
|
Randy Smith (Not in Mondays)
2012/05/18 20:17:02
nit: Small comment ahead of these describing the s
| |
| 139 bool was_deferred_; | |
| 140 | |
| 133 static const int kReadBufSize = 32768; // bytes | 141 static const int kReadBufSize = 32768; // bytes |
| 134 static const int kThrottleTimeMs = 200; // milliseconds | 142 static const int kThrottleTimeMs = 200; // milliseconds |
| 135 | 143 |
| 136 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 144 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 137 }; | 145 }; |
| 138 | 146 |
| 139 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 147 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |