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

Side by Side Diff: chrome/browser/safe_browsing/threat_details_cache.cc

Issue 2697193003: Network traffic annotation added to safe_browsing (Closed)
Patch Set: 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implementation of the ThreatDetails class. 5 // Implementation of the ThreatDetails class.
6 6
7 #include "chrome/browser/safe_browsing/threat_details.h" 7 #include "chrome/browser/safe_browsing/threat_details.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/browser/safe_browsing/threat_details_cache.h" 16 #include "chrome/browser/safe_browsing/threat_details_cache.h"
17 #include "chrome/common/safe_browsing/csd.pb.h" 17 #include "chrome/common/safe_browsing/csd.pb.h"
18 #include "components/data_use_measurement/core/data_use_user_data.h" 18 #include "components/data_use_measurement/core/data_use_user_data.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "net/base/host_port_pair.h" 20 #include "net/base/host_port_pair.h"
21 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
24 #include "net/traffic_annotation/network_traffic_annotation.h"
24 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
25 #include "net/url_request/url_request_context_getter.h" 26 #include "net/url_request/url_request_context_getter.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 28
28 using content::BrowserThread; 29 using content::BrowserThread;
29 30
30 // Only send small files for now, a better strategy would use the size 31 // Only send small files for now, a better strategy would use the size
31 // of the whole report and the user's bandwidth. 32 // of the whole report and the user's bandwidth.
32 static const uint32_t kMaxBodySizeBytes = 1024; 33 static const uint32_t kMaxBodySizeBytes = 1024;
33 34
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 AllDone(true); 75 AllDone(true);
75 return; 76 return;
76 } 77 }
77 78
78 if (!request_context_getter_.get()) { 79 if (!request_context_getter_.get()) {
79 DVLOG(1) << "Missing request context getter"; 80 DVLOG(1) << "Missing request context getter";
80 AllDone(false); 81 AllDone(false);
81 return; 82 return;
82 } 83 }
83 84
84 current_fetch_ = net::URLFetcher::Create(GURL(resources_it_->first), 85 // Create traffic annotation tag.
85 net::URLFetcher::GET, this); 86 net::NetworkTrafficAnnotationTag traffic_annotation =
87 net::DefineNetworkTrafficAnnotation("...", R"(
88 semantics {
89 sender: "..."
90 description: "..."
91 trigger: "..."
92 data: "..."
93 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
94 }
95 policy {
96 cookies_allowed: false/true
97 cookies_store: "..."
98 setting: "..."
99 policy {
100 [POLICY_NAME] {
101 policy_options {mode: MANDATORY/RECOMMENDED/UNSET}
102 value: ...
103 }
104 }
105 policy_exception_justification: "..."
106 })");
107
108 current_fetch_ =
109 net::URLFetcher::Create(GURL(resources_it_->first), net::URLFetcher::GET,
110 this, traffic_annotation);
86 data_use_measurement::DataUseUserData::AttachToFetcher( 111 data_use_measurement::DataUseUserData::AttachToFetcher(
87 current_fetch_.get(), 112 current_fetch_.get(),
88 data_use_measurement::DataUseUserData::SAFE_BROWSING); 113 data_use_measurement::DataUseUserData::SAFE_BROWSING);
89 current_fetch_->SetRequestContext(request_context_getter_.get()); 114 current_fetch_->SetRequestContext(request_context_getter_.get());
90 // Only from cache, and don't save cookies. 115 // Only from cache, and don't save cookies.
91 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE | 116 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE |
mattm 2017/02/18 02:23:45 Are annotations needed on LOAD_ONLY_FROM_CACHE fet
Ramin Halavati 2017/02/20 09:08:35 No, they are required for all network requests.
92 net::LOAD_SKIP_CACHE_VALIDATION | 117 net::LOAD_SKIP_CACHE_VALIDATION |
93 net::LOAD_DO_NOT_SAVE_COOKIES); 118 net::LOAD_DO_NOT_SAVE_COOKIES);
94 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries. 119 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries.
95 current_fetch_->Start(); // OnURLFetchComplete will be called when done. 120 current_fetch_->Start(); // OnURLFetchComplete will be called when done.
96 } 121 }
97 122
98 ClientSafeBrowsingReportRequest::Resource* 123 ClientSafeBrowsingReportRequest::Resource*
99 ThreatDetailsCacheCollector::GetResource(const GURL& url) { 124 ThreatDetailsCacheCollector::GetResource(const GURL& url) {
100 ResourceMap::iterator it = resources_->find(url.spec()); 125 ResourceMap::iterator it = resources_->find(url.spec());
101 if (it != resources_->end()) { 126 if (it != resources_->end()) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 229
205 void ThreatDetailsCacheCollector::AllDone(bool success) { 230 void ThreatDetailsCacheCollector::AllDone(bool success) {
206 DVLOG(1) << "AllDone"; 231 DVLOG(1) << "AllDone";
207 DCHECK_CURRENTLY_ON(BrowserThread::IO); 232 DCHECK_CURRENTLY_ON(BrowserThread::IO);
208 *result_ = success; 233 *result_ = success;
209 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); 234 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
210 callback_.Reset(); 235 callback_.Reset();
211 } 236 }
212 237
213 } // namespace safe_browsing 238 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/two_phase_uploader.cc » ('j') | chrome/browser/safe_browsing/two_phase_uploader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698