Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/browser/net/file_downloader.cc

Issue 2421333002: Protobuf for Traffic Annotation and first use by a URLFetcher. (Closed)
Patch Set: Comments addressed. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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)),
29 local_path_(path), 28 local_path_(path),
30 weak_ptr_factory_(this) { 29 weak_ptr_factory_(this) {
30 net::NetworkTrafficAnnotationTag traffic_annotation =
battre 2017/02/01 16:25:58 FileDownloader should take a net::NetworkTrafficAn
Ramin Halavati 2017/02/02 07:44:24 Done.
31 net::DefineNetworkTrafficAnnotation("", R"(
32 semantics {
33 sender: ""
34 description: ""
35 trigger: ""
36 data: ""
37 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
38 }
39 policy {
40 cookies_allowed: false/true
41 cookies_store_exceptions: ""
42 setting: ""
43 policy {
44 [POLICY_NAME] {
45 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
46 value: ...
47 }
48 }
49 })");
50 fetcher_.reset(URLFetcher::Create(url,
51 URLFetcher::GET,
52 this,
53 traffic_annotation).release());
54
31 fetcher_->SetRequestContext(request_context); 55 fetcher_->SetRequestContext(request_context);
32 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 56 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
33 net::LOAD_DO_NOT_SAVE_COOKIES); 57 net::LOAD_DO_NOT_SAVE_COOKIES);
34 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); 58 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
35 fetcher_->SaveResponseToTemporaryFile( 59 fetcher_->SaveResponseToTemporaryFile(
36 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); 60 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE));
37 61
38 if (overwrite) { 62 if (overwrite) {
39 fetcher_->Start(); 63 fetcher_->Start();
40 } else { 64 } else {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 119 }
96 120
97 void FileDownloader::OnFileMoveDone(bool success) { 121 void FileDownloader::OnFileMoveDone(bool success) {
98 if (!success) { 122 if (!success) {
99 DLOG(WARNING) << "Could not move file to " 123 DLOG(WARNING) << "Could not move file to "
100 << local_path_.LossyDisplayName(); 124 << local_path_.LossyDisplayName();
101 } 125 }
102 126
103 callback_.Run(success ? DOWNLOADED : FAILED); 127 callback_.Run(success ? DOWNLOADED : FAILED);
104 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698