| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/net/file_downloader.h" | 5 #include "chrome/browser/net/file_downloader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 14 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 using net::URLFetcher; | 18 using net::URLFetcher; |
| 19 | 19 |
| 20 const int kNumRetries = 1; | 20 const int kNumRetries = 1; |
| 21 | 21 |
| 22 FileDownloader::FileDownloader(const GURL& url, | 22 FileDownloader::FileDownloader(const GURL& url, |
| 23 const base::FilePath& path, | 23 const base::FilePath& path, |
| 24 bool overwrite, | 24 bool overwrite, |
| 25 net::URLRequestContextGetter* request_context, | 25 net::URLRequestContextGetter* request_context, |
| 26 const DownloadFinishedCallback& callback) | 26 const DownloadFinishedCallback& callback) |
| 27 : callback_(callback), | 27 : callback_(callback), |
| 28 fetcher_(URLFetcher::Create(url, URLFetcher::GET, this)), | 28 fetcher_(URLFetcher::Create(url, |
| 29 URLFetcher::GET, |
| 30 this, |
| 31 NO_TRAFFIC_ANNOTATION_YET)), |
| 29 local_path_(path), | 32 local_path_(path), |
| 30 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
| 31 fetcher_->SetRequestContext(request_context); | 34 fetcher_->SetRequestContext(request_context); |
| 32 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 35 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 33 net::LOAD_DO_NOT_SAVE_COOKIES); | 36 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 34 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); | 37 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); |
| 35 fetcher_->SaveResponseToTemporaryFile( | 38 fetcher_->SaveResponseToTemporaryFile( |
| 36 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); | 39 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); |
| 37 | 40 |
| 38 if (overwrite) { | 41 if (overwrite) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 98 } |
| 96 | 99 |
| 97 void FileDownloader::OnFileMoveDone(bool success) { | 100 void FileDownloader::OnFileMoveDone(bool success) { |
| 98 if (!success) { | 101 if (!success) { |
| 99 DLOG(WARNING) << "Could not move file to " | 102 DLOG(WARNING) << "Could not move file to " |
| 100 << local_path_.LossyDisplayName(); | 103 << local_path_.LossyDisplayName(); |
| 101 } | 104 } |
| 102 | 105 |
| 103 callback_.Run(success ? DOWNLOADED : FAILED); | 106 callback_.Run(success ? DOWNLOADED : FAILED); |
| 104 } | 107 } |
| OLD | NEW |