summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/component_updater/background_downloader_win.cc73
-rw-r--r--chrome/browser/component_updater/component_updater_ping_manager.cc9
-rw-r--r--chrome/browser/component_updater/component_updater_service.cc28
-rw-r--r--chrome/browser/component_updater/component_updater_service.h3
-rw-r--r--chrome/browser/component_updater/crx_downloader.cc26
-rw-r--r--chrome/browser/component_updater/crx_downloader.h28
-rw-r--r--chrome/browser/component_updater/test/component_updater_ping_manager_unittest.cc9
-rw-r--r--chrome/browser/component_updater/test/component_updater_service_unittest.cc13
-rw-r--r--chrome/browser/component_updater/test/crx_downloader_unittest.cc48
-rw-r--r--chrome/browser/component_updater/url_fetcher_downloader.cc14
-rw-r--r--chrome/browser/component_updater/url_fetcher_downloader.h1
11 files changed, 192 insertions, 60 deletions
diff --git a/chrome/browser/component_updater/background_downloader_win.cc b/chrome/browser/component_updater/background_downloader_win.cc
index af8d0dd..d656a4e 100644
--- a/chrome/browser/component_updater/background_downloader_win.cc
+++ b/chrome/browser/component_updater/background_downloader_win.cc
@@ -99,7 +99,7 @@ namespace {
const base::char16 kJobDescription[] = L"Chrome Component Updater";
// How often the code looks for changes in the BITS job state.
-const int kJobPollingIntervalSec = 10;
+const int kJobPollingIntervalSec = 4;
// How long BITS waits before retrying a job after the job encountered
// a transient error. If this value is not set, the BITS default is 10 minutes.
@@ -197,10 +197,10 @@ HRESULT GetJobFileProperties(IBackgroundCopyFile* file,
// in the job. If the values are not known or if an error has occurred,
// a value of -1 is reported.
HRESULT GetJobByteCount(IBackgroundCopyJob* job,
- int64* bytes_downloaded,
- int64* bytes_total) {
- *bytes_downloaded = -1;
- *bytes_total = -1;
+ int64* downloaded_bytes,
+ int64* total_bytes) {
+ *downloaded_bytes = -1;
+ *total_bytes = -1;
if (!job)
return E_FAIL;
@@ -211,11 +211,11 @@ HRESULT GetJobByteCount(IBackgroundCopyJob* job,
return hr;
if (job_progress.BytesTransferred <= kint64max)
- *bytes_downloaded = job_progress.BytesTransferred;
+ *downloaded_bytes = job_progress.BytesTransferred;
if (job_progress.BytesTotal <= kint64max &&
job_progress.BytesTotal != BG_SIZE_UNKNOWN)
- *bytes_total = job_progress.BytesTotal;
+ *total_bytes = job_progress.BytesTotal;
return S_OK;
}
@@ -413,12 +413,11 @@ BackgroundDownloader::~BackgroundDownloader() {
void BackgroundDownloader::DoStartDownload(const GURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&BackgroundDownloader::BeginDownload,
- base::Unretained(this),
- url));
+ BrowserThread::PostTask(BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&BackgroundDownloader::BeginDownload,
+ base::Unretained(this),
+ url));
}
// Called once when this class is asked to do a download. Creates or opens
@@ -517,9 +516,9 @@ void BackgroundDownloader::EndDownload(HRESULT error) {
download_end_time >= download_start_time_ ?
download_end_time - download_start_time_ : base::TimeDelta();
- int64 bytes_downloaded = -1;
- int64 bytes_total = -1;
- GetJobByteCount(job_, &bytes_downloaded, &bytes_total);
+ int64 downloaded_bytes = -1;
+ int64 total_bytes = -1;
+ GetJobByteCount(job_, &downloaded_bytes, &total_bytes);
base::FilePath response;
if (SUCCEEDED(error)) {
@@ -535,8 +534,8 @@ void BackgroundDownloader::EndDownload(HRESULT error) {
// the file and job invariants. The byte counts for a job and its file
// must match as a job only contains one file.
DCHECK(progress.Completed);
- DCHECK(bytes_downloaded == static_cast<int64>(progress.BytesTransferred));
- DCHECK(bytes_total == static_cast<int64>(progress.BytesTotal));
+ DCHECK(downloaded_bytes == static_cast<int64>(progress.BytesTransferred));
+ DCHECK(total_bytes == static_cast<int64>(progress.BytesTotal));
response = base::FilePath(local_name);
} else {
error = hr;
@@ -561,8 +560,8 @@ void BackgroundDownloader::EndDownload(HRESULT error) {
download_metrics.url = url();
download_metrics.downloader = DownloadMetrics::kBits;
download_metrics.error = error_to_report;
- download_metrics.bytes_downloaded = bytes_downloaded;
- download_metrics.bytes_total = bytes_total;
+ download_metrics.downloaded_bytes = downloaded_bytes;
+ download_metrics.total_bytes = total_bytes;
download_metrics.download_time_ms = download_time.InMilliseconds();
// Clean up stale jobs before invoking the callback.
@@ -573,14 +572,15 @@ void BackgroundDownloader::EndDownload(HRESULT error) {
Result result;
result.error = error_to_report;
result.response = response;
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&BackgroundDownloader::OnDownloadComplete,
- base::Unretained(this),
- is_handled,
- result,
- download_metrics));
+ 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
// by its owner. It is not safe to access members of this object on the
@@ -639,6 +639,22 @@ void BackgroundDownloader::OnStateTransferring() {
// Resets the baseline for detecting a stuck job since the job is transferring
// data and it is making progress.
job_stuck_begin_time_ = base::Time::Now();
+
+ int64 downloaded_bytes = -1;
+ int64 total_bytes = -1;
+ HRESULT hr = GetJobByteCount(job_, &downloaded_bytes, &total_bytes);
+ if (FAILED(hr))
+ return;
+
+ Result result;
+ result.downloaded_bytes = downloaded_bytes;
+ result.total_bytes = total_bytes;
+
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&BackgroundDownloader::OnDownloadProgress,
+ base::Unretained(this),
+ result));
}
// Called when the download was cancelled. Since the observer should have
@@ -749,4 +765,3 @@ bool BackgroundDownloader::IsStuck() {
}
} // namespace component_updater
-
diff --git a/chrome/browser/component_updater/component_updater_ping_manager.cc b/chrome/browser/component_updater/component_updater_ping_manager.cc
index fb5cf30..9fe4955 100644
--- a/chrome/browser/component_updater/component_updater_ping_manager.cc
+++ b/chrome/browser/component_updater/component_updater_ping_manager.cc
@@ -113,13 +113,13 @@ std::string PingSender::BuildDownloadCompleteEventElements(
StringAppendF(&event, " url=\"%s\"", metrics.url.spec().c_str());
// -1 means that the byte counts are not known.
- if (metrics.bytes_downloaded != -1) {
+ if (metrics.downloaded_bytes != -1) {
StringAppendF(&event, " downloaded=\"%s\"",
- base::Int64ToString(metrics.bytes_downloaded).c_str());
+ base::Int64ToString(metrics.downloaded_bytes).c_str());
}
- if (metrics.bytes_total != -1) {
+ if (metrics.total_bytes != -1) {
StringAppendF(&event, " total=\"%s\"",
- base::Int64ToString(metrics.bytes_total).c_str());
+ base::Int64ToString(metrics.total_bytes).c_str());
}
if (metrics.download_time_ms) {
@@ -189,4 +189,3 @@ void PingManager::OnUpdateComplete(const CrxUpdateItem* item) {
}
} // namespace component_updater
-
diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc
index 5d6e71d..268cfb2 100644
--- a/chrome/browser/component_updater/component_updater_service.cc
+++ b/chrome/browser/component_updater/component_updater_service.cc
@@ -203,9 +203,11 @@ class CrxUpdateService : public ComponentUpdateService {
void OnUpdateCheckSucceeded(const UpdateResponse::Results& results);
void OnUpdateCheckFailed(int error, const std::string& error_message);
- void DownloadComplete(
- scoped_ptr<CRXContext> crx_context,
- const CrxDownloader::Result& download_result);
+ void DownloadProgress(const std::string& component_id,
+ const CrxDownloader::Result& download_result);
+
+ void DownloadComplete(scoped_ptr<CRXContext> crx_context,
+ const CrxDownloader::Result& download_result);
Status OnDemandUpdateInternal(CrxUpdateItem* item);
@@ -697,6 +699,10 @@ void CrxUpdateService::UpdateComponent(CrxUpdateItem* workitem) {
crx_downloader_.reset(CrxDownloader::Create(is_background_download,
config_->RequestContext(),
blocking_task_runner_));
+ crx_downloader_->set_progress_callback(
+ base::Bind(&CrxUpdateService::DownloadProgress,
+ base::Unretained(this),
+ crx_context->id));
crx_downloader_->StartDownload(*urls,
base::Bind(&CrxUpdateService::DownloadComplete,
base::Unretained(this),
@@ -812,6 +818,16 @@ void CrxUpdateService::OnUpdateCheckFailed(int error,
ScheduleNextRun(kStepDelayLong);
}
+// Called when progress is being made downloading a CRX. The progress may
+// not monotonically increase due to how the CRX downloader switches between
+// different downloaders and fallback urls.
+void CrxUpdateService::DownloadProgress(
+ const std::string& component_id,
+ const CrxDownloader::Result& download_result) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ NotifyObservers(Observer::COMPONENT_UPDATE_DOWNLOADING, component_id);
+}
+
// Called when the CRX package has been downloaded to a temporary location.
// Here we fire the notifications and schedule the component-specific installer
// to be called in the file thread.
@@ -827,6 +843,8 @@ void CrxUpdateService::DownloadComplete(
AppendDownloadMetrics(crx_downloader_->download_metrics(),
&crx->download_metrics);
+ crx_downloader_.reset();
+
if (download_result.error) {
if (crx->status == CrxUpdateItem::kDownloadingDiff) {
crx->diff_error_category = kNetworkError;
@@ -835,7 +853,6 @@ void CrxUpdateService::DownloadComplete(
size_t count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff,
CrxUpdateItem::kCanUpdate);
DCHECK_EQ(count, 1ul);
- crx_downloader_.reset();
ScheduleNextRun(kStepDelayShort);
return;
@@ -845,7 +862,6 @@ void CrxUpdateService::DownloadComplete(
size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading,
CrxUpdateItem::kNoUpdate);
DCHECK_EQ(count, 1ul);
- crx_downloader_.reset();
// At this point, since both the differential and the full downloads failed,
// the update for this component has finished with an error.
@@ -863,7 +879,6 @@ void CrxUpdateService::DownloadComplete(
CrxUpdateItem::kUpdating);
}
DCHECK_EQ(count, 1ul);
- crx_downloader_.reset();
// Why unretained? See comment at top of file.
blocking_task_runner_->PostDelayedTask(
@@ -1042,4 +1057,3 @@ ComponentUpdateService* ComponentUpdateServiceFactory(
}
} // namespace component_updater
-
diff --git a/chrome/browser/component_updater/component_updater_service.h b/chrome/browser/component_updater/component_updater_service.h
index 217e472..4474c3d 100644
--- a/chrome/browser/component_updater/component_updater_service.h
+++ b/chrome/browser/component_updater/component_updater_service.h
@@ -176,6 +176,9 @@ class ComponentUpdateService {
// Sent when a component has not been updated following an update check:
// either there was no update available, or an update failed.
COMPONENT_NOT_UPDATED,
+
+ // Sent when component bytes are being downloaded.
+ COMPONENT_UPDATE_DOWNLOADING,
};
virtual ~Observer() {}
diff --git a/chrome/browser/component_updater/crx_downloader.cc b/chrome/browser/component_updater/crx_downloader.cc
index 9591b9c..fbffe66 100644
--- a/chrome/browser/component_updater/crx_downloader.cc
+++ b/chrome/browser/component_updater/crx_downloader.cc
@@ -14,14 +14,17 @@ using content::BrowserThread;
namespace component_updater {
-CrxDownloader::Result::Result() : error(0) {}
+CrxDownloader::Result::Result()
+ : error(0), downloaded_bytes(-1), total_bytes(-1) {
+}
CrxDownloader::DownloadMetrics::DownloadMetrics()
: downloader(kNone),
error(0),
- bytes_downloaded(-1),
- bytes_total(-1),
- download_time_ms(0) {}
+ downloaded_bytes(-1),
+ total_bytes(-1),
+ download_time_ms(0) {
+}
// On Windows, the first downloader in the chain is a background downloader,
// which uses the BITS service.
@@ -52,6 +55,11 @@ CrxDownloader::CrxDownloader(scoped_ptr<CrxDownloader> successor)
CrxDownloader::~CrxDownloader() {
}
+void CrxDownloader::set_progress_callback(
+ const ProgressCallback& progress_callback) {
+ progress_callback_ = progress_callback;
+}
+
GURL CrxDownloader::url() const {
return current_url_ != urls_.end() ? *current_url_ : GURL();
}
@@ -139,5 +147,13 @@ void CrxDownloader::OnDownloadComplete(
download_callback_.Run(result);
}
-} // namespace component_updater
+void CrxDownloader::OnDownloadProgress(const Result& result) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (progress_callback_.is_null())
+ return;
+
+ progress_callback_.Run(result);
+}
+
+} // namespace component_updater
diff --git a/chrome/browser/component_updater/crx_downloader.h b/chrome/browser/component_updater/crx_downloader.h
index 1648d27..9b83140 100644
--- a/chrome/browser/component_updater/crx_downloader.h
+++ b/chrome/browser/component_updater/crx_downloader.h
@@ -48,13 +48,13 @@ class CrxDownloader {
int error;
- int64 bytes_downloaded; // -1 means that the byte count is unknown.
- int64 bytes_total;
+ int64 downloaded_bytes; // -1 means that the byte count is unknown.
+ int64 total_bytes;
uint64 download_time_ms;
};
- // Contains the outcome of the download.
+ // Contains the progress or the outcome of the download.
struct Result {
Result();
@@ -63,6 +63,13 @@ class CrxDownloader {
// Path of the downloaded file if the download was successful.
base::FilePath response;
+
+ // Number of bytes actually downloaded, not including the bytes downloaded
+ // as a result of falling back on urls.
+ int64 downloaded_bytes;
+
+ // Number of bytes expected to be downloaded.
+ int64 total_bytes;
};
// The callback fires only once, regardless of how many urls are tried, and
@@ -72,6 +79,12 @@ class CrxDownloader {
// specific error codes and download metrics.
typedef base::Callback<void (const Result& result)> DownloadCallback;
+ // The callback may fire 0 or many times during a download. Since this
+ // class implements a chain of responsibility, the callback can fire for
+ // different urls and different downloaders. The number of actual downloaded
+ // bytes is not guaranteed to monotonically increment over time.
+ typedef base::Callback<void(const Result& result)> ProgressCallback;
+
// Factory method to create an instance of this class and build the
// chain of responsibility. |is_background_download| specifies that a
// background downloader be used, if the platform supports it.
@@ -81,6 +94,8 @@ class CrxDownloader {
scoped_refptr<base::SequencedTaskRunner> task_runner);
virtual ~CrxDownloader();
+ void set_progress_callback(const ProgressCallback& progress_callback);
+
// Starts the download. One instance of the class handles one download only.
// One instance of CrxDownloader can only be started once, otherwise the
// behavior is undefined. The callback gets invoked if the download can't
@@ -107,7 +122,10 @@ class CrxDownloader {
const Result& result,
const DownloadMetrics& download_metrics);
- // Returns the url which is currently downloaded from.
+ // Calls the callback when progress is made.
+ void OnDownloadProgress(const Result& result);
+
+ // Returns the url which is currently being downloaded from.
GURL url() const;
private:
@@ -116,6 +134,7 @@ class CrxDownloader {
std::vector<GURL> urls_;
scoped_ptr<CrxDownloader> successor_;
DownloadCallback download_callback_;
+ ProgressCallback progress_callback_;
std::vector<GURL>::iterator current_url_;
@@ -127,4 +146,3 @@ class CrxDownloader {
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_
-
diff --git a/chrome/browser/component_updater/test/component_updater_ping_manager_unittest.cc b/chrome/browser/component_updater/test/component_updater_ping_manager_unittest.cc
index da693dd..5588384 100644
--- a/chrome/browser/component_updater/test/component_updater_ping_manager_unittest.cc
+++ b/chrome/browser/component_updater/test/component_updater_ping_manager_unittest.cc
@@ -143,8 +143,8 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) {
download_metrics.url = GURL("http://host1/path1");
download_metrics.downloader = CrxDownloader::DownloadMetrics::kUrlFetcher;
download_metrics.error = -1;
- download_metrics.bytes_downloaded = 123;
- download_metrics.bytes_total = 456;
+ download_metrics.downloaded_bytes = 123;
+ download_metrics.total_bytes = 456;
download_metrics.download_time_ms = 987;
item.download_metrics.push_back(download_metrics);
@@ -152,8 +152,8 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) {
download_metrics.url = GURL("http://host2/path2");
download_metrics.downloader = CrxDownloader::DownloadMetrics::kBits;
download_metrics.error = 0;
- download_metrics.bytes_downloaded = 1230;
- download_metrics.bytes_total = 4560;
+ download_metrics.downloaded_bytes = 1230;
+ download_metrics.total_bytes = 4560;
download_metrics.download_time_ms = 9870;
item.download_metrics.push_back(download_metrics);
@@ -175,4 +175,3 @@ TEST_F(ComponentUpdaterPingManagerTest, DISABLED_PingManagerTest) {
}
} // namespace component_updater
-
diff --git a/chrome/browser/component_updater/test/component_updater_service_unittest.cc b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
index 86fc313..462ecf7 100644
--- a/chrome/browser/component_updater/test/component_updater_service_unittest.cc
+++ b/chrome/browser/component_updater/test/component_updater_service_unittest.cc
@@ -26,6 +26,7 @@
using content::BrowserThread;
using ::testing::_;
+using ::testing::AnyNumber;
using ::testing::InSequence;
using ::testing::Mock;
@@ -373,6 +374,10 @@ TEST_F(ComponentUpdaterTest, InstallCrx) {
"abagagagagagagagagagagagagagagag"))
.Times(1);
EXPECT_CALL(observer,
+ OnEvent(ServiceObserver::COMPONENT_UPDATE_DOWNLOADING,
+ "jebgalgnebhfojomionfpkfelancnnkf"))
+ .Times(AnyNumber());
+ EXPECT_CALL(observer,
OnEvent(ServiceObserver::COMPONENT_UPDATE_READY,
"jebgalgnebhfojomionfpkfelancnnkf"))
.Times(1);
@@ -560,6 +565,10 @@ TEST_F(ComponentUpdaterTest, OnDemandUpdate) {
"abagagagagagagagagagagagagagagag"))
.Times(1);
EXPECT_CALL(observer,
+ OnEvent(ServiceObserver::COMPONENT_UPDATE_DOWNLOADING,
+ "jebgalgnebhfojomionfpkfelancnnkf"))
+ .Times(AnyNumber());
+ EXPECT_CALL(observer,
OnEvent(ServiceObserver::COMPONENT_UPDATE_READY,
"jebgalgnebhfojomionfpkfelancnnkf"))
.Times(1);
@@ -747,6 +756,10 @@ TEST_F(ComponentUpdaterTest, CheckReRegistration) {
"abagagagagagagagagagagagagagagag"))
.Times(1);
EXPECT_CALL(observer,
+ OnEvent(ServiceObserver::COMPONENT_UPDATE_DOWNLOADING,
+ "jebgalgnebhfojomionfpkfelancnnkf"))
+ .Times(AnyNumber());
+ EXPECT_CALL(observer,
OnEvent(ServiceObserver::COMPONENT_UPDATE_READY,
"jebgalgnebhfojomionfpkfelancnnkf"))
.Times(1);
diff --git a/chrome/browser/component_updater/test/crx_downloader_unittest.cc b/chrome/browser/component_updater/test/crx_downloader_unittest.cc
index eb5bf3f..037ba76 100644
--- a/chrome/browser/component_updater/test/crx_downloader_unittest.cc
+++ b/chrome/browser/component_updater/test/crx_downloader_unittest.cc
@@ -54,16 +54,23 @@ class CrxDownloaderTest : public testing::Test {
void DownloadComplete(int crx_context, const CrxDownloader::Result& result);
+ void DownloadProgress(int crx_context, const CrxDownloader::Result& result);
+
protected:
scoped_ptr<CrxDownloader> crx_downloader_;
CrxDownloader::DownloadCallback callback_;
+ CrxDownloader::ProgressCallback progress_callback_;
int crx_context_;
int num_download_complete_calls_;
CrxDownloader::Result download_complete_result_;
+ // These members are updated by DownloadProgress.
+ int num_progress_calls_;
+ CrxDownloader::Result download_progress_result_;
+
// A magic value for the context to be used in the tests.
static const int kExpectedContext = 0xaabb;
@@ -80,8 +87,12 @@ CrxDownloaderTest::CrxDownloaderTest()
: callback_(base::Bind(&CrxDownloaderTest::DownloadComplete,
base::Unretained(this),
kExpectedContext)),
+ progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress,
+ base::Unretained(this),
+ kExpectedContext)),
crx_context_(0),
num_download_complete_calls_(0),
+ num_progress_calls_(0),
blocking_task_runner_(BrowserThread::GetBlockingPool()->
GetSequencedTaskRunnerWithShutdownBehavior(
BrowserThread::GetBlockingPool()->GetSequenceToken(),
@@ -98,13 +109,17 @@ CrxDownloaderTest::~CrxDownloaderTest() {
void CrxDownloaderTest::SetUp() {
num_download_complete_calls_ = 0;
download_complete_result_ = CrxDownloader::Result();
+ num_progress_calls_ = 0;
+ download_progress_result_ = CrxDownloader::Result();
crx_downloader_.reset(CrxDownloader::Create(
false, // Do not use the background downloader in these tests.
context_.get(),
blocking_task_runner_));
+ crx_downloader_->set_progress_callback(progress_callback_);
}
void CrxDownloaderTest::TearDown() {
+ crx_downloader_.reset();
}
void CrxDownloaderTest::Quit() {
@@ -120,6 +135,12 @@ void CrxDownloaderTest::DownloadComplete(int crx_context,
Quit();
}
+void CrxDownloaderTest::DownloadProgress(int crx_context,
+ const CrxDownloader::Result& result) {
+ ++num_progress_calls_;
+ download_progress_result_ = result;
+}
+
void CrxDownloaderTest::RunThreads() {
base::RunLoop runloop;
quit_closure_ = runloop.QuitClosure();
@@ -146,6 +167,9 @@ TEST_F(CrxDownloaderTest, NoUrl) {
EXPECT_EQ(kExpectedContext, crx_context_);
EXPECT_EQ(-1, download_complete_result_.error);
EXPECT_TRUE(download_complete_result_.response.empty());
+ EXPECT_EQ(-1, download_complete_result_.downloaded_bytes);
+ EXPECT_EQ(-1, download_complete_result_.total_bytes);
+ EXPECT_EQ(0, num_progress_calls_);
}
// Tests that downloading from one url is successful.
@@ -165,9 +189,15 @@ TEST_F(CrxDownloaderTest, OneUrl) {
EXPECT_EQ(1, num_download_complete_calls_);
EXPECT_EQ(kExpectedContext, crx_context_);
EXPECT_EQ(0, download_complete_result_.error);
+ EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_complete_result_.total_bytes);
EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
+
+ EXPECT_LE(1, num_progress_calls_);
+ EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_progress_result_.total_bytes);
}
// Tests that specifying from two urls has no side effects. Expect a successful
@@ -198,9 +228,15 @@ TEST_F(CrxDownloaderTest, MAYBE_TwoUrls) {
EXPECT_EQ(1, num_download_complete_calls_);
EXPECT_EQ(kExpectedContext, crx_context_);
EXPECT_EQ(0, download_complete_result_.error);
+ EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_complete_result_.total_bytes);
EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
+
+ EXPECT_LE(1, num_progress_calls_);
+ EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_progress_result_.total_bytes);
}
// Tests that an invalid host results in a download error.
@@ -275,9 +311,15 @@ TEST_F(CrxDownloaderTest, MAYBE_TwoUrls_FirstInvalid) {
EXPECT_EQ(1, num_download_complete_calls_);
EXPECT_EQ(kExpectedContext, crx_context_);
EXPECT_EQ(0, download_complete_result_.error);
+ EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_complete_result_.total_bytes);
EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
+
+ EXPECT_LE(1, num_progress_calls_);
+ EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_progress_result_.total_bytes);
}
// Tests that the download succeeds if the first url is correct and the
@@ -302,9 +344,15 @@ TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) {
EXPECT_EQ(1, num_download_complete_calls_);
EXPECT_EQ(kExpectedContext, crx_context_);
EXPECT_EQ(0, download_complete_result_.error);
+ EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_complete_result_.total_bytes);
EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
+
+ EXPECT_LE(1, num_progress_calls_);
+ EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
+ EXPECT_EQ(1843, download_progress_result_.total_bytes);
}
// Tests that the download fails if both urls are bad.
diff --git a/chrome/browser/component_updater/url_fetcher_downloader.cc b/chrome/browser/component_updater/url_fetcher_downloader.cc
index 39579cd..7de3b30 100644
--- a/chrome/browser/component_updater/url_fetcher_downloader.cc
+++ b/chrome/browser/component_updater/url_fetcher_downloader.cc
@@ -71,13 +71,15 @@ void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
if (!fetch_error) {
source->GetResponseAsFilePath(true, &result.response);
}
+ result.downloaded_bytes = downloaded_bytes_;
+ result.total_bytes = total_bytes_;
DownloadMetrics download_metrics;
download_metrics.url = url();
download_metrics.downloader = DownloadMetrics::kUrlFetcher;
download_metrics.error = fetch_error;
- download_metrics.bytes_downloaded = downloaded_bytes_;
- download_metrics.bytes_total = total_bytes_;
+ download_metrics.downloaded_bytes = downloaded_bytes_;
+ download_metrics.total_bytes = total_bytes_;
download_metrics.download_time_ms = download_time.InMilliseconds();
base::FilePath local_path_;
@@ -94,9 +96,15 @@ void UrlFetcherDownloader::OnURLFetchDownloadProgress(
int64 current,
int64 total) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
downloaded_bytes_ = current;
total_bytes_ = total;
+
+ Result result;
+ result.downloaded_bytes = downloaded_bytes_;
+ result.total_bytes = total_bytes_;
+
+ OnDownloadProgress(result);
}
} // namespace component_updater
-
diff --git a/chrome/browser/component_updater/url_fetcher_downloader.h b/chrome/browser/component_updater/url_fetcher_downloader.h
index ddd9ae8..2132aa3 100644
--- a/chrome/browser/component_updater/url_fetcher_downloader.h
+++ b/chrome/browser/component_updater/url_fetcher_downloader.h
@@ -53,4 +53,3 @@ class UrlFetcherDownloader : public CrxDownloader,
} // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_URL_FETCHER_DOWNLOADER_H_
-