diff options
author | sorin@chromium.org <sorin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-31 19:04:50 +0000 |
---|---|---|
committer | sorin@chromium.org <sorin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-31 19:04:50 +0000 |
commit | ec4015dec1ef7d433957c1165874e1bd0401018e (patch) | |
tree | bfc67e87bb5e60568ec18d52d3a3f32fd5cf82dd | |
parent | de7791bf6aa6fdccaaf1692fa86a8df3cada5b19 (diff) | |
download | chromium_src-ec4015dec1ef7d433957c1165874e1bd0401018e.zip chromium_src-ec4015dec1ef7d433957c1165874e1bd0401018e.tar.gz chromium_src-ec4015dec1ef7d433957c1165874e1bd0401018e.tar.bz2 |
Merge 242824 "Implement download metrics byte counts for UrlFetc..."
> Implement download metrics byte counts for UrlFetcherDownloader.
>
> BUG=331162
>
> Review URL: https://codereview.chromium.org/99463007
R=waffles@chromium.org
TBR=sorin@chromium.org
Review URL: https://codereview.chromium.org/145023018
git-svn-id: svn://svn.chromium.org/chrome/branches/1750/src@248237 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 44 insertions, 14 deletions
diff --git a/chrome/browser/component_updater/background_downloader_win.cc b/chrome/browser/component_updater/background_downloader_win.cc index 59919d7..48eebb0 100644 --- a/chrome/browser/component_updater/background_downloader_win.cc +++ b/chrome/browser/component_updater/background_downloader_win.cc @@ -505,7 +505,8 @@ void BackgroundDownloader::EndDownload(HRESULT error) { download_end_time >= download_start_time_ ? download_end_time - download_start_time_ : base::TimeDelta(); - BG_FILE_PROGRESS progress = {0}; + int64 bytes_downloaded = -1; + int64 bytes_total = -1; GetJobByteCount(job_, &bytes_downloaded, &bytes_total); base::FilePath response; @@ -515,6 +516,7 @@ void BackgroundDownloader::EndDownload(HRESULT error) { GetFilesInJob(job_, &files); DCHECK(files.size() == 1); base::string16 local_name; + BG_FILE_PROGRESS progress = {0}; HRESULT hr = GetJobFileProperties(files[0], &local_name, NULL, &progress); if (SUCCEEDED(hr)) { // Sanity check the post-conditions of a successful download, including @@ -524,6 +526,10 @@ void BackgroundDownloader::EndDownload(HRESULT error) { DCHECK(bytes_downloaded == static_cast<int64>(progress.BytesTransferred)); DCHECK(bytes_total == static_cast<int64>(progress.BytesTotal)); response = base::FilePath(local_name); + if (progress.BytesTransferred <= kint64max) + bytes_downloaded = progress.BytesTransferred; + if (progress.BytesTotal <= kint64max) + bytes_total = progress.BytesTotal; } else { error = hr; } @@ -547,8 +553,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 = progress.BytesTransferred; - download_metrics.bytes_total = progress.BytesTotal; + download_metrics.bytes_downloaded = bytes_downloaded; + download_metrics.bytes_total = bytes_total; download_metrics.download_time_ms = download_time.InMilliseconds(); // Clean up stale jobs before invoking the callback. diff --git a/chrome/browser/component_updater/component_updater_ping_manager.cc b/chrome/browser/component_updater/component_updater_ping_manager.cc index e16e6e3..c283ed0 100644 --- a/chrome/browser/component_updater/component_updater_ping_manager.cc +++ b/chrome/browser/component_updater/component_updater_ping_manager.cc @@ -109,14 +109,17 @@ std::string PingSender::BuildDownloadCompleteEventElements( if (metrics.error) StringAppendF(&event, " errorcode=\"%d\"", metrics.error); StringAppendF(&event, " url=\"%s\"", metrics.url.spec().c_str()); - if (metrics.bytes_downloaded) { + + // -1 means that the byte counts are not known. + if (metrics.bytes_downloaded != -1) { StringAppendF(&event, " downloaded=\"%s\"", - base::Uint64ToString(metrics.bytes_downloaded).c_str()); + base::Int64ToString(metrics.bytes_downloaded).c_str()); } - if (metrics.bytes_total) { + if (metrics.bytes_total != -1) { StringAppendF(&event, " total=\"%s\"", - base::Uint64ToString(metrics.bytes_total).c_str()); + base::Int64ToString(metrics.bytes_total).c_str()); } + if (metrics.download_time_ms) { StringAppendF(&event, " download_time_ms=\"%s\"", base::Uint64ToString(metrics.download_time_ms).c_str()); diff --git a/chrome/browser/component_updater/crx_downloader.cc b/chrome/browser/component_updater/crx_downloader.cc index 606c2ca..535ffbe 100644 --- a/chrome/browser/component_updater/crx_downloader.cc +++ b/chrome/browser/component_updater/crx_downloader.cc @@ -19,8 +19,8 @@ CrxDownloader::Result::Result() : error(0) {} CrxDownloader::DownloadMetrics::DownloadMetrics() : downloader(kNone), error(0), - bytes_downloaded(0), - bytes_total(0), + bytes_downloaded(-1), + bytes_total(-1), download_time_ms(0) {} // On Windows, the first downloader in the chain is a background downloader, diff --git a/chrome/browser/component_updater/crx_downloader.h b/chrome/browser/component_updater/crx_downloader.h index 029f380..408290c 100644 --- a/chrome/browser/component_updater/crx_downloader.h +++ b/chrome/browser/component_updater/crx_downloader.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_ #include <vector> + #include "base/basictypes.h" #include "base/callback.h" #include "base/files/file_path.h" @@ -47,8 +48,8 @@ class CrxDownloader { int error; - uint64 bytes_downloaded; - uint64 bytes_total; + int64 bytes_downloaded; // -1 means that the byte count is unknown. + int64 bytes_total; uint64 download_time_ms; }; diff --git a/chrome/browser/component_updater/url_fetcher_downloader.cc b/chrome/browser/component_updater/url_fetcher_downloader.cc index b2d16da..4d2f0e2 100644 --- a/chrome/browser/component_updater/url_fetcher_downloader.cc +++ b/chrome/browser/component_updater/url_fetcher_downloader.cc @@ -21,7 +21,9 @@ UrlFetcherDownloader::UrlFetcherDownloader( const DownloadCallback& download_callback) : CrxDownloader(successor.Pass(), download_callback), context_getter_(context_getter), - task_runner_(task_runner) { + task_runner_(task_runner), + downloaded_bytes_(-1), + total_bytes_(-1) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -44,6 +46,9 @@ void UrlFetcherDownloader::DoStartDownload(const GURL& url) { url_fetcher_->Start(); download_start_time_ = base::Time::Now(); + + downloaded_bytes_ = -1; + total_bytes_ = -1; } void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { @@ -66,15 +71,25 @@ void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { source->GetResponseAsFilePath(true, &result.response); } - // The URLFetcher does not provide accessors for the number of bytes yet. 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.download_time_ms = download_time.InMilliseconds(); CrxDownloader::OnDownloadComplete(is_handled, result, download_metrics); } +void UrlFetcherDownloader::OnURLFetchDownloadProgress( + const net::URLFetcher* source, + int64 current, + int64 total) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + downloaded_bytes_ = current; + total_bytes_ = total; +} + } // namespace component_updater diff --git a/chrome/browser/component_updater/url_fetcher_downloader.h b/chrome/browser/component_updater/url_fetcher_downloader.h index 622758d..37272c7 100644 --- a/chrome/browser/component_updater/url_fetcher_downloader.h +++ b/chrome/browser/component_updater/url_fetcher_downloader.h @@ -36,13 +36,18 @@ class UrlFetcherDownloader : public CrxDownloader, // Overrides for URLFetcherDelegate. virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; - + virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, + int64 current, + int64 total) OVERRIDE; scoped_ptr<net::URLFetcher> url_fetcher_; net::URLRequestContextGetter* context_getter_; scoped_refptr<base::SequencedTaskRunner> task_runner_; base::Time download_start_time_; + int64 downloaded_bytes_; + int64 total_bytes_; + DISALLOW_COPY_AND_ASSIGN(UrlFetcherDownloader); }; |