Commit 81293f48 authored by shalev@chromium.org's avatar shalev@chromium.org

Removed checks that verify URLRequest has a Context

Due to a recent cl, URLRequest must get a non-NULL context in the constructor.
This means that if-statements and DCHECKs that verify the existence of context
are no longer needed.

BUG=None


Review URL: https://chromiumcodereview.appspot.com/10830124

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151326 0039d316-1c4b-4281-b951-d872f2087c98
parent cde8b3c3
...@@ -416,21 +416,19 @@ void URLRequestAutomationJob::StartAsync() { ...@@ -416,21 +416,19 @@ void URLRequestAutomationJob::StartAsync() {
for (size_t i = 0; i < arraysize(kFilteredHeaderStrings); ++i) for (size_t i = 0; i < arraysize(kFilteredHeaderStrings); ++i)
new_request_headers.RemoveHeader(kFilteredHeaderStrings[i]); new_request_headers.RemoveHeader(kFilteredHeaderStrings[i]);
if (request_->context()) { // Only add default Accept-Language and Accept-Charset if the request
// Only add default Accept-Language and Accept-Charset if the request // didn't have them specified.
// didn't have them specified. if (!new_request_headers.HasHeader(
if (!new_request_headers.HasHeader( net::HttpRequestHeaders::kAcceptLanguage) &&
net::HttpRequestHeaders::kAcceptLanguage) && !request_->context()->accept_language().empty()) {
!request_->context()->accept_language().empty()) { new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage,
new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage, request_->context()->accept_language());
request_->context()->accept_language()); }
} if (!new_request_headers.HasHeader(
if (!new_request_headers.HasHeader( net::HttpRequestHeaders::kAcceptCharset) &&
net::HttpRequestHeaders::kAcceptCharset) && !request_->context()->accept_charset().empty()) {
!request_->context()->accept_charset().empty()) { new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset,
new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, request_->context()->accept_charset());
request_->context()->accept_charset());
}
} }
// Ensure that we do not send username and password fields in the referrer. // Ensure that we do not send username and password fields in the referrer.
......
...@@ -611,7 +611,7 @@ void URLRequest::NotifyResponseStarted() { ...@@ -611,7 +611,7 @@ void URLRequest::NotifyResponseStarted() {
// In some cases (e.g. an event was canceled), we might have sent the // In some cases (e.g. an event was canceled), we might have sent the
// completion event and receive a NotifyResponseStarted() later. // completion event and receive a NotifyResponseStarted() later.
if (!has_notified_completion_ && status_.is_success()) { if (!has_notified_completion_ && status_.is_success()) {
if (context_ && context_->network_delegate()) if (context_->network_delegate())
context_->network_delegate()->NotifyResponseStarted(this); context_->network_delegate()->NotifyResponseStarted(this);
} }
...@@ -695,7 +695,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { ...@@ -695,7 +695,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) {
NetLog::StringCallback("location", &location.possibly_invalid_spec())); NetLog::StringCallback("location", &location.possibly_invalid_spec()));
} }
if (context_ && context_->network_delegate()) if (context_->network_delegate())
context_->network_delegate()->NotifyBeforeRedirect(this, location); context_->network_delegate()->NotifyBeforeRedirect(this, location);
if (redirect_limit_ <= 0) { if (redirect_limit_ <= 0) {
...@@ -789,7 +789,7 @@ void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { ...@@ -789,7 +789,7 @@ void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) {
NetworkDelegate::AuthRequiredResponse rv = NetworkDelegate::AuthRequiredResponse rv =
NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
auth_info_ = auth_info; auth_info_ = auth_info;
if (context_ && context_->network_delegate()) { if (context_->network_delegate()) {
rv = context_->network_delegate()->NotifyAuthRequired( rv = context_->network_delegate()->NotifyAuthRequired(
this, this,
*auth_info, *auth_info,
...@@ -856,7 +856,7 @@ void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info, ...@@ -856,7 +856,7 @@ void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info,
bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { bool URLRequest::CanGetCookies(const CookieList& cookie_list) const {
DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES));
if (context_ && context_->network_delegate()) { if (context_->network_delegate()) {
return context_->network_delegate()->CanGetCookies(*this, return context_->network_delegate()->CanGetCookies(*this,
cookie_list); cookie_list);
} }
...@@ -866,7 +866,7 @@ bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { ...@@ -866,7 +866,7 @@ bool URLRequest::CanGetCookies(const CookieList& cookie_list) const {
bool URLRequest::CanSetCookie(const std::string& cookie_line, bool URLRequest::CanSetCookie(const std::string& cookie_line,
CookieOptions* options) const { CookieOptions* options) const {
DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES));
if (context_ && context_->network_delegate()) { if (context_->network_delegate()) {
return context_->network_delegate()->CanSetCookie(*this, return context_->network_delegate()->CanSetCookie(*this,
cookie_line, cookie_line,
options); options);
...@@ -899,7 +899,7 @@ void URLRequest::NotifyRequestCompleted() { ...@@ -899,7 +899,7 @@ void URLRequest::NotifyRequestCompleted() {
is_pending_ = false; is_pending_ = false;
has_notified_completion_ = true; has_notified_completion_ = true;
if (context_ && context_->network_delegate()) if (context_->network_delegate())
context_->network_delegate()->NotifyCompleted(this, job_ != NULL); context_->network_delegate()->NotifyCompleted(this, job_ != NULL);
} }
......
...@@ -253,10 +253,7 @@ void URLRequestFileJob::SetExtraRequestHeaders( ...@@ -253,10 +253,7 @@ void URLRequestFileJob::SetExtraRequestHeaders(
// static // static
bool URLRequestFileJob::IsFileAccessAllowed(const URLRequest& request, bool URLRequestFileJob::IsFileAccessAllowed(const URLRequest& request,
const FilePath& path) { const FilePath& path) {
const URLRequestContext* context = request.context(); const NetworkDelegate* delegate = request.context()->network_delegate();
if (!context)
return false;
const NetworkDelegate* delegate = context->network_delegate();
if (delegate) if (delegate)
return delegate->CanAccessFile(request, path); return delegate->CanAccessFile(request, path);
return false; return false;
......
...@@ -172,8 +172,7 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, ...@@ -172,8 +172,7 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
const std::string& scheme) { const std::string& scheme) {
DCHECK(scheme == "http" || scheme == "https"); DCHECK(scheme == "http" || scheme == "https");
if (!request->context() || if (!request->context()->http_transaction_factory()) {
!request->context()->http_transaction_factory()) {
NOTREACHED() << "requires a valid context"; NOTREACHED() << "requires a valid context";
return new URLRequestErrorJob(request, ERR_INVALID_ARGUMENT); return new URLRequestErrorJob(request, ERR_INVALID_ARGUMENT);
} }
...@@ -294,7 +293,7 @@ void URLRequestHttpJob::DestroyTransaction() { ...@@ -294,7 +293,7 @@ void URLRequestHttpJob::DestroyTransaction() {
} }
void URLRequestHttpJob::StartTransaction() { void URLRequestHttpJob::StartTransaction() {
if (request_->context() && request_->context()->network_delegate()) { if (request_->context()->network_delegate()) {
int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders( int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders(
request_, notify_before_headers_sent_callback_, request_, notify_before_headers_sent_callback_,
&request_info_.extra_headers); &request_info_.extra_headers);
...@@ -332,7 +331,7 @@ void URLRequestHttpJob::StartTransactionInternal() { ...@@ -332,7 +331,7 @@ void URLRequestHttpJob::StartTransactionInternal() {
int rv; int rv;
if (request_->context() && request_->context()->network_delegate()) { if (request_->context()->network_delegate()) {
request_->context()->network_delegate()->NotifySendHeaders( request_->context()->network_delegate()->NotifySendHeaders(
request_, request_info_.extra_headers); request_, request_info_.extra_headers);
} }
...@@ -341,7 +340,6 @@ void URLRequestHttpJob::StartTransactionInternal() { ...@@ -341,7 +340,6 @@ void URLRequestHttpJob::StartTransactionInternal() {
rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_);
auth_credentials_ = AuthCredentials(); auth_credentials_ = AuthCredentials();
} else { } else {
DCHECK(request_->context());
DCHECK(request_->context()->http_transaction_factory()); DCHECK(request_->context()->http_transaction_factory());
rv = request_->context()->http_transaction_factory()->CreateTransaction( rv = request_->context()->http_transaction_factory()->CreateTransaction(
...@@ -435,19 +433,17 @@ void URLRequestHttpJob::AddExtraHeaders() { ...@@ -435,19 +433,17 @@ void URLRequestHttpJob::AddExtraHeaders() {
} }
const URLRequestContext* context = request_->context(); const URLRequestContext* context = request_->context();
if (context) { // Only add default Accept-Language and Accept-Charset if the request
// Only add default Accept-Language and Accept-Charset if the request // didn't have them specified.
// didn't have them specified. if (!context->accept_language().empty()) {
if (!context->accept_language().empty()) { request_info_.extra_headers.SetHeaderIfMissing(
request_info_.extra_headers.SetHeaderIfMissing( HttpRequestHeaders::kAcceptLanguage,
HttpRequestHeaders::kAcceptLanguage, context->accept_language());
context->accept_language()); }
} if (!context->accept_charset().empty()) {
if (!context->accept_charset().empty()) { request_info_.extra_headers.SetHeaderIfMissing(
request_info_.extra_headers.SetHeaderIfMissing( HttpRequestHeaders::kAcceptCharset,
HttpRequestHeaders::kAcceptCharset, context->accept_charset());
context->accept_charset());
}
} }
} }
...@@ -460,8 +456,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() { ...@@ -460,8 +456,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
if (!request_) if (!request_)
return; return;
CookieStore* cookie_store = CookieStore* cookie_store = request_->context()->cookie_store();
request_->context()->cookie_store();
if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
if (cookie_monster) { if (cookie_monster) {
...@@ -650,7 +645,7 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { ...@@ -650,7 +645,7 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() {
// Only accept strict transport security headers on HTTPS connections that // Only accept strict transport security headers on HTTPS connections that
// have no certificate errors. // have no certificate errors.
if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) ||
!ctx || !ctx->transport_security_state()) { !ctx->transport_security_state()) {
return; return;
} }
...@@ -687,7 +682,7 @@ void URLRequestHttpJob::ProcessPublicKeyPinsHeader() { ...@@ -687,7 +682,7 @@ void URLRequestHttpJob::ProcessPublicKeyPinsHeader() {
// Only accept public key pins headers on HTTPS connections that have no // Only accept public key pins headers on HTTPS connections that have no
// certificate errors. // certificate errors.
if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) ||
!ctx || !ctx->transport_security_state()) { !ctx->transport_security_state()) {
return; return;
} }
...@@ -750,7 +745,7 @@ void URLRequestHttpJob::OnStartCompleted(int result) { ...@@ -750,7 +745,7 @@ void URLRequestHttpJob::OnStartCompleted(int result) {
if (result == OK) { if (result == OK) {
scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders();
if (context && context->network_delegate()) { if (context->network_delegate()) {
// Note that |this| may not be deleted until // Note that |this| may not be deleted until
// |on_headers_received_callback_| or // |on_headers_received_callback_| or
// |NetworkDelegate::URLRequestDestroyed()| has been called. // |NetworkDelegate::URLRequestDestroyed()| has been called.
...@@ -876,11 +871,9 @@ void URLRequestHttpJob::Start() { ...@@ -876,11 +871,9 @@ void URLRequestHttpJob::Start() {
referrer.spec()); referrer.spec());
} }
if (request_->context()) { request_info_.extra_headers.SetHeaderIfMissing(
request_info_.extra_headers.SetHeaderIfMissing( HttpRequestHeaders::kUserAgent,
HttpRequestHeaders::kUserAgent, request_->context()->GetUserAgent(request_->url()));
request_->context()->GetUserAgent(request_->url()));
}
AddExtraHeaders(); AddExtraHeaders();
AddCookieHeaderAndStart(); AddCookieHeaderAndStart();
......
...@@ -57,8 +57,7 @@ URLRequestJob* URLRequestJobManager::CreateJob( ...@@ -57,8 +57,7 @@ URLRequestJob* URLRequestJobManager::CreateJob(
// We do this here to avoid asking interceptors about unsupported schemes. // We do this here to avoid asking interceptors about unsupported schemes.
const URLRequestJobFactory* job_factory = NULL; const URLRequestJobFactory* job_factory = NULL;
if (request->context()) job_factory = request->context()->job_factory();
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase const std::string& scheme = request->url().scheme(); // already lowercase
if (job_factory) { if (job_factory) {
...@@ -138,8 +137,7 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( ...@@ -138,8 +137,7 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect(
} }
const URLRequestJobFactory* job_factory = NULL; const URLRequestJobFactory* job_factory = NULL;
if (request->context()) job_factory = request->context()->job_factory();
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase const std::string& scheme = request->url().scheme(); // already lowercase
if (job_factory) { if (job_factory) {
...@@ -175,8 +173,7 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( ...@@ -175,8 +173,7 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptResponse(
} }
const URLRequestJobFactory* job_factory = NULL; const URLRequestJobFactory* job_factory = NULL;
if (request->context()) job_factory = request->context()->job_factory();
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase const std::string& scheme = request->url().scheme(); // already lowercase
if (job_factory) { if (job_factory) {
......
...@@ -153,7 +153,7 @@ bool URLRequestThrottlerEntry::ShouldRejectRequest( ...@@ -153,7 +153,7 @@ bool URLRequestThrottlerEntry::ShouldRejectRequest(
const URLRequest& request) const { const URLRequest& request) const {
bool reject_request = false; bool reject_request = false;
if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) && if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) &&
(!request.context() || !request.context()->network_delegate() || (!request.context()->network_delegate() ||
request.context()->network_delegate()->CanThrottleRequest(request)) && request.context()->network_delegate()->CanThrottleRequest(request)) &&
GetBackoffEntry()->ShouldRejectRequest()) { GetBackoffEntry()->ShouldRejectRequest()) {
int num_failures = GetBackoffEntry()->failure_count(); int num_failures = GetBackoffEntry()->failure_count();
......
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