OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/update_client/background_downloader_win.h" | 5 #include "components/update_client/background_downloader_win.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 DCHECK(thread_checker_.CalledOnValidThread()); | 453 DCHECK(thread_checker_.CalledOnValidThread()); |
454 task_runner()->PostTask(FROM_HERE, | 454 task_runner()->PostTask(FROM_HERE, |
455 base::Bind(&BackgroundDownloader::BeginDownload, | 455 base::Bind(&BackgroundDownloader::BeginDownload, |
456 base::Unretained(this), url)); | 456 base::Unretained(this), url)); |
457 } | 457 } |
458 | 458 |
459 // Called one time when this class is asked to do a download. | 459 // Called one time when this class is asked to do a download. |
460 void BackgroundDownloader::BeginDownload(const GURL& url) { | 460 void BackgroundDownloader::BeginDownload(const GURL& url) { |
461 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 461 DCHECK(task_runner()->RunsTasksOnCurrentThread()); |
462 | 462 |
463 download_start_time_ = base::Time::Now(); | 463 download_start_time_ = base::TimeTicks::Now(); |
464 job_stuck_begin_time_ = download_start_time_; | 464 job_stuck_begin_time_ = download_start_time_; |
465 | 465 |
466 HRESULT hr = BeginDownloadHelper(url); | 466 HRESULT hr = BeginDownloadHelper(url); |
467 if (FAILED(hr)) { | 467 if (FAILED(hr)) { |
468 EndDownload(hr); | 468 EndDownload(hr); |
469 return; | 469 return; |
470 } | 470 } |
471 | 471 |
472 ResetInterfacePointers(); | 472 ResetInterfacePointers(); |
473 main_task_runner()->PostTask( | 473 main_task_runner()->PostTask( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 base::Bind(&BackgroundDownloader::StartTimer, base::Unretained(this))); | 566 base::Bind(&BackgroundDownloader::StartTimer, base::Unretained(this))); |
567 } | 567 } |
568 | 568 |
569 // Completes the BITS download, picks up the file path of the response, and | 569 // Completes the BITS download, picks up the file path of the response, and |
570 // notifies the CrxDownloader. The function should be called only once. | 570 // notifies the CrxDownloader. The function should be called only once. |
571 void BackgroundDownloader::EndDownload(HRESULT error) { | 571 void BackgroundDownloader::EndDownload(HRESULT error) { |
572 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 572 DCHECK(task_runner()->RunsTasksOnCurrentThread()); |
573 | 573 |
574 DCHECK(!TimerIsRunning()); | 574 DCHECK(!TimerIsRunning()); |
575 | 575 |
576 const base::Time download_end_time(base::Time::Now()); | 576 const base::TimeTicks download_end_time(base::TimeTicks::Now()); |
577 const base::TimeDelta download_time = | 577 const base::TimeDelta download_time = |
578 download_end_time >= download_start_time_ | 578 download_end_time >= download_start_time_ |
579 ? download_end_time - download_start_time_ | 579 ? download_end_time - download_start_time_ |
580 : base::TimeDelta(); | 580 : base::TimeDelta(); |
581 | 581 |
582 int64_t downloaded_bytes = -1; | 582 int64_t downloaded_bytes = -1; |
583 int64_t total_bytes = -1; | 583 int64_t total_bytes = -1; |
584 GetJobByteCount(job_.get(), &downloaded_bytes, &total_bytes); | 584 GetJobByteCount(job_.get(), &downloaded_bytes, &total_bytes); |
585 | 585 |
586 if (FAILED(error) && job_.get()) { | 586 if (FAILED(error) && job_.get()) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return false; | 684 return false; |
685 | 685 |
686 // Terminate the download if the job has not made progress in a while. | 686 // Terminate the download if the job has not made progress in a while. |
687 EndDownload(E_ABORT); | 687 EndDownload(E_ABORT); |
688 return true; | 688 return true; |
689 } | 689 } |
690 | 690 |
691 bool BackgroundDownloader::OnStateTransferring() { | 691 bool BackgroundDownloader::OnStateTransferring() { |
692 // Resets the baseline for detecting a stuck job since the job is transferring | 692 // Resets the baseline for detecting a stuck job since the job is transferring |
693 // data and it is making progress. | 693 // data and it is making progress. |
694 job_stuck_begin_time_ = base::Time::Now(); | 694 job_stuck_begin_time_ = base::TimeTicks::Now(); |
695 | 695 |
696 int64_t downloaded_bytes = -1; | 696 int64_t downloaded_bytes = -1; |
697 int64_t total_bytes = -1; | 697 int64_t total_bytes = -1; |
698 HRESULT hr = GetJobByteCount(job_.get(), &downloaded_bytes, &total_bytes); | 698 HRESULT hr = GetJobByteCount(job_.get(), &downloaded_bytes, &total_bytes); |
699 if (FAILED(hr)) | 699 if (FAILED(hr)) |
700 return false; | 700 return false; |
701 | 701 |
702 Result result; | 702 Result result; |
703 result.downloaded_bytes = downloaded_bytes; | 703 result.downloaded_bytes = downloaded_bytes; |
704 result.total_bytes = total_bytes; | 704 result.total_bytes = total_bytes; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 hr = job->SetNoProgressTimeout(kSecondsDay * kSetNoProgressTimeoutDays); | 793 hr = job->SetNoProgressTimeout(kSecondsDay * kSetNoProgressTimeoutDays); |
794 if (FAILED(hr)) | 794 if (FAILED(hr)) |
795 return hr; | 795 return hr; |
796 | 796 |
797 return S_OK; | 797 return S_OK; |
798 } | 798 } |
799 | 799 |
800 bool BackgroundDownloader::IsStuck() { | 800 bool BackgroundDownloader::IsStuck() { |
801 const base::TimeDelta job_stuck_timeout( | 801 const base::TimeDelta job_stuck_timeout( |
802 base::TimeDelta::FromMinutes(kJobStuckTimeoutMin)); | 802 base::TimeDelta::FromMinutes(kJobStuckTimeoutMin)); |
803 return job_stuck_begin_time_ + job_stuck_timeout < base::Time::Now(); | 803 return job_stuck_begin_time_ + job_stuck_timeout < base::TimeTicks::Now(); |
804 } | 804 } |
805 | 805 |
806 HRESULT BackgroundDownloader::CompleteJob() { | 806 HRESULT BackgroundDownloader::CompleteJob() { |
807 HRESULT hr = job_->Complete(); | 807 HRESULT hr = job_->Complete(); |
808 if (FAILED(hr) && hr != BG_S_UNABLE_TO_DELETE_FILES) | 808 if (FAILED(hr) && hr != BG_S_UNABLE_TO_DELETE_FILES) |
809 return hr; | 809 return hr; |
810 | 810 |
811 std::vector<ScopedComPtr<IBackgroundCopyFile>> files; | 811 std::vector<ScopedComPtr<IBackgroundCopyFile>> files; |
812 hr = GetFilesInJob(job_.get(), &files); | 812 hr = GetFilesInJob(job_.get(), &files); |
813 if (FAILED(hr)) | 813 if (FAILED(hr)) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 875 |
876 for (auto cookie : cookies) { | 876 for (auto cookie : cookies) { |
877 // TODO(sorin): check the result of the call, see crbug.com/644857. | 877 // TODO(sorin): check the result of the call, see crbug.com/644857. |
878 git->RevokeInterfaceFromGlobal(cookie); | 878 git->RevokeInterfaceFromGlobal(cookie); |
879 } | 879 } |
880 | 880 |
881 return S_OK; | 881 return S_OK; |
882 } | 882 } |
883 | 883 |
884 } // namespace update_client | 884 } // namespace update_client |
OLD | NEW |