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

Side by Side Diff: chrome/browser/component_updater/crx_downloader.cc

Issue 385013002: Componentize component_updater: Replace content::BrowserThread usage with task runners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extraneous includes Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/component_updater/crx_downloader.h" 5 #include "chrome/browser/component_updater/crx_downloader.h"
6
7 #include "base/logging.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/single_thread_task_runner.h"
6 #include "chrome/browser/component_updater/url_fetcher_downloader.h" 10 #include "chrome/browser/component_updater/url_fetcher_downloader.h"
7 #include "content/public/browser/browser_thread.h"
8 11
9 #if defined(OS_WIN) 12 #if defined(OS_WIN)
10 #include "chrome/browser/component_updater/background_downloader_win.h" 13 #include "chrome/browser/component_updater/background_downloader_win.h"
11 #endif 14 #endif
12 15
13 using content::BrowserThread;
14
15 namespace component_updater { 16 namespace component_updater {
16 17
17 CrxDownloader::Result::Result() 18 CrxDownloader::Result::Result()
18 : error(0), downloaded_bytes(-1), total_bytes(-1) { 19 : error(0), downloaded_bytes(-1), total_bytes(-1) {
19 } 20 }
20 21
21 CrxDownloader::DownloadMetrics::DownloadMetrics() 22 CrxDownloader::DownloadMetrics::DownloadMetrics()
22 : downloader(kNone), 23 : downloader(kNone),
23 error(0), 24 error(0),
24 downloaded_bytes(-1), 25 downloaded_bytes(-1),
25 total_bytes(-1), 26 total_bytes(-1),
26 download_time_ms(0) { 27 download_time_ms(0) {
27 } 28 }
28 29
29 // On Windows, the first downloader in the chain is a background downloader, 30 // On Windows, the first downloader in the chain is a background downloader,
30 // which uses the BITS service. 31 // which uses the BITS service.
31 CrxDownloader* CrxDownloader::Create( 32 CrxDownloader* CrxDownloader::Create(
32 bool is_background_download, 33 bool is_background_download,
33 net::URLRequestContextGetter* context_getter, 34 net::URLRequestContextGetter* context_getter,
34 scoped_refptr<base::SequencedTaskRunner> task_runner) { 35 scoped_refptr<base::SequencedTaskRunner> url_fetcher_task_runner,
36 scoped_refptr<base::SingleThreadTaskRunner> background_task_runner) {
35 scoped_ptr<CrxDownloader> url_fetcher_downloader( 37 scoped_ptr<CrxDownloader> url_fetcher_downloader(
36 new UrlFetcherDownloader(scoped_ptr<CrxDownloader>().Pass(), 38 new UrlFetcherDownloader(scoped_ptr<CrxDownloader>().Pass(),
37 context_getter, 39 context_getter,
38 task_runner)); 40 url_fetcher_task_runner));
39 #if defined(OS_WIN) 41 #if defined(OS_WIN)
40 if (is_background_download) { 42 if (is_background_download) {
41 return new BackgroundDownloader(url_fetcher_downloader.Pass(), 43 return new BackgroundDownloader(
42 context_getter, 44 url_fetcher_downloader.Pass(), context_getter, background_task_runner);
43 task_runner);
44 } 45 }
45 #endif 46 #endif
46 47
47 return url_fetcher_downloader.release(); 48 return url_fetcher_downloader.release();
48 } 49 }
49 50
50 CrxDownloader::CrxDownloader(scoped_ptr<CrxDownloader> successor) 51 CrxDownloader::CrxDownloader(scoped_ptr<CrxDownloader> successor)
51 : successor_(successor.Pass()) { 52 : successor_(successor.Pass()) {
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
53 } 53 }
54 54
55 CrxDownloader::~CrxDownloader() { 55 CrxDownloader::~CrxDownloader() {
56 } 56 }
57 57
58 void CrxDownloader::set_progress_callback( 58 void CrxDownloader::set_progress_callback(
59 const ProgressCallback& progress_callback) { 59 const ProgressCallback& progress_callback) {
60 progress_callback_ = progress_callback; 60 progress_callback_ = progress_callback;
61 } 61 }
62 62
(...skipping 15 matching lines...) Expand all
78 void CrxDownloader::StartDownloadFromUrl( 78 void CrxDownloader::StartDownloadFromUrl(
79 const GURL& url, 79 const GURL& url,
80 const DownloadCallback& download_callback) { 80 const DownloadCallback& download_callback) {
81 std::vector<GURL> urls; 81 std::vector<GURL> urls;
82 urls.push_back(url); 82 urls.push_back(url);
83 StartDownload(urls, download_callback); 83 StartDownload(urls, download_callback);
84 } 84 }
85 85
86 void CrxDownloader::StartDownload(const std::vector<GURL>& urls, 86 void CrxDownloader::StartDownload(const std::vector<GURL>& urls,
87 const DownloadCallback& download_callback) { 87 const DownloadCallback& download_callback) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 88 DCHECK(thread_checker_.CalledOnValidThread());
89 89
90 if (urls.empty()) { 90 if (urls.empty()) {
91 // Make a result and complete the download with a generic error for now. 91 // Make a result and complete the download with a generic error for now.
92 Result result; 92 Result result;
93 result.error = -1; 93 result.error = -1;
94 download_callback.Run(result); 94 download_callback.Run(result);
95 return; 95 return;
96 } 96 }
97 97
98 // If the urls are mutated while this downloader is active, then the 98 // If the urls are mutated while this downloader is active, then the
99 // behavior is undefined in the sense that the outcome of the download could 99 // behavior is undefined in the sense that the outcome of the download could
100 // be inconsistent for the list of urls. At any rate, the |current_url_| is 100 // be inconsistent for the list of urls. At any rate, the |current_url_| is
101 // reset at this point, and the iterator will be valid in all conditions. 101 // reset at this point, and the iterator will be valid in all conditions.
102 urls_ = urls; 102 urls_ = urls;
103 current_url_ = urls_.begin(); 103 current_url_ = urls_.begin();
104 download_callback_ = download_callback; 104 download_callback_ = download_callback;
105 105
106 DoStartDownload(*current_url_); 106 DoStartDownload(*current_url_);
107 } 107 }
108 108
109 void CrxDownloader::OnDownloadComplete( 109 void CrxDownloader::OnDownloadComplete(
110 bool is_handled, 110 bool is_handled,
111 const Result& result, 111 const Result& result,
112 const DownloadMetrics& download_metrics) { 112 const DownloadMetrics& download_metrics) {
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 113 DCHECK(thread_checker_.CalledOnValidThread());
114 114
115 download_metrics_.push_back(download_metrics); 115 download_metrics_.push_back(download_metrics);
116 116
117 if (result.error) { 117 if (result.error) {
118 // If an error has occured, in general try the next url if there is any, 118 // If an error has occured, in general try the next url if there is any,
119 // then move on to the successor in the chain if there is any successor. 119 // then move on to the successor in the chain if there is any successor.
120 // If this downloader has received a 5xx error for the current url, 120 // If this downloader has received a 5xx error for the current url,
121 // as indicated by the |is_handled| flag, remove that url from the list of 121 // as indicated by the |is_handled| flag, remove that url from the list of
122 // urls so the url is never retried. In both cases, move on to the 122 // urls so the url is never retried. In both cases, move on to the
123 // next url. 123 // next url.
(...skipping 16 matching lines...) Expand all
140 if (successor_ && !urls_.empty()) { 140 if (successor_ && !urls_.empty()) {
141 successor_->StartDownload(urls_, download_callback_); 141 successor_->StartDownload(urls_, download_callback_);
142 return; 142 return;
143 } 143 }
144 } 144 }
145 145
146 download_callback_.Run(result); 146 download_callback_.Run(result);
147 } 147 }
148 148
149 void CrxDownloader::OnDownloadProgress(const Result& result) { 149 void CrxDownloader::OnDownloadProgress(const Result& result) {
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 150 DCHECK(thread_checker_.CalledOnValidThread());
151 151
152 if (progress_callback_.is_null()) 152 if (progress_callback_.is_null())
153 return; 153 return;
154 154
155 progress_callback_.Run(result); 155 progress_callback_.Run(result);
156 } 156 }
157 157
158 } // namespace component_updater 158 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/crx_downloader.h ('k') | chrome/browser/component_updater/default_component_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698