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 #include "content/browser/download/download_resource_handler.h" | 5 #include "content/browser/download/download_resource_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 render_view_id_(render_view_id), | 65 render_view_id_(render_view_id), |
66 content_length_(0), | 66 content_length_(0), |
67 download_file_manager_(download_file_manager), | 67 download_file_manager_(download_file_manager), |
68 request_(request), | 68 request_(request), |
69 started_cb_(started_cb), | 69 started_cb_(started_cb), |
70 save_info_(save_info), | 70 save_info_(save_info), |
71 buffer_(new content::DownloadBuffer), | 71 buffer_(new content::DownloadBuffer), |
72 last_buffer_size_(0), | 72 last_buffer_size_(0), |
73 bytes_read_(0), | 73 bytes_read_(0), |
74 pause_count_(0), | 74 pause_count_(0), |
75 was_deferred_(false) { | 75 was_deferred_(false), |
| 76 on_response_started_called_(false) { |
76 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); | 77 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); |
77 } | 78 } |
78 | 79 |
79 bool DownloadResourceHandler::OnUploadProgress(int request_id, | 80 bool DownloadResourceHandler::OnUploadProgress(int request_id, |
80 uint64 position, | 81 uint64 position, |
81 uint64 size) { | 82 uint64 size) { |
82 return true; | 83 return true; |
83 } | 84 } |
84 | 85 |
85 // Not needed, as this event handler ought to be the final resource. | 86 // Not needed, as this event handler ought to be the final resource. |
86 bool DownloadResourceHandler::OnRequestRedirected( | 87 bool DownloadResourceHandler::OnRequestRedirected( |
87 int request_id, | 88 int request_id, |
88 const GURL& url, | 89 const GURL& url, |
89 content::ResourceResponse* response, | 90 content::ResourceResponse* response, |
90 bool* defer) { | 91 bool* defer) { |
91 return true; | 92 return true; |
92 } | 93 } |
93 | 94 |
94 // Send the download creation information to the download thread. | 95 // Send the download creation information to the download thread. |
95 bool DownloadResourceHandler::OnResponseStarted( | 96 bool DownloadResourceHandler::OnResponseStarted( |
96 int request_id, | 97 int request_id, |
97 content::ResourceResponse* response, | 98 content::ResourceResponse* response, |
98 bool* defer) { | 99 bool* defer) { |
| 100 // There can be only one (call) |
| 101 DCHECK(!on_response_started_called_); |
| 102 on_response_started_called_ = true; |
| 103 |
99 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 104 VLOG(20) << __FUNCTION__ << "()" << DebugString() |
100 << " request_id = " << request_id; | 105 << " request_id = " << request_id; |
101 download_start_time_ = base::TimeTicks::Now(); | 106 download_start_time_ = base::TimeTicks::Now(); |
102 | 107 |
103 // If it's a download, we don't want to poison the cache with it. | 108 // If it's a download, we don't want to poison the cache with it. |
104 request_->StopCaching(); | 109 request_->StopCaching(); |
105 | 110 |
106 std::string content_disposition; | 111 std::string content_disposition; |
107 request_->GetResponseHeaderByName("content-disposition", | 112 request_->GetResponseHeaderByName("content-disposition", |
108 &content_disposition); | 113 &content_disposition); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (download_id_ == DownloadId::Invalid()) | 500 if (download_id_ == DownloadId::Invalid()) |
496 return; | 501 return; |
497 if (buffer_.get() && (buffer_->size() > kLoadsToWrite)) | 502 if (buffer_.get() && (buffer_->size() > kLoadsToWrite)) |
498 return; | 503 return; |
499 | 504 |
500 was_deferred_ = false; | 505 was_deferred_ = false; |
501 ResourceDispatcherHostImpl::Get()->ResumeDeferredRequest( | 506 ResourceDispatcherHostImpl::Get()->ResumeDeferredRequest( |
502 global_id_.child_id, | 507 global_id_.child_id, |
503 global_id_.request_id); | 508 global_id_.request_id); |
504 } | 509 } |
OLD | NEW |