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

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

Issue 118703008: Merge 241734 "Added support for multiple urls in the component u..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1750/src/
Patch Set: Created 7 years 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 #include "chrome/browser/component_updater/url_fetcher_downloader.h" 6 #include "chrome/browser/component_updater/url_fetcher_downloader.h"
7 #include "content/public/browser/browser_thread.h" 7 #include "content/public/browser/browser_thread.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include "chrome/browser/component_updater/background_downloader_win.h" 10 #include "chrome/browser/component_updater/background_downloader_win.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 if (!successor_) 67 if (!successor_)
68 return download_metrics_; 68 return download_metrics_;
69 69
70 std::vector<DownloadMetrics> retval(successor_->download_metrics()); 70 std::vector<DownloadMetrics> retval(successor_->download_metrics());
71 retval.insert(retval.begin(), 71 retval.insert(retval.begin(),
72 download_metrics_.begin(), 72 download_metrics_.begin(),
73 download_metrics_.end()); 73 download_metrics_.end());
74 return retval; 74 return retval;
75 } 75 }
76 76
77 bool CrxDownloader::StartDownloadFromUrl(const GURL& url) { 77 void CrxDownloader::StartDownloadFromUrl(const GURL& url) {
78 std::vector<GURL> urls; 78 std::vector<GURL> urls;
79 urls.push_back(url); 79 urls.push_back(url);
80 return StartDownload(urls); 80 StartDownload(urls);
81 } 81 }
82 82
83 bool CrxDownloader::StartDownload(const std::vector<GURL>& urls) { 83 void CrxDownloader::StartDownload(const std::vector<GURL>& urls) {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
85 85
86 if (urls.empty()) 86 if (urls.empty()) {
87 return false; 87 // Make a result and complete the download with a generic error for now.
88 Result result;
89 result.error = -1;
90 download_callback_.Run(result);
91 return;
92 }
88 93
89 // If the urls are mutated while this downloader is active, then the 94 // If the urls are mutated while this downloader is active, then the
90 // behavior is undefined in the sense that the outcome of the download could 95 // behavior is undefined in the sense that the outcome of the download could
91 // be inconsistent for the list of urls. At any rate, the |current_url_| is 96 // be inconsistent for the list of urls. At any rate, the |current_url_| is
92 // reset at this point, and the iterator will be valid in all conditions. 97 // reset at this point, and the iterator will be valid in all conditions.
93 urls_ = urls; 98 urls_ = urls;
94 current_url_ = urls_.begin(); 99 current_url_ = urls_.begin();
95 100
96 DoStartDownload(*current_url_); 101 DoStartDownload(*current_url_);
97 return true;
98 } 102 }
99 103
100 void CrxDownloader::OnDownloadComplete( 104 void CrxDownloader::OnDownloadComplete(
101 bool is_handled, 105 bool is_handled,
102 const Result& result, 106 const Result& result,
103 const DownloadMetrics& download_metrics) { 107 const DownloadMetrics& download_metrics) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 109
106 download_metrics_.push_back(download_metrics); 110 download_metrics_.push_back(download_metrics);
107 111
(...skipping 13 matching lines...) Expand all
121 // Try downloading from another url from the list. 125 // Try downloading from another url from the list.
122 if (current_url_ != urls_.end()) { 126 if (current_url_ != urls_.end()) {
123 DoStartDownload(*current_url_); 127 DoStartDownload(*current_url_);
124 return; 128 return;
125 } 129 }
126 130
127 // If there is another downloader that can accept this request, then hand 131 // If there is another downloader that can accept this request, then hand
128 // the request over to it so that the successor can try the pruned list 132 // the request over to it so that the successor can try the pruned list
129 // of urls. Otherwise, the request ends here since the current downloader 133 // of urls. Otherwise, the request ends here since the current downloader
130 // has tried all urls and it can't fall back on any other downloader. 134 // has tried all urls and it can't fall back on any other downloader.
131 if (successor_ && successor_->StartDownload(urls_)) 135 if (successor_ && !urls_.empty()) {
136 successor_->StartDownload(urls_);
132 return; 137 return;
138 }
133 } 139 }
134 140
135 download_callback_.Run(result); 141 download_callback_.Run(result);
136 } 142 }
137 143
138 } // namespace component_updater 144 } // namespace component_updater
139 145
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/crx_downloader.h ('k') | chrome/browser/component_updater/crx_update_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698