Commit 49c44f6b authored by meacer's avatar meacer Committed by Commit bot

Remove unused CookiePreferences from report sender and never send cookies

All non-test callers of ReportSender use CookiePreferences::DO_NOT_SEND_COOKIES.
Remove the enum altogether.

BUG=716098

Review-Url: https://codereview.chromium.org/2851493003
Cr-Commit-Position: refs/heads/master@{#468150}
parent 10cd268f
......@@ -1039,8 +1039,8 @@ void ProfileIOData::Init(
base::SequencedWorkerPool::BLOCK_SHUTDOWN),
IsOffTheRecord()));
certificate_report_sender_.reset(new net::ReportSender(
main_request_context_.get(), net::ReportSender::DO_NOT_SEND_COOKIES));
certificate_report_sender_.reset(
new net::ReportSender(main_request_context_.get()));
transport_security_state_->SetReportSender(certificate_report_sender_.get());
expect_ct_reporter_.reset(
......
......@@ -305,15 +305,14 @@ void CertificateReportingService::ResetOnIOThread(
std::unique_ptr<certificate_reporting::ErrorReporter> error_reporter;
if (server_public_key) {
// Only used in tests.
std::unique_ptr<net::ReportSender> report_sender(new net::ReportSender(
url_request_context, net::ReportSender::DO_NOT_SEND_COOKIES));
std::unique_ptr<net::ReportSender> report_sender(
new net::ReportSender(url_request_context));
error_reporter.reset(new certificate_reporting::ErrorReporter(
GURL(kExtendedReportingUploadUrl), server_public_key,
server_public_key_version, std::move(report_sender)));
} else {
error_reporter.reset(new certificate_reporting::ErrorReporter(
url_request_context, GURL(kExtendedReportingUploadUrl),
net::ReportSender::DO_NOT_SEND_COOKIES));
url_request_context, GURL(kExtendedReportingUploadUrl)));
}
reporter_.reset(
new Reporter(std::move(error_reporter),
......
......@@ -205,8 +205,7 @@ TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_SSL_PROTOCOL_ERROR);
certificate_reporting::ErrorReporter* certificate_error_reporter =
new certificate_reporting::ErrorReporter(
url_request_context_getter()->GetURLRequestContext(), kFailureURL,
net::ReportSender::DO_NOT_SEND_COOKIES);
url_request_context_getter()->GetURLRequestContext(), kFailureURL);
CertificateReportingService::BoundedReportList* list =
new CertificateReportingService::BoundedReportList(2);
......@@ -296,8 +295,7 @@ TEST_F(CertificateReportingServiceReporterOnIOThreadTest,
net::URLRequestFailedJob::GetMockHttpsUrl(net::ERR_SSL_PROTOCOL_ERROR);
certificate_reporting::ErrorReporter* certificate_error_reporter =
new certificate_reporting::ErrorReporter(
url_request_context_getter()->GetURLRequestContext(), kFailureURL,
net::ReportSender::DO_NOT_SEND_COOKIES);
url_request_context_getter()->GetURLRequestContext(), kFailureURL);
CertificateReportingService::BoundedReportList* list =
new CertificateReportingService::BoundedReportList(2);
......
......@@ -9,8 +9,7 @@
namespace safe_browsing {
MockPermissionReportSender::MockPermissionReportSender()
: net::ReportSender(nullptr, DO_NOT_SEND_COOKIES),
number_of_reports_(0) {
: net::ReportSender(nullptr), number_of_reports_(0) {
DCHECK(quit_closure_.is_null());
}
......
......@@ -59,9 +59,8 @@ const char NotificationImageReporter::kReportingUploadUrl[] =
NotificationImageReporter::NotificationImageReporter(
net::URLRequestContext* request_context)
: NotificationImageReporter(base::MakeUnique<net::ReportSender>(
request_context,
net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) {}
: NotificationImageReporter(
base::MakeUnique<net::ReportSender>(request_context)) {}
NotificationImageReporter::NotificationImageReporter(
std::unique_ptr<net::ReportSender> report_sender)
......
......@@ -144,11 +144,8 @@ std::size_t PermissionAndOriginHash::operator()(
}
PermissionReporter::PermissionReporter(net::URLRequestContext* request_context)
: PermissionReporter(
base::MakeUnique<net::ReportSender>(
request_context,
net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES),
base::WrapUnique(new base::DefaultClock)) {}
: PermissionReporter(base::MakeUnique<net::ReportSender>(request_context),
base::WrapUnique(new base::DefaultClock)) {}
PermissionReporter::PermissionReporter(
std::unique_ptr<net::ReportSender> report_sender,
......
......@@ -116,9 +116,7 @@ void RecordUMAOnFailure(const GURL& report_uri,
ChromeExpectCTReporter::ChromeExpectCTReporter(
net::URLRequestContext* request_context)
: report_sender_(
new net::ReportSender(request_context,
net::ReportSender::DO_NOT_SEND_COOKIES)) {}
: report_sender_(new net::ReportSender(request_context)) {}
ChromeExpectCTReporter::~ChromeExpectCTReporter() {}
......
......@@ -35,8 +35,7 @@ const char kFailureHistogramName[] = "SSL.ExpectCTReportFailure2";
// serialized report to be sent.
class TestCertificateReportSender : public net::ReportSender {
public:
TestCertificateReportSender()
: ReportSender(nullptr, net::ReportSender::DO_NOT_SEND_COOKIES) {}
TestCertificateReportSender() : ReportSender(nullptr) {}
~TestCertificateReportSender() override {}
void Send(const GURL& report_uri,
......
......@@ -100,15 +100,12 @@ bool EncryptSerializedReport(const uint8_t* server_public_key,
} // namespace
ErrorReporter::ErrorReporter(
net::URLRequestContext* request_context,
const GURL& upload_url,
net::ReportSender::CookiesPreference cookies_preference)
ErrorReporter::ErrorReporter(net::URLRequestContext* request_context,
const GURL& upload_url)
: ErrorReporter(upload_url,
kServerPublicKey,
kServerPublicKeyVersion,
base::MakeUnique<net::ReportSender>(request_context,
cookies_preference)) {}
base::MakeUnique<net::ReportSender>(request_context)) {}
ErrorReporter::ErrorReporter(
const GURL& upload_url,
......
......@@ -30,11 +30,9 @@ class ErrorReporter {
public:
// Creates a certificate error reporter that will send certificate
// error reports to |upload_url|, using |request_context| as the
// context for the reports. |cookies_preference| controls whether
// cookies will be sent along with the reports.
// context for the reports.
ErrorReporter(net::URLRequestContext* request_context,
const GURL& upload_url,
net::ReportSender::CookiesPreference cookies_preference);
const GURL& upload_url);
// Allows tests to use a server public key with known private key and
// a mock ReportSender. |server_public_key| must outlive
......
......@@ -51,8 +51,7 @@ void SuccessCallback(bool* called) {
// sent.
class MockCertificateReportSender : public net::ReportSender {
public:
MockCertificateReportSender()
: net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {}
MockCertificateReportSender() : net::ReportSender(nullptr) {}
~MockCertificateReportSender() override {}
void Send(const GURL& report_uri,
......@@ -179,8 +178,7 @@ TEST_F(ErrorReporterTest, ErroredRequestCallsCallback) {
const GURL report_uri(
net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_FAILED));
ErrorReporter reporter(&context, report_uri,
net::ReportSender::DO_NOT_SEND_COOKIES);
ErrorReporter reporter(&context, report_uri);
bool error_callback_called = false;
bool success_callback_called = false;
......@@ -206,8 +204,7 @@ TEST_F(ErrorReporterTest, SuccessfulRequestCallsCallback) {
const GURL report_uri(
net::URLRequestMockDataJob::GetMockHttpUrl("some data", 1));
ErrorReporter reporter(&context, report_uri,
net::ReportSender::DO_NOT_SEND_COOKIES);
ErrorReporter reporter(&context, report_uri);
bool error_callback_called = false;
bool success_callback_called = false;
......
......@@ -363,8 +363,8 @@ void ChromeBrowserStateIOData::Init(
pool->GetSequenceToken(), base::SequencedWorkerPool::BLOCK_SHUTDOWN),
IsOffTheRecord()));
certificate_report_sender_.reset(new net::ReportSender(
main_request_context_.get(), net::ReportSender::DO_NOT_SEND_COOKIES));
certificate_report_sender_ =
base::MakeUnique<net::ReportSender>(main_request_context_.get());
transport_security_state_->SetReportSender(certificate_report_sender_.get());
// Take ownership over these parameters.
......
......@@ -41,10 +41,8 @@ class CallbackInfo : public base::SupportsUserData::Data {
namespace net {
ReportSender::ReportSender(URLRequestContext* request_context,
CookiesPreference cookies_preference)
: request_context_(request_context),
cookies_preference_(cookies_preference) {}
ReportSender::ReportSender(URLRequestContext* request_context)
: request_context_(request_context) {}
ReportSender::~ReportSender() {
}
......@@ -61,12 +59,9 @@ void ReportSender::Send(const GURL& report_uri,
&kUserDataKey,
base::MakeUnique<CallbackInfo>(success_callback, error_callback));
int load_flags =
LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA;
if (cookies_preference_ != SEND_COOKIES) {
load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
}
url_request->SetLoadFlags(load_flags);
url_request->SetLoadFlags(
LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA |
LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES);
HttpRequestHeaders extra_headers;
extra_headers.SetHeader(HttpRequestHeaders::kContentType, content_type);
......
......@@ -34,15 +34,10 @@ class NET_EXPORT ReportSender
using ErrorCallback = base::Callback<
void(const GURL&, int /* net_error */, int /* http_response_code */)>;
// Represents whether or not to send cookies along with reports.
enum CookiesPreference { SEND_COOKIES, DO_NOT_SEND_COOKIES };
// Constructs a ReportSender that sends reports with the
// given |request_context| and includes or excludes cookies based on
// |cookies_preference|. |request_context| must outlive the
// ReportSender.
ReportSender(URLRequestContext* request_context,
CookiesPreference cookies_preference);
// given |request_context|, always excluding cookies. |request_context| must
// outlive the ReportSender.
explicit ReportSender(URLRequestContext* request_context);
~ReportSender() override;
......@@ -59,9 +54,6 @@ class NET_EXPORT ReportSender
private:
net::URLRequestContext* const request_context_;
CookiesPreference cookies_preference_;
std::map<URLRequest*, std::unique_ptr<URLRequest>> inflight_requests_;
DISALLOW_COPY_AND_ASSIGN(ReportSender);
......
......@@ -120,8 +120,7 @@ class TestReportSenderNetworkDelegate : public NetworkDelegateImpl {
TestReportSenderNetworkDelegate()
: url_request_destroyed_callback_(base::Bind(&base::DoNothing)),
all_url_requests_destroyed_callback_(base::Bind(&base::DoNothing)),
num_requests_(0),
expect_cookies_(false) {}
num_requests_(0) {}
void ExpectReport(const std::string& report) {
expect_reports_.insert(report);
......@@ -139,11 +138,6 @@ class TestReportSenderNetworkDelegate : public NetworkDelegateImpl {
size_t num_requests() const { return num_requests_; }
// Sets whether cookies are expected to be sent on requests.
void set_expect_cookies(bool expect_cookies) {
expect_cookies_ = expect_cookies;
}
void set_expected_content_type(const std::string& content_type) {
expected_content_type_ = content_type;
}
......@@ -155,14 +149,8 @@ class TestReportSenderNetworkDelegate : public NetworkDelegateImpl {
num_requests_++;
EXPECT_EQ(expect_url_, request->url());
EXPECT_STRCASEEQ("POST", request->method().data());
if (expect_cookies_) {
EXPECT_FALSE(request->load_flags() & LOAD_DO_NOT_SEND_COOKIES);
EXPECT_FALSE(request->load_flags() & LOAD_DO_NOT_SAVE_COOKIES);
} else {
EXPECT_TRUE(request->load_flags() & LOAD_DO_NOT_SEND_COOKIES);
EXPECT_TRUE(request->load_flags() & LOAD_DO_NOT_SAVE_COOKIES);
}
EXPECT_TRUE(request->load_flags() & LOAD_DO_NOT_SEND_COOKIES);
EXPECT_TRUE(request->load_flags() & LOAD_DO_NOT_SAVE_COOKIES);
const HttpRequestHeaders& extra_headers = request->extra_request_headers();
std::string content_type;
......@@ -189,7 +177,6 @@ class TestReportSenderNetworkDelegate : public NetworkDelegateImpl {
size_t num_requests_;
GURL expect_url_;
std::set<std::string> expect_reports_;
bool expect_cookies_;
std::string expected_content_type_;
DISALLOW_COPY_AND_ASSIGN(TestReportSenderNetworkDelegate);
......@@ -263,13 +250,13 @@ class ReportSenderTest : public ::testing::Test {
// endpoint and sends the expected data.
TEST_F(ReportSenderTest, SendsRequest) {
GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
SendReport(&reporter, kDummyReport, url, 0);
}
TEST_F(ReportSenderTest, SendMultipleReportsSequentially) {
GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
SendReport(&reporter, kDummyReport, url, 0);
SendReport(&reporter, kDummyReport, url, 1);
}
......@@ -285,7 +272,7 @@ TEST_F(ReportSenderTest, SendMultipleReportsSimultaneously) {
network_delegate_.ExpectReport(kSecondDummyReport);
network_delegate_.set_expected_content_type("application/foobar");
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
EXPECT_EQ(0u, network_delegate_.num_requests());
......@@ -316,8 +303,7 @@ TEST_F(ReportSenderTest, PendingRequestGetsDeleted) {
EXPECT_EQ(0u, network_delegate_.num_requests());
std::unique_ptr<ReportSender> reporter(
new ReportSender(context(), ReportSender::DO_NOT_SEND_COOKIES));
std::unique_ptr<ReportSender> reporter(new ReportSender(context()));
reporter->Send(url, "application/foobar", kDummyReport,
base::Callback<void()>(),
base::Callback<void(const GURL&, int, int)>());
......@@ -330,7 +316,7 @@ TEST_F(ReportSenderTest, PendingRequestGetsDeleted) {
// Test that a request that returns an error gets cleaned up.
TEST_F(ReportSenderTest, ErroredRequestGetsDeleted) {
GURL url = URLRequestFailedJob::GetMockHttpsUrl(ERR_FAILED);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
// SendReport will block until the URLRequest is destroyed.
SendReport(&reporter, kDummyReport, url, 0);
}
......@@ -341,7 +327,7 @@ TEST_F(ReportSenderTest, ErroredRequestCallsErrorCallback) {
bool error_callback_called = false;
bool success_callback_called = false;
const GURL url = URLRequestFailedJob::GetMockHttpsUrl(ERR_FAILED);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
// SendReport will block until the URLRequest is destroyed.
SendReport(&reporter, kDummyReport, url, 0,
base::Bind(SuccessCallback, &success_callback_called),
......@@ -357,7 +343,7 @@ TEST_F(ReportSenderTest, BadResponseCodeCallsErrorCallback) {
bool error_callback_called = false;
bool success_callback_called = false;
const GURL url(std::string("http://") + kServerErrorHostname);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
// SendReport will block until the URLRequest is destroyed.
SendReport(&reporter, kDummyReport, url, 0,
base::Bind(SuccessCallback, &success_callback_called),
......@@ -372,7 +358,7 @@ TEST_F(ReportSenderTest, SuccessfulRequestCallsSuccessCallback) {
bool error_callback_called = false;
bool success_callback_called = false;
const GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
ReportSender reporter(context());
SendReport(&reporter, kDummyReport, url, 0,
base::Bind(SuccessCallback, &success_callback_called),
base::Bind(ErrorCallback, &error_callback_called));
......@@ -380,24 +366,5 @@ TEST_F(ReportSenderTest, SuccessfulRequestCallsSuccessCallback) {
EXPECT_TRUE(success_callback_called);
}
// Test that cookies are sent or not sent according to the error
// reporter's cookies preference.
TEST_F(ReportSenderTest, SendCookiesPreference) {
GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
ReportSender reporter(context(), ReportSender::SEND_COOKIES);
network_delegate_.set_expect_cookies(true);
SendReport(&reporter, kDummyReport, url, 0);
}
TEST_F(ReportSenderTest, DoNotSendCookiesPreference) {
GURL url = URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
ReportSender reporter(context(), ReportSender::DO_NOT_SEND_COOKIES);
network_delegate_.set_expect_cookies(false);
SendReport(&reporter, kDummyReport, url, 0);
}
} // namespace
} // namespace net
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