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

Side by Side Diff: content/browser/download/download_manager_impl.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: Try to appease MSVC 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_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const std::vector<GURL>& url_chain, 112 const std::vector<GURL>& url_chain,
113 const GURL& referrer_url, 113 const GURL& referrer_url,
114 const std::string& mime_type, 114 const std::string& mime_type,
115 const std::string& original_mime_type, 115 const std::string& original_mime_type,
116 const base::Time& start_time, 116 const base::Time& start_time,
117 const base::Time& end_time, 117 const base::Time& end_time,
118 const std::string& etag, 118 const std::string& etag,
119 const std::string& last_modified, 119 const std::string& last_modified,
120 int64_t received_bytes, 120 int64_t received_bytes,
121 int64_t total_bytes, 121 int64_t total_bytes,
122 const std::string& hash,
122 DownloadItem::DownloadState state, 123 DownloadItem::DownloadState state,
123 DownloadDangerType danger_type, 124 DownloadDangerType danger_type,
124 DownloadInterruptReason interrupt_reason, 125 DownloadInterruptReason interrupt_reason,
125 bool opened, 126 bool opened,
126 const net::BoundNetLog& bound_net_log) override { 127 const net::BoundNetLog& bound_net_log) override {
127 return new DownloadItemImpl( 128 return new DownloadItemImpl(
128 delegate, 129 delegate, download_id, current_path, target_path, url_chain,
svaldez 2016/03/09 19:27:34 Possibly revert to make it easier to read.
asanka 2016/03/10 16:48:08 Hmm. Perhaps we should revisit the BinPackArgument
129 download_id, 130 referrer_url, mime_type, original_mime_type, start_time, end_time, etag,
130 current_path, 131 last_modified, received_bytes, total_bytes, hash, state, danger_type,
131 target_path, 132 interrupt_reason, opened, bound_net_log);
132 url_chain,
133 referrer_url,
134 mime_type,
135 original_mime_type,
136 start_time,
137 end_time,
138 etag,
139 last_modified,
140 received_bytes,
141 total_bytes,
142 state,
143 danger_type,
144 interrupt_reason,
145 opened,
146 bound_net_log);
147 } 133 }
148 134
149 DownloadItemImpl* CreateActiveItem( 135 DownloadItemImpl* CreateActiveItem(
150 DownloadItemImplDelegate* delegate, 136 DownloadItemImplDelegate* delegate,
151 uint32_t download_id, 137 uint32_t download_id,
152 const DownloadCreateInfo& info, 138 const DownloadCreateInfo& info,
153 const net::BoundNetLog& bound_net_log) override { 139 const net::BoundNetLog& bound_net_log) override {
154 return new DownloadItemImpl(delegate, download_id, info, bound_net_log); 140 return new DownloadItemImpl(delegate, download_id, info, bound_net_log);
155 } 141 }
156 142
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 bool skip_dir_check = false; // Unused 341 bool skip_dir_check = false; // Unused
356 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, 342 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory,
357 &default_download_directory, &skip_dir_check); 343 &default_download_directory, &skip_dir_check);
358 } 344 }
359 345
360 scoped_ptr<DownloadFile> download_file; 346 scoped_ptr<DownloadFile> download_file;
361 347
362 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) { 348 if (info->result == DOWNLOAD_INTERRUPT_REASON_NONE) {
363 DCHECK(stream.get()); 349 DCHECK(stream.get());
364 download_file.reset(file_factory_->CreateFile( 350 download_file.reset(file_factory_->CreateFile(
365 *info->save_info, default_download_directory, info->url(), 351 std::move(info->save_info), default_download_directory,
366 info->referrer_url, delegate_ && delegate_->GenerateFileHash(), 352 std::move(stream), download->GetBoundNetLog(),
367 std::move(info->save_info->file), std::move(stream), 353 download->DestinationObserverAsWeakPtr()));
368 download->GetBoundNetLog(), download->DestinationObserverAsWeakPtr()));
369
370 if (download_file.get() && delegate_) {
371 download_file->SetClientGuid(
372 delegate_->ApplicationClientIdForFileScanning());
373 }
374 } 354 }
355 // It is important to leave info->save_info intact in the case of an interrupt
356 // so that the DownloadItem can salvage what it can out of a failed resumption
357 // attempt.
375 358
376 download->Start(std::move(download_file), std::move(info->request_handle), 359 download->Start(std::move(download_file), std::move(info->request_handle),
377 *info); 360 *info);
378 361
379 // For interrupted downloads, Start() will transition the state to 362 // For interrupted downloads, Start() will transition the state to
380 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated(). 363 // IN_PROGRESS and consumers will be notified via OnDownloadUpdated().
381 // For new downloads, we notify here, rather than earlier, so that 364 // For new downloads, we notify here, rather than earlier, so that
382 // the download_file is bound to download and all the usual 365 // the download_file is bound to download and all the usual
383 // setters (e.g. Cancel) work. 366 // setters (e.g. Cancel) work.
384 if (new_download) 367 if (new_download)
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 const std::vector<GURL>& url_chain, 585 const std::vector<GURL>& url_chain,
603 const GURL& referrer_url, 586 const GURL& referrer_url,
604 const std::string& mime_type, 587 const std::string& mime_type,
605 const std::string& original_mime_type, 588 const std::string& original_mime_type,
606 const base::Time& start_time, 589 const base::Time& start_time,
607 const base::Time& end_time, 590 const base::Time& end_time,
608 const std::string& etag, 591 const std::string& etag,
609 const std::string& last_modified, 592 const std::string& last_modified,
610 int64_t received_bytes, 593 int64_t received_bytes,
611 int64_t total_bytes, 594 int64_t total_bytes,
595 const std::string& hash,
612 DownloadItem::DownloadState state, 596 DownloadItem::DownloadState state,
613 DownloadDangerType danger_type, 597 DownloadDangerType danger_type,
614 DownloadInterruptReason interrupt_reason, 598 DownloadInterruptReason interrupt_reason,
615 bool opened) { 599 bool opened) {
616 if (ContainsKey(downloads_, id)) { 600 if (ContainsKey(downloads_, id)) {
617 NOTREACHED(); 601 NOTREACHED();
618 return NULL; 602 return NULL;
619 } 603 }
620 DownloadItemImpl* item = item_factory_->CreatePersistedItem( 604 DownloadItemImpl* item = item_factory_->CreatePersistedItem(
621 this, 605 this, id, current_path, target_path, url_chain, referrer_url, mime_type,
622 id, 606 original_mime_type, start_time, end_time, etag, last_modified,
623 current_path, 607 received_bytes, total_bytes, hash, state, danger_type, interrupt_reason,
624 target_path, 608 opened, net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD));
625 url_chain,
626 referrer_url,
627 mime_type,
628 original_mime_type,
629 start_time,
630 end_time,
631 etag,
632 last_modified,
633 received_bytes,
634 total_bytes,
635 state,
636 danger_type,
637 interrupt_reason,
638 opened,
639 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD));
640 downloads_[id] = item; 609 downloads_[id] = item;
641 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); 610 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item));
642 DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); 611 DVLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true);
643 return item; 612 return item;
644 } 613 }
645 614
646 int DownloadManagerImpl::InProgressCount() const { 615 int DownloadManagerImpl::InProgressCount() const {
647 int count = 0; 616 int count = 0;
648 for (const auto& it : downloads_) { 617 for (const auto& it : downloads_) {
649 if (it.second->GetState() == DownloadItem::IN_PROGRESS) 618 if (it.second->GetState() == DownloadItem::IN_PROGRESS)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (delegate_) 659 if (delegate_)
691 delegate_->OpenDownload(download); 660 delegate_->OpenDownload(download);
692 } 661 }
693 662
694 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 663 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
695 if (delegate_) 664 if (delegate_)
696 delegate_->ShowDownloadInShell(download); 665 delegate_->ShowDownloadInShell(download);
697 } 666 }
698 667
699 } // namespace content 668 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698