Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / component_updater / url_fetcher_downloader.cc
index 4d2f0e2..ed00523 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "chrome/browser/component_updater/url_fetcher_downloader.h"
 
+#include "base/logging.h"
 #include "chrome/browser/component_updater/component_updater_utils.h"
 #include "content/public/browser/browser_thread.h"
 #include "net/base/load_flags.h"
@@ -17,9 +18,8 @@ namespace component_updater {
 UrlFetcherDownloader::UrlFetcherDownloader(
     scoped_ptr<CrxDownloader> successor,
     net::URLRequestContextGetter* context_getter,
-    scoped_refptr<base::SequencedTaskRunner> task_runner,
-    const DownloadCallback& download_callback)
-    : CrxDownloader(successor.Pass(), download_callback),
+    scoped_refptr<base::SequencedTaskRunner> task_runner)
+    : CrxDownloader(successor.Pass()),
       context_getter_(context_getter),
       task_runner_(task_runner),
       downloaded_bytes_(-1),
@@ -27,15 +27,14 @@ UrlFetcherDownloader::UrlFetcherDownloader(
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 }
 
-UrlFetcherDownloader::~UrlFetcherDownloader() {}
+UrlFetcherDownloader::~UrlFetcherDownloader() {
+}
 
 void UrlFetcherDownloader::DoStartDownload(const GURL& url) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-  url_fetcher_.reset(net::URLFetcher::Create(0,
-                                             url,
-                                             net::URLFetcher::GET,
-                                             this));
+  url_fetcher_.reset(
+      net::URLFetcher::Create(0, url, net::URLFetcher::GET, this));
   url_fetcher_->SetRequestContext(context_getter_);
   url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
                              net::LOAD_DO_NOT_SAVE_COOKIES |
@@ -43,6 +42,7 @@ void UrlFetcherDownloader::DoStartDownload(const GURL& url) {
   url_fetcher_->SetAutomaticallyRetryOn5xx(false);
   url_fetcher_->SaveResponseToTemporaryFile(task_runner_);
 
+  VLOG(1) << "Starting background download: " << url.spec();
   url_fetcher_->Start();
 
   download_start_time_ = base::Time::Now();
@@ -56,8 +56,9 @@ void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
 
   const base::Time download_end_time(base::Time::Now());
   const base::TimeDelta download_time =
-    download_end_time >= download_start_time_ ?
-    download_end_time - download_start_time_ : base::TimeDelta();
+      download_end_time >= download_start_time_
+          ? download_end_time - download_start_time_
+          : base::TimeDelta();
 
   // Consider a 5xx response from the server as an indication to terminate
   // the request and avoid overloading the server in this case.
@@ -70,15 +71,22 @@ 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_;
+  source->GetResponseAsFilePath(false, &local_path_);
+  VLOG(1) << "Downloaded " << downloaded_bytes_ << " bytes in "
+          << download_time.InMilliseconds() << "ms from "
+          << source->GetURL().spec() << " to " << local_path_.value();
   CrxDownloader::OnDownloadComplete(is_handled, result, download_metrics);
 }
 
@@ -87,9 +95,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
-