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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: Make compilers happy. Created 3 years, 10 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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 22 matching lines...) Expand all
33 #include "base/logging.h" 33 #include "base/logging.h"
34 #include "base/metrics/histogram_macros.h" 34 #include "base/metrics/histogram_macros.h"
35 #include "base/stl_util.h" 35 #include "base/stl_util.h"
36 #include "base/strings/string_util.h" 36 #include "base/strings/string_util.h"
37 #include "base/strings/stringprintf.h" 37 #include "base/strings/stringprintf.h"
38 #include "base/strings/utf_string_conversions.h" 38 #include "base/strings/utf_string_conversions.h"
39 #include "content/browser/download/download_create_info.h" 39 #include "content/browser/download/download_create_info.h"
40 #include "content/browser/download/download_file.h" 40 #include "content/browser/download/download_file.h"
41 #include "content/browser/download/download_interrupt_reasons_impl.h" 41 #include "content/browser/download/download_interrupt_reasons_impl.h"
42 #include "content/browser/download/download_item_impl_delegate.h" 42 #include "content/browser/download/download_item_impl_delegate.h"
43 #include "content/browser/download/download_job_factory.h"
44 #include "content/browser/download/download_job_impl.h"
43 #include "content/browser/download/download_net_log_parameters.h" 45 #include "content/browser/download/download_net_log_parameters.h"
44 #include "content/browser/download/download_request_handle.h" 46 #include "content/browser/download/download_request_handle.h"
45 #include "content/browser/download/download_stats.h" 47 #include "content/browser/download/download_stats.h"
46 #include "content/browser/renderer_host/render_view_host_impl.h" 48 #include "content/browser/renderer_host/render_view_host_impl.h"
47 #include "content/browser/web_contents/web_contents_impl.h" 49 #include "content/browser/web_contents/web_contents_impl.h"
48 #include "content/public/browser/browser_context.h" 50 #include "content/public/browser/browser_context.h"
49 #include "content/public/browser/browser_thread.h" 51 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/content_browser_client.h" 52 #include "content/public/browser/content_browser_client.h"
51 #include "content/public/browser/download_danger_type.h" 53 #include "content/public/browser/download_danger_type.h"
52 #include "content/public/browser/download_interrupt_reasons.h" 54 #include "content/public/browser/download_interrupt_reasons.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // Constructing for the "Save Page As..." feature: 232 // Constructing for the "Save Page As..." feature:
231 DownloadItemImpl::DownloadItemImpl( 233 DownloadItemImpl::DownloadItemImpl(
232 DownloadItemImplDelegate* delegate, 234 DownloadItemImplDelegate* delegate,
233 uint32_t download_id, 235 uint32_t download_id,
234 const base::FilePath& path, 236 const base::FilePath& path,
235 const GURL& url, 237 const GURL& url,
236 const std::string& mime_type, 238 const std::string& mime_type,
237 std::unique_ptr<DownloadRequestHandleInterface> request_handle, 239 std::unique_ptr<DownloadRequestHandleInterface> request_handle,
238 const net::NetLogWithSource& net_log) 240 const net::NetLogWithSource& net_log)
239 : is_save_package_download_(true), 241 : is_save_package_download_(true),
240 request_handle_(std::move(request_handle)),
241 guid_(base::ToUpperASCII(base::GenerateGUID())), 242 guid_(base::ToUpperASCII(base::GenerateGUID())),
242 download_id_(download_id), 243 download_id_(download_id),
243 target_path_(path), 244 target_path_(path),
244 url_chain_(1, url), 245 url_chain_(1, url),
245 mime_type_(mime_type), 246 mime_type_(mime_type),
246 original_mime_type_(mime_type), 247 original_mime_type_(mime_type),
247 start_tick_(base::TimeTicks::Now()), 248 start_tick_(base::TimeTicks::Now()),
248 state_(IN_PROGRESS_INTERNAL), 249 state_(IN_PROGRESS_INTERNAL),
249 start_time_(base::Time::Now()), 250 start_time_(base::Time::Now()),
250 delegate_(delegate), 251 delegate_(delegate),
251 current_path_(path), 252 current_path_(path),
252 net_log_(net_log), 253 net_log_(net_log),
253 weak_ptr_factory_(this) { 254 weak_ptr_factory_(this) {
255 job_ = base::MakeUnique<DownloadJobImpl>(this, std::move(request_handle));
254 delegate_->Attach(); 256 delegate_->Attach();
255 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); 257 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS);
256 } 258 }
257 259
258 DownloadItemImpl::~DownloadItemImpl() { 260 DownloadItemImpl::~DownloadItemImpl() {
259 DCHECK_CURRENTLY_ON(BrowserThread::UI); 261 DCHECK_CURRENTLY_ON(BrowserThread::UI);
260 262
261 // Should always have been nuked before now, at worst in 263 // Should always have been nuked before now, at worst in
262 // DownloadManager shutdown. 264 // DownloadManager shutdown.
263 DCHECK(!download_file_.get()); 265 DCHECK(!download_file_.get());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback); 342 base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback);
341 } else { 343 } else {
342 callback.Run(current_path_); 344 callback.Run(current_path_);
343 } 345 }
344 } 346 }
345 347
346 void DownloadItemImpl::Pause() { 348 void DownloadItemImpl::Pause() {
347 DCHECK_CURRENTLY_ON(BrowserThread::UI); 349 DCHECK_CURRENTLY_ON(BrowserThread::UI);
348 350
349 // Ignore irrelevant states. 351 // Ignore irrelevant states.
350 if (is_paused_) 352 if (IsPaused())
351 return; 353 return;
352 354
353 switch (state_) { 355 switch (state_) {
354 case CANCELLED_INTERNAL: 356 case CANCELLED_INTERNAL:
355 case COMPLETE_INTERNAL: 357 case COMPLETE_INTERNAL:
356 case COMPLETING_INTERNAL: 358 case COMPLETING_INTERNAL:
357 case INITIAL_INTERNAL: 359 case INITIAL_INTERNAL:
358 case INTERRUPTED_INTERNAL: 360 case INTERRUPTED_INTERNAL:
359 case INTERRUPTED_TARGET_PENDING_INTERNAL: 361 case INTERRUPTED_TARGET_PENDING_INTERNAL:
360 case RESUMING_INTERNAL: 362 case RESUMING_INTERNAL:
361 // No active request. 363 // No active request.
362 // TODO(asanka): In the case of RESUMING_INTERNAL, consider setting 364 // TODO(asanka): In the case of RESUMING_INTERNAL, consider setting
363 // is_paused_ even if there's no request currently associated with this 365 // |DownloadJob::is_paused_| even if there's no request currently
364 // DII. When a request is assigned (due to a resumption, for example) we 366 // associated with this DII. When a request is assigned (due to a
365 // can honor the is_paused_ setting. 367 // resumption, for example) we can honor the |DownloadJob::is_paused_|
368 // setting.
366 return; 369 return;
367 370
368 case IN_PROGRESS_INTERNAL: 371 case IN_PROGRESS_INTERNAL:
369 case TARGET_PENDING_INTERNAL: 372 case TARGET_PENDING_INTERNAL:
370 request_handle_->PauseRequest(); 373 job_->Pause();
371 is_paused_ = true;
372 UpdateObservers(); 374 UpdateObservers();
373 return; 375 return;
374 376
375 case MAX_DOWNLOAD_INTERNAL_STATE: 377 case MAX_DOWNLOAD_INTERNAL_STATE:
376 case TARGET_RESOLVED_INTERNAL: 378 case TARGET_RESOLVED_INTERNAL:
377 NOTREACHED(); 379 NOTREACHED();
378 } 380 }
379 } 381 }
380 382
381 void DownloadItemImpl::Resume() { 383 void DownloadItemImpl::Resume() {
382 DCHECK_CURRENTLY_ON(BrowserThread::UI); 384 DCHECK_CURRENTLY_ON(BrowserThread::UI);
383 DVLOG(20) << __func__ << "() download = " << DebugString(true); 385 DVLOG(20) << __func__ << "() download = " << DebugString(true);
384 switch (state_) { 386 switch (state_) {
385 case CANCELLED_INTERNAL: // Nothing to resume. 387 case CANCELLED_INTERNAL: // Nothing to resume.
386 case COMPLETE_INTERNAL: 388 case COMPLETE_INTERNAL:
387 case COMPLETING_INTERNAL: 389 case COMPLETING_INTERNAL:
388 case INITIAL_INTERNAL: 390 case INITIAL_INTERNAL:
389 case INTERRUPTED_TARGET_PENDING_INTERNAL: 391 case INTERRUPTED_TARGET_PENDING_INTERNAL:
390 case RESUMING_INTERNAL: // Resumption in progress. 392 case RESUMING_INTERNAL: // Resumption in progress.
391 return; 393 return;
392 394
393 case TARGET_PENDING_INTERNAL: 395 case TARGET_PENDING_INTERNAL:
394 case IN_PROGRESS_INTERNAL: 396 case IN_PROGRESS_INTERNAL:
395 if (!is_paused_) 397 if (!IsPaused())
396 return; 398 return;
397 request_handle_->ResumeRequest(); 399 if (job_)
398 is_paused_ = false; 400 job_->Resume();
399 UpdateObservers(); 401 UpdateObservers();
400 return; 402 return;
401 403
402 case INTERRUPTED_INTERNAL: 404 case INTERRUPTED_INTERNAL:
403 auto_resume_count_ = 0; // User input resets the counter. 405 auto_resume_count_ = 0; // User input resets the counter.
404 ResumeInterruptedDownload(ResumptionRequestSource::USER); 406 ResumeInterruptedDownload(ResumptionRequestSource::USER);
405 UpdateObservers(); 407 UpdateObservers();
406 return; 408 return;
407 409
408 case MAX_DOWNLOAD_INTERNAL_STATE: 410 case MAX_DOWNLOAD_INTERNAL_STATE:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 478
477 DownloadItem::DownloadState DownloadItemImpl::GetState() const { 479 DownloadItem::DownloadState DownloadItemImpl::GetState() const {
478 return InternalToExternalState(state_); 480 return InternalToExternalState(state_);
479 } 481 }
480 482
481 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { 483 DownloadInterruptReason DownloadItemImpl::GetLastReason() const {
482 return last_reason_; 484 return last_reason_;
483 } 485 }
484 486
485 bool DownloadItemImpl::IsPaused() const { 487 bool DownloadItemImpl::IsPaused() const {
486 return is_paused_; 488 return job_ ? job_->is_paused() : false;
487 } 489 }
488 490
489 bool DownloadItemImpl::IsTemporary() const { 491 bool DownloadItemImpl::IsTemporary() const {
490 return is_temporary_; 492 return is_temporary_;
491 } 493 }
492 494
493 bool DownloadItemImpl::CanResume() const { 495 bool DownloadItemImpl::CanResume() const {
494 DCHECK_CURRENTLY_ON(BrowserThread::UI); 496 DCHECK_CURRENTLY_ON(BrowserThread::UI);
495 switch (state_) { 497 switch (state_) {
496 case INITIAL_INTERNAL: 498 case INITIAL_INTERNAL:
497 case COMPLETING_INTERNAL: 499 case COMPLETING_INTERNAL:
498 case COMPLETE_INTERNAL: 500 case COMPLETE_INTERNAL:
499 case CANCELLED_INTERNAL: 501 case CANCELLED_INTERNAL:
500 case RESUMING_INTERNAL: 502 case RESUMING_INTERNAL:
501 case INTERRUPTED_TARGET_PENDING_INTERNAL: 503 case INTERRUPTED_TARGET_PENDING_INTERNAL:
502 return false; 504 return false;
503 505
504 case TARGET_PENDING_INTERNAL: 506 case TARGET_PENDING_INTERNAL:
505 case TARGET_RESOLVED_INTERNAL: 507 case TARGET_RESOLVED_INTERNAL:
506 case IN_PROGRESS_INTERNAL: 508 case IN_PROGRESS_INTERNAL:
507 return is_paused_; 509 return IsPaused();
508 510
509 case INTERRUPTED_INTERNAL: { 511 case INTERRUPTED_INTERNAL: {
510 ResumeMode resume_mode = GetResumeMode(); 512 ResumeMode resume_mode = GetResumeMode();
511 // Only allow Resume() calls if the resumption mode requires a user 513 // Only allow Resume() calls if the resumption mode requires a user
512 // action. 514 // action.
513 return resume_mode == RESUME_MODE_USER_RESTART || 515 return resume_mode == RESUME_MODE_USER_RESTART ||
514 resume_mode == RESUME_MODE_USER_CONTINUE; 516 resume_mode == RESUME_MODE_USER_CONTINUE;
515 } 517 }
516 518
517 case MAX_DOWNLOAD_INTERNAL_STATE: 519 case MAX_DOWNLOAD_INTERNAL_STATE:
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 int64_t speed = CurrentSpeed(); 693 int64_t speed = CurrentSpeed();
692 if (speed == 0) 694 if (speed == 0)
693 return false; 695 return false;
694 696
695 *remaining = base::TimeDelta::FromSeconds( 697 *remaining = base::TimeDelta::FromSeconds(
696 (total_bytes_ - received_bytes_) / speed); 698 (total_bytes_ - received_bytes_) / speed);
697 return true; 699 return true;
698 } 700 }
699 701
700 int64_t DownloadItemImpl::CurrentSpeed() const { 702 int64_t DownloadItemImpl::CurrentSpeed() const {
701 if (is_paused_) 703 if (IsPaused())
702 return 0; 704 return 0;
703 return bytes_per_sec_; 705 return bytes_per_sec_;
704 } 706 }
705 707
706 int DownloadItemImpl::PercentComplete() const { 708 int DownloadItemImpl::PercentComplete() const {
707 // If the delegate is delaying completion of the download, then we have no 709 // If the delegate is delaying completion of the download, then we have no
708 // idea how long it will take. 710 // idea how long it will take.
709 if (delegate_delayed_complete_ || total_bytes_ <= 0) 711 if (delegate_delayed_complete_ || total_bytes_ <= 0)
710 return -1; 712 return -1;
711 713
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 767
766 BrowserContext* DownloadItemImpl::GetBrowserContext() const { 768 BrowserContext* DownloadItemImpl::GetBrowserContext() const {
767 return delegate_->GetBrowserContext(); 769 return delegate_->GetBrowserContext();
768 } 770 }
769 771
770 WebContents* DownloadItemImpl::GetWebContents() const { 772 WebContents* DownloadItemImpl::GetWebContents() const {
771 // TODO(rdsmith): Remove null check after removing GetWebContents() from 773 // TODO(rdsmith): Remove null check after removing GetWebContents() from
772 // paths that might be used by DownloadItems created from history import. 774 // paths that might be used by DownloadItems created from history import.
773 // Currently such items have null request_handle_s, where other items 775 // Currently such items have null request_handle_s, where other items
774 // (regular and SavePackage downloads) have actual objects off the pointer. 776 // (regular and SavePackage downloads) have actual objects off the pointer.
775 if (request_handle_) 777 if (job_)
776 return request_handle_->GetWebContents(); 778 return job_->GetWebContents();
777 return NULL; 779 return nullptr;
778 } 780 }
779 781
780 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { 782 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) {
781 DCHECK_CURRENTLY_ON(BrowserThread::UI); 783 DCHECK_CURRENTLY_ON(BrowserThread::UI);
782 DCHECK(AllDataSaved()); 784 DCHECK(AllDataSaved());
783 785
784 // Danger type is only allowed to be set on an active download after all data 786 // Danger type is only allowed to be set on an active download after all data
785 // has been saved. This excludes all other states. In particular, 787 // has been saved. This excludes all other states. In particular,
786 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since 788 // OnContentCheckCompleted() isn't allowed on an INTERRUPTED download since
787 // such an interruption would need to happen between OnAllDataSaved() and 789 // such an interruption would need to happen between OnAllDataSaved() and
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 874
873 // We can't continue without a handle on the intermediate file. 875 // We can't continue without a handle on the intermediate file.
874 // We also can't continue if we don't have some verifier to make sure 876 // We also can't continue if we don't have some verifier to make sure
875 // we're getting the same file. 877 // we're getting the same file.
876 bool restart_required = 878 bool restart_required =
877 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); 879 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty()));
878 880
879 // We won't auto-restart if we've used up our attempts or the 881 // We won't auto-restart if we've used up our attempts or the
880 // download has been paused by user action. 882 // download has been paused by user action.
881 bool user_action_required = 883 bool user_action_required =
882 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); 884 (auto_resume_count_ >= kMaxAutoResumeAttempts || IsPaused());
883 885
884 switch(last_reason_) { 886 switch(last_reason_) {
885 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: 887 case DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR:
886 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: 888 case DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT:
887 break; 889 break;
888 890
889 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE: 891 case DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE:
890 // The server disagreed with the file offset that we sent. 892 // The server disagreed with the file offset that we sent.
891 893
892 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH: 894 case DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH:
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 // We're starting the download. 1167 // We're starting the download.
1166 void DownloadItemImpl::Start( 1168 void DownloadItemImpl::Start(
1167 std::unique_ptr<DownloadFile> file, 1169 std::unique_ptr<DownloadFile> file,
1168 std::unique_ptr<DownloadRequestHandleInterface> req_handle, 1170 std::unique_ptr<DownloadRequestHandleInterface> req_handle,
1169 const DownloadCreateInfo& new_create_info) { 1171 const DownloadCreateInfo& new_create_info) {
1170 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1172 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1171 DCHECK(!download_file_.get()); 1173 DCHECK(!download_file_.get());
1172 DVLOG(20) << __func__ << "() this=" << DebugString(true); 1174 DVLOG(20) << __func__ << "() this=" << DebugString(true);
1173 1175
1174 download_file_ = std::move(file); 1176 download_file_ = std::move(file);
1175 request_handle_ = std::move(req_handle); 1177 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle),
1178 new_create_info);
1176 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; 1179 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
1177 1180
1178 if (state_ == CANCELLED_INTERNAL) { 1181 if (state_ == CANCELLED_INTERNAL) {
1179 // The download was in the process of resuming when it was cancelled. Don't 1182 // The download was in the process of resuming when it was cancelled. Don't
1180 // proceed. 1183 // proceed.
1181 ReleaseDownloadFile(true); 1184 ReleaseDownloadFile(true);
1182 if (request_handle_) 1185 job_->Cancel(true);
1183 request_handle_->CancelRequest();
1184 return; 1186 return;
1185 } 1187 }
1186 1188
1187 // The state could be one of the following: 1189 // The state could be one of the following:
1188 // 1190 //
1189 // INITIAL_INTERNAL: A normal download attempt. 1191 // INITIAL_INTERNAL: A normal download attempt.
1190 // 1192 //
1191 // RESUMING_INTERNAL: A resumption attempt. May or may not have been 1193 // RESUMING_INTERNAL: A resumption attempt. May or may not have been
1192 // successful. 1194 // successful.
1193 DCHECK(state_ == INITIAL_INTERNAL || state_ == RESUMING_INTERNAL); 1195 DCHECK(state_ == INITIAL_INTERNAL || state_ == RESUMING_INTERNAL);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 // interruption. Continue with current target path. 1227 // interruption. Continue with current target path.
1226 TransitionTo(TARGET_RESOLVED_INTERNAL); 1228 TransitionTo(TARGET_RESOLVED_INTERNAL);
1227 InterruptWithPartialState( 1229 InterruptWithPartialState(
1228 offset, std::move(hash_state), new_create_info.result); 1230 offset, std::move(hash_state), new_create_info.result);
1229 UpdateObservers(); 1231 UpdateObservers();
1230 return; 1232 return;
1231 } 1233 }
1232 1234
1233 // Successful download start. 1235 // Successful download start.
1234 DCHECK(download_file_.get()); 1236 DCHECK(download_file_.get());
1235 DCHECK(request_handle_.get()); 1237 DCHECK(job_.get());
qinmin 2017/02/23 07:26:56 nit: DCHECK(job_);
xingliu 2017/02/24 23:43:13 Done.
1236 1238
1237 if (state_ == RESUMING_INTERNAL) 1239 if (state_ == RESUMING_INTERNAL)
1238 UpdateValidatorsOnResumption(new_create_info); 1240 UpdateValidatorsOnResumption(new_create_info);
1239 1241
1240 TransitionTo(TARGET_PENDING_INTERNAL); 1242 TransitionTo(TARGET_PENDING_INTERNAL);
1241 1243
1244 job_->Start();
1245 }
1246
1247 void DownloadItemImpl::StartDownloadProgress() {
1242 BrowserThread::PostTask( 1248 BrowserThread::PostTask(
1243 BrowserThread::FILE, FROM_HERE, 1249 BrowserThread::FILE, FROM_HERE,
1244 base::Bind(&DownloadFile::Initialize, 1250 base::Bind(&DownloadFile::Initialize,
1245 // Safe because we control download file lifetime. 1251 // Safe because we control download file lifetime.
1246 base::Unretained(download_file_.get()), 1252 base::Unretained(download_file_.get()),
1247 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, 1253 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized,
1248 weak_ptr_factory_.GetWeakPtr()))); 1254 weak_ptr_factory_.GetWeakPtr())));
1249 } 1255 }
1250 1256
1251 void DownloadItemImpl::OnDownloadFileInitialized( 1257 void DownloadItemImpl::OnDownloadFileInitialized(
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 1634
1629 if (current_path_.empty()) { 1635 if (current_path_.empty()) {
1630 hash_state_.reset(); 1636 hash_state_.reset();
1631 hash_.clear(); 1637 hash_.clear();
1632 received_bytes_ = 0; 1638 received_bytes_ = 0;
1633 } else { 1639 } else {
1634 UpdateProgress(bytes_so_far, 0); 1640 UpdateProgress(bytes_so_far, 0);
1635 SetHashState(std::move(hash_state)); 1641 SetHashState(std::move(hash_state));
1636 } 1642 }
1637 1643
1638 if (request_handle_) 1644 if (job_.get())
qinmin 2017/02/23 07:26:57 nit: if (job_)
xingliu 2017/02/24 23:43:13 Done.
1639 request_handle_->CancelRequest(); 1645 job_->Cancel(false);
1640 1646
1641 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || 1647 if (reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED ||
1642 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { 1648 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) {
1643 if (IsDangerous()) { 1649 if (IsDangerous()) {
1644 RecordDangerousDownloadDiscard( 1650 RecordDangerousDownloadDiscard(
1645 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED 1651 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
1646 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION 1652 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION
1647 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, 1653 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN,
1648 GetDangerType(), GetTargetFilePath()); 1654 GetDangerType(), GetTargetFilePath());
1649 } 1655 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 case TARGET_RESOLVED_INTERNAL: 1775 case TARGET_RESOLVED_INTERNAL:
1770 case INTERRUPTED_TARGET_PENDING_INTERNAL: 1776 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1771 break; 1777 break;
1772 1778
1773 case IN_PROGRESS_INTERNAL: 1779 case IN_PROGRESS_INTERNAL:
1774 DCHECK(!current_path_.empty()) << "Current output path must be known."; 1780 DCHECK(!current_path_.empty()) << "Current output path must be known.";
1775 DCHECK(!target_path_.empty()) << "Target path must be known."; 1781 DCHECK(!target_path_.empty()) << "Target path must be known.";
1776 DCHECK(current_path_.DirName() == target_path_.DirName()) 1782 DCHECK(current_path_.DirName() == target_path_.DirName())
1777 << "Current output directory must match target directory."; 1783 << "Current output directory must match target directory.";
1778 DCHECK(download_file_) << "Output file must be owned by download item."; 1784 DCHECK(download_file_) << "Output file must be owned by download item.";
1779 DCHECK(request_handle_) << "Download source must be active."; 1785 DCHECK(job_) << "Must have active download job.";
1780 DCHECK(!is_paused_) << "At the time a download enters IN_PROGRESS state, " 1786 DCHECK(!job_->is_paused())
1781 "it must not be paused."; 1787 << "At the time a download enters IN_PROGRESS state, "
1788 "it must not be paused.";
1782 break; 1789 break;
1783 1790
1784 case COMPLETING_INTERNAL: 1791 case COMPLETING_INTERNAL:
1785 DCHECK(all_data_saved_) << "All data must be saved prior to completion."; 1792 DCHECK(all_data_saved_) << "All data must be saved prior to completion.";
1786 DCHECK(!download_file_) 1793 DCHECK(!download_file_)
1787 << "Download file must be released prior to completion."; 1794 << "Download file must be released prior to completion.";
1788 DCHECK(!target_path_.empty()) << "Target path must be known."; 1795 DCHECK(!target_path_.empty()) << "Target path must be known.";
1789 DCHECK(current_path_ == target_path_) 1796 DCHECK(current_path_ == target_path_)
1790 << "Current output path must match target path."; 1797 << "Current output path must match target path.";
1791 1798
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 // (which is the contents of the Referer header for the last download request) 1946 // (which is the contents of the Referer header for the last download request)
1940 // will only be sent to the URL returned by GetURL(). 1947 // will only be sent to the URL returned by GetURL().
1941 download_params->set_referrer( 1948 download_params->set_referrer(
1942 Referrer(GetReferrerUrl(), blink::WebReferrerPolicyAlways)); 1949 Referrer(GetReferrerUrl(), blink::WebReferrerPolicyAlways));
1943 1950
1944 TransitionTo(RESUMING_INTERNAL); 1951 TransitionTo(RESUMING_INTERNAL);
1945 RecordDownloadSource(source == ResumptionRequestSource::USER 1952 RecordDownloadSource(source == ResumptionRequestSource::USER
1946 ? INITIATED_BY_MANUAL_RESUMPTION 1953 ? INITIATED_BY_MANUAL_RESUMPTION
1947 : INITIATED_BY_AUTOMATIC_RESUMPTION); 1954 : INITIATED_BY_AUTOMATIC_RESUMPTION);
1948 delegate_->ResumeInterruptedDownload(std::move(download_params), GetId()); 1955 delegate_->ResumeInterruptedDownload(std::move(download_params), GetId());
1949 // Just in case we were interrupted while paused. 1956 // Just in case we were interrupted while paused. |job_| may be null
1950 is_paused_ = false; 1957 // when no WebContents is associated with a download resumption.
1958 if (job_)
1959 job_->set_is_paused(false);
qinmin 2017/02/23 07:26:57 shouldn't this be calling job_->Resume()?
xingliu 2017/02/24 23:43:13 Done, not sure if this is totally correct. job_ m
xingliu 2017/02/25 00:12:13 Maybe we should just remove this call, since the p
qinmin 2017/02/27 17:15:46 I would rather change the DownloadJob::Resume() ca
xingliu 2017/02/27 20:44:52 Done, now job_->Resume(false) will set is_paused t
1951 } 1960 }
1952 1961
1953 // static 1962 // static
1954 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( 1963 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState(
1955 DownloadInternalState internal_state) { 1964 DownloadInternalState internal_state) {
1956 switch (internal_state) { 1965 switch (internal_state) {
1957 case INITIAL_INTERNAL: 1966 case INITIAL_INTERNAL:
1958 case TARGET_PENDING_INTERNAL: 1967 case TARGET_PENDING_INTERNAL:
1959 case TARGET_RESOLVED_INTERNAL: 1968 case TARGET_RESOLVED_INTERNAL:
1960 case INTERRUPTED_TARGET_PENDING_INTERNAL: 1969 case INTERRUPTED_TARGET_PENDING_INTERNAL:
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 case RESUME_MODE_USER_CONTINUE: 2129 case RESUME_MODE_USER_CONTINUE:
2121 return "USER_CONTINUE"; 2130 return "USER_CONTINUE";
2122 case RESUME_MODE_USER_RESTART: 2131 case RESUME_MODE_USER_RESTART:
2123 return "USER_RESTART"; 2132 return "USER_RESTART";
2124 } 2133 }
2125 NOTREACHED() << "Unknown resume mode " << mode; 2134 NOTREACHED() << "Unknown resume mode " << mode;
2126 return "unknown"; 2135 return "unknown";
2127 } 2136 }
2128 2137
2129 } // namespace content 2138 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698