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

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

Issue 1751603002: [Downloads] Rework how hashes are calculated for download files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on top of https://codereview.chromium.org/1781983002 since that's going in first. Created 4 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
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_request_core.h" 5 #include "content/browser/download/download_request_core.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 }; 71 };
72 72
73 // static 73 // static
74 const int DownloadRequestData::kKey = 0; 74 const int DownloadRequestData::kKey = 0;
75 75
76 // static 76 // static
77 void DownloadRequestData::Attach(net::URLRequest* request, 77 void DownloadRequestData::Attach(net::URLRequest* request,
78 DownloadUrlParameters* parameters, 78 DownloadUrlParameters* parameters,
79 uint32_t download_id) { 79 uint32_t download_id) {
80 DownloadRequestData* request_data = new DownloadRequestData; 80 DownloadRequestData* request_data = new DownloadRequestData;
81 request_data->save_info_.reset(new DownloadSaveInfo); 81 request_data->save_info_.reset(
82 request_data->save_info_->file_path = parameters->file_path(); 82 new DownloadSaveInfo(parameters->GetSaveInfo()));
83 request_data->save_info_->suggested_name = parameters->suggested_name();
84 request_data->save_info_->file = parameters->GetFile();
85 request_data->save_info_->offset = parameters->offset();
86 request_data->save_info_->hash_state = parameters->hash_state();
87 request_data->save_info_->prompt_for_save_location = parameters->prompt();
88 request_data->download_id_ = download_id; 83 request_data->download_id_ = download_id;
89 request_data->on_started_callback_ = parameters->callback(); 84 request_data->on_started_callback_ = parameters->callback();
90 request->SetUserData(&kKey, request_data); 85 request->SetUserData(&kKey, request_data);
91 } 86 }
92 87
93 // static 88 // static
94 DownloadRequestData* DownloadRequestData::Get(net::URLRequest* request) { 89 DownloadRequestData* DownloadRequestData::Get(net::URLRequest* request) {
95 return static_cast<DownloadRequestData*>(request->GetUserData(&kKey)); 90 return static_cast<DownloadRequestData*>(request->GetUserData(&kKey));
96 } 91 }
97 92
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 DCHECK_NE(1, http_headers.response_code() / 100); 592 DCHECK_NE(1, http_headers.response_code() / 100);
598 return DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; 593 return DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED;
599 } 594 }
600 595
601 if (save_info && save_info->offset > 0) { 596 if (save_info && save_info->offset > 0) {
602 // The caller is expecting a partial response. 597 // The caller is expecting a partial response.
603 598
604 if (http_headers.response_code() != net::HTTP_PARTIAL_CONTENT) { 599 if (http_headers.response_code() != net::HTTP_PARTIAL_CONTENT) {
605 // Requested a partial range, but received the entire response. 600 // Requested a partial range, but received the entire response.
606 save_info->offset = 0; 601 save_info->offset = 0;
607 save_info->hash_state.clear(); 602 save_info->hash_of_partial_file.clear();
603 save_info->hash_state.reset();
608 return DOWNLOAD_INTERRUPT_REASON_NONE; 604 return DOWNLOAD_INTERRUPT_REASON_NONE;
609 } 605 }
610 606
611 int64_t first_byte = -1; 607 int64_t first_byte = -1;
612 int64_t last_byte = -1; 608 int64_t last_byte = -1;
613 int64_t length = -1; 609 int64_t length = -1;
614 if (!http_headers.GetContentRange(&first_byte, &last_byte, &length)) 610 if (!http_headers.GetContentRange(&first_byte, &last_byte, &length))
615 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; 611 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT;
616 DCHECK_GE(first_byte, 0); 612 DCHECK_GE(first_byte, 0);
617 613
(...skipping 10 matching lines...) Expand all
628 return DOWNLOAD_INTERRUPT_REASON_NONE; 624 return DOWNLOAD_INTERRUPT_REASON_NONE;
629 } 625 }
630 626
631 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) 627 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT)
632 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; 628 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT;
633 629
634 return DOWNLOAD_INTERRUPT_REASON_NONE; 630 return DOWNLOAD_INTERRUPT_REASON_NONE;
635 } 631 }
636 632
637 } // namespace content 633 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_net_log_parameters.cc ('k') | content/browser/download/mock_download_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698