Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: content/browser/download/download_resource_handler.cc

Issue 9639001: Move download interrupt reasons to content\public (the enum that's used by chrome). The rest keep i… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nits Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/metrics/stats_counters.h" 12 #include "base/metrics/stats_counters.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "content/browser/download/download_buffer.h" 14 #include "content/browser/download/download_buffer.h"
15 #include "content/browser/download/download_create_info.h" 15 #include "content/browser/download/download_create_info.h"
16 #include "content/browser/download/download_file_manager.h" 16 #include "content/browser/download/download_file_manager.h"
17 #include "content/browser/download/download_interrupt_reasons_impl.h"
17 #include "content/browser/download/download_manager_impl.h" 18 #include "content/browser/download/download_manager_impl.h"
18 #include "content/browser/download/download_request_handle.h" 19 #include "content/browser/download/download_request_handle.h"
19 #include "content/browser/download/download_stats.h" 20 #include "content/browser/download/download_stats.h"
20 #include "content/browser/download/interrupt_reasons.h"
21 #include "content/browser/renderer_host/resource_dispatcher_host.h" 21 #include "content/browser/renderer_host/resource_dispatcher_host.h"
22 #include "content/browser/renderer_host/resource_request_info_impl.h" 22 #include "content/browser/renderer_host/resource_request_info_impl.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/download_interrupt_reasons.h"
24 #include "content/public/browser/download_item.h" 25 #include "content/public/browser/download_item.h"
25 #include "content/public/browser/download_manager_delegate.h" 26 #include "content/public/browser/download_manager_delegate.h"
26 #include "content/public/common/resource_response.h" 27 #include "content/public/common/resource_response.h"
27 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
28 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
29 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
30 #include "net/url_request/url_request_context.h" 31 #include "net/url_request/url_request_context.h"
31 32
32 using content::BrowserThread; 33 using content::BrowserThread;
33 using content::DownloadId; 34 using content::DownloadId;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 net::Error error_code = net::OK; 259 net::Error error_code = net::OK;
259 if (status.status() == net::URLRequestStatus::FAILED) 260 if (status.status() == net::URLRequestStatus::FAILED)
260 error_code = static_cast<net::Error>(status.error()); // Normal case. 261 error_code = static_cast<net::Error>(status.error()); // Normal case.
261 // ERR_CONNECTION_CLOSED is allowed since a number of servers in the wild 262 // ERR_CONNECTION_CLOSED is allowed since a number of servers in the wild
262 // advertise a larger Content-Length than the amount of bytes in the message 263 // advertise a larger Content-Length than the amount of bytes in the message
263 // body, and then close the connection. Other browsers - IE8, Firefox 4.0.1, 264 // body, and then close the connection. Other browsers - IE8, Firefox 4.0.1,
264 // and Safari 5.0.4 - treat the download as complete in this case, so we 265 // and Safari 5.0.4 - treat the download as complete in this case, so we
265 // follow their lead. 266 // follow their lead.
266 if (error_code == net::ERR_CONNECTION_CLOSED) 267 if (error_code == net::ERR_CONNECTION_CLOSED)
267 error_code = net::OK; 268 error_code = net::OK;
268 InterruptReason reason = 269 content::DownloadInterruptReason reason =
269 ConvertNetErrorToInterruptReason(error_code, 270 content::ConvertNetErrorToInterruptReason(
270 DOWNLOAD_INTERRUPT_FROM_NETWORK); 271 error_code, content::DOWNLOAD_INTERRUPT_FROM_NETWORK);
271 272
272 if ((status.status() == net::URLRequestStatus::CANCELED) && 273 if ((status.status() == net::URLRequestStatus::CANCELED) &&
273 (status.error() == net::ERR_ABORTED)) { 274 (status.error() == net::ERR_ABORTED)) {
274 // TODO(ahendrickson) -- Find a better set of codes to use here, as 275 // TODO(ahendrickson) -- Find a better set of codes to use here, as
275 // CANCELED/ERR_ABORTED can occur for reasons other than user cancel. 276 // CANCELED/ERR_ABORTED can occur for reasons other than user cancel.
276 reason = DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; // User canceled. 277 reason = content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED;
277 } 278 }
278 279
279 if (status.is_success()) { 280 if (status.is_success()) {
280 int response_code = request_->GetResponseCode(); 281 int response_code = request_->GetResponseCode();
281 if (response_code >= 400) { 282 if (response_code >= 400) {
282 switch(response_code) { 283 switch(response_code) {
283 case 404: // File Not Found. 284 case 404: // File Not Found.
284 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; 285 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT;
285 break; 286 break;
286 case 416: // Range Not Satisfiable. 287 case 416: // Range Not Satisfiable.
287 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE; 288 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE;
288 break; 289 break;
289 case 412: // Precondition Failed. 290 case 412: // Precondition Failed.
290 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; 291 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION;
291 break; 292 break;
292 default: 293 default:
293 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; 294 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED;
294 break; 295 break;
295 } 296 }
296 } 297 }
297 } 298 }
298 299
299 download_stats::RecordAcceptsRanges(accept_ranges_, bytes_read_); 300 download_stats::RecordAcceptsRanges(accept_ranges_, bytes_read_);
300 301
301 // If the callback was already run on the UI thread, this will be a noop. 302 // If the callback was already run on the UI thread, this will be a noop.
302 BrowserThread::PostTask( 303 BrowserThread::PostTask(
303 BrowserThread::UI, FROM_HERE, 304 BrowserThread::UI, FROM_HERE,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 " render_view_id_ = " "%d" 403 " render_view_id_ = " "%d"
403 " save_info_.file_path = \"%" PRFilePath "\"" 404 " save_info_.file_path = \"%" PRFilePath "\""
404 " }", 405 " }",
405 request_->url().spec().c_str(), 406 request_->url().spec().c_str(),
406 download_id_.local(), 407 download_id_.local(),
407 global_id_.child_id, 408 global_id_.child_id,
408 global_id_.request_id, 409 global_id_.request_id,
409 render_view_id_, 410 render_view_id_,
410 save_info_.file_path.value().c_str()); 411 save_info_.file_path.value().c_str());
411 } 412 }
OLDNEW
« no previous file with comments | « content/browser/download/download_net_log_parameters.cc ('k') | content/browser/download/download_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698