OLD | NEW |
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/url_fetcher_downloader.h" | 5 #include "chrome/browser/component_updater/url_fetcher_downloader.h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "chrome/browser/component_updater/component_updater_utils.h" | 8 #include "chrome/browser/component_updater/component_updater_utils.h" |
8 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
9 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
10 #include "net/url_request/url_fetcher.h" | 11 #include "net/url_request/url_fetcher.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 using content::BrowserThread; | 14 using content::BrowserThread; |
14 | 15 |
15 namespace component_updater { | 16 namespace component_updater { |
16 | 17 |
(...skipping 19 matching lines...) Expand all Loading... |
36 url, | 37 url, |
37 net::URLFetcher::GET, | 38 net::URLFetcher::GET, |
38 this)); | 39 this)); |
39 url_fetcher_->SetRequestContext(context_getter_); | 40 url_fetcher_->SetRequestContext(context_getter_); |
40 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 41 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
41 net::LOAD_DO_NOT_SAVE_COOKIES | | 42 net::LOAD_DO_NOT_SAVE_COOKIES | |
42 net::LOAD_DISABLE_CACHE); | 43 net::LOAD_DISABLE_CACHE); |
43 url_fetcher_->SetAutomaticallyRetryOn5xx(false); | 44 url_fetcher_->SetAutomaticallyRetryOn5xx(false); |
44 url_fetcher_->SaveResponseToTemporaryFile(task_runner_); | 45 url_fetcher_->SaveResponseToTemporaryFile(task_runner_); |
45 | 46 |
| 47 VLOG(1) << "Starting background download: " << url.spec(); |
46 url_fetcher_->Start(); | 48 url_fetcher_->Start(); |
47 | 49 |
48 download_start_time_ = base::Time::Now(); | 50 download_start_time_ = base::Time::Now(); |
49 | 51 |
50 downloaded_bytes_ = -1; | 52 downloaded_bytes_ = -1; |
51 total_bytes_ = -1; | 53 total_bytes_ = -1; |
52 } | 54 } |
53 | 55 |
54 void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 56 void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 16 matching lines...) Expand all Loading... |
72 } | 74 } |
73 | 75 |
74 DownloadMetrics download_metrics; | 76 DownloadMetrics download_metrics; |
75 download_metrics.url = url(); | 77 download_metrics.url = url(); |
76 download_metrics.downloader = DownloadMetrics::kUrlFetcher; | 78 download_metrics.downloader = DownloadMetrics::kUrlFetcher; |
77 download_metrics.error = fetch_error; | 79 download_metrics.error = fetch_error; |
78 download_metrics.bytes_downloaded = downloaded_bytes_; | 80 download_metrics.bytes_downloaded = downloaded_bytes_; |
79 download_metrics.bytes_total = total_bytes_; | 81 download_metrics.bytes_total = total_bytes_; |
80 download_metrics.download_time_ms = download_time.InMilliseconds(); | 82 download_metrics.download_time_ms = download_time.InMilliseconds(); |
81 | 83 |
| 84 base::FilePath local_path_; |
| 85 source->GetResponseAsFilePath(false, &local_path_); |
| 86 VLOG(1) << "Downloaded " << downloaded_bytes_ << " bytes in " |
| 87 << download_time.InMilliseconds() << "ms from " |
| 88 << source->GetURL().spec() |
| 89 << " to " << local_path_.value(); |
82 CrxDownloader::OnDownloadComplete(is_handled, result, download_metrics); | 90 CrxDownloader::OnDownloadComplete(is_handled, result, download_metrics); |
83 } | 91 } |
84 | 92 |
85 void UrlFetcherDownloader::OnURLFetchDownloadProgress( | 93 void UrlFetcherDownloader::OnURLFetchDownloadProgress( |
86 const net::URLFetcher* source, | 94 const net::URLFetcher* source, |
87 int64 current, | 95 int64 current, |
88 int64 total) { | 96 int64 total) { |
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
90 downloaded_bytes_ = current; | 98 downloaded_bytes_ = current; |
91 total_bytes_ = total; | 99 total_bytes_ = total; |
92 } | 100 } |
93 | 101 |
94 } // namespace component_updater | 102 } // namespace component_updater |
95 | 103 |
OLD | NEW |