| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class DownloadResourceHandler | 34 class DownloadResourceHandler |
| 35 : public content::ResourceHandler, | 35 : public content::ResourceHandler, |
| 36 public base::SupportsWeakPtr<DownloadResourceHandler> { | 36 public base::SupportsWeakPtr<DownloadResourceHandler> { |
| 37 public: | 37 public: |
| 38 typedef content::DownloadUrlParameters::OnStartedCallback OnStartedCallback; | 38 typedef content::DownloadUrlParameters::OnStartedCallback OnStartedCallback; |
| 39 | 39 |
| 40 // started_cb will be called exactly once on the UI thread. | 40 // started_cb will be called exactly once on the UI thread. |
| 41 DownloadResourceHandler( | 41 DownloadResourceHandler( |
| 42 net::URLRequest* request, | 42 net::URLRequest* request, |
| 43 const OnStartedCallback& started_cb, | 43 const OnStartedCallback& started_cb, |
| 44 const content::DownloadSaveInfo& save_info); | 44 scoped_ptr<content::DownloadSaveInfo> save_info); |
| 45 | 45 |
| 46 virtual bool OnUploadProgress(int request_id, | 46 virtual bool OnUploadProgress(int request_id, |
| 47 uint64 position, | 47 uint64 position, |
| 48 uint64 size) OVERRIDE; | 48 uint64 size) OVERRIDE; |
| 49 | 49 |
| 50 // Not needed, as this event handler ought to be the final resource. | 50 // Not needed, as this event handler ought to be the final resource. |
| 51 virtual bool OnRequestRedirected(int request_id, | 51 virtual bool OnRequestRedirected(int request_id, |
| 52 const GURL& url, | 52 const GURL& url, |
| 53 content::ResourceResponse* response, | 53 content::ResourceResponse* response, |
| 54 bool* defer) OVERRIDE; | 54 bool* defer) OVERRIDE; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void SetContentDisposition(const std::string& content_disposition); | 99 void SetContentDisposition(const std::string& content_disposition); |
| 100 | 100 |
| 101 content::GlobalRequestID global_id_; | 101 content::GlobalRequestID global_id_; |
| 102 int render_view_id_; | 102 int render_view_id_; |
| 103 std::string content_disposition_; | 103 std::string content_disposition_; |
| 104 int64 content_length_; | 104 int64 content_length_; |
| 105 net::URLRequest* request_; | 105 net::URLRequest* request_; |
| 106 // This is read only on the IO thread, but may only | 106 // This is read only on the IO thread, but may only |
| 107 // be called on the UI thread. | 107 // be called on the UI thread. |
| 108 OnStartedCallback started_cb_; | 108 OnStartedCallback started_cb_; |
| 109 content::DownloadSaveInfo save_info_; | 109 scoped_ptr<content::DownloadSaveInfo> save_info_; |
| 110 | 110 |
| 111 // Data flow | 111 // Data flow |
| 112 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest. | 112 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest. |
| 113 scoped_ptr<content::ByteStreamWriter> stream_writer_; // To rest of system. | 113 scoped_ptr<content::ByteStreamWriter> stream_writer_; // To rest of system. |
| 114 | 114 |
| 115 // The following are used to collect stats. | 115 // The following are used to collect stats. |
| 116 base::TimeTicks download_start_time_; | 116 base::TimeTicks download_start_time_; |
| 117 base::TimeTicks last_read_time_; | 117 base::TimeTicks last_read_time_; |
| 118 base::TimeTicks last_stream_pause_time_; | 118 base::TimeTicks last_stream_pause_time_; |
| 119 base::TimeDelta total_pause_time_; | 119 base::TimeDelta total_pause_time_; |
| 120 size_t last_buffer_size_; | 120 size_t last_buffer_size_; |
| 121 int64 bytes_read_; | 121 int64 bytes_read_; |
| 122 std::string accept_ranges_; | 122 std::string accept_ranges_; |
| 123 | 123 |
| 124 int pause_count_; | 124 int pause_count_; |
| 125 bool was_deferred_; | 125 bool was_deferred_; |
| 126 | 126 |
| 127 // For DCHECKing | 127 // For DCHECKing |
| 128 bool on_response_started_called_; | 128 bool on_response_started_called_; |
| 129 | 129 |
| 130 static const int kReadBufSize = 32768; // bytes | 130 static const int kReadBufSize = 32768; // bytes |
| 131 static const int kThrottleTimeMs = 200; // milliseconds | 131 static const int kThrottleTimeMs = 200; // milliseconds |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 133 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 136 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |