| 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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 // static | 133 // static |
| 134 std::unique_ptr<ResourceHandler> DownloadResourceHandler::Create( | 134 std::unique_ptr<ResourceHandler> DownloadResourceHandler::Create( |
| 135 net::URLRequest* request) { | 135 net::URLRequest* request) { |
| 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 136 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 137 std::unique_ptr<ResourceHandler> handler( | 137 std::unique_ptr<ResourceHandler> handler( |
| 138 new DownloadResourceHandler(request)); | 138 new DownloadResourceHandler(request)); |
| 139 return handler; | 139 return handler; |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool DownloadResourceHandler::OnRequestRedirected( | 142 void DownloadResourceHandler::OnRequestRedirected( |
| 143 const net::RedirectInfo& redirect_info, | 143 const net::RedirectInfo& redirect_info, |
| 144 ResourceResponse* response, | 144 ResourceResponse* response, |
| 145 bool* defer) { | 145 bool* defer_or_cancel) { |
| 146 return core_.OnRequestRedirected(); | 146 if (!core_.OnRequestRedirected()) { |
| 147 *defer_or_cancel = true; |
| 148 controller()->Cancel(); |
| 149 } |
| 147 } | 150 } |
| 148 | 151 |
| 149 // Send the download creation information to the download thread. | 152 // Send the download creation information to the download thread. |
| 150 bool DownloadResourceHandler::OnResponseStarted( | 153 void DownloadResourceHandler::OnResponseStarted(ResourceResponse* response, |
| 151 ResourceResponse* response, | 154 bool* defer_or_cancel) { |
| 152 bool* defer) { | |
| 153 // The MIME type in ResourceResponse is the product of | 155 // The MIME type in ResourceResponse is the product of |
| 154 // MimeTypeResourceHandler. | 156 // MimeTypeResourceHandler. |
| 155 return core_.OnResponseStarted(response->head.mime_type); | 157 if (!core_.OnResponseStarted(response->head.mime_type)) { |
| 158 *defer_or_cancel = true; |
| 159 controller()->Cancel(); |
| 160 } |
| 156 } | 161 } |
| 157 | 162 |
| 158 bool DownloadResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 163 void DownloadResourceHandler::OnWillStart(const GURL& url, |
| 159 return true; | 164 bool* defer_or_cancel) {} |
| 160 } | |
| 161 | 165 |
| 162 // Create a new buffer, which will be handed to the download thread for file | 166 // Create a new buffer, which will be handed to the download thread for file |
| 163 // writing and deletion. | 167 // writing and deletion. |
| 164 bool DownloadResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 168 bool DownloadResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 165 int* buf_size, | 169 int* buf_size, |
| 166 int min_size) { | 170 int min_size) { |
| 167 return core_.OnWillRead(buf, buf_size, min_size); | 171 return core_.OnWillRead(buf, buf_size, min_size); |
| 168 } | 172 } |
| 169 | 173 |
| 170 // Pass the buffer to the download file writer. | 174 // Pass the buffer to the download file writer. |
| 171 bool DownloadResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { | 175 void DownloadResourceHandler::OnReadCompleted(int bytes_read, |
| 172 return core_.OnReadCompleted(bytes_read, defer); | 176 bool* defer_or_cancel) { |
| 177 if (!core_.OnReadCompleted(bytes_read, defer_or_cancel)) { |
| 178 *defer_or_cancel = true; |
| 179 controller()->Cancel(); |
| 180 } |
| 173 } | 181 } |
| 174 | 182 |
| 175 void DownloadResourceHandler::OnResponseCompleted( | 183 void DownloadResourceHandler::OnResponseCompleted( |
| 176 const net::URLRequestStatus& status, | 184 const net::URLRequestStatus& status, |
| 177 bool* defer) { | 185 bool* defer) { |
| 178 core_.OnResponseCompleted(status); | 186 core_.OnResponseCompleted(status); |
| 179 } | 187 } |
| 180 | 188 |
| 181 void DownloadResourceHandler::OnDataDownloaded(int bytes_downloaded) { | 189 void DownloadResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
| 182 NOTREACHED(); | 190 NOTREACHED(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 " }", | 259 " }", |
| 252 request() ? | 260 request() ? |
| 253 request()->url().spec().c_str() : | 261 request()->url().spec().c_str() : |
| 254 "<NULL request>", | 262 "<NULL request>", |
| 255 info->GetChildID(), | 263 info->GetChildID(), |
| 256 info->GetRequestID(), | 264 info->GetRequestID(), |
| 257 info->GetRouteID()); | 265 info->GetRouteID()); |
| 258 } | 266 } |
| 259 | 267 |
| 260 } // namespace content | 268 } // namespace content |
| OLD | NEW |