OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/update_client/url_fetcher_downloader.h" | 5 #include "components/update_client/url_fetcher_downloader.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 url_fetcher_->SetRequestContext(context_getter_); | 39 url_fetcher_->SetRequestContext(context_getter_); |
40 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 40 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
41 net::LOAD_DO_NOT_SAVE_COOKIES | | 41 net::LOAD_DO_NOT_SAVE_COOKIES | |
42 net::LOAD_DISABLE_CACHE); | 42 net::LOAD_DISABLE_CACHE); |
43 url_fetcher_->SetAutomaticallyRetryOn5xx(false); | 43 url_fetcher_->SetAutomaticallyRetryOn5xx(false); |
44 url_fetcher_->SaveResponseToTemporaryFile(task_runner()); | 44 url_fetcher_->SaveResponseToTemporaryFile(task_runner()); |
45 | 45 |
46 VLOG(1) << "Starting background download: " << url.spec(); | 46 VLOG(1) << "Starting background download: " << url.spec(); |
47 url_fetcher_->Start(); | 47 url_fetcher_->Start(); |
48 | 48 |
49 download_start_time_ = base::Time::Now(); | 49 download_start_time_ = base::TimeTicks::Now(); |
50 | 50 |
51 downloaded_bytes_ = -1; | 51 downloaded_bytes_ = -1; |
52 total_bytes_ = -1; | 52 total_bytes_ = -1; |
53 } | 53 } |
54 | 54 |
55 void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 55 void UrlFetcherDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
56 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
57 | 57 |
58 const base::Time download_end_time(base::Time::Now()); | 58 const base::TimeTicks download_end_time(base::TimeTicks::Now()); |
59 const base::TimeDelta download_time = | 59 const base::TimeDelta download_time = |
60 download_end_time >= download_start_time_ | 60 download_end_time >= download_start_time_ |
61 ? download_end_time - download_start_time_ | 61 ? download_end_time - download_start_time_ |
62 : base::TimeDelta(); | 62 : base::TimeDelta(); |
63 | 63 |
64 // Consider a 5xx response from the server as an indication to terminate | 64 // Consider a 5xx response from the server as an indication to terminate |
65 // the request and avoid overloading the server in this case. | 65 // the request and avoid overloading the server in this case. |
66 // is not accepting requests for the moment. | 66 // is not accepting requests for the moment. |
67 const int fetch_error(GetFetchError(*url_fetcher_)); | 67 const int fetch_error(GetFetchError(*url_fetcher_)); |
68 const bool is_handled = fetch_error == 0 || IsHttpServerError(fetch_error); | 68 const bool is_handled = fetch_error == 0 || IsHttpServerError(fetch_error); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 total_bytes_ = total; | 105 total_bytes_ = total; |
106 | 106 |
107 Result result; | 107 Result result; |
108 result.downloaded_bytes = downloaded_bytes_; | 108 result.downloaded_bytes = downloaded_bytes_; |
109 result.total_bytes = total_bytes_; | 109 result.total_bytes = total_bytes_; |
110 | 110 |
111 OnDownloadProgress(result); | 111 OnDownloadProgress(result); |
112 } | 112 } |
113 | 113 |
114 } // namespace update_client | 114 } // namespace update_client |
OLD | NEW |