| 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 <objbase.h> | 9 #include <objbase.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 void BackgroundDownloader::DoStartDownload(const GURL& url) { | 453 void BackgroundDownloader::DoStartDownload(const GURL& url) { |
| 454 DCHECK(thread_checker_.CalledOnValidThread()); | 454 DCHECK(thread_checker_.CalledOnValidThread()); |
| 455 task_runner()->PostTask(FROM_HERE, | 455 task_runner()->PostTask(FROM_HERE, |
| 456 base::Bind(&BackgroundDownloader::BeginDownload, | 456 base::Bind(&BackgroundDownloader::BeginDownload, |
| 457 base::Unretained(this), url)); | 457 base::Unretained(this), url)); |
| 458 } | 458 } |
| 459 | 459 |
| 460 // Called one time when this class is asked to do a download. | 460 // Called one time when this class is asked to do a download. |
| 461 void BackgroundDownloader::BeginDownload(const GURL& url) { | 461 void BackgroundDownloader::BeginDownload(const GURL& url) { |
| 462 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 462 DCHECK(task_runner()->RunsTasksInCurrentSequence()); |
| 463 | 463 |
| 464 download_start_time_ = base::TimeTicks::Now(); | 464 download_start_time_ = base::TimeTicks::Now(); |
| 465 job_stuck_begin_time_ = download_start_time_; | 465 job_stuck_begin_time_ = download_start_time_; |
| 466 | 466 |
| 467 HRESULT hr = BeginDownloadHelper(url); | 467 HRESULT hr = BeginDownloadHelper(url); |
| 468 if (FAILED(hr)) { | 468 if (FAILED(hr)) { |
| 469 EndDownload(hr); | 469 EndDownload(hr); |
| 470 return; | 470 return; |
| 471 } | 471 } |
| 472 | 472 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 498 | 498 |
| 499 hr = RegisterInterfaceInGit(git, job_, &git_cookie_job_); | 499 hr = RegisterInterfaceInGit(git, job_, &git_cookie_job_); |
| 500 if (FAILED(hr)) | 500 if (FAILED(hr)) |
| 501 return hr; | 501 return hr; |
| 502 | 502 |
| 503 return S_OK; | 503 return S_OK; |
| 504 } | 504 } |
| 505 | 505 |
| 506 // Called any time the timer fires. | 506 // Called any time the timer fires. |
| 507 void BackgroundDownloader::OnDownloading() { | 507 void BackgroundDownloader::OnDownloading() { |
| 508 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 508 DCHECK(task_runner()->RunsTasksInCurrentSequence()); |
| 509 | 509 |
| 510 HRESULT hr = UpdateInterfacePointers(); | 510 HRESULT hr = UpdateInterfacePointers(); |
| 511 if (FAILED(hr)) { | 511 if (FAILED(hr)) { |
| 512 EndDownload(hr); | 512 EndDownload(hr); |
| 513 return; | 513 return; |
| 514 } | 514 } |
| 515 | 515 |
| 516 BG_JOB_STATE job_state = BG_JOB_STATE_ERROR; | 516 BG_JOB_STATE job_state = BG_JOB_STATE_ERROR; |
| 517 hr = job_->GetState(&job_state); | 517 hr = job_->GetState(&job_state); |
| 518 if (FAILED(hr)) { | 518 if (FAILED(hr)) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 563 |
| 564 ResetInterfacePointers(); | 564 ResetInterfacePointers(); |
| 565 main_task_runner()->PostTask( | 565 main_task_runner()->PostTask( |
| 566 FROM_HERE, | 566 FROM_HERE, |
| 567 base::Bind(&BackgroundDownloader::StartTimer, base::Unretained(this))); | 567 base::Bind(&BackgroundDownloader::StartTimer, base::Unretained(this))); |
| 568 } | 568 } |
| 569 | 569 |
| 570 // Completes the BITS download, picks up the file path of the response, and | 570 // Completes the BITS download, picks up the file path of the response, and |
| 571 // notifies the CrxDownloader. The function should be called only once. | 571 // notifies the CrxDownloader. The function should be called only once. |
| 572 void BackgroundDownloader::EndDownload(HRESULT error) { | 572 void BackgroundDownloader::EndDownload(HRESULT error) { |
| 573 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 573 DCHECK(task_runner()->RunsTasksInCurrentSequence()); |
| 574 | 574 |
| 575 DCHECK(!TimerIsRunning()); | 575 DCHECK(!TimerIsRunning()); |
| 576 | 576 |
| 577 const base::TimeTicks download_end_time(base::TimeTicks::Now()); | 577 const base::TimeTicks download_end_time(base::TimeTicks::Now()); |
| 578 const base::TimeDelta download_time = | 578 const base::TimeDelta download_time = |
| 579 download_end_time >= download_start_time_ | 579 download_end_time >= download_start_time_ |
| 580 ? download_end_time - download_start_time_ | 580 ? download_end_time - download_start_time_ |
| 581 : base::TimeDelta(); | 581 : base::TimeDelta(); |
| 582 | 582 |
| 583 int64_t downloaded_bytes = -1; | 583 int64_t downloaded_bytes = -1; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 main_task_runner()->PostTask( | 707 main_task_runner()->PostTask( |
| 708 FROM_HERE, base::Bind(&BackgroundDownloader::OnDownloadProgress, | 708 FROM_HERE, base::Bind(&BackgroundDownloader::OnDownloadProgress, |
| 709 base::Unretained(this), result)); | 709 base::Unretained(this), result)); |
| 710 return false; | 710 return false; |
| 711 } | 711 } |
| 712 | 712 |
| 713 // Creates or opens a job for the given url and queues it up. Tries to | 713 // Creates or opens a job for the given url and queues it up. Tries to |
| 714 // install a job observer but continues on if an observer can't be set up. | 714 // install a job observer but continues on if an observer can't be set up. |
| 715 HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url, | 715 HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url, |
| 716 IBackgroundCopyJob** job) { | 716 IBackgroundCopyJob** job) { |
| 717 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 717 DCHECK(task_runner()->RunsTasksInCurrentSequence()); |
| 718 | 718 |
| 719 ScopedComPtr<IBackgroundCopyJob> p; | 719 ScopedComPtr<IBackgroundCopyJob> p; |
| 720 HRESULT hr = CreateOrOpenJob(url, p.GetAddressOf()); | 720 HRESULT hr = CreateOrOpenJob(url, p.GetAddressOf()); |
| 721 if (FAILED(hr)) | 721 if (FAILED(hr)) |
| 722 return hr; | 722 return hr; |
| 723 | 723 |
| 724 if (hr == S_OK) { | 724 if (hr == S_OK) { |
| 725 // This is a new job and it needs initialization. | 725 // This is a new job and it needs initialization. |
| 726 hr = InitializeNewJob(p, url); | 726 hr = InitializeNewJob(p, url); |
| 727 if (FAILED(hr)) | 727 if (FAILED(hr)) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // must match as a job only contains one file. | 828 // must match as a job only contains one file. |
| 829 DCHECK(progress.Completed); | 829 DCHECK(progress.Completed); |
| 830 DCHECK_EQ(progress.BytesTotal, progress.BytesTransferred); | 830 DCHECK_EQ(progress.BytesTotal, progress.BytesTransferred); |
| 831 | 831 |
| 832 response_ = base::FilePath(local_name); | 832 response_ = base::FilePath(local_name); |
| 833 | 833 |
| 834 return S_OK; | 834 return S_OK; |
| 835 } | 835 } |
| 836 | 836 |
| 837 HRESULT BackgroundDownloader::UpdateInterfacePointers() { | 837 HRESULT BackgroundDownloader::UpdateInterfacePointers() { |
| 838 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 838 DCHECK(task_runner()->RunsTasksInCurrentSequence()); |
| 839 | 839 |
| 840 ScopedComPtr<IGlobalInterfaceTable> git; | 840 ScopedComPtr<IGlobalInterfaceTable> git; |
| 841 HRESULT hr = GetGit(&git); | 841 HRESULT hr = GetGit(&git); |
| 842 if (FAILED(hr)) | 842 if (FAILED(hr)) |
| 843 return hr; | 843 return hr; |
| 844 | 844 |
| 845 bits_manager_ = nullptr; | 845 bits_manager_ = nullptr; |
| 846 hr = GetInterfaceFromGit(git.Get(), git_cookie_bits_manager_, | 846 hr = GetInterfaceFromGit(git.Get(), git_cookie_bits_manager_, |
| 847 IID_PPV_ARGS(&bits_manager_)); | 847 IID_PPV_ARGS(&bits_manager_)); |
| 848 if (FAILED(hr)) | 848 if (FAILED(hr)) |
| 849 return hr; | 849 return hr; |
| 850 | 850 |
| 851 job_ = nullptr; | 851 job_ = nullptr; |
| 852 hr = GetInterfaceFromGit(git.Get(), git_cookie_job_, IID_PPV_ARGS(&job_)); | 852 hr = GetInterfaceFromGit(git.Get(), git_cookie_job_, IID_PPV_ARGS(&job_)); |
| 853 if (FAILED(hr)) | 853 if (FAILED(hr)) |
| 854 return hr; | 854 return hr; |
| 855 | 855 |
| 856 return S_OK; | 856 return S_OK; |
| 857 } | 857 } |
| 858 | 858 |
| 859 void BackgroundDownloader::ResetInterfacePointers() { | 859 void BackgroundDownloader::ResetInterfacePointers() { |
| 860 job_ = nullptr; | 860 job_ = nullptr; |
| 861 bits_manager_ = nullptr; | 861 bits_manager_ = nullptr; |
| 862 } | 862 } |
| 863 | 863 |
| 864 HRESULT BackgroundDownloader::ClearGit() { | 864 HRESULT BackgroundDownloader::ClearGit() { |
| 865 DCHECK(task_runner()->RunsTasksOnCurrentThread()); | 865 DCHECK(task_runner()->RunsTasksInCurrentSequence()); |
| 866 | 866 |
| 867 ResetInterfacePointers(); | 867 ResetInterfacePointers(); |
| 868 | 868 |
| 869 ScopedComPtr<IGlobalInterfaceTable> git; | 869 ScopedComPtr<IGlobalInterfaceTable> git; |
| 870 HRESULT hr = GetGit(&git); | 870 HRESULT hr = GetGit(&git); |
| 871 if (FAILED(hr)) | 871 if (FAILED(hr)) |
| 872 return hr; | 872 return hr; |
| 873 | 873 |
| 874 const DWORD cookies[] = { | 874 const DWORD cookies[] = { |
| 875 git_cookie_job_, git_cookie_bits_manager_ | 875 git_cookie_job_, git_cookie_bits_manager_ |
| 876 }; | 876 }; |
| 877 | 877 |
| 878 for (auto cookie : cookies) { | 878 for (auto cookie : cookies) { |
| 879 // TODO(sorin): check the result of the call, see crbug.com/644857. | 879 // TODO(sorin): check the result of the call, see crbug.com/644857. |
| 880 git->RevokeInterfaceFromGlobal(cookie); | 880 git->RevokeInterfaceFromGlobal(cookie); |
| 881 } | 881 } |
| 882 | 882 |
| 883 return S_OK; | 883 return S_OK; |
| 884 } | 884 } |
| 885 | 885 |
| 886 } // namespace update_client | 886 } // namespace update_client |
| OLD | NEW |