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

Unified Diff: net/url_request/url_request_http_job.cc

Issue 10702137: Replaced static URLRequestHTTPJob factory with non-static protocol handler for HTTP jobs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes requested in comments Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_request_http_job.cc
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 718b4542d4790836675ce642c19050584cb5c5e3..d592f16d7849f4a5409ce64b96179850dc272f3d 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -134,8 +134,7 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
const std::string& scheme) {
DCHECK(scheme == "http" || scheme == "https");
- if (!request->context() ||
- !request->context()->http_transaction_factory()) {
+ if (!request->context()->http_transaction_factory()) {
NOTREACHED() << "requires a valid context";
return new URLRequestErrorJob(request, ERR_INVALID_ARGUMENT);
}
@@ -143,12 +142,32 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
GURL redirect_url;
if (request->GetHSTSRedirect(&redirect_url))
return new URLRequestRedirectJob(request, redirect_url);
- return new URLRequestHttpJob(request);
-}
-
-
-URLRequestHttpJob::URLRequestHttpJob(URLRequest* request)
- : URLRequestJob(request, request->context()->network_delegate()),
+ return new URLRequestHttpJob(
+ request,
+ request->context()->http_transaction_factory(),
+ request->context()->network_delegate(),
+ request->context()->throttler_manager(),
+ request->context()->accept_language(),
+ request->context()->accept_charset(),
+ request->context()->cookie_store(),
+ request->context()->fraudulent_certificate_reporter(),
+ request->context()->ssl_config_service(),
+ request->context()->transport_security_state());
+}
+
+
+URLRequestHttpJob::URLRequestHttpJob(
+ URLRequest* request,
+ HttpTransactionFactory* http_transaction_factory,
+ NetworkDelegate* network_delegate,
+ URLRequestThrottlerManager* throttler_manager,
+ const std::string& accept_language,
+ const std::string& accept_charset,
+ CookieStore* cookie_store,
+ FraudulentCertificateReporter* fraudulent_certificate_reporter,
+ SSLConfigService* ssl_config_service,
+ TransportSecurityState* transport_security_state)
+ : URLRequestJob(request, network_delegate),
response_info_(NULL),
response_cookies_save_index_(0),
proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
@@ -178,10 +197,18 @@ URLRequestHttpJob::URLRequestHttpJob(URLRequest* request)
ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_(
base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback,
base::Unretained(this)))),
- awaiting_callback_(false) {
- URLRequestThrottlerManager* manager = request->context()->throttler_manager();
- if (manager)
- throttling_entry_ = manager->RegisterRequestUrl(request->url());
+ awaiting_callback_(false),
+ http_transaction_factory_(http_transaction_factory),
+ network_delegate_(network_delegate),
+ accept_language_(accept_language),
+ accept_charset_(accept_charset),
+ cookie_store_(cookie_store),
+ fraudulent_certificate_reporter_(fraudulent_certificate_reporter),
+ ssl_config_service_(ssl_config_service),
+ transport_security_state_(transport_security_state) {
+ DCHECK(http_transaction_factory_);
+ if (throttler_manager)
+ throttling_entry_ = throttler_manager->RegisterRequestUrl(request->url());
ResetTimer();
}
@@ -255,8 +282,8 @@ void URLRequestHttpJob::DestroyTransaction() {
}
void URLRequestHttpJob::StartTransaction() {
- if (request_->context() && request_->context()->network_delegate()) {
- int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders(
+ if (network_delegate_) {
+ int rv = network_delegate_->NotifyBeforeSendHeaders(
request_, notify_before_headers_sent_callback_,
&request_info_.extra_headers);
// If an extension blocks the request, we rely on the callback to
@@ -293,20 +320,14 @@ void URLRequestHttpJob::StartTransactionInternal() {
int rv;
- if (request_->context() && request_->context()->network_delegate()) {
- request_->context()->network_delegate()->NotifySendHeaders(
- request_, request_info_.extra_headers);
- }
+ if (network_delegate_)
+ network_delegate_->NotifySendHeaders(request_, request_info_.extra_headers);
if (transaction_.get()) {
rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_);
auth_credentials_ = AuthCredentials();
} else {
- DCHECK(request_->context());
- DCHECK(request_->context()->http_transaction_factory());
-
- rv = request_->context()->http_transaction_factory()->CreateTransaction(
- &transaction_);
+ rv = http_transaction_factory_->CreateTransaction(&transaction_);
if (rv == OK) {
if (!throttling_entry_ ||
!throttling_entry_->ShouldRejectRequest(*request_)) {
@@ -395,20 +416,17 @@ void URLRequestHttpJob::AddExtraHeaders() {
}
}
- const URLRequestContext* context = request_->context();
- if (context) {
- // Only add default Accept-Language and Accept-Charset if the request
- // didn't have them specified.
- if (!context->accept_language().empty()) {
- request_info_.extra_headers.SetHeaderIfMissing(
- HttpRequestHeaders::kAcceptLanguage,
- context->accept_language());
- }
- if (!context->accept_charset().empty()) {
- request_info_.extra_headers.SetHeaderIfMissing(
- HttpRequestHeaders::kAcceptCharset,
- context->accept_charset());
- }
+ // Only add default Accept-Language and Accept-Charset if the request
+ // didn't have them specified.
+ if (!accept_language_.empty()) {
+ request_info_.extra_headers.SetHeaderIfMissing(
+ HttpRequestHeaders::kAcceptLanguage,
+ accept_language_);
+ }
+ if (!accept_charset_.empty()) {
+ request_info_.extra_headers.SetHeaderIfMissing(
+ HttpRequestHeaders::kAcceptCharset,
+ accept_charset_);
}
}
@@ -421,10 +439,8 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
if (!request_)
return;
- CookieStore* cookie_store =
- request_->context()->cookie_store();
- if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
- net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
+ if (cookie_store_ && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
+ net::CookieMonster* cookie_monster = cookie_store_->GetCookieMonster();
if (cookie_monster) {
cookie_monster->GetAllCookiesForURLAsync(
request_->url(),
@@ -441,7 +457,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
void URLRequestHttpJob::DoLoadCookies() {
CookieOptions options;
options.set_include_httponly();
- request_->context()->cookie_store()->GetCookiesWithInfoAsync(
+ cookie_store_->GetCookiesWithInfoAsync(
request_->url(), options,
base::Bind(&URLRequestHttpJob::OnCookiesLoaded,
weak_factory_.GetWeakPtr()));
@@ -518,7 +534,7 @@ void URLRequestHttpJob::SaveNextCookie() {
new SharedBoolean(true);
if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) &&
- request_->context()->cookie_store() &&
+ cookie_store_ &&
response_cookies_.size() > 0) {
CookieOptions options;
options.set_include_httponly();
@@ -537,7 +553,7 @@ void URLRequestHttpJob::SaveNextCookie() {
if (CanSetCookie(
response_cookies_[response_cookies_save_index_], &options)) {
callback_pending->data = true;
- request_->context()->cookie_store()->SetCookieWithOptionsAsync(
+ cookie_store_->SetCookieWithOptionsAsync(
request_->url(), response_cookies_[response_cookies_save_index_],
options, callback);
}
@@ -605,27 +621,27 @@ void URLRequestHttpJob::FetchResponseCookies(
void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() {
DCHECK(response_info_);
- const URLRequestContext* ctx = request_->context();
const SSLInfo& ssl_info = response_info_->ssl_info;
// Only accept strict transport security headers on HTTPS connections that
// have no certificate errors.
if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) ||
- !ctx || !ctx->transport_security_state()) {
+ !transport_security_state_) {
return;
}
- TransportSecurityState* security_state = ctx->transport_security_state();
TransportSecurityState::DomainState domain_state;
const std::string& host = request_info_.url.host();
bool sni_available =
- SSLConfigService::IsSNIAvailable(ctx->ssl_config_service());
- if (!security_state->GetDomainState(host, sni_available, &domain_state))
+ SSLConfigService::IsSNIAvailable(ssl_config_service_);
+ if (!transport_security_state_->GetDomainState(
+ host, sni_available, &domain_state)) {
// |GetDomainState| may have altered |domain_state| while searching. If
// not found, start with a fresh state.
domain_state.upgrade_mode =
TransportSecurityState::DomainState::MODE_FORCE_HTTPS;
+ }
HttpResponseHeaders* headers = GetResponseHeaders();
std::string value;
@@ -635,34 +651,34 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() {
while (headers->EnumerateHeader(&iter, "Strict-Transport-Security", &value)) {
TransportSecurityState::DomainState domain_state;
if (domain_state.ParseSTSHeader(now, value))
- security_state->EnableHost(host, domain_state);
+ transport_security_state_->EnableHost(host, domain_state);
}
}
void URLRequestHttpJob::ProcessPublicKeyPinsHeader() {
DCHECK(response_info_);
- const URLRequestContext* ctx = request_->context();
const SSLInfo& ssl_info = response_info_->ssl_info;
// Only accept public key pins headers on HTTPS connections that have no
// certificate errors.
if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) ||
- !ctx || !ctx->transport_security_state()) {
+ !transport_security_state_) {
return;
}
- TransportSecurityState* security_state = ctx->transport_security_state();
TransportSecurityState::DomainState domain_state;
const std::string& host = request_info_.url.host();
bool sni_available =
- SSLConfigService::IsSNIAvailable(ctx->ssl_config_service());
- if (!security_state->GetDomainState(host, sni_available, &domain_state))
+ SSLConfigService::IsSNIAvailable(ssl_config_service_);
+ if (!transport_security_state_->GetDomainState(
+ host, sni_available, &domain_state)) {
// |GetDomainState| may have altered |domain_state| while searching. If
// not found, start with a fresh state.
domain_state.upgrade_mode =
TransportSecurityState::DomainState::MODE_DEFAULT;
+ }
HttpResponseHeaders* headers = GetResponseHeaders();
void* iter = NULL;
@@ -674,7 +690,7 @@ void URLRequestHttpJob::ProcessPublicKeyPinsHeader() {
// correctly), but does not completely overwrite it. It just updates the
// dynamic pinning metadata.
if (domain_state.ParsePinsHeader(now, value, ssl_info))
- security_state->EnableHost(host, domain_state);
+ transport_security_state_->EnableHost(host, domain_state);
}
}
@@ -693,29 +709,26 @@ void URLRequestHttpJob::OnStartCompleted(int result) {
// Clear the IO_PENDING status
SetStatus(URLRequestStatus());
- const URLRequestContext* context = request_->context();
-
if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN &&
transaction_->GetResponseInfo() != NULL) {
- FraudulentCertificateReporter* reporter =
- context->fraudulent_certificate_reporter();
- if (reporter != NULL) {
+ if (fraudulent_certificate_reporter_) {
const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info;
bool sni_available = SSLConfigService::IsSNIAvailable(
- context->ssl_config_service());
+ ssl_config_service_);
const std::string& host = request_->url().host();
- reporter->SendReport(host, ssl_info, sni_available);
+ fraudulent_certificate_reporter_->SendReport(
+ host, ssl_info, sni_available);
}
}
if (result == OK) {
scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders();
- if (context && context->network_delegate()) {
+ if (network_delegate_) {
// Note that |this| may not be deleted until
// |on_headers_received_callback_| or
// |NetworkDelegate::URLRequestDestroyed()| has been called.
- int error = context->network_delegate()->
+ int error = network_delegate_->
NotifyHeadersReceived(request_, on_headers_received_callback_,
headers, &override_response_headers_);
if (error != net::OK) {
@@ -740,12 +753,11 @@ void URLRequestHttpJob::OnStartCompleted(int result) {
// what we should do.
TransportSecurityState::DomainState domain_state;
- const URLRequestContext* context = request_->context();
const bool fatal =
- context->transport_security_state() &&
- context->transport_security_state()->GetDomainState(
+ transport_security_state_ &&
+ transport_security_state_->GetDomainState(
request_info_.url.host(),
- SSLConfigService::IsSNIAvailable(context->ssl_config_service()),
+ SSLConfigService::IsSNIAvailable(ssl_config_service_),
&domain_state);
NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal);
} else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
@@ -837,11 +849,10 @@ void URLRequestHttpJob::Start() {
referrer.spec());
}
- if (request_->context()) {
- request_info_.extra_headers.SetHeaderIfMissing(
- HttpRequestHeaders::kUserAgent,
- request_->context()->GetUserAgent(request_->url()));
- }
+ // TODO(shalev): Fix this to not go through URLRequestContext.
+ request_info_.extra_headers.SetHeaderIfMissing(
+ HttpRequestHeaders::kUserAgent,
+ request_->context()->GetUserAgent(request_->url()));
AddExtraHeaders();
AddCookieHeaderAndStart();
« net/url_request/http_protocol_handler.cc ('K') | « net/url_request/url_request_http_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698