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

Side by Side Diff: components/update_client/background_downloader_win.cc

Issue 2889683003: Rename TaskRunner::RunsTasksOnCurrentThread() in //components (Closed)
Patch Set: rebase Created 3 years, 6 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
« no previous file with comments | « components/timers/alarm_timer_chromeos.cc ('k') | components/update_client/component.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 void BackgroundDownloader::DoStartDownload(const GURL& url) { 451 void BackgroundDownloader::DoStartDownload(const GURL& url) {
452 DCHECK(thread_checker_.CalledOnValidThread()); 452 DCHECK(thread_checker_.CalledOnValidThread());
453 task_runner()->PostTask(FROM_HERE, 453 task_runner()->PostTask(FROM_HERE,
454 base::Bind(&BackgroundDownloader::BeginDownload, 454 base::Bind(&BackgroundDownloader::BeginDownload,
455 base::Unretained(this), url)); 455 base::Unretained(this), url));
456 } 456 }
457 457
458 // Called one time when this class is asked to do a download. 458 // Called one time when this class is asked to do a download.
459 void BackgroundDownloader::BeginDownload(const GURL& url) { 459 void BackgroundDownloader::BeginDownload(const GURL& url) {
460 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 460 DCHECK(task_runner()->RunsTasksInCurrentSequence());
461 461
462 download_start_time_ = base::TimeTicks::Now(); 462 download_start_time_ = base::TimeTicks::Now();
463 job_stuck_begin_time_ = download_start_time_; 463 job_stuck_begin_time_ = download_start_time_;
464 464
465 HRESULT hr = BeginDownloadHelper(url); 465 HRESULT hr = BeginDownloadHelper(url);
466 if (FAILED(hr)) { 466 if (FAILED(hr)) {
467 EndDownload(hr); 467 EndDownload(hr);
468 return; 468 return;
469 } 469 }
470 470
(...skipping 25 matching lines...) Expand all
496 496
497 hr = RegisterInterfaceInGit(git, job_, &git_cookie_job_); 497 hr = RegisterInterfaceInGit(git, job_, &git_cookie_job_);
498 if (FAILED(hr)) 498 if (FAILED(hr))
499 return hr; 499 return hr;
500 500
501 return S_OK; 501 return S_OK;
502 } 502 }
503 503
504 // Called any time the timer fires. 504 // Called any time the timer fires.
505 void BackgroundDownloader::OnDownloading() { 505 void BackgroundDownloader::OnDownloading() {
506 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 506 DCHECK(task_runner()->RunsTasksInCurrentSequence());
507 507
508 HRESULT hr = UpdateInterfacePointers(); 508 HRESULT hr = UpdateInterfacePointers();
509 if (FAILED(hr)) { 509 if (FAILED(hr)) {
510 EndDownload(hr); 510 EndDownload(hr);
511 return; 511 return;
512 } 512 }
513 513
514 BG_JOB_STATE job_state = BG_JOB_STATE_ERROR; 514 BG_JOB_STATE job_state = BG_JOB_STATE_ERROR;
515 hr = job_->GetState(&job_state); 515 hr = job_->GetState(&job_state);
516 if (FAILED(hr)) { 516 if (FAILED(hr)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 561
562 ResetInterfacePointers(); 562 ResetInterfacePointers();
563 main_task_runner()->PostTask( 563 main_task_runner()->PostTask(
564 FROM_HERE, 564 FROM_HERE,
565 base::Bind(&BackgroundDownloader::StartTimer, base::Unretained(this))); 565 base::Bind(&BackgroundDownloader::StartTimer, base::Unretained(this)));
566 } 566 }
567 567
568 // Completes the BITS download, picks up the file path of the response, and 568 // Completes the BITS download, picks up the file path of the response, and
569 // notifies the CrxDownloader. The function should be called only once. 569 // notifies the CrxDownloader. The function should be called only once.
570 void BackgroundDownloader::EndDownload(HRESULT error) { 570 void BackgroundDownloader::EndDownload(HRESULT error) {
571 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 571 DCHECK(task_runner()->RunsTasksInCurrentSequence());
572 572
573 const base::TimeTicks download_end_time(base::TimeTicks::Now()); 573 const base::TimeTicks download_end_time(base::TimeTicks::Now());
574 const base::TimeDelta download_time = 574 const base::TimeDelta download_time =
575 download_end_time >= download_start_time_ 575 download_end_time >= download_start_time_
576 ? download_end_time - download_start_time_ 576 ? download_end_time - download_start_time_
577 : base::TimeDelta(); 577 : base::TimeDelta();
578 578
579 int64_t downloaded_bytes = -1; 579 int64_t downloaded_bytes = -1;
580 int64_t total_bytes = -1; 580 int64_t total_bytes = -1;
581 GetJobByteCount(job_.Get(), &downloaded_bytes, &total_bytes); 581 GetJobByteCount(job_.Get(), &downloaded_bytes, &total_bytes);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 main_task_runner()->PostTask( 702 main_task_runner()->PostTask(
703 FROM_HERE, base::Bind(&BackgroundDownloader::OnDownloadProgress, 703 FROM_HERE, base::Bind(&BackgroundDownloader::OnDownloadProgress,
704 base::Unretained(this), result)); 704 base::Unretained(this), result));
705 return false; 705 return false;
706 } 706 }
707 707
708 // Creates or opens a job for the given url and queues it up. Tries to 708 // Creates or opens a job for the given url and queues it up. Tries to
709 // install a job observer but continues on if an observer can't be set up. 709 // install a job observer but continues on if an observer can't be set up.
710 HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url, 710 HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url,
711 IBackgroundCopyJob** job) { 711 IBackgroundCopyJob** job) {
712 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 712 DCHECK(task_runner()->RunsTasksInCurrentSequence());
713 713
714 ScopedComPtr<IBackgroundCopyJob> p; 714 ScopedComPtr<IBackgroundCopyJob> p;
715 HRESULT hr = CreateOrOpenJob(url, p.GetAddressOf()); 715 HRESULT hr = CreateOrOpenJob(url, p.GetAddressOf());
716 if (FAILED(hr)) 716 if (FAILED(hr))
717 return hr; 717 return hr;
718 718
719 if (hr == S_OK) { 719 if (hr == S_OK) {
720 // This is a new job and it needs initialization. 720 // This is a new job and it needs initialization.
721 hr = InitializeNewJob(p, url); 721 hr = InitializeNewJob(p, url);
722 if (FAILED(hr)) 722 if (FAILED(hr))
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 // must match as a job only contains one file. 823 // must match as a job only contains one file.
824 DCHECK(progress.Completed); 824 DCHECK(progress.Completed);
825 DCHECK_EQ(progress.BytesTotal, progress.BytesTransferred); 825 DCHECK_EQ(progress.BytesTotal, progress.BytesTransferred);
826 826
827 response_ = base::FilePath(local_name); 827 response_ = base::FilePath(local_name);
828 828
829 return S_OK; 829 return S_OK;
830 } 830 }
831 831
832 HRESULT BackgroundDownloader::UpdateInterfacePointers() { 832 HRESULT BackgroundDownloader::UpdateInterfacePointers() {
833 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 833 DCHECK(task_runner()->RunsTasksInCurrentSequence());
834 834
835 ScopedComPtr<IGlobalInterfaceTable> git; 835 ScopedComPtr<IGlobalInterfaceTable> git;
836 HRESULT hr = GetGit(&git); 836 HRESULT hr = GetGit(&git);
837 if (FAILED(hr)) 837 if (FAILED(hr))
838 return hr; 838 return hr;
839 839
840 bits_manager_ = nullptr; 840 bits_manager_ = nullptr;
841 hr = GetInterfaceFromGit(git.Get(), git_cookie_bits_manager_, 841 hr = GetInterfaceFromGit(git.Get(), git_cookie_bits_manager_,
842 IID_PPV_ARGS(&bits_manager_)); 842 IID_PPV_ARGS(&bits_manager_));
843 if (FAILED(hr)) 843 if (FAILED(hr))
844 return hr; 844 return hr;
845 845
846 job_ = nullptr; 846 job_ = nullptr;
847 hr = GetInterfaceFromGit(git.Get(), git_cookie_job_, IID_PPV_ARGS(&job_)); 847 hr = GetInterfaceFromGit(git.Get(), git_cookie_job_, IID_PPV_ARGS(&job_));
848 if (FAILED(hr)) 848 if (FAILED(hr))
849 return hr; 849 return hr;
850 850
851 return S_OK; 851 return S_OK;
852 } 852 }
853 853
854 void BackgroundDownloader::ResetInterfacePointers() { 854 void BackgroundDownloader::ResetInterfacePointers() {
855 job_ = nullptr; 855 job_ = nullptr;
856 bits_manager_ = nullptr; 856 bits_manager_ = nullptr;
857 } 857 }
858 858
859 HRESULT BackgroundDownloader::ClearGit() { 859 HRESULT BackgroundDownloader::ClearGit() {
860 DCHECK(task_runner()->RunsTasksOnCurrentThread()); 860 DCHECK(task_runner()->RunsTasksInCurrentSequence());
861 861
862 ResetInterfacePointers(); 862 ResetInterfacePointers();
863 863
864 ScopedComPtr<IGlobalInterfaceTable> git; 864 ScopedComPtr<IGlobalInterfaceTable> git;
865 HRESULT hr = GetGit(&git); 865 HRESULT hr = GetGit(&git);
866 if (FAILED(hr)) 866 if (FAILED(hr))
867 return hr; 867 return hr;
868 868
869 const DWORD cookies[] = { 869 const DWORD cookies[] = {
870 git_cookie_job_, git_cookie_bits_manager_ 870 git_cookie_job_, git_cookie_bits_manager_
871 }; 871 };
872 872
873 for (auto cookie : cookies) { 873 for (auto cookie : cookies) {
874 // TODO(sorin): check the result of the call, see crbug.com/644857. 874 // TODO(sorin): check the result of the call, see crbug.com/644857.
875 git->RevokeInterfaceFromGlobal(cookie); 875 git->RevokeInterfaceFromGlobal(cookie);
876 } 876 }
877 877
878 return S_OK; 878 return S_OK;
879 } 879 }
880 880
881 } // namespace update_client 881 } // namespace update_client
OLDNEW
« no previous file with comments | « components/timers/alarm_timer_chromeos.cc ('k') | components/update_client/component.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698