Commit 70960300 authored by rhalavati's avatar rhalavati Committed by Commit bot

Network traffic annotation added to safe_browsing.

Network traffic annotation added to four files in Safe Browsing.

BUG=656607

Review-Url: https://codereview.chromium.org/2697193003
Cr-Commit-Position: refs/heads/master@{#455737}
parent d0242a5f
...@@ -128,12 +128,48 @@ void DownloadFeedbackImpl::Start(const base::Closure& finish_callback) { ...@@ -128,12 +128,48 @@ void DownloadFeedbackImpl::Start(const base::Closure& finish_callback) {
std::string metadata_string; std::string metadata_string;
bool ok = report_metadata.SerializeToString(&metadata_string); bool ok = report_metadata.SerializeToString(&metadata_string);
DCHECK(ok); DCHECK(ok);
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("safe_browsing_feedback", R"(
semantics {
sender: "Safe Browsing Download Protection Feedback"
description:
"When a user downloads a binary that Safe Browsing declares as "
"suspicious, opted-in clients may upload that binary to Safe "
"Browsing to improve the classification. This helps protect users "
"from malware and unwanted software."
trigger:
"The browser will upload the binary to Google when a "
"download-protection verdict is 'Not Safe', and the user is opted "
"in to extended reporting."
data:
"The suspicious binary file."
destination: GOOGLE_OWNED_SERVICE
}
policy {
cookies_allowed: true
cookies_store: "Safe Browsing Cookie Store"
setting:
"Users can enable or disable this feature by stopping sending "
"security incident reports to Google via disabling 'Automatically "
"report details of possible security incidents to Google.' in "
"Chrome's settings under Advanced Settings, Privacy. The feature "
"is disabled by default."
chrome_policy {
SafeBrowsingExtendedReportingOptInAllowed {
policy_options {mode: MANDATORY}
SafeBrowsingExtendedReportingOptInAllowed: false
}
}
})");
uploader_ = TwoPhaseUploader::Create( uploader_ = TwoPhaseUploader::Create(
request_context_getter_.get(), file_task_runner_.get(), request_context_getter_.get(), file_task_runner_.get(),
GURL(kSbFeedbackURL), metadata_string, file_path_, GURL(kSbFeedbackURL), metadata_string, file_path_,
TwoPhaseUploader::ProgressCallback(), TwoPhaseUploader::ProgressCallback(),
base::Bind(&DownloadFeedbackImpl::FinishedUpload, base::Unretained(this), base::Bind(&DownloadFeedbackImpl::FinishedUpload, base::Unretained(this),
finish_callback)); finish_callback),
traffic_annotation);
uploader_->Start(); uploader_->Start();
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/common/safe_browsing/csd.pb.h" #include "chrome/common/safe_browsing/csd.pb.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -75,7 +76,8 @@ class FakeUploaderFactory : public TwoPhaseUploaderFactory { ...@@ -75,7 +76,8 @@ class FakeUploaderFactory : public TwoPhaseUploaderFactory {
const std::string& metadata, const std::string& metadata,
const base::FilePath& file_path, const base::FilePath& file_path,
const TwoPhaseUploader::ProgressCallback& progress_callback, const TwoPhaseUploader::ProgressCallback& progress_callback,
const TwoPhaseUploader::FinishCallback& finish_callback) override; const TwoPhaseUploader::FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) override;
FakeUploader* uploader_; FakeUploader* uploader_;
}; };
...@@ -87,7 +89,8 @@ std::unique_ptr<TwoPhaseUploader> FakeUploaderFactory::CreateTwoPhaseUploader( ...@@ -87,7 +89,8 @@ std::unique_ptr<TwoPhaseUploader> FakeUploaderFactory::CreateTwoPhaseUploader(
const std::string& metadata, const std::string& metadata,
const base::FilePath& file_path, const base::FilePath& file_path,
const TwoPhaseUploader::ProgressCallback& progress_callback, const TwoPhaseUploader::ProgressCallback& progress_callback,
const TwoPhaseUploader::FinishCallback& finish_callback) { const TwoPhaseUploader::FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) {
EXPECT_FALSE(uploader_); EXPECT_FALSE(uploader_);
uploader_ = new FakeUploader(url_request_context_getter, file_task_runner, uploader_ = new FakeUploader(url_request_context_getter, file_task_runner,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h" #include "net/url_request/url_request_status.h"
...@@ -81,8 +82,38 @@ void ThreatDetailsCacheCollector::OpenEntry() { ...@@ -81,8 +82,38 @@ void ThreatDetailsCacheCollector::OpenEntry() {
return; return;
} }
current_fetch_ = net::URLFetcher::Create(GURL(resources_it_->first), net::NetworkTrafficAnnotationTag traffic_annotation =
net::URLFetcher::GET, this); net::DefineNetworkTrafficAnnotation("safe_browsing_cache_collector", R"(
semantics {
sender: "Threat Details Cache Collector"
description:
"This request fetches different items from safe browsing cache "
"and DOES NOT make an actual network request."
trigger:
"When safe browsing extended report is collecting data."
data:
"None"
destination: OTHER
}
policy {
cookies_allowed: false
setting:
"Users can enable or disable this feature by stopping sending "
"security incident reports to Google via disabling 'Automatically "
"report details of possible security incdients to Google.' in "
"Chrome's settings under Advanced Settings, Privacy. The feature "
"is disabled by default."
chrome_policy {
SafeBrowsingExtendedReportingOptInAllowed {
policy_options {mode: MANDATORY}
SafeBrowsingExtendedReportingOptInAllowed: false
}
}
})");
current_fetch_ =
net::URLFetcher::Create(GURL(resources_it_->first), net::URLFetcher::GET,
this, traffic_annotation);
data_use_measurement::DataUseUserData::AttachToFetcher( data_use_measurement::DataUseUserData::AttachToFetcher(
current_fetch_.get(), current_fetch_.get(),
data_use_measurement::DataUseUserData::SAFE_BROWSING); data_use_measurement::DataUseUserData::SAFE_BROWSING);
......
...@@ -33,13 +33,15 @@ const char kUploadContentType[] = "application/octet-stream"; ...@@ -33,13 +33,15 @@ const char kUploadContentType[] = "application/octet-stream";
class TwoPhaseUploaderImpl : public net::URLFetcherDelegate, class TwoPhaseUploaderImpl : public net::URLFetcherDelegate,
public TwoPhaseUploader { public TwoPhaseUploader {
public: public:
TwoPhaseUploaderImpl(net::URLRequestContextGetter* url_request_context_getter, TwoPhaseUploaderImpl(
base::TaskRunner* file_task_runner, net::URLRequestContextGetter* url_request_context_getter,
const GURL& base_url, base::TaskRunner* file_task_runner,
const std::string& metadata, const GURL& base_url,
const base::FilePath& file_path, const std::string& metadata,
const ProgressCallback& progress_callback, const base::FilePath& file_path,
const FinishCallback& finish_callback); const ProgressCallback& progress_callback,
const FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation);
~TwoPhaseUploaderImpl() override; ~TwoPhaseUploaderImpl() override;
// Begins the upload process. // Begins the upload process.
...@@ -65,6 +67,7 @@ class TwoPhaseUploaderImpl : public net::URLFetcherDelegate, ...@@ -65,6 +67,7 @@ class TwoPhaseUploaderImpl : public net::URLFetcherDelegate,
const base::FilePath file_path_; const base::FilePath file_path_;
ProgressCallback progress_callback_; ProgressCallback progress_callback_;
FinishCallback finish_callback_; FinishCallback finish_callback_;
net::NetworkTrafficAnnotationTag traffic_annotation_;
std::unique_ptr<net::URLFetcher> url_fetcher_; std::unique_ptr<net::URLFetcher> url_fetcher_;
...@@ -78,7 +81,8 @@ TwoPhaseUploaderImpl::TwoPhaseUploaderImpl( ...@@ -78,7 +81,8 @@ TwoPhaseUploaderImpl::TwoPhaseUploaderImpl(
const std::string& metadata, const std::string& metadata,
const base::FilePath& file_path, const base::FilePath& file_path,
const ProgressCallback& progress_callback, const ProgressCallback& progress_callback,
const FinishCallback& finish_callback) const FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation)
: state_(STATE_NONE), : state_(STATE_NONE),
url_request_context_getter_(url_request_context_getter), url_request_context_getter_(url_request_context_getter),
file_task_runner_(file_task_runner), file_task_runner_(file_task_runner),
...@@ -86,7 +90,8 @@ TwoPhaseUploaderImpl::TwoPhaseUploaderImpl( ...@@ -86,7 +90,8 @@ TwoPhaseUploaderImpl::TwoPhaseUploaderImpl(
metadata_(metadata), metadata_(metadata),
file_path_(file_path), file_path_(file_path),
progress_callback_(progress_callback), progress_callback_(progress_callback),
finish_callback_(finish_callback) { finish_callback_(finish_callback),
traffic_annotation_(traffic_annotation) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
} }
...@@ -168,8 +173,9 @@ void TwoPhaseUploaderImpl::OnURLFetchUploadProgress( ...@@ -168,8 +173,9 @@ void TwoPhaseUploaderImpl::OnURLFetchUploadProgress(
void TwoPhaseUploaderImpl::UploadMetadata() { void TwoPhaseUploaderImpl::UploadMetadata() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
state_ = UPLOAD_METADATA; state_ = UPLOAD_METADATA;
url_fetcher_ = url_fetcher_ = net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this,
net::URLFetcher::Create(base_url_, net::URLFetcher::POST, this); traffic_annotation_);
data_use_measurement::DataUseUserData::AttachToFetcher( data_use_measurement::DataUseUserData::AttachToFetcher(
url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
url_fetcher_->SetRequestContext(url_request_context_getter_.get()); url_fetcher_->SetRequestContext(url_request_context_getter_.get());
...@@ -182,8 +188,8 @@ void TwoPhaseUploaderImpl::UploadFile() { ...@@ -182,8 +188,8 @@ void TwoPhaseUploaderImpl::UploadFile() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
state_ = UPLOAD_FILE; state_ = UPLOAD_FILE;
url_fetcher_ = url_fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT,
net::URLFetcher::Create(upload_url_, net::URLFetcher::PUT, this); this, traffic_annotation_);
data_use_measurement::DataUseUserData::AttachToFetcher( data_use_measurement::DataUseUserData::AttachToFetcher(
url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); url_fetcher_.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
url_fetcher_->SetRequestContext(url_request_context_getter_.get()); url_fetcher_->SetRequestContext(url_request_context_getter_.get());
...@@ -213,13 +219,14 @@ std::unique_ptr<TwoPhaseUploader> TwoPhaseUploader::Create( ...@@ -213,13 +219,14 @@ std::unique_ptr<TwoPhaseUploader> TwoPhaseUploader::Create(
const std::string& metadata, const std::string& metadata,
const base::FilePath& file_path, const base::FilePath& file_path,
const ProgressCallback& progress_callback, const ProgressCallback& progress_callback,
const FinishCallback& finish_callback) { const FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) {
if (!factory_) { if (!factory_) {
return base::WrapUnique(new TwoPhaseUploaderImpl( return base::WrapUnique(new TwoPhaseUploaderImpl(
url_request_context_getter, file_task_runner, base_url, metadata, url_request_context_getter, file_task_runner, base_url, metadata,
file_path, progress_callback, finish_callback)); file_path, progress_callback, finish_callback, traffic_annotation));
} }
return TwoPhaseUploader::factory_->CreateTwoPhaseUploader( return TwoPhaseUploader::factory_->CreateTwoPhaseUploader(
url_request_context_getter, file_task_runner, base_url, metadata, url_request_context_getter, file_task_runner, base_url, metadata,
file_path, progress_callback, finish_callback); file_path, progress_callback, finish_callback, traffic_annotation);
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -69,7 +70,8 @@ class TwoPhaseUploader { ...@@ -69,7 +70,8 @@ class TwoPhaseUploader {
const std::string& metadata, const std::string& metadata,
const base::FilePath& file_path, const base::FilePath& file_path,
const ProgressCallback& progress_callback, const ProgressCallback& progress_callback,
const FinishCallback& finish_callback); const FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation);
// Makes the passed |factory| the factory used to instantiate // Makes the passed |factory| the factory used to instantiate
// a TwoPhaseUploader. Useful for tests. // a TwoPhaseUploader. Useful for tests.
...@@ -97,7 +99,8 @@ class TwoPhaseUploaderFactory { ...@@ -97,7 +99,8 @@ class TwoPhaseUploaderFactory {
const std::string& metadata, const std::string& metadata,
const base::FilePath& file_path, const base::FilePath& file_path,
const TwoPhaseUploader::ProgressCallback& progress_callback, const TwoPhaseUploader::ProgressCallback& progress_callback,
const TwoPhaseUploader::FinishCallback& finish_callback) = 0; const TwoPhaseUploader::FinishCallback& finish_callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) = 0;
}; };
#endif // CHROME_BROWSER_SAFE_BROWSING_TWO_PHASE_UPLOADER_H_ #endif // CHROME_BROWSER_SAFE_BROWSING_TWO_PHASE_UPLOADER_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -84,7 +85,8 @@ TEST_F(TwoPhaseUploaderTest, UploadFile) { ...@@ -84,7 +85,8 @@ TEST_F(TwoPhaseUploaderTest, UploadFile) {
test_server.GetURL("start"), "metadata", GetTestFilePath(), test_server.GetURL("start"), "metadata", GetTestFilePath(),
base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)),
base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate), base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate),
runner))); runner),
TRAFFIC_ANNOTATION_FOR_TESTS));
uploader->Start(); uploader->Start();
runner->Run(); runner->Run();
EXPECT_EQ(TwoPhaseUploader::STATE_SUCCESS, delegate.state_); EXPECT_EQ(TwoPhaseUploader::STATE_SUCCESS, delegate.state_);
...@@ -108,7 +110,8 @@ TEST_F(TwoPhaseUploaderTest, BadPhaseOneResponse) { ...@@ -108,7 +110,8 @@ TEST_F(TwoPhaseUploaderTest, BadPhaseOneResponse) {
test_server.GetURL("start?p1code=500"), "metadata", GetTestFilePath(), test_server.GetURL("start?p1code=500"), "metadata", GetTestFilePath(),
base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)),
base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate), base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate),
runner))); runner),
TRAFFIC_ANNOTATION_FOR_TESTS));
uploader->Start(); uploader->Start();
runner->Run(); runner->Run();
EXPECT_EQ(TwoPhaseUploader::UPLOAD_METADATA, delegate.state_); EXPECT_EQ(TwoPhaseUploader::UPLOAD_METADATA, delegate.state_);
...@@ -128,7 +131,8 @@ TEST_F(TwoPhaseUploaderTest, BadPhaseTwoResponse) { ...@@ -128,7 +131,8 @@ TEST_F(TwoPhaseUploaderTest, BadPhaseTwoResponse) {
test_server.GetURL("start?p2code=500"), "metadata", GetTestFilePath(), test_server.GetURL("start?p2code=500"), "metadata", GetTestFilePath(),
base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)),
base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate), base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate),
runner))); runner),
TRAFFIC_ANNOTATION_FOR_TESTS));
uploader->Start(); uploader->Start();
runner->Run(); runner->Run();
EXPECT_EQ(TwoPhaseUploader::UPLOAD_FILE, delegate.state_); EXPECT_EQ(TwoPhaseUploader::UPLOAD_FILE, delegate.state_);
...@@ -152,7 +156,8 @@ TEST_F(TwoPhaseUploaderTest, PhaseOneConnectionClosed) { ...@@ -152,7 +156,8 @@ TEST_F(TwoPhaseUploaderTest, PhaseOneConnectionClosed) {
test_server.GetURL("start?p1close=1"), "metadata", GetTestFilePath(), test_server.GetURL("start?p1close=1"), "metadata", GetTestFilePath(),
base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)),
base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate), base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate),
runner))); runner),
TRAFFIC_ANNOTATION_FOR_TESTS));
uploader->Start(); uploader->Start();
runner->Run(); runner->Run();
EXPECT_EQ(TwoPhaseUploader::UPLOAD_METADATA, delegate.state_); EXPECT_EQ(TwoPhaseUploader::UPLOAD_METADATA, delegate.state_);
...@@ -172,7 +177,8 @@ TEST_F(TwoPhaseUploaderTest, PhaseTwoConnectionClosed) { ...@@ -172,7 +177,8 @@ TEST_F(TwoPhaseUploaderTest, PhaseTwoConnectionClosed) {
test_server.GetURL("start?p2close=1"), "metadata", GetTestFilePath(), test_server.GetURL("start?p2close=1"), "metadata", GetTestFilePath(),
base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)), base::Bind(&Delegate::ProgressCallback, base::Unretained(&delegate)),
base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate), base::Bind(&Delegate::FinishCallback, base::Unretained(&delegate),
runner))); runner),
TRAFFIC_ANNOTATION_FOR_TESTS));
uploader->Start(); uploader->Start();
runner->Run(); runner->Run();
EXPECT_EQ(TwoPhaseUploader::UPLOAD_FILE, delegate.state_); EXPECT_EQ(TwoPhaseUploader::UPLOAD_FILE, delegate.state_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment