Chromium Code Reviews| Index: chrome/browser/component_updater/background_downloader_win.cc |
| diff --git a/chrome/browser/component_updater/background_downloader_win.cc b/chrome/browser/component_updater/background_downloader_win.cc |
| index 9cfa01f8a374f76357b5d48c176b311f263dc1c0..88c3600edd85dda9a25385096a4c2f0d6b3ac71a 100644 |
| --- a/chrome/browser/component_updater/background_downloader_win.cc |
| +++ b/chrome/browser/component_updater/background_downloader_win.cc |
| @@ -12,22 +12,20 @@ |
| #include <vector> |
| #include "base/file_util.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/win/scoped_co_mem.h" |
| #include "chrome/browser/component_updater/component_updater_utils.h" |
| -#include "content/public/browser/browser_thread.h" |
| #include "ui/base/win/atl_module.h" |
| #include "url/gurl.h" |
| using base::win::ScopedCoMem; |
| using base::win::ScopedComPtr; |
| -using content::BrowserThread; |
| // The class BackgroundDownloader in this module is an adapter between |
| // the CrxDownloader interface and the BITS service interfaces. |
| -// The interface exposed on the CrxDownloader code runs on the UI thread, while |
| -// the BITS specific code runs in a single threaded apartment on the FILE |
| -// thread. |
| +// The interface exposed on the CrxDownloader code runs on the main thread, |
| +// while the BITS specific code runs on a single thread task runner. |
|
blundell
2014/07/15 08:45:20
I would say something like "a separate thread pass
tommycli
2014/07/15 18:58:25
Done.
|
| // For every url to download, a BITS job is created, unless there is already |
| // an existing job for that url, in which case, the downloader connects to it. |
| // Once a job is associated with the url, the code looks for changes in the |
| @@ -387,19 +385,20 @@ HRESULT CleanupStaleJobs( |
| BackgroundDownloader::BackgroundDownloader( |
| scoped_ptr<CrxDownloader> successor, |
| net::URLRequestContextGetter* context_getter, |
| - scoped_refptr<base::SequencedTaskRunner> task_runner) |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| : CrxDownloader(successor.Pass()), |
| + main_loop_(base::MessageLoopProxy::current()), |
| context_getter_(context_getter), |
| task_runner_(task_runner), |
| is_completed_(false) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
|
blundell
2014/07/15 08:45:20
this DCHECK is meaningless I think as thread_check
tommycli
2014/07/15 18:58:25
Done.
|
| } |
| BackgroundDownloader::~BackgroundDownloader() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| // The following objects have thread affinity and can't be destroyed on the |
| - // UI thread. The resources managed by these objects are acquired at the |
| + // main thread. The resources managed by these objects are acquired at the |
| // beginning of a download and released at the end of the download. Most of |
| // the time, when this destructor is called, these resources have been already |
| // disposed by. Releasing the ownership here is a NOP. However, if the browser |
| @@ -412,10 +411,9 @@ BackgroundDownloader::~BackgroundDownloader() { |
| } |
| void BackgroundDownloader::DoStartDownload(const GURL& url) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, |
| + task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind( |
| &BackgroundDownloader::BeginDownload, base::Unretained(this), url)); |
| @@ -424,7 +422,7 @@ void BackgroundDownloader::DoStartDownload(const GURL& url) { |
| // Called once when this class is asked to do a download. Creates or opens |
| // an existing bits job, hooks up the notifications, and starts the timer. |
| void BackgroundDownloader::BeginDownload(const GURL& url) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| DCHECK(!timer_); |
| @@ -449,7 +447,7 @@ void BackgroundDownloader::BeginDownload(const GURL& url) { |
| // Called any time the timer fires. |
| void BackgroundDownloader::OnDownloading() { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| DCHECK(job_); |
| @@ -505,7 +503,7 @@ void BackgroundDownloader::OnDownloading() { |
| // Completes the BITS download, picks up the file path of the response, and |
| // notifies the CrxDownloader. The function should be called only once. |
| void BackgroundDownloader::EndDownload(HRESULT error) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| DCHECK(!is_completed_); |
| is_completed_ = true; |
| @@ -552,17 +550,16 @@ void BackgroundDownloader::EndDownload(HRESULT error) { |
| result.response = response_; |
| result.downloaded_bytes = downloaded_bytes; |
| result.total_bytes = total_bytes; |
| - BrowserThread::PostTask(BrowserThread::UI, |
| - FROM_HERE, |
| - base::Bind(&BackgroundDownloader::OnDownloadComplete, |
| - base::Unretained(this), |
| - is_handled, |
| - result, |
| - download_metrics)); |
| - |
| - // Once the task is posted to the the UI thread, this object may be deleted |
| + main_loop_->PostTask(FROM_HERE, |
| + base::Bind(&BackgroundDownloader::OnDownloadComplete, |
| + base::Unretained(this), |
| + is_handled, |
| + result, |
| + download_metrics)); |
| + |
| + // Once the task is posted to the the main thread, this object may be deleted |
| // by its owner. It is not safe to access members of this object on the |
| - // FILE thread from this point on. The timer is stopped and all BITS |
| + // task runner from this point on. The timer is stopped and all BITS |
| // interface pointers have been released. |
| } |
| @@ -625,11 +622,10 @@ void BackgroundDownloader::OnStateTransferring() { |
| result.downloaded_bytes = downloaded_bytes; |
| result.total_bytes = total_bytes; |
| - BrowserThread::PostTask(BrowserThread::UI, |
| - FROM_HERE, |
| - base::Bind(&BackgroundDownloader::OnDownloadProgress, |
| - base::Unretained(this), |
| - result)); |
| + main_loop_->PostTask(FROM_HERE, |
| + base::Bind(&BackgroundDownloader::OnDownloadProgress, |
| + base::Unretained(this), |
| + result)); |
| } |
| // Called when the download was cancelled. Since the observer should have |
| @@ -646,7 +642,7 @@ void BackgroundDownloader::OnStateAcknowledged() { |
| // Creates or opens a job for the given url and queues it up. Tries to |
| // install a job observer but continues on if an observer can't be set up. |
| HRESULT BackgroundDownloader::QueueBitsJob(const GURL& url) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| HRESULT hr = S_OK; |
| if (bits_manager_ == NULL) { |